Construct an array object. More...

Functions

AFAPI af_err af_device_array (af_array *arr, const void *data, const unsigned ndims, const dim_t *const dims, const af_dtype type)
 Create array from device memory. More...
 
AFAPI af_err af_create_array (af_array *arr, const void *const data, const unsigned ndims, const dim_t *const dims, const af_dtype type)
 Create an af_array handle initialized with user defined data. More...
 
AFAPI af_err af_create_handle (af_array *arr, const unsigned ndims, const dim_t *const dims, const af_dtype type)
 Create af_array handle. More...
 
 array ()
 Create undimensioned array (no data, undefined size) More...
 
 array (const af_array handle)
 Creates an array from an af_array handle. More...
 
 array (const array &in)
 Creates a copy to the in array. More...
 
 array (dim_t dim0, dtype ty=f32)
 Allocate a one-dimensional array of a specified size with undefined contents. More...
 
 array (dim_t dim0, dim_t dim1, dtype ty=f32)
 Allocate a two-dimensional array of a specified size with undefined contents. More...
 
 array (dim_t dim0, dim_t dim1, dim_t dim2, dtype ty=f32)
 Allocate a three-dimensional (3D) array of a specified size with undefined contents. More...
 
 array (dim_t dim0, dim_t dim1, dim_t dim2, dim_t dim3, dtype ty=f32)
 Allocate a four-dimensional (4D) array of a specified size with undefined contents. More...
 
 array (const dim4 &dims, dtype ty=f32)
 Allocate an array of a specified size with undefined contents. More...
 
template<typename T >
 array (dim_t dim0, const T *pointer, af::source src=afHost)
 Create a column vector on the device using a host/device pointer. More...
 
template<typename T >
 array (dim_t dim0, dim_t dim1, const T *pointer, af::source src=afHost)
 Create a 2D array on the device using a host/device pointer. More...
 
template<typename T >
 array (dim_t dim0, dim_t dim1, dim_t dim2, const T *pointer, af::source src=afHost)
 Create a 3D array on the device using a host/device pointer. More...
 
template<typename T >
 array (dim_t dim0, dim_t dim1, dim_t dim2, dim_t dim3, const T *pointer, af::source src=afHost)
 Create a 4D array on the device using a host/device pointer. More...
 
template<typename T >
 array (const dim4 &dims, const T *pointer, af::source src=afHost)
 Create an array of specified size on the device using a host/device pointer. More...
 
 array (const array &input, const dim4 &dims)
 Adjust the dimensions of an N-D array (fast). More...
 
 array (const array &input, const dim_t dim0, const dim_t dim1=1, const dim_t dim2=1, const dim_t dim3=1)
 Adjust the dimensions of an N-D array (fast). More...
 

Detailed Description

Construct an array object.

Function Documentation

AFAPI af_err af_create_array ( af_array arr,
const void *const  data,
const unsigned  ndims,
const dim_t *const  dims,
const af_dtype  type 
)

Create an af_array handle initialized with user defined data.

This function will create an af_array handle from the memory provided in data

Parameters
[out]arrThe pointer to the returned object.
[in]dataThe data which will be loaded into the array
[in]ndimsThe number of dimensions read from the dims parameter
[in]dimsA C pointer with ndims elements. Each value represents the size of that dimension
[in]typeThe type of the af_array object
Returns
AF_SUCCESS if the operation was a success
AFAPI af_err af_create_handle ( af_array arr,
const unsigned  ndims,
const dim_t *const  dims,
const af_dtype  type 
)

Create af_array handle.

Parameters
[out]arrThe pointer to the retured object.
[in]ndimsThe number of dimensions read from the dims parameter
[in]dimsA C pointer with ndims elements. Each value represents the size of that dimension
[in]typeThe type of the af_array object
Returns
AF_SUCCESS if the operation was a success
AFAPI af_err af_device_array ( af_array arr,
const void *  data,
const unsigned  ndims,
const dim_t *const  dims,
const af_dtype  type 
)

Create array from device memory.

array ( )

Create undimensioned array (no data, undefined size)

array A, B, C; // creates three arrays called A, B and C
array ( const af_array  handle)
explicit

Creates an array from an af_array handle.

Parameters
handlethe af_array object.
array ( const array in)

Creates a copy to the in array.

Parameters
inThe input array
array ( dim_t  dim0,
dtype  ty = f32 
)

Allocate a one-dimensional array of a specified size with undefined contents.

Declare a two-dimensional array by passing the number of rows and the number of columns as the first two parameters. The (optional) second parameter is the type of the array. The default type is f32 or 4-byte single-precision floating-point numbers.

// allocate space for an array with 10 rows
array A(10); // type is the default f32
// allocate space for a column vector with 100 rows
array A(100, f64); // f64 = double precision
Parameters
[in]dim0number of columns in the array
[in]tyoptional label describing the data type (default is f32)
array ( dim_t  dim0,
dim_t  dim1,
dtype  ty = f32 
)

Allocate a two-dimensional array of a specified size with undefined contents.

Declare a two-dimensional array by passing the number of rows and the number of columns as the first two parameters. The (optional) third parameter is the type of the array. The default type is f32 or 4-byte single-precision floating-point numbers.

// allocate space for an array with 10 rows and 8 columns
array A(10, 8); // type is the default f32
// allocate space for a column vector with 100 rows (and 1 column)
array A(100, 1, f64); // f64 = double precision
Parameters
[in]dim0number of columns in the array
[in]dim1number of rows in the array
[in]tyoptional label describing the data type (default is f32)
array ( dim_t  dim0,
dim_t  dim1,
dim_t  dim2,
dtype  ty = f32 
)

Allocate a three-dimensional (3D) array of a specified size with undefined contents.

This is useful to quickly declare a three-dimensional array by passing the size as the first three parameters. The (optional) fourth parameter is the type of the array. The default type is f32 or 4-byte single-precision floating point numbers.

// allocate space for a 10 x 10 x 10 array
array A(10, 10, 10); // type is the default f32
// allocate space for a 3D, double precision array
array A(10, 10, 10, f64); // f64 = double precision
Parameters
[in]dim0first dimension of the array
[in]dim1second dimension of the array
[in]dim2third dimension of the array
[in]tyoptional label describing the data type (default is f32)
array ( dim_t  dim0,
dim_t  dim1,
dim_t  dim2,
dim_t  dim3,
dtype  ty = f32 
)

Allocate a four-dimensional (4D) array of a specified size with undefined contents.

This is useful to quickly declare a four-dimensional array by passing the size as the first four parameters. The (optional) fifth parameter is the type of the array. The default type is f32 or 4-byte floating point numbers.

// allocate space for a 10 x 10 x 10 x 20 array
array A(10, 10, 10, 20); // type is the default f32
// allocate space for a 4D, double precision array
array A(10, 10, 10, 20, f64); // f64 = double precision
Parameters
[in]dim0first dimension of the array
[in]dim1second dimension of the array
[in]dim2third dimension of the array
[in]dim3fourth dimension of the array
[in]tyoptional label describing the data type (default is f32)
array ( const dim4 dims,
dtype  ty = f32 
)
explicit

Allocate an array of a specified size with undefined contents.

This can be useful when the dimensions of the array are calculated somewhere else within the code. The first parameter specifies the size of the array via dim4(). The second parameter is the type of the array. The default type is f32 or 4-byte single-precision floating point numbers.

// create a two-dimensional 10 x 10 array
dim4 dims(10, 10); // converted to (10, 10, 1, 1)
array a1(dims); // create the array (type is f32, the default)
// create a three-dimensional 10 x 10 x 20 array
dim4 dims(10, 10, 20); // converted to (10, 10, 20, 1)
array a2(dims,f64); // f64 = double precision
Parameters
[in]dimssize of the array
[in]tyoptional label describing the data type (default is f32)
array ( dim_t  dim0,
const T pointer,
af::source  src = afHost 
)

Create a column vector on the device using a host/device pointer.

Parameters
[in]dim0number of elements in the column vector
[in]pointerpointer (points to a buffer on the host/device)
[in]srcsource of the data (default is afHost, can also be afDevice)
// allocate data on the host
int h_buffer[] = {23, 34, 18, 99, 34};
array A(4, h_buffer); // copy host data to device
//
// A = 23
// = 34
// = 18
// = 99
Note
If src is afHost, the first dim0 elements are copied. If src is afDevice, no copy is done; the array object wraps the device pointer AND takes ownership of the underlying memory.
array ( dim_t  dim0,
dim_t  dim1,
const T pointer,
af::source  src = afHost 
)

Create a 2D array on the device using a host/device pointer.

Parameters
[in]dim0number of rows
[in]dim1number of columns
[in]pointerpointer (points to a buffer on the host/device)
[in]srcsource of the data (default is afHost, can also be afDevice)
int h_buffer[] = {0, 1, 2, 3, 4, 5}; // host array
array A(2, 3, h_buffer); // copy host data to device
2dArray.png
Note
If src is afHost, the first dim0 * dim1 elements are copied. If src is afDevice, no copy is done; the array object wraps the device pointer AND takes ownership of the underlying memory. The data is treated as column major format when performing linear algebra operations.
array ( dim_t  dim0,
dim_t  dim1,
dim_t  dim2,
const T pointer,
af::source  src = afHost 
)

Create a 3D array on the device using a host/device pointer.

Parameters
[in]dim0first dimension
[in]dim1second dimension
[in]dim2third dimension
[in]pointerpointer (points to a buffer on the host/device)
[in]srcsource of the data (default is afHost, can also be afDevice)
int h_buffer[] = {0, 1, 2, 3, 4, 5, 6, 7, 8
9, 0, 1, 2, 3, 4, 5, 6, 7}; // host array
array A(3, 3, 2, h_buffer); // copy host data to 3D device array
Note
If src is afHost, the first dim0 * dim1 * dim2 elements are copied. If src is afDevice, no copy is done; the array object just wraps the device pointer and does not take ownership of the underlying memory. The data is treated as column major format when performing linear algebra operations.
3dArray.png
array ( dim_t  dim0,
dim_t  dim1,
dim_t  dim2,
dim_t  dim3,
const T pointer,
af::source  src = afHost 
)

Create a 4D array on the device using a host/device pointer.

Parameters
[in]dim0first dimension
[in]dim1second dimension
[in]dim2third dimension
[in]dim3fourth dimension
[in]pointerpointer (points to a buffer on the host/device)
[in]srcsource of the data (default is afHost, can also be afDevice)
int h_buffer[] = {0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 0, 1,
2, 3, 4, 5}; // host array with 16 elements
array A(2, 2, 2, 2, h_buffer); // copy host data to 4D device array
Note
If src is afHost, the first dim0 * dim1 * dim2 * dim3 elements are copied. If src is afDevice, no copy is done; the array object just wraps the device pointer and does not take ownership of the underlying memory. The data is treated as column major format when performing linear algebra operations.
array ( const dim4 dims,
const T pointer,
af::source  src = afHost 
)
explicit

Create an array of specified size on the device using a host/device pointer.

This function copies data from the location specified by the pointer to a 1D/2D/3D/4D array on the device. The data is arranged in "column-major" format (similar to that used by FORTRAN).

Parameters
[in]dimsvector data type containing the dimension of the array
[in]pointerpointer (points to a buffer on the host/device)
[in]srcsource of the data (default is afHost, can also be afDevice)
int h_buffer[] = {0, 1, 2, 3, // host array with 16 elements
4, 5, 6, 7, // written in "row-major" format
8, 9, 0, 1,
2, 3, 4, 5};
dim4 dims(4, 4);
array A(dims, h_buffer); // A = 0 4 8 2
// 1 5 9 3
// 2 6 0 4
// 3 7 1 5
// Note the "column-major" ordering
// used in ArrayFire
Note
If src is afHost, the first dims.elements() elements are copied. If src is afDevice, no copy is done; the array object just wraps the device pointer and does not take ownership of the underlying memory. The data is treated as column major format when performing linear algebra operations.
array ( const array input,
const dim4 dims 
)

Adjust the dimensions of an N-D array (fast).

This operation simply rearranges the description of the array. No memory transfers or transformations are performed. The total number of elements must not change.

float f[] = {1,2,3,4};
array a(2,2,f);
//a=[1 3]
// [2 4]
array b = array(a, dim4(4));
//b=[1]
// [2]
// [3]
// [4]
array c = array(a, b.T().dims() );
//c=[1 2 3 4]
Parameters
[in]input
[in]dimstotal number of elements must not change.
Returns
same underlying array data with different dimensions
array ( const array input,
const dim_t  dim0,
const dim_t  dim1 = 1,
const dim_t  dim2 = 1,
const dim_t  dim3 = 1 
)

Adjust the dimensions of an N-D array (fast).

This operation simply rearranges the description of the array. No memory transfers or transformations are performed. The total number of elements must not change.

float f[] = {1,2,3,4};
array a(2,2,f);
//a=[1 3]
// [2 4]
array b = array(a, 4);
//b=[1]
// [2]
// [3]
// [4]
array c = array(a, 1, 4);
//c=[1 2 3 4]
Parameters
[in]input
[in]dim0first dimension
[in]dim1second dimension
[in]dim2third dimension
[in]dim3fourth dimension
Returns
same underlying array data with different dimensions