Generate and fill Arrays

Generate constant or random values on the device of specified type. More...

Generate column vector

array constant (float, unsigned nx, dtype ty=f32)
 
array identity (unsigned nx, dtype ty=f32)
 
array randu (unsigned nx, dtype ty=f32)
 
array randn (unsigned nx, dtype ty=f32)
 
array rand (unsigned nx, dtype ty=u32)
 

Generate matrix

array constant (float, unsigned nx, unsigned ny, dtype ty=f32)
 
array identity (unsigned nx, unsigned ny, dtype ty=f32)
 
array randu (unsigned nx, unsigned ny, dtype ty=f32)
 
array randn (unsigned nx, unsigned ny, dtype ty=f32)
 
array rand (unsigned nx, unsigned ny, dtype ty=u32)
 

Generate volume

array constant (float, unsigned nx, unsigned ny, unsigned nz, dtype ty=f32)
 
array identity (unsigned nx, unsigned ny, unsigned nz, dtype ty=f32)
 
array randu (unsigned nx, unsigned ny, unsigned nz, dtype ty=f32)
 
array randn (unsigned nx, unsigned ny, unsigned nz, dtype ty=f32)
 
array rand (unsigned nx, unsigned ny, unsigned nz, dtype ty=u32)
 

Generate 4D array

array constant (float, unsigned d0, unsigned d1, unsigned d2, unsigned d3, dtype ty=f32)
 
array identity (unsigned d0, unsigned d1, unsigned d2, unsigned d3, dtype ty=f32)
 
array randu (unsigned d0, unsigned d1, unsigned d2, unsigned d3, dtype ty=f32)
 
array randn (unsigned d0, unsigned d1, unsigned d2, unsigned d3, dtype ty=f32)
 
array rand (unsigned d0, unsigned d1, unsigned d2, unsigned d3, dtype ty=u32)
 

Generate array

array constant (float, const dim4 &dims, dtype ty=f32)
 
array identity (const dim4 &dims, dtype ty=f32)
 
array randu (const dim4 &dims, dtype ty=f32)
 
array randn (const dim4 &dims, dtype ty=f32)
 
array rand (const dim4 &dims, dtype ty=u32)
 

Detailed Description

Generate constant or random values on the device of specified type.

There are five different initializations:

table_0001.png
// generate column vectors
array A = constant(3, 5); // A = 3.0000
// 3.0000
// 3.0000
// 3.0000
// 3.0000
// generate a identity matrix of size 3
array B = identity(3, 3); // B = 1.0000 0.0000 0.0000
// 0.0000 1.0000 0.0000
// 0.0000 0.0000 1.0000
// generate column vector of specified size and fill it with
// uniformly distributed random numbers between [0-1]
array C = randu(4); // C = 0.5035
// 0.1096
// 0.8892
// 0.6739
// generate constant matrix (2D array)
array D = constant(11.8, 3, 3); // D = 11.8 11.8 11.8
// 11.8 11.8 11.8
// 11.8 11.8 11.8
// generate column vector with random values in a normal
// distribution with an average value of ZERO
// and a standard deviation of UNITY
array E = randn(100000,1);

Shown below is a histogram generated using the 100,000 elements of E, clearly showing the normal distribution of the elements in E.

randn_histogram.png
// generate random matrix (2D array) with normalized numbers
// with an average of ZERO and a standard deviation of UNITY
//
// F =
// 0.2925 2.5470 0.1290
// -0.7184 -0.0034 0.3728
// 0.1000 0.0083 1.0822
// -0.3932 -0.2510 -0.6650
array F = randn(4,3);
// generate a random column vector of type u32
// where each bit is randomly 0 or 1
array G = rand(4);
// G =
// 3179217846
// 3955638199
// 167591721
// 4161663997
rand.png

Function Documentation

array af::identity ( unsigned  nx,
dtype  ty = f32 
)
array af::randn ( unsigned  nx,
dtype  ty = f32 
)
array af::rand ( unsigned  nx,
dtype  ty = u32 
)
array af::constant ( float  ,
unsigned  nx,
unsigned  ny,
dtype  ty = f32 
)
array af::identity ( unsigned  nx,
unsigned  ny,
dtype  ty = f32 
)
array af::randu ( unsigned  nx,
unsigned  ny,
dtype  ty = f32 
)
array af::randn ( unsigned  nx,
unsigned  ny,
dtype  ty = f32 
)
array af::rand ( unsigned  nx,
unsigned  ny,
dtype  ty = u32 
)
array af::constant ( float  ,
unsigned  nx,
unsigned  ny,
unsigned  nz,
dtype  ty = f32 
)
array af::identity ( unsigned  nx,
unsigned  ny,
unsigned  nz,
dtype  ty = f32 
)
array af::randu ( unsigned  nx,
unsigned  ny,
unsigned  nz,
dtype  ty = f32 
)
array af::randn ( unsigned  nx,
unsigned  ny,
unsigned  nz,
dtype  ty = f32 
)
array af::rand ( unsigned  nx,
unsigned  ny,
unsigned  nz,
dtype  ty = u32 
)
array af::constant ( float  ,
unsigned  d0,
unsigned  d1,
unsigned  d2,
unsigned  d3,
dtype  ty = f32 
)
array af::identity ( unsigned  d0,
unsigned  d1,
unsigned  d2,
unsigned  d3,
dtype  ty = f32 
)
array af::randu ( unsigned  d0,
unsigned  d1,
unsigned  d2,
unsigned  d3,
dtype  ty = f32 
)
array af::randn ( unsigned  d0,
unsigned  d1,
unsigned  d2,
unsigned  d3,
dtype  ty = f32 
)
array af::rand ( unsigned  d0,
unsigned  d1,
unsigned  d2,
unsigned  d3,
dtype  ty = u32 
)
array af::constant ( float  ,
const dim4 &  dims,
dtype  ty = f32 
)
array af::identity ( const dim4 &  dims,
dtype  ty = f32 
)
array af::randu ( const dim4 &  dims,
dtype  ty = f32 
)
array af::randn ( const dim4 &  dims,
dtype  ty = f32 
)
array af::rand ( const dim4 &  dims,
dtype  ty = u32 
)