A high-performance general-purpose compute library

- Main Page
- Tutorials
- Release Notes
- Examples

Functions
C API to manage arrays
ArrayFire Functions by Category » Functions to create and modify Arrays

Create, release, copy, fetch-properties of af_array More...

## Functions
AFAPI af_err | af_device_array (af_array *arr, void *data, const unsigned ndims, const dim_t *const dims, const af_dtype type)
| Create array from device memory.
AFAPI af_err | af_create_array (af_array *arr, const void *const data, const unsigned ndims, const dim_t *const dims, const af_dtype type)
| Create an af_array handle initialized with user defined data.
AFAPI af_err | af_create_handle (af_array *arr, const unsigned ndims, const dim_t *const dims, const af_dtype type)
| Create af_array handle.
AFAPI af_err | af_copy_array (af_array *arr, const af_array in)
| Deep copy an array to another.
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.
AFAPI af_err | af_get_data_ptr (void *data, const af_array arr)
| Copy data from an af_array to a C pointer.
AFAPI af_err | af_release_array (af_array arr)
| Reduce the reference count of the af_array.
AFAPI af_err | af_retain_array (af_array *out, const af_array in)
| Increments an af_array reference count.
AFAPI af_err | af_get_data_ref_count (int *use_count, const af_array in)
| Get the reference count of af_array.
AFAPI af_err | af_eval (af_array in)
| Evaluate any expressions in the Array.
AFAPI af_err | af_eval_multiple (const int num, af_array *arrays)
| Evaluate multiple arrays together.
AFAPI af_err | af_set_manual_eval_flag (bool flag)
| Turn the manual eval flag on or off.
AFAPI af_err | af_get_manual_eval_flag (bool *flag)
| Get the manual eval flag.
AFAPI af_err | af_get_elements (dim_t *elems, const af_array arr)
| Get the total number of elements across all dimensions of the array.
AFAPI af_err | af_get_type (af_dtype *type, const af_array arr)
| Gets the type of an 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 dimensions of an array.
AFAPI af_err | af_get_numdims (unsigned *result, const af_array arr)
| Gets the number of dimensions of an array.
AFAPI af_err | af_is_empty (bool *result, const af_array arr)
| Check if an array is empty.
AFAPI af_err | af_is_scalar (bool *result, const af_array arr)
| Check if an array is scalar, ie.
AFAPI af_err | af_is_row (bool *result, const af_array arr)
| Check if an array is row vector.
AFAPI af_err | af_is_column (bool *result, const af_array arr)
| Check if an array is a column vector.
AFAPI af_err | af_is_vector (bool *result, const af_array arr)
| Check if an array is a vector.
AFAPI af_err | af_is_complex (bool *result, const af_array arr)
| Check if an array is complex type.
AFAPI af_err | af_is_real (bool *result, const af_array arr)
| Check if an array is real type.
AFAPI af_err | af_is_double (bool *result, const af_array arr)
| Check if an array is double precision type.
AFAPI af_err | af_is_single (bool *result, const af_array arr)
| Check if an array is single precision type.
AFAPI af_err | af_is_half (bool *result, const af_array arr)
| Check if an array is 16 bit floating point type.
AFAPI af_err | af_is_realfloating (bool *result, const af_array arr)
| Check if an array is real floating point type.
AFAPI af_err | af_is_floating (bool *result, const af_array arr)
| Check if an array is floating precision type.
AFAPI af_err | af_is_integer (bool *result, const af_array arr)
| Check if an array is integer type.
AFAPI af_err | af_is_bool (bool *result, const af_array arr)
| Check if an array is bool type.
AFAPI af_err | af_is_sparse (bool *result, const af_array arr)
| Check if an array is sparse.
AFAPI af_err | af_get_scalar (void *output_value, const af_array arr)
| Get first element from an array.

## Detailed Description

Create, release, copy, fetch-properties of af_array

## Function Documentation

## ◆ af_copy_array()

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

Deep copy an array to another.

## ◆ af_create_array()

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

Create an af_array handle initialized with user defined data.

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

Parameters

  [out] | arr | The pointer to the returned object.
  [in] | data | The data which will be loaded into the array
  [in] | ndims | The number of dimensions read from the `dims` parameter
  [in] | dims | A C pointer with `ndims` elements. Each value represents the size of that dimension
  [in] | type | The type of the af_array object

Returns
  AF_SUCCESS if the operation was a success

## ◆ af_create_handle()

AFAPI af_err af_create_handle | ( | af_array * | arr,
|  | const unsigned | ndims,
|  | const dim_t *const | dims,
|  | const af_dtype | type )

Create af_array handle.

To release the memory allocated by this call you would have to call af_release_array once your use of this af_array is complete.

Parameters

  [out] | arr | The pointer to the retured object.
  [in] | ndims | The number of dimensions read from the `dims` parameter
  [in] | dims | A C pointer with `ndims` elements. Each value represents the size of that dimension
  [in] | type | The type of the af_array object

Returns
  AF_SUCCESS if the operation was a success

## ◆ af_device_array()

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

Create array from device memory.

## ◆ af_eval()

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

Evaluate any expressions in the Array.

## ◆ af_eval_multiple()

AFAPI af_err af_eval_multiple | ( | const int | num,
|  | af_array * | arrays )

Evaluate multiple arrays together.

## ◆ af_get_data_ptr()

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

## ◆ af_get_data_ref_count()

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

Get the reference count of af_array.

## ◆ af_get_dims()

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

Gets the dimensions 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

## ◆ af_get_elements()

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

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

Parameters

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

Returns
  error codes

## ◆ af_get_manual_eval_flag()

AFAPI af_err af_get_manual_eval_flag | ( | bool * | flag | ) |

Get the manual eval flag.

## ◆ af_get_numdims()

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

## ◆ af_get_scalar()

AFAPI af_err af_get_scalar | ( | void * | output_value,
|  | const af_array | arr )

Get first element from an array.

Parameters

  [out] | output_value | is the element requested
  [in] | arr | is the input array

Returns
  AF_SUCCESS if the execution completes properly

## ◆ af_get_type()

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

## ◆ af_is_bool()

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

## ◆ af_is_column()

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

## ◆ af_is_complex()

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

## ◆ af_is_double()

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

## ◆ af_is_empty()

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

## ◆ af_is_floating()

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 f16 f32, f64, c32 or c64, otherwise false
  [in] | arr | is the input array

Returns
  error codes

## ◆ af_is_half()

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

Check if an array is 16 bit floating point type.

Parameters

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

Returns
  error codes

## ◆ af_is_integer()

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

## ◆ af_is_real()

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 c32 or c64, otherwise false
  [in] | arr | is the input array

Returns
  error codes

## ◆ af_is_realfloating()

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

## ◆ af_is_row()

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

## ◆ af_is_scalar()

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

## ◆ af_is_single()

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

## ◆ af_is_sparse()

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

Check if an array is sparse.

Parameters

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

Returns
  error codes

## ◆ af_is_vector()

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

## ◆ af_release_array()

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

Reduce the reference count of the af_array.

Note
  Zero initialized af_arrays can be accepted after version 3.7

## ◆ af_retain_array()

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

Increments an af_array reference count.

## ◆ af_set_manual_eval_flag()

AFAPI af_err af_set_manual_eval_flag | ( | bool | flag | ) |

Turn the manual eval flag on or off.

## ◆ af_write_array()

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.