array Class Reference

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

◆ 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
handlethe af_array object.

◆ array() [3/15]

array ( const array in)

Creates a copy to the in array.

Parameters
inThe input array

◆ array() [4/15]

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

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

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

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() [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
Parameters
[in]dimssize of the array
[in]tyoptional label describing the data type (default is f32)

◆ array() [9/15]

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

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
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]

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.

◆ array() [12/15]

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

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() [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]
Parameters
[in]input
[in]dimstotal 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]dim0first dimension
[in]dim1second dimension
[in]dim2third dimension
[in]dim3fourth 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()

◆ bytes()

size_t bytes ( ) const

Get the size of the array in bytes.

Examples
benchmarks/cg.cpp.

◆ copy()

◆ device()

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]

◆ dims() [2/2]

dim_t dims ( unsigned  dim) const

Get dimensions of the array.

◆ elements()

◆ eval()

◆ 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]

T* host ( ) const

◆ 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 657 of file array.h.

◆ 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()

T scalar ( ) const

Get the first element of the array as a scalar.

Note
This is recommended for use while debugging. Calling this method constantly reduces 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()

◆ type()

dtype type ( ) const

◆ 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()

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:
f64
@ f64
64-bit complex floating point values
Definition: defines.h:213
af::array::array
array()
Create an uninitialized array (no data, undefined size)
af::array::dims
dim4 dims() const
Get dimensions of the array.