- Main Page
- Tutorials
- Functions
- Release Notes
- Examples

Functions
Methods of array class
ArrayFire Functions by Category » Functions to create and modify Arrays

Get information about the array object. More...

## Functions
const array | as (dtype type) const
| Converts the array into another type. More...
array | T () const
| Get the transposed the array. More...
array | H () const
| Get the conjugate-transpose of the current array. More...
AFAPI af_err | af_copy_array (af_array *arr, const af_array in)
| Deep copy an array to another. More...
AFAPI af_err | af_get_data_ref_count (int *use_count, const af_array in)
| Get the use count of `af_array` More...
AFAPI af_err | af_write_array (af_array arr, const void *data, const size_t bytes, af_source src)
| Copy data from a C pointer (host/device) to an existing array. More...
AFAPI af_err | af_get_data_ptr (void *data, const af_array arr)
| Copy data from an af_array to a C pointer. More...
AFAPI af_err | af_release_array (af_array arr)
| Reduce the reference count of the af_array. More...
AFAPI af_err | af_retain_array (af_array *out, const af_array in)
| Increments an af_array reference count. More...
AFAPI af_err | af_eval (af_array in)
| Evaluate any expressions in the Array. More...
AFAPI af_err | af_get_elements (dim_t *elems, const af_array arr)
| Gets the number of elements in an array. More...
AFAPI af_err | af_get_type (af_dtype *type, const af_array arr)
| Gets the type of an array. More...
AFAPI af_err | af_get_dims (dim_t *d0, dim_t *d1, dim_t *d2, dim_t *d3, const af_array arr)
| Gets the dimseions of an array. More...
AFAPI af_err | af_get_numdims (unsigned *result, const af_array arr)
| Gets the number of dimensions of an array. More...
AFAPI af_err | af_is_empty (bool *result, const af_array arr)
| Check if an array is empty. More...
AFAPI af_err | af_is_scalar (bool *result, const af_array arr)
| Check if an array is scalar, ie. More...
AFAPI af_err | af_is_row (bool *result, const af_array arr)
| Check if an array is row vector. More...
AFAPI af_err | af_is_column (bool *result, const af_array arr)
| Check if an array is a column vector. More...
AFAPI af_err | af_is_vector (bool *result, const af_array arr)
| Check if an array is a vector. More...
AFAPI af_err | af_is_complex (bool *result, const af_array arr)
| Check if an array is complex type. More...
AFAPI af_err | af_is_real (bool *result, const af_array arr)
| Check if an array is real type. More...
AFAPI af_err | af_is_double (bool *result, const af_array arr)
| Check if an array is double precision type. More...
AFAPI af_err | af_is_single (bool *result, const af_array arr)
| Check if an array is single precision type. More...
AFAPI af_err | af_is_realfloating (bool *result, const af_array arr)
| Check if an array is real floating point type. More...
AFAPI af_err | af_is_floating (bool *result, const af_array arr)
| Check if an array is floating precision type. More...
AFAPI af_err | af_is_integer (bool *result, const af_array arr)
| Check if an array is integer type. More...
AFAPI af_err | af_is_bool (bool *result, const af_array arr)
| Check if an array is bool type. More...
array & | eval (array &a)
| Evaluate an expression (nonblocking). More...
void | eval (array &a, array &b)
void | eval (array &a, array &b, array &c)
void | eval (array &a, array &b, array &c, array &d)
void | eval (array &a, array &b, array &c, array &d, array &e)
void | eval (array &a, array &b, array &c, array &d, array &e, array &f)
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 number of elements in 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...
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 neither f64 nor c64. More...
bool | isrealfloating () const
| Returns true if the array type is f32 or f64. More...
bool | isfloating () const
| Returns true if the array type is f32, f64, c32 or c64. More...
bool | isinteger () const
| Returns true if the array type is u8, b8, s32 u32, s64, u64. More...
bool | isbool () const
| Returns true if the array type is b8. 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...

## Detailed Description

Get information about the array object.

## Function Documentation

AFAPI af_err af_copy_array | ( | af_array * | arr,
|  | const af_array | in
| ) |  |

Deep copy an array to another.

AFAPI af_err af_eval | ( | af_array | in | ) |

Evaluate any expressions in the Array.

AFAPI af_err af_get_data_ptr | ( | void * | data,
|  | const af_array | arr
| ) |  |

Copy data from an af_array to a C pointer.

Needs to used in conjunction with the two functions above

Examples:
  blas.cpp, convolve.cpp, fast.cpp, fft.cpp, harris.cpp, and histogram.cpp.

AFAPI af_err af_get_data_ref_count | ( | int * | use_count,
|  | const af_array | in
| ) |  |

Get the use count of `af_array`

AFAPI af_err af_get_dims | ( | dim_t * | d0,
|  | dim_t * | d1,
|  | dim_t * | d2,
|  | dim_t * | d3,
|  | const af_array | arr
| ) |  |

Gets the dimseions of an array.

Parameters

  [out] | d0 | is the output that contains the size of first dimension of `arr`
  [out] | d1 | is the output that contains the size of second dimension of `arr`
  [out] | d2 | is the output that contains the size of third dimension of `arr`
  [out] | d3 | is the output that contains the size of fourth dimension of `arr`
  [in] | arr | is the input array

Returns
  error codes

AFAPI af_err af_get_elements | ( | dim_t * | elems,
|  | const af_array | arr
| ) |  |

Gets the number of elements in an array.

Parameters

  [out] | elems | is the output that contains number of elements of `arr`
  [in] | arr | is the input array

Returns
  error codes

Examples:
  blas.cpp, fast.cpp, and harris.cpp.

AFAPI af_err af_get_numdims | ( | unsigned * | result,
|  | const af_array | arr
| ) |  |

Gets the number of dimensions of an array.

Parameters

  [out] | result | is the output that contains the number of dims of `arr`
  [in] | arr | is the input array

Returns
  error codes

AFAPI af_err af_get_type | ( | af_dtype * | type,
|  | const af_array | arr
| ) |  |

Gets the type of an array.

Parameters

  [out] | type | is the output that contains the type of `arr`
  [in] | arr | is the input array

Returns
  error codes

AFAPI af_err af_is_bool | ( | bool * | result,
|  | const af_array | arr
| ) |  |

Check if an array is bool type.

Parameters

  [out] | result | is true if arr is of b8 type, otherwise false
  [in] | arr | is the input array

Returns
  error codes

AFAPI af_err af_is_column | ( | bool * | result,
|  | const af_array | arr
| ) |  |

Check if an array is a column vector.

Parameters

  [out] | result | is true if arr has dims [x 1 1 1], false otherwise
  [in] | arr | is the input array

Returns
  error codes

AFAPI af_err af_is_complex | ( | bool * | result,
|  | const af_array | arr
| ) |  |

Check if an array is complex type.

Parameters

  [out] | result | is true if arr is of type c32 or c64, otherwise false
  [in] | arr | is the input array

Returns
  error codes

AFAPI af_err af_is_double | ( | bool * | result,
|  | const af_array | arr
| ) |  |

Check if an array is double precision type.

Parameters

  [out] | result | is true if arr is of type f64 or c64, otherwise false
  [in] | arr | is the input array

Returns
  error codes

AFAPI af_err af_is_empty | ( | bool * | result,
|  | const af_array | arr
| ) |  |

Check if an array is empty.

Parameters

  [out] | result | is true if elements of arr is 0, otherwise false
  [in] | arr | is the input array

Returns
  error codes

AFAPI af_err af_is_floating | ( | bool * | result,
|  | const af_array | arr
| ) |  |

Check if an array is floating precision type.

This is a combination of af_is_realfloating and af_is_complex

Parameters

  [out] | result | is true if arr is of type f32, f64, c32 or c64, otherwise false
  [in] | arr | is the input array

Returns
  error codes

AFAPI af_err af_is_integer | ( | bool * | result,
|  | const af_array | arr
| ) |  |

Check if an array is integer type.

Parameters

  [out] | result | is true if arr is of integer types, otherwise false
  [in] | arr | is the input array

Returns
  error codes

AFAPI af_err af_is_real | ( | bool * | result,
|  | const af_array | arr
| ) |  |

Check if an array is real type.

This is mutually exclusive to af_is_complex

Parameters

  [out] | result | is true if arr is NOT of type c32 or c64, otherwise false
  [in] | arr | is the input array

Returns
  error codes

AFAPI af_err af_is_realfloating | ( | bool * | result,
|  | const af_array | arr
| ) |  |

Check if an array is real floating point type.

Parameters

  [out] | result | is true if arr is of type f32 or f64, otherwise false
  [in] | arr | is the input array

Returns
  error codes

AFAPI af_err af_is_row | ( | bool * | result,
|  | const af_array | arr
| ) |  |

Check if an array is row vector.

Parameters

  [out] | result | is true if arr has dims [1 x 1 1], false otherwise
  [in] | arr | is the input array

Returns
  error codes

AFAPI af_err af_is_scalar | ( | bool * | result,
|  | const af_array | arr
| ) |  |

Check if an array is scalar, ie.

single element.

Parameters

  [out] | result | is true if elements of arr is 1, otherwise false
  [in] | arr | is the input array

Returns
  error codes

AFAPI af_err af_is_single | ( | bool * | result,
|  | const af_array | arr
| ) |  |

Check if an array is single precision type.

Parameters

  [out] | result | is true if arr is of type f32 or c32, otherwise false
  [in] | arr | is the input array

Returns
  error codes

AFAPI af_err af_is_vector | ( | bool * | result,
|  | const af_array | arr
| ) |  |

Check if an array is a vector.

A vector is any array that has exactly 1 dimension not equal to 1.

Parameters

  [out] | result | is true if arr is a vector, false otherwise
  [in] | arr | is the input array

Returns
  error codes

AFAPI af_err af_release_array | ( | af_array | arr | ) |

Reduce the reference count of the af_array.

Examples:
  blas.cpp, convolve.cpp, fast.cpp, fft.cpp, harris.cpp, and histogram.cpp.

AFAPI af_err af_retain_array | ( | af_array * | out,
|  | const af_array | in
| ) |  |

Increments an af_array reference count.

AFAPI af_err af_write_array | ( | af_array | arr,
|  | const void * | data,
|  | const size_t | bytes,
|  | af_source | src
| ) |  |

Copy data from a C pointer (host/device) to an existing array.

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

Converts the array into another type.

Parameters

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

Returns
  an array with the type specified by `type`

Examples:
  brain_segmentation.cpp, conway.cpp, conway_pretty.cpp, deep_belief_net.cpp, and rbm.cpp.

size_t bytes | ( |  | ) | const

Get the size of the array in bytes.

array copy | ( |  | ) | const

Perform deep copy of the array.

Examples:
  adaptive_thresholding.cpp, binary_thresholding.cpp, cholesky.cpp, filters.cpp, lu.cpp, pyramids.cpp, and qr.cpp.

dim4 dims | ( |  | ) | const

Get dimensions of the array.

Examples:
  adaptive_thresholding.cpp, bagging.cpp, binary_thresholding.cpp, black_scholes_options.cpp, brain_segmentation.cpp, deep_belief_net.cpp, edge.cpp, fft.cpp, filters.cpp, fractal.cpp, heston_model.cpp, image_editing.cpp, kmeans.cpp, knn.cpp, logistic_regression.cpp, matching.cpp, morphing.cpp, naive_bayes.cpp, neural_network.cpp, optical_flow.cpp, perceptron.cpp, pyramids.cpp, rbm.cpp, softmax_regression.cpp, and vectorize.cpp.

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

Get dimensions of the array.

dim_t elements | ( |  | ) | const

get the number of elements in array

Examples:
  bagging.cpp, binary_thresholding.cpp, convolve.cpp, deep_belief_net.cpp, fft.cpp, filters.cpp, fractal.cpp, histogram.cpp, knn.cpp, logistic_regression.cpp, naive_bayes.cpp, neural_network.cpp, perceptron.cpp, rbm.cpp, and softmax_regression.cpp.

void eval | ( |  | ) | const

Evaluate any JIT expressions to generate data for the array.

Examples:
  bagging.cpp, fractal.cpp, knn.cpp, logistic_regression.cpp, naive_bayes.cpp, perceptron.cpp, and softmax_regression.cpp.

array& af::eval | ( | array & | a | ) |
| inline

Evaluate an expression (nonblocking).

Examples:
  black_scholes_options.cpp.

void af::eval | ( | array & | a,
|  | array & | b
| ) |  |
| inline

void af::eval | ( | array & | a,
|  | array & | b,
|  | array & | c
| ) |  |
| inline

void af::eval | ( | array & | a,
|  | array & | b,
|  | array & | c,
|  | array & | d
| ) |  |
| inline

void af::eval | ( | array & | a,
|  | array & | b,
|  | array & | c,
|  | array & | d,
|  | array & | e
| ) |  |
| inline

void af::eval | ( | array & | a,
|  | array & | b,
|  | array & | c,
|  | array & | d,
|  | array & | e,
|  | array & | f
| ) |  |
| inline

af_array get | ( |  | ) |

get the af_array handle

af_array get | ( |  | ) | const

get the af_array handle

array H | ( |  | ) | const

Get the conjugate-transpose of the current array.

Returns
  conjugate-transpose matrix

T* host | ( |  | ) | const

Copy array data to host and return host pointer.

Examples:
  binary_thresholding.cpp, convolve.cpp, fast.cpp, fft.cpp, harris.cpp, histogram.cpp, and susan.cpp.

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 iscomplex | ( |  | ) | const

Returns true if the array type is c32 or c64.

bool isdouble | ( |  | ) | const

Returns true if the array type is f64 or c64.

bool isempty | ( |  | ) | const

Returns true of the array is empty.

bool isfloating | ( |  | ) | const

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

bool isinteger | ( |  | ) | const

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

bool isreal | ( |  | ) | const
| inline

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

bool isrealfloating | ( |  | ) | const

Returns true if the array type is f32 or f64.

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 issingle | ( |  | ) | const

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

bool isvector | ( |  | ) | const

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

unsigned numdims | ( |  | ) | const

Get the number of dimensions of the array.

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:
  binary_thresholding.cpp.

array T | ( |  | ) | const

Get the transposed the array.

Returns
  Transposed matrix

Examples:
  bagging.cpp, deep_belief_net.cpp, filters.cpp, fractal.cpp, integer.cpp, knn.cpp, logistic_regression.cpp, naive_bayes.cpp, neural_network.cpp, perceptron.cpp, rbm.cpp, softmax_regression.cpp, and vectorize.cpp.

dtype type | ( |  | ) | const

Get array data type.

Examples:
  brain_segmentation.cpp, and morphing.cpp.

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

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