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 > | |
T * | host () 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 > | |
T * | device () 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 |
Casts the array into another data 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... | |
array | operator~ () const |
Performs a bitwise 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... | |
array & | operator= (const array &val) |
Assignes the value(s) of val to the elements of the array. More... | |
array & | operator= (const double &val) |
Assignes the value(s) of val to the elements of the array. More... | |
array & | operator= (const cdouble &val) |
Assignes the value(s) of val to the elements of the array. More... | |
array & | operator= (const cfloat &val) |
Assignes the value(s) of val to the elements of the array. More... | |
array & | operator= (const float &val) |
Assignes the value(s) of val to the elements of the array. More... | |
array & | operator= (const int &val) |
Assignes the value(s) of val to the elements of the array. More... | |
array & | operator= (const unsigned &val) |
Assignes the value(s) of val to the elements of the array. More... | |
array & | operator= (const bool &val) |
Assignes the value(s) of val to the elements of the array. More... | |
array & | operator= (const char &val) |
Assignes the value(s) of val to the elements of the array. More... | |
array & | operator= (const unsigned char &val) |
Assignes the value(s) of val to the elements of the array. More... | |
array & | operator= (const long &val) |
Assignes the value(s) of val to the elements of the array. More... | |
array & | operator= (const unsigned long &val) |
Assignes the value(s) of val to the elements of the array. More... | |
array & | operator= (const long long &val) |
Assignes the value(s) of val to the elements of the array. More... | |
array & | operator= (const unsigned long long &val) |
array & | operator= (const short &val) |
Assignes the value(s) of val to the elements of the array. More... | |
array & | operator= (const unsigned short &val) |
array & | operator+= (const array &val) |
Adds the value(s) of val to the elements of the array. More... | |
array & | operator+= (const double &val) |
Adds the value(s) of val to the elements of the array. More... | |
array & | operator+= (const cdouble &val) |
Adds the value(s) of val to the elements of the array. More... | |
array & | operator+= (const cfloat &val) |
Adds the value(s) of val to the elements of the array. More... | |
array & | operator+= (const float &val) |
Adds the value(s) of val to the elements of the array. More... | |
array & | operator+= (const int &val) |
Adds the value(s) of val to the elements of the array. More... | |
array & | operator+= (const unsigned &val) |
Adds the value(s) of val to the elements of the array. More... | |
array & | operator+= (const bool &val) |
Adds the value(s) of val to the elements of the array. More... | |
array & | operator+= (const char &val) |
Adds the value(s) of val to the elements of the array. More... | |
array & | operator+= (const unsigned char &val) |
Adds the value(s) of val to the elements of the array. More... | |
array & | operator+= (const long &val) |
Adds the value(s) of val to the elements of the array. More... | |
array & | operator+= (const unsigned long &val) |
Adds the value(s) of val to the elements of the array. More... | |
array & | operator+= (const long long &val) |
Adds the value(s) of val to the elements of the array. More... | |
array & | operator+= (const unsigned long long &val) |
array & | operator+= (const short &val) |
Adds the value(s) of val to the elements of the array. More... | |
array & | operator+= (const unsigned short &val) |
array & | operator-= (const array &val) |
Subtracts the value(s) of val to the elements of the array. More... | |
array & | operator-= (const double &val) |
Subtracts the value(s) of val to the elements of the array. More... | |
array & | operator-= (const cdouble &val) |
Subtracts the value(s) of val to the elements of the array. More... | |
array & | operator-= (const cfloat &val) |
Subtracts the value(s) of val to the elements of the array. More... | |
array & | operator-= (const float &val) |
Subtracts the value(s) of val to the elements of the array. More... | |
array & | operator-= (const int &val) |
Subtracts the value(s) of val to the elements of the array. More... | |
array & | operator-= (const unsigned &val) |
Subtracts the value(s) of val to the elements of the array. More... | |
array & | operator-= (const bool &val) |
Subtracts the value(s) of val to the elements of the array. More... | |
array & | operator-= (const char &val) |
Subtracts the value(s) of val to the elements of the array. More... | |
array & | operator-= (const unsigned char &val) |
Subtracts the value(s) of val to the elements of the array. More... | |
array & | operator-= (const long &val) |
Subtracts the value(s) of val to the elements of the array. More... | |
array & | operator-= (const unsigned long &val) |
Subtracts the value(s) of val to the elements of the array. More... | |
array & | operator-= (const long long &val) |
Subtracts the value(s) of val to the elements of the array. More... | |
array & | operator-= (const unsigned long long &val) |
array & | operator-= (const short &val) |
Subtracts the value(s) of val to the elements of the array. More... | |
array & | operator-= (const unsigned short &val) |
array & | operator*= (const array &val) |
Multiplies the value(s) of val to the elements of the array. More... | |
array & | operator*= (const double &val) |
Multiplies the value(s) of val to the elements of the array. More... | |
array & | operator*= (const cdouble &val) |
Multiplies the value(s) of val to the elements of the array. More... | |
array & | operator*= (const cfloat &val) |
Multiplies the value(s) of val to the elements of the array. More... | |
array & | operator*= (const float &val) |
Multiplies the value(s) of val to the elements of the array. More... | |
array & | operator*= (const int &val) |
Multiplies the value(s) of val to the elements of the array. More... | |
array & | operator*= (const unsigned &val) |
Multiplies the value(s) of val to the elements of the array. More... | |
array & | operator*= (const bool &val) |
Multiplies the value(s) of val to the elements of the array. More... | |
array & | operator*= (const char &val) |
Multiplies the value(s) of val to the elements of the array. More... | |
array & | operator*= (const unsigned char &val) |
Multiplies the value(s) of val to the elements of the array. More... | |
array & | operator*= (const long &val) |
Multiplies the value(s) of val to the elements of the array. More... | |
array & | operator*= (const unsigned long &val) |
Multiplies the value(s) of val to the elements of the array. More... | |
array & | operator*= (const long long &val) |
Multiplies the value(s) of val to the elements of the array. More... | |
array & | operator*= (const unsigned long long &val) |
array & | operator*= (const short &val) |
Multiplies the value(s) of val to the elements of the array. More... | |
array & | operator*= (const unsigned short &val) |
array & | operator/= (const array &val) |
Divides the value(s) of val to the elements of the array. More... | |
array & | operator/= (const double &val) |
Divides the value(s) of val to the elements of the array. More... | |
array & | operator/= (const cdouble &val) |
Divides the value(s) of val to the elements of the array. More... | |
array & | operator/= (const cfloat &val) |
Divides the value(s) of val to the elements of the array. More... | |
array & | operator/= (const float &val) |
Divides the value(s) of val to the elements of the array. More... | |
array & | operator/= (const int &val) |
Divides the value(s) of val to the elements of the array. More... | |
array & | operator/= (const unsigned &val) |
Divides the value(s) of val to the elements of the array. More... | |
array & | operator/= (const bool &val) |
Divides the value(s) of val to the elements of the array. More... | |
array & | operator/= (const char &val) |
Divides the value(s) of val to the elements of the array. More... | |
array & | operator/= (const unsigned char &val) |
Divides the value(s) of val to the elements of the array. More... | |
array & | operator/= (const long &val) |
Divides the value(s) of val to the elements of the array. More... | |
array & | operator/= (const unsigned long &val) |
Divides the value(s) of val to the elements of the array. More... | |
array & | operator/= (const long long &val) |
Divides the value(s) of val to the elements of the array. More... | |
array & | operator/= (const unsigned long long &val) |
array & | operator/= (const short &val) |
Divides the value(s) of val to the elements of the array. More... | |
array & | operator/= (const unsigned short &val) |
A multi dimensional data container.
array | ( | ) |
Create an uninitialized array (no data, undefined size)
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.
handle | the af_array object. |
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.
[in] | dim0 | number of columns in the array |
[in] | ty | optional label describing the data type (default is 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.
[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) |
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.
[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) |
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.
[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) |
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.
[in] | dims | size of the array |
[in] | ty | optional label describing the data type (default is f32) |
|
explicit |
Create a column vector on the device using a host/device pointer.
[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) |
Create a 2D array on the device using a host/device pointer.
[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) |
Create a 3D array on the device using a host/device pointer.
[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) |
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.
|
explicit |
Create a 4D array on the device using a host/device pointer.
[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) |
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.
|
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).
[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) |
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.
[in] | input | |
[in] | dims | total number of elements must not change. |
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.
[in] | input | |
[in] | dim0 | first dimension |
[in] | dim1 | second dimension |
[in] | dim2 | third dimension |
[in] | dim3 | fourth dimension |
~array | ( | ) |
size_t allocated | ( | ) | const |
Get the size of the array in memory.
This will return the parent's bytes() if the array is indexed.
Casts the array into another data type.
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 |
[in] | type | is the desired type(f32, s64, etc.) |
type
size_t bytes | ( | ) | const |
Get the size of the array in bytes.
array copy | ( | ) | const |
Perform deep copy of the array.
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.
dim4 dims | ( | ) | const |
Get dimensions of the array.
dim_t dims | ( | unsigned | dim | ) | const |
Get dimensions of the array.
dim_t elements | ( | ) | const |
Get the total number of elements across all dimensions of the array.
void eval | ( | ) | const |
Evaluate any JIT expressions to generate data for the array.
array H | ( | ) | const |
Get the conjugate-transpose of the current array.
T * host | ( | ) | const |
Copy array data to host and return host pointer.
void host | ( | void * | ptr | ) | const |
Copy array data to existing host pointer.
bool isbool | ( | ) | const |
Returns true if the array type is b8.
bool iscolumn | ( | ) | const |
Returns true if only the first dimension has more than one element.
bool isempty | ( | ) | const |
Returns true of the array is empty.
bool ishalf | ( | ) | const |
Returns true if the array type is f16.
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.
|
inline |
bool isrow | ( | ) | const |
Returns true if only the second dimension has more than one element.
bool isscalar | ( | ) | const |
Returns true of the array contains only one value.
bool issparse | ( | ) | const |
Returns true if the array is a sparse array.
bool isvector | ( | ) | const |
Returns true if only one of the array dimensions has more than one element.
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.
int nonzeros | ( | ) | const |
Get the count of non-zero elements in the array.
For dense matrix, this is the same as count<int>(arr);
unsigned numdims | ( | ) | const |
Get the number of dimensions of the array.
T scalar | ( | ) | const |
Get the first element of the array as a scalar.
void set | ( | af_array | tmp | ) |
array T | ( | ) | const |
Get the transposed the array.
dtype type | ( | ) | const |
Get array data type.
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.
void write | ( | const T * | ptr, |
const size_t | bytes, | ||
af::source | src = afHost |
||
) |
Perform deep copy from host/device pointer to an existing array.