CUDA
C/C++    Fortran   

Array manipulation (transpose, join, tile, shift, ...)

Functions

array T () const
 Transpose matrix or vector.
array H () const
 Conjugate transpose (1+2i becomes 1-2i).
array lower (const array &input, int diagonal=0)
 Extract lower triangular matrix.
array upper (const array &input, int diagonal=0)
 Extract upper triangular matrix.
array diag (const array &input)
 Extract or form diagonal matrix.
array join (int dim, const array &A, const array &B)
 Join two arrays along dimension dim.
array join (int dim, const array &A, const array &B, const array &C)
array join (int dim, const array &A, const array &B, const array &C, const array &D)
array flip (const array &in, unsigned dim)
 Flip array along a given dimension (base-zero index).
array tile (const array &A, unsigned d0, unsigned d1=1, unsigned d2=1)
 tile (repeat) array along specified dimensions
array tile (const array &A, const dim4 &dims)
 tile (repeat) array along specified dimensions
array flat (const array &A)
 Flatten an array into column vector.
array shift (const array &in, int dim0=0, int dim1=0, int dim2=0, int dim3=0)
 Shift the values of an array around dimension (wrap around).
array shift (const array &in, const array &shift)
 Shift the values of an array around dimension (wrap around).
array reorder (const array &in, int dim0=-1, int dim1=-1, int dim2=-1, int dim3=-1)
 Reorder dimensions of array.

Function Documentation

array T ( ) const [inherited]

Transpose matrix or vector.

       array X = randn(2,3);
       print(X);
       print(X.T());
    X =
        0.5434    -1.4913     0.1374
       -0.7168     1.4805    -1.2208
    X.T() =
        0.5434    -0.7168
       -1.4913     1.4805
        0.1374    -1.2208
    
Examples:
examples/getting_started/integer.cpp, examples/image_processing/image_demo.cpp, examples/machine_learning/neuralnetwork.cpp, examples/machine_learning/pca.cpp, and examples/pde/fdtd.cpp.
array H ( ) const [inherited]

Conjugate transpose (1+2i becomes 1-2i).

Real arrays are simply transposed.

       array X = randn(2,3,c32);
       print(X);
       print(X.H());
    X =
        0.2925 -    0.7184i    2.5470 -    0.0034i    0.1290 +    0.3728i
        0.1000 -    0.3932i    0.0083 -    0.2510i    1.0822 -    0.6650i

    X.H() =
        0.2925 +    0.7184i    0.1000 +    0.3932i
        2.5470 +    0.0034i    0.0083 +    0.2510i
        0.1290 -    0.3728i    1.0822 +    0.6650i
    
array af::lower ( const array &  input,
int  diagonal = 0 
)

Extract lower triangular matrix.

Parameters:
[in]inputmatrix
[in]diagonalto include in extraction: diagonal==0 is the center diagonal (default), diagonal>0 is above, and diagonal<0 is below.
Returns:
lower triangular part of the matrix
array af::upper ( const array &  input,
int  diagonal = 0 
)

Extract upper triangular matrix.

Parameters:
[in]inputmatrix
[in]diagonalto include in extraction: diagonal==0 is the center diagonal (default), diagonal>0 is above, and diagonal<0 is below.
Returns:
lower triangular part of the matrix
array af::diag ( const array &  input)

Extract or form diagonal matrix.

Parameters:
[in]inputif vector then produce diagonal matrix, if matrix then extract diagonal vector
Returns:
diagonal matrix formed from vector, or vector extracted from diagonal of a matrix
Examples:
examples/machine_learning/pca.cpp.
array af::join ( int  dim,
const array &  A,
const array &  B 
)

Join two arrays along dimension dim.

Parameters:
[in]dimalong which to join
[in]A
[in]B
Returns:
composite array
   array a = constant(1,2,3), b = constant(0,2,3);
   print(join(0,a,b));
   print(join(1,a,b));
   print(join(0, a, a, b, b)); // You can cascade up to four matrices
join(0,a,b) =
        1.0000     1.0000     1.0000
        1.0000     1.0000     1.0000
        0.0000     0.0000     0.0000
        0.0000     0.0000     0.0000

join(1,a,b) =
        1.0000     1.0000     1.0000     0.0000     0.0000     0.0000
        1.0000     1.0000     1.0000     0.0000     0.0000     0.0000
Examples:
examples/machine_learning/geneticalgorithm.cpp, and examples/machine_learning/neuralnetwork.cpp.
array af::join ( int  dim,
const array &  A,
const array &  B,
const array &  C 
)
array af::join ( int  dim,
const array &  A,
const array &  B,
const array &  C,
const array &  D 
)
array af::flip ( const array &  in,
unsigned  dim 
)

Flip array along a given dimension (base-zero index).

   float f[] = {1,2,3,4};
   array a(2,2,f);
   //a=[1 3]
   //  [2 4]

   array b = flip(a,0);
   //b=[2 4]
   //  [1 3]

   array b = flip(a,1);
   //b=[3 1]
   //  [4 2]
Parameters:
[in]in(vector or matrix)
[in]dimdimension along which to flip
Returns:
array with the elements along the specified dimension reversed
Examples:
examples/getting_started/integer.cpp, and examples/machine_learning/geneticalgorithm.cpp.
array af::tile ( const array &  A,
unsigned  d0,
unsigned  d1 = 1,
unsigned  d2 = 1 
)

tile (repeat) array along specified dimensions

   array a(seq(5)); //a=[1 2 3 4 5]

   a = tile(a, 2);  //a=[1 2 3 4 5]
                    //  [1 2 3 4 5]
Parameters:
[in]A
[in]d0repetitions along first dimension (1 indicates no repeat)
[in]d1repetitions along second dimension (default: 1, no repeat)
[in]d2repetitions along third dimension (default: 1, no repeat)
Returns:
A repeated according to specified repetitions
Examples:
examples/financial/blackscholes.cpp, examples/machine_learning/geneticalgorithm.cpp, examples/machine_learning/neuralnetwork.cpp, examples/machine_learning/pca.cpp, examples/pde/fdtd.cpp, examples/pde/swe.cpp, and examples/visualization/blip.cpp.
array af::tile ( const array &  A,
const dim4 &  dims 
)

tile (repeat) array along specified dimensions

   array a(seq(5)); //a=[0]
                    //  [1]
                    //  [2]
                    //  [3]
                    //  [4]

   a = tile(a, dim4(1,2)); //a=[0 0]
                           //  [1 1]
                           //  [2 2]
                           //  [3 3]
                           //  [4 4]
Parameters:
[in]A
[in]dimsspecifications of number of times to repeat
Returns:
A repeated according to specified repetitions
array af::flat ( const array &  A)

Flatten an array into column vector.

No work is done (data is simply shared) so this is effectively a noop.

   array a; //a=[1 3]
            //  [2 4]
   a = flat(a); //a=[1 2 3 4]
Parameters:
[in]A
Returns:
column vector with same elements as original
Examples:
examples/machine_learning/geneticalgorithm.cpp, examples/machine_learning/kmeans.cpp, and examples/machine_learning/neuralnetwork.cpp.
array af::shift ( const array &  in,
int  dim0 = 0,
int  dim1 = 0,
int  dim2 = 0,
int  dim3 = 0 
)

Shift the values of an array around dimension (wrap around).

   array a(seq(5)); //a=[0 1 2 3 4]
   a = shift(a,2);  //a=[3 4 0 1 2]
Parameters:
[in]in
[in]dim0Shift along first dimension
[in]dim1Shift along second dimension
[in]dim2Shift along third dimension
[in]dim3Shift along fourth dimension
Returns:
shifted version of array
array af::shift ( const array &  in,
const array &  shift 
)

Shift the values of an array around dimension (wrap around).

   array a(seq(5)); //a=[0 1 2 3 4]
   array b = constant(1,1,af::s32);
   a = shift(a,b);  //a=[4 0 1 2 3]
Parameters:
[in]in
[in]shiftinteger array (s32 preferred) indicating shifts for each dimension
Returns:
shifted version of array
array af::reorder ( const array &  in,
int  dim0 = -1,
int  dim1 = -1,
int  dim2 = -1,
int  dim3 = -1 
)

Reorder dimensions of array.

   array a(seq(3));
   a = tile(a,1,3); //a = [0 0 0]
                    //    [1 1 1]
                    //    [2 2 2]
   a = reorder(a, 1, 0); //Switch first and second dimension
                    //a = [0 1 2]
                    //    [0 1 2]
                    //    [0 1 2]
Parameters:
[in]in
[in]dim0first reordering dimension (-1 indicates leave in place, default)
[in]dim1second reordering dimension (-1 indicates leave in place, default)
[in]dim2third reordering dimension (-1 indicates leave in place, default)
[in]dim3fourth reordering dimension (-1 indicates leave in place, default)