A high-performance general-purpose compute library

- Main Page
- Tutorials
- Release Notes
- Examples

Data Structures | Public Member Functions
array Class Reference
ArrayFire Classes

A multi dimensional data container. More...

`#include <array.h>`

## Data Structures
class | array_proxy
| Intermediate data class. More...

## Public Member Functions
void | set (af_array tmp)
| Updates the internal af_array object.
| array ()
| Create an uninitialized array (no data, undefined size)
| array (const af_array handle)
| Creates an array from an af_array handle.
| array (const array &in)
| Creates a copy to the `in` array.
| array (dim_t dim0, dtype ty=f32)
| Allocate a one-dimensional array of a specified size with undefined contents.
| array (dim_t dim0, dim_t dim1, dtype ty=f32)
| Allocate a two-dimensional array of a specified size with undefined contents.
| 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.
| 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.
| array (const dim4 &dims, dtype ty=f32)
| Allocate an array of a specified size with undefined contents.
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.
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.
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.
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.
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.
| array (const array &input, const dim4 &dims)
| Adjust the dimensions of an N-D array (fast).
| 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).
af_array | get ()
| get the af_array handle
af_array | get () const
| get the af_array handle
dim_t | elements () const
| Get the total number of elements across all dimensions of the array.
template<typename T >
T * | host () const
| Copy array data to host and return host pointer.
void | host (void *ptr) const
| Copy array data to existing host pointer.
template<typename T >
void | write (const T *ptr, const size_t bytes, af::source src=afHost)
| Perform deep copy from host/device pointer to an existing array.
dtype | type () const
| Get array data type.
dim4 | dims () const
| Get dimensions of the array.
dim_t | dims (unsigned dim) const
| Get dimensions of the array.
unsigned | numdims () const
| Get the number of dimensions of the array.
size_t | bytes () const
| Get the size of the array in bytes.
size_t | allocated () const
| Get the size of the array in memory.
array | copy () const
| Perform deep copy of the array.
bool | isempty () const
| Returns true of the array is empty.
bool | isscalar () const
| Returns true of the array contains only one value.
bool | isvector () const
| Returns true if only one of the array dimensions has more than one element.
bool | isrow () const
| Returns true if only the second dimension has more than one element.
bool | iscolumn () const
| Returns true if only the first dimension has more than one element.
bool | iscomplex () const
| Returns true if the array type is c32 or c64.
bool | isreal () const
| Returns true if the array type is neither c32 nor c64.
bool | isdouble () const
| Returns true if the array type is f64 or c64.
bool | issingle () const
| Returns true if the array type is either f32 nor c32.
bool | ishalf () const
| Returns true if the array type is f16.
bool | isrealfloating () const
| Returns true if the array type is f16 f32 or f64.
bool | isfloating () const
| Returns true if the array type is f16 f32, f64, c32 or c64.
bool | isinteger () const
| Returns true if the array type is u8, b8, s32 u32, s64, u64, s16, u16.
bool | isbool () const
| Returns true if the array type is b8.
bool | issparse () const
| Returns true if the array is a sparse array.
void | eval () const
| Evaluate any JIT expressions to generate data for the array.
template<typename T >
T | scalar () const
| Get the first element of the array as a scalar.
template<typename T >
T * | device () const
| Get the device pointer from the array and lock the buffer in memory manager.
array::array_proxy | operator() (const index &s0)
| This operator returns a reference of the original array at a given coordinate.
const array::array_proxy | operator() (const index &s0) const
| This operator returns a reference of the original array at a given coordinate.
array::array_proxy | operator() (const index &s0, const index &s1, const index &s2=span, const index &s3=span)
| This operator returns a reference of the original array at a given coordinate.
const array::array_proxy | operator() (const index &s0, const index &s1, const index &s2=span, const index &s3=span) const
| This operator returns a reference of the original array at a given coordinate.
const array | as (dtype type) const
| Casts the array into another data type.
| ~array ()
array | T () const
| Get the transposed the array.
array | H () const
| Get the conjugate-transpose of the current array.
array | operator- () const
| Negates the values of the array.
array | operator! () const
| Performs a not operation on the values of the array.
array | operator~ () const
| Performs a bitwise not operation on the values of the array.
int | nonzeros () const
| Get the count of non-zero elements in the array.
void | lock () const
| Locks the device buffer in the memory manager.
bool | isLocked () const
| Query if the array has been locked by the user.
void | unlock () const
| Unlocks the device buffer in the memory manager.
array::array_proxy | row (int index)
| Returns a reference to a row.
const array::array_proxy | row (int index) const
| Returns a reference to a row.
array::array_proxy | rows (int first, int last)
| Returns a reference to sequence of rows.
const array::array_proxy | rows (int first, int last) const
| Returns a reference to sequence of rows.
array::array_proxy | col (int index)
| Returns a reference to a col.
const array::array_proxy | col (int index) const
| Returns a reference to a col.
array::array_proxy | cols (int first, int last)
| Returns a reference to sequence of columns.
const array::array_proxy | cols (int first, int last) const
| Returns a reference to sequence of columns.
array::array_proxy | slice (int index)
| Returns a reference to a matrix in a volume.
const array::array_proxy | slice (int index) const
| Returns a reference to a matrix in a volume.
array::array_proxy | slices (int first, int last)
| Returns a reference to a matrix in a volume.
const array::array_proxy | slices (int first, int last) const
| Returns a reference to a matrix in a volume.
array & | operator= (const array &val)
| Assignes the value(s) of val to the elements of the array.
array & | operator= (const double &val)
| Assignes the value(s) of val to the elements of the array.
array & | operator= (const cdouble &val)
| Assignes the value(s) of val to the elements of the array.
array & | operator= (const cfloat &val)
| Assignes the value(s) of val to the elements of the array.
array & | operator= (const float &val)
| Assignes the value(s) of val to the elements of the array.
array & | operator= (const int &val)
| Assignes the value(s) of val to the elements of the array.
array & | operator= (const unsigned &val)
| Assignes the value(s) of val to the elements of the array.
array & | operator= (const bool &val)
| Assignes the value(s) of val to the elements of the array.
array & | operator= (const char &val)
| Assignes the value(s) of val to the elements of the array.
array & | operator= (const unsigned char &val)
| Assignes the value(s) of val to the elements of the array.
array & | operator= (const long &val)
| Assignes the value(s) of val to the elements of the array.
array & | operator= (const unsigned long &val)
| Assignes the value(s) of val to the elements of the array.
array & | operator= (const long long &val)
| Assignes the value(s) of val to the elements of the array.
array & | operator= (const unsigned long long &val)
array & | operator= (const short &val)
| Assignes the value(s) of val to the elements of the array.
array & | operator= (const unsigned short &val)
array & | operator+= (const array &val)
| Adds the value(s) of val to the elements of the array.
array & | operator+= (const double &val)
| Adds the value(s) of val to the elements of the array.
array & | operator+= (const cdouble &val)
| Adds the value(s) of val to the elements of the array.
array & | operator+= (const cfloat &val)
| Adds the value(s) of val to the elements of the array.
array & | operator+= (const float &val)
| Adds the value(s) of val to the elements of the array.
array & | operator+= (const int &val)
| Adds the value(s) of val to the elements of the array.
array & | operator+= (const unsigned &val)
| Adds the value(s) of val to the elements of the array.
array & | operator+= (const bool &val)
| Adds the value(s) of val to the elements of the array.
array & | operator+= (const char &val)
| Adds the value(s) of val to the elements of the array.
array & | operator+= (const unsigned char &val)
| Adds the value(s) of val to the elements of the array.
array & | operator+= (const long &val)
| Adds the value(s) of val to the elements of the array.
array & | operator+= (const unsigned long &val)
| Adds the value(s) of val to the elements of the array.
array & | operator+= (const long long &val)
| Adds the value(s) of val to the elements of the array.
array & | operator+= (const unsigned long long &val)
array & | operator+= (const short &val)
| Adds the value(s) of val to the elements of the array.
array & | operator+= (const unsigned short &val)
array & | operator-= (const array &val)
| Subtracts the value(s) of val to the elements of the array.
array & | operator-= (const double &val)
| Subtracts the value(s) of val to the elements of the array.
array & | operator-= (const cdouble &val)
| Subtracts the value(s) of val to the elements of the array.
array & | operator-= (const cfloat &val)
| Subtracts the value(s) of val to the elements of the array.
array & | operator-= (const float &val)
| Subtracts the value(s) of val to the elements of the array.
array & | operator-= (const int &val)
| Subtracts the value(s) of val to the elements of the array.
array & | operator-= (const unsigned &val)
| Subtracts the value(s) of val to the elements of the array.
array & | operator-= (const bool &val)
| Subtracts the value(s) of val to the elements of the array.
array & | operator-= (const char &val)
| Subtracts the value(s) of val to the elements of the array.
array & | operator-= (const unsigned char &val)
| Subtracts the value(s) of val to the elements of the array.
array & | operator-= (const long &val)
| Subtracts the value(s) of val to the elements of the array.
array & | operator-= (const unsigned long &val)
| Subtracts the value(s) of val to the elements of the array.
array & | operator-= (const long long &val)
| Subtracts the value(s) of val to the elements of the array.
array & | operator-= (const unsigned long long &val)
array & | operator-= (const short &val)
| Subtracts the value(s) of val to the elements of the array.
array & | operator-= (const unsigned short &val)
array & | operator*= (const array &val)
| Multiplies the value(s) of val to the elements of the array.
array & | operator*= (const double &val)
| Multiplies the value(s) of val to the elements of the array.
array & | operator*= (const cdouble &val)
| Multiplies the value(s) of val to the elements of the array.
array & | operator*= (const cfloat &val)
| Multiplies the value(s) of val to the elements of the array.
array & | operator*= (const float &val)
| Multiplies the value(s) of val to the elements of the array.
array & | operator*= (const int &val)
| Multiplies the value(s) of val to the elements of the array.
array & | operator*= (const unsigned &val)
| Multiplies the value(s) of val to the elements of the array.
array & | operator*= (const bool &val)
| Multiplies the value(s) of val to the elements of the array.
array & | operator*= (const char &val)
| Multiplies the value(s) of val to the elements of the array.
array & | operator*= (const unsigned char &val)
| Multiplies the value(s) of val to the elements of the array.
array & | operator*= (const long &val)
| Multiplies the value(s) of val to the elements of the array.
array & | operator*= (const unsigned long &val)
| Multiplies the value(s) of val to the elements of the array.
array & | operator*= (const long long &val)
| Multiplies the value(s) of val to the elements of the array.
array & | operator*= (const unsigned long long &val)
array & | operator*= (const short &val)
| Multiplies the value(s) of val to the elements of the array.
array & | operator*= (const unsigned short &val)
array & | operator/= (const array &val)
| Divides the value(s) of val to the elements of the array.
array & | operator/= (const double &val)
| Divides the value(s) of val to the elements of the array.
array & | operator/= (const cdouble &val)
| Divides the value(s) of val to the elements of the array.
array & | operator/= (const cfloat &val)
| Divides the value(s) of val to the elements of the array.
array & | operator/= (const float &val)
| Divides the value(s) of val to the elements of the array.
array & | operator/= (const int &val)
| Divides the value(s) of val to the elements of the array.
array & | operator/= (const unsigned &val)
| Divides the value(s) of val to the elements of the array.
array & | operator/= (const bool &val)
| Divides the value(s) of val to the elements of the array.
array & | operator/= (const char &val)
| Divides the value(s) of val to the elements of the array.
array & | operator/= (const unsigned char &val)
| Divides the value(s) of val to the elements of the array.
array & | operator/= (const long &val)
| Divides the value(s) of val to the elements of the array.
array & | operator/= (const unsigned long &val)
| Divides the value(s) of val to the elements of the array.
array & | operator/= (const long long &val)
| Divides the value(s) of val to the elements of the array.
array & | operator/= (const unsigned long long &val)
array & | operator/= (const short &val)
| Divides the value(s) of val to the elements of the array.
array & | operator/= (const unsigned short &val)

## Detailed Description

A multi dimensional data container.

Examples
  benchmarks/blas.cpp, benchmarks/cg.cpp, benchmarks/fft.cpp, benchmarks/pi.cpp, computer_vision/fast.cpp, computer_vision/harris.cpp, computer_vision/matching.cpp, computer_vision/susan.cpp, financial/black_scholes_options.cpp, financial/heston_model.cpp, financial/monte_carlo_options.cpp, getting_started/convolve.cpp, getting_started/integer.cpp, getting_started/rainfall.cpp, getting_started/vectorize.cpp, graphics/conway.cpp, graphics/conway_pretty.cpp, graphics/field.cpp, graphics/fractal.cpp, graphics/gravity_sim.cpp, graphics/histogram.cpp, graphics/plot2d.cpp, graphics/plot3.cpp, graphics/surface.cpp, helloworld/helloworld.cpp, image_processing/adaptive_thresholding.cpp, image_processing/binary_thresholding.cpp, image_processing/brain_segmentation.cpp, image_processing/confidence_connected_components.cpp, image_processing/deconvolution.cpp, image_processing/edge.cpp, image_processing/filters.cpp, image_processing/gradient_diffusion.cpp, image_processing/image_demo.cpp, image_processing/image_editing.cpp, image_processing/morphing.cpp, image_processing/optical_flow.cpp, image_processing/pyramids.cpp, lin_algebra/cholesky.cpp, lin_algebra/lu.cpp, lin_algebra/qr.cpp, lin_algebra/svd.cpp, machine_learning/bagging.cpp, machine_learning/deep_belief_net.cpp, machine_learning/geneticalgorithm.cpp, machine_learning/kmeans.cpp, machine_learning/knn.cpp, machine_learning/logistic_regression.cpp, machine_learning/naive_bayes.cpp, machine_learning/neural_network.cpp, machine_learning/perceptron.cpp, machine_learning/rbm.cpp, machine_learning/softmax_regression.cpp, pde/swe.cpp, and unified/basic.cpp.

Definition at line 37 of file array.h.

## Constructor & Destructor Documentation

## ◆ array() [1/15]

array | ( |  | ) |

Create an uninitialized array (no data, undefined size)

array A, B, C; // creates three arrays called A, B and C
af::array
A multi dimensional data container.
Definition array.h:37

## ◆ array() [2/15]

array | ( | const af_array | handle | ) |
| explicit

Creates an array from an af_array handle.

Does not increment a reference counter: the array assumes ownership of the handle. To share the array between multiple objects, use this in conjunction with af_retain_array.

Parameters

  handle | the af_array object.

## ◆ array() [3/15]

array | ( | const array & | in | ) |

Creates a copy to the `in` array.

Parameters

  in | The input array

## ◆ array() [4/15]

array | ( | dim_t | dim0,
|  | dtype | ty = f32 )
| explicit

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
f64
@ f64
64-bit floating point values
Definition defines.h:213

Parameters

  [in] | dim0 | number of columns in the array
  [in] | ty | optional label describing the data type (default is f32)

## ◆ array() [5/15]

array | ( | dim_t | dim0,
|  | dim_t | dim1,
|  | dtype | ty = f32 )
| explicit

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] | dim0 | number of columns in the array
  [in] | dim1 | number of rows in the array
  [in] | ty | optional label describing the data type (default is f32)

## ◆ array() [6/15]

array | ( | dim_t | dim0,
|  | dim_t | dim1,
|  | dim_t | dim2,
|  | dtype | ty = f32 )
| explicit

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] | dim0 | first dimension of the array
  [in] | dim1 | second dimension of the array
  [in] | dim2 | third dimension of the array
  [in] | ty | optional label describing the data type (default is f32)

## ◆ array() [7/15]

array | ( | dim_t | dim0,
|  | dim_t | dim1,
|  | dim_t | dim2,
|  | dim_t | dim3,
|  | dtype | ty = f32 )
| explicit

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] | dim0 | first dimension of the array
  [in] | dim1 | second dimension of the array
  [in] | dim2 | third dimension of the array
  [in] | dim3 | fourth dimension of the array
  [in] | ty | optional label describing the data type (default is f32)

## ◆ array() [8/15]

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
af::array::dims
dim4 dims() const
Get dimensions of the array.
af::dim4
Generic object that represents size and shape.
Definition dim4.hpp:26

Parameters

  [in] | dims | size of the array
  [in] | ty | optional label describing the data type (default is f32)

## ◆ array() [9/15]

template<typename T >

array | ( | dim_t | dim0,
|  | const T * | pointer,
|  | af::source | src = afHost )
| explicit

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

Parameters

  [in] | dim0 | number of elements in the column vector
  [in] | pointer | pointer (points to a buffer on the host/device)
  [in] | src | source 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() [10/15]

template<typename T >

array | ( | dim_t | dim0,
|  | dim_t | dim1,
|  | const T * | pointer,
|  | af::source | src = afHost )
| explicit

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

Parameters

  [in] | dim0 | number of rows
  [in] | dim1 | number of columns
  [in] | pointer | pointer (points to a buffer on the host/device)
  [in] | src | source 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

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() [11/15]

template<typename T >

array | ( | dim_t | dim0,
|  | dim_t | dim1,
|  | dim_t | dim2,
|  | const T * | pointer,
|  | af::source | src = afHost )
| explicit

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

Parameters

  [in] | dim0 | first dimension
  [in] | dim1 | second dimension
  [in] | dim2 | third dimension
  [in] | pointer | pointer (points to a buffer on the host/device)
  [in] | src | source 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.

## ◆ array() [12/15]

template<typename T >

array | ( | dim_t | dim0,
|  | dim_t | dim1,
|  | dim_t | dim2,
|  | dim_t | dim3,
|  | const T * | pointer,
|  | af::source | src = afHost )
| explicit

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

Parameters

  [in] | dim0 | first dimension
  [in] | dim1 | second dimension
  [in] | dim2 | third dimension
  [in] | dim3 | fourth dimension
  [in] | pointer | pointer (points to a buffer on the host/device)
  [in] | src | source 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() [13/15]

template<typename T >

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] | dims | vector data type containing the dimension of the array
  [in] | pointer | pointer (points to a buffer on the host/device)
  [in] | src | source 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() [14/15]

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]
af::array::T
array T() const
Get the transposed the array.
af::array::array
array()
Create an uninitialized array (no data, undefined size)

Parameters

  [in] | input |
  [in] | dims | total number of elements must not change.

## ◆ array() [15/15]

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] | dim0 | first dimension
  [in] | dim1 | second dimension
  [in] | dim2 | third dimension
  [in] | dim3 | fourth dimension

## ◆ ~array()

~array | ( |  | ) |

## Member Function Documentation

## ◆ allocated()

size_t allocated | ( |  | ) | const

Get the size of the array in memory.

This will return the parent's bytes() if the array is indexed.

## ◆ as()

const array as | ( | dtype | type | ) | const

Casts the array into another data type.

Note
  Consecitive casting operations may be may be optimized out if the original type of the af::array is the same as the final type. For example if the original type is f64 which is then cast to f32 and then back to f64, then the cast to f32 will be skipped and that operation will NOT be performed by ArrayFire. The following table shows which casts will be optimized out. outer -> inner -> outer

  inner-> | f32 | f64 | c32 | c64 | s32 | u32 | u8 | b8 | s64 | u64 | s16 | u16 | f16
  --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
  f32 | x | x | x | x |  |  |  |  |  |  |  |  | x
  f64 | x | x | x | x |  |  |  |  |  |  |  |  | x
  c32 | x | x | x | x |  |  |  |  |  |  |  |  | x
  c64 | x | x | x | x |  |  |  |  |  |  |  |  | x
  s32 | x | x | x | x | x | x |  |  | x | x |  |  | x
  u32 | x | x | x | x | x | x |  |  | x | x |  |  | x
  u8 | x | x | x | x | x | x | x | x | x | x | x | x | x
  b8 | x | x | x | x | x | x | x | x | x | x | x | x | x
  s64 | x | x | x | x |  |  |  |  | x | x |  |  | x
  u64 | x | x | x | x |  |  |  |  | x | x |  |  | x
  s16 | x | x | x | x | x | x |  |  | x | x | x | x | x
  u16 | x | x | x | x | x | x |  |  | x | x | x | x | x
  f16 | x | x | x | x |  |  |  |  |  |  |  |  | x

  If you want to avoid this behavior use af_eval after the first cast operation. This will ensure that the cast operation is performed on the af::array

Parameters

  [in] | type | is the desired type(f32, s64, etc.)

Returns
  an array with the type specified by `type`

Examples
  graphics/conway_pretty.cpp, graphics/gravity_sim.cpp, graphics/histogram.cpp, image_processing/brain_segmentation.cpp, image_processing/deconvolution.cpp, image_processing/edge.cpp, machine_learning/deep_belief_net.cpp, machine_learning/geneticalgorithm.cpp, machine_learning/neural_network.cpp, and machine_learning/rbm.cpp.

## ◆ bytes()

size_t bytes | ( |  | ) | const

Get the size of the array in bytes.

Examples
  benchmarks/cg.cpp.

## ◆ copy()

array copy | ( |  | ) | const

Perform deep copy of the array.

Examples
  image_processing/adaptive_thresholding.cpp, image_processing/binary_thresholding.cpp, image_processing/filters.cpp, image_processing/pyramids.cpp, lin_algebra/cholesky.cpp, lin_algebra/lu.cpp, and lin_algebra/qr.cpp.

## ◆ device()

template<typename T >

T * device | ( |  | ) | const

Get the device pointer from the array and lock the buffer in memory manager.

The device memory returned by this function is not freed until unlock() is called.

/note When using the OpenCL backend and using the cl_mem template argument, the delete function should be called on the pointer returned by this function.

## ◆ dims() [1/2]

dim4 dims | ( |  | ) | const

Get dimensions of the array.

Examples
  benchmarks/cg.cpp, computer_vision/harris.cpp, computer_vision/matching.cpp, financial/black_scholes_options.cpp, financial/heston_model.cpp, getting_started/vectorize.cpp, graphics/field.cpp, graphics/fractal.cpp, graphics/gravity_sim.cpp, graphics/plot2d.cpp, image_processing/adaptive_thresholding.cpp, image_processing/binary_thresholding.cpp, image_processing/brain_segmentation.cpp, image_processing/edge.cpp, image_processing/filters.cpp, image_processing/gradient_diffusion.cpp, image_processing/image_editing.cpp, image_processing/morphing.cpp, image_processing/optical_flow.cpp, image_processing/pyramids.cpp, machine_learning/bagging.cpp, machine_learning/deep_belief_net.cpp, machine_learning/kmeans.cpp, machine_learning/knn.cpp, machine_learning/logistic_regression.cpp, machine_learning/naive_bayes.cpp, machine_learning/neural_network.cpp, machine_learning/perceptron.cpp, machine_learning/rbm.cpp, machine_learning/softmax_regression.cpp, and pde/swe.cpp.

## ◆ dims() [2/2]

dim_t dims | ( | unsigned | dim | ) | const

Get dimensions of the array.

## ◆ elements()

dim_t elements | ( |  | ) | const

Get the total number of elements across all dimensions of the array.

Examples
  benchmarks/cg.cpp, graphics/field.cpp, image_processing/binary_thresholding.cpp, image_processing/filters.cpp, machine_learning/bagging.cpp, machine_learning/deep_belief_net.cpp, machine_learning/geneticalgorithm.cpp, machine_learning/knn.cpp, machine_learning/logistic_regression.cpp, machine_learning/naive_bayes.cpp, machine_learning/neural_network.cpp, machine_learning/perceptron.cpp, machine_learning/rbm.cpp, machine_learning/softmax_regression.cpp, and pde/swe.cpp.

## ◆ eval()

void eval | ( |  | ) | const

Evaluate any JIT expressions to generate data for the array.

Examples
  benchmarks/fft.cpp, graphics/field.cpp, graphics/fractal.cpp, graphics/gravity_sim.cpp, machine_learning/bagging.cpp, machine_learning/knn.cpp, machine_learning/logistic_regression.cpp, machine_learning/naive_bayes.cpp, machine_learning/perceptron.cpp, and machine_learning/softmax_regression.cpp.

## ◆ get() [1/2]

af_array get | ( |  | ) |

get the af_array handle

## ◆ get() [2/2]

af_array get | ( |  | ) | const

get the af_array handle

## ◆ H()

array H | ( |  | ) | const

Get the conjugate-transpose of the current array.

Returns
  conjugate-transpose matrix

## ◆ host() [1/2]

template<typename T >

T * host | ( |  | ) | const

Copy array data to host and return host pointer.

Examples
  computer_vision/fast.cpp, computer_vision/harris.cpp, computer_vision/susan.cpp, and image_processing/binary_thresholding.cpp.

## ◆ host() [2/2]

void host | ( | void * | ptr | ) | const

Copy array data to existing host pointer.

## ◆ isbool()

bool isbool | ( |  | ) | const

Returns true if the array type is b8.

## ◆ iscolumn()

bool iscolumn | ( |  | ) | const

Returns true if only the first dimension has more than one element.

## ◆ iscomplex()

bool iscomplex | ( |  | ) | const

Returns true if the array type is c32 or c64.

## ◆ isdouble()

bool isdouble | ( |  | ) | const

Returns true if the array type is f64 or c64.

## ◆ isempty()

bool isempty | ( |  | ) | const

Returns true of the array is empty.

## ◆ isfloating()

bool isfloating | ( |  | ) | const

Returns true if the array type is f16 f32, f64, c32 or c64.

## ◆ ishalf()

bool ishalf | ( |  | ) | const

Returns true if the array type is f16.

## ◆ isinteger()

bool isinteger | ( |  | ) | const

Returns true if the array type is u8, b8, s32 u32, s64, u64, s16, u16.

## ◆ isLocked()

bool isLocked | ( |  | ) | const

Query if the array has been locked by the user.

An array can be locked by the user by calling `arry.lock` or `arr.device` or `getRawPtr` function.

## ◆ isreal()

bool isreal | ( |  | ) | const
| inline

Returns true if the array type is neither c32 nor c64.

Definition at line 733 of file array.h.

733{ return !iscomplex(); }
af::array::iscomplex
bool iscomplex() const
Returns true if the array type is c32 or c64.

## ◆ isrealfloating()

bool isrealfloating | ( |  | ) | const

Returns true if the array type is f16 f32 or f64.

## ◆ isrow()

bool isrow | ( |  | ) | const

Returns true if only the second dimension has more than one element.

## ◆ isscalar()

bool isscalar | ( |  | ) | const

Returns true of the array contains only one value.

## ◆ issingle()

bool issingle | ( |  | ) | const

Returns true if the array type is either f32 nor c32.

## ◆ issparse()

bool issparse | ( |  | ) | const

Returns true if the array is a sparse array.

## ◆ isvector()

bool isvector | ( |  | ) | const

Returns true if only one of the array dimensions has more than one element.

## ◆ lock()

void lock | ( |  | ) | const

Locks the device buffer in the memory manager.

This method can be called to take control of the device pointer from the memory manager. While a buffer is locked, the memory manager doesn't free the memory until unlock() is invoked.

## ◆ nonzeros()

int nonzeros | ( |  | ) | const

Get the count of non-zero elements in the array.

For dense matrix, this is the same as count<int>(arr);

## ◆ numdims()

unsigned numdims | ( |  | ) | const

Get the number of dimensions of the array.

## ◆ scalar()

template<typename T >

T scalar | ( |  | ) | const

Get the first element of the array as a scalar.

Note
  The scalar function is recommended for use while debugging. Calling this method often will affect performance.

Examples
  image_processing/binary_thresholding.cpp, and machine_learning/kmeans.cpp.

## ◆ set()

void set | ( | af_array | tmp | ) |

Updates the internal af_array object.

Note
  This function will reduce the reference of the previous af_array object

## ◆ T()

array T | ( |  | ) | const

Get the transposed the array.

Returns
  Transposed matrix

Examples
  getting_started/integer.cpp, getting_started/vectorize.cpp, graphics/field.cpp, image_processing/filters.cpp, machine_learning/bagging.cpp, machine_learning/deep_belief_net.cpp, machine_learning/knn.cpp, machine_learning/logistic_regression.cpp, machine_learning/naive_bayes.cpp, machine_learning/neural_network.cpp, machine_learning/perceptron.cpp, machine_learning/rbm.cpp, and machine_learning/softmax_regression.cpp.

## ◆ type()

dtype type | ( |  | ) | const

Get array data type.

Examples
  image_processing/brain_segmentation.cpp, and image_processing/morphing.cpp.

## ◆ unlock()

void unlock | ( |  | ) | const

Unlocks the device buffer in the memory manager.

This method can be called after called after calling array::lock() Calling this method gives back the control of the device pointer to the memory manager.

## ◆ write()

template<typename T >

void write | ( | const T * | ptr,
|  | const size_t | bytes,
|  | af::source | src = afHost )

Perform deep copy from host/device pointer to an existing array.

The documentation for this class was generated from the following file:

- array.h