A high-performance general-purpose compute library

- Main Page
- Tutorials
- Release Notes
- Examples

Functions
constant
ArrayFire Functions | ArrayFire Functions by Category » Functions to create and modify Arrays » Functions to create arrays.

## Functions
template<typename T >
array | constant (T val, const dim4 &dims, const dtype ty=(af_dtype) dtype_traits< T >::ctype)
| C++ Interface to generate an array with elements set to a specified value.
template<typename T >
array | constant (T val, const dim_t d0, const af_dtype ty=(af_dtype) dtype_traits< T >::ctype)
| C++ Interface to generate a 1-D array with elements set to a specified value.
template<typename T >
array | constant (T val, const dim_t d0, const dim_t d1, const af_dtype ty=(af_dtype) dtype_traits< T >::ctype)
| C++ Interface to generate a 2-D array with elements set to a specified value.
template<typename T >
array | constant (T val, const dim_t d0, const dim_t d1, const dim_t d2, const af_dtype ty=(af_dtype) dtype_traits< T >::ctype)
| C++ Interface to generate a 3-D array with elements set to a specified value.
template<typename T >
array | constant (T val, const dim_t d0, const dim_t d1, const dim_t d2, const dim_t d3, const af_dtype ty=(af_dtype) dtype_traits< T >::ctype)
| C++ Interface to generate a 4-D array with elements set to a specified value.
AFAPI af_err | af_constant (af_array *arr, const double val, const unsigned ndims, const dim_t *const dims, const af_dtype type)
| C Interface to generate an array with elements set to a specified value.
AFAPI af_err | af_constant_complex (af_array *arr, const double real, const double imag, const unsigned ndims, const dim_t *const dims, const af_dtype type)
| C Interface to generate a complex array with elements set to a specified value.
AFAPI af_err | af_constant_long (af_array *arr, const long long val, const unsigned ndims, const dim_t *const dims)
| C Interface to generate an array with elements set to a specified value.
AFAPI af_err | af_constant_ulong (af_array *arr, const unsigned long long val, const unsigned ndims, const dim_t *const dims)
| C Interface to generate an array with elements set to a specified value.

## Detailed Description

Create an array from a scalar input value.

Generate an array with elements set to a specified value.

## Function Documentation

## ◆ af_constant()

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

C Interface to generate an array with elements set to a specified value.

Parameters

  [out] | arr | constant array
  [in] | val | constant value
  [in] | ndims | size of the dimension array
  [in] | dims | dimensions of the array to be generated
  [in] | type | type

Returns
  AF_SUCCESS, if function returns successfully, else an af_err code is given

## ◆ af_constant_complex()

AFAPI af_err af_constant_complex | ( | af_array * | arr,
|  | const double | real,
|  | const double | imag,
|  | const unsigned | ndims,
|  | const dim_t *const | dims,
|  | const af_dtype | type )

C Interface to generate a complex array with elements set to a specified value.

Parameters

  [out] | arr | constant complex array
  [in] | real | real constant value
  [in] | imag | imaginary constant value
  [in] | ndims | size of the dimension array
  [in] | dims | dimensions of the array to be generated
  [in] | type | type, c32 or c64

Returns
  AF_SUCCESS, if function returns successfully, else an af_err code is given

## ◆ af_constant_long()

AFAPI af_err af_constant_long | ( | af_array * | arr,
|  | const long long | val,
|  | const unsigned | ndims,
|  | const dim_t *const | dims )

C Interface to generate an array with elements set to a specified value.

Output type is s64.

Parameters

  [out] | arr | constant array
  [in] | val | constant value
  [in] | ndims | size of the dimension array
  [in] | dims | dimensions of the array to be generated

Returns
  AF_SUCCESS, if function returns successfully, else an af_err code is given

## ◆ af_constant_ulong()

AFAPI af_err af_constant_ulong | ( | af_array * | arr,
|  | const unsigned long long | val,
|  | const unsigned | ndims,
|  | const dim_t *const | dims )

C Interface to generate an array with elements set to a specified value.

Output type is u64.

Parameters

  [out] | arr | constant array
  [in] | val | constant value
  [in] | ndims | size of the dimension array
  [in] | dims | dimensions of the array to be generated

Returns
  AF_SUCCESS, if function returns successfully, else an af_err code is given

## ◆ constant() [1/5]

template<typename T >

array constant | ( | T | val,
|  | const dim4 & | dims,
|  | const dtype | ty = (af_dtype) dtype_traits< T >::ctype )

C++ Interface to generate an array with elements set to a specified value.

Parameters

  [in] | val | constant value
  [in] | dims | dimensions of the array to be generated
  [in] | ty | type

Returns
  constant array

Examples
  financial/heston_model.cpp, graphics/gravity_sim.cpp, and unified/basic.cpp.

## ◆ constant() [2/5]

template<typename T >

array constant | ( | T | val,
|  | const dim_t | d0,
|  | const af_dtype | ty = (af_dtype) dtype_traits< T >::ctype )

C++ Interface to generate a 1-D array with elements set to a specified value.

Parameters

  [in] | val | constant value
  [in] | d0 | size of the first dimension
  [in] | ty | type

Returns
  constant 1-D array

## ◆ constant() [3/5]

template<typename T >

array constant | ( | T | val,
|  | const dim_t | d0,
|  | const dim_t | d1,
|  | const af_dtype | ty = (af_dtype) dtype_traits< T >::ctype )

C++ Interface to generate a 2-D array with elements set to a specified value.

Parameters

  [in] | val | constant value
  [in] | d0 | size of the first dimension
  [in] | d1 | size of the second dimension
  [in] | ty | type

Returns
  constant 2-D array

## ◆ constant() [4/5]

template<typename T >

array constant | ( | T | val,
|  | const dim_t | d0,
|  | const dim_t | d1,
|  | const dim_t | d2,
|  | const af_dtype | ty = (af_dtype) dtype_traits< T >::ctype )

C++ Interface to generate a 3-D array with elements set to a specified value.

Parameters

  [in] | val | constant value
  [in] | d0 | size of the first dimension
  [in] | d1 | size of the second dimension
  [in] | d2 | size of the third dimension
  [in] | ty | type

Returns
  constant 3-D array

## ◆ constant() [5/5]

template<typename T >

array constant | ( | T | val,
|  | const dim_t | d0,
|  | const dim_t | d1,
|  | const dim_t | d2,
|  | const dim_t | d3,
|  | const af_dtype | ty = (af_dtype) dtype_traits< T >::ctype )

C++ Interface to generate a 4-D array with elements set to a specified value.

Parameters

  [in] | val | constant value
  [in] | d0 | size of the first dimension
  [in] | d1 | size of the second dimension
  [in] | d2 | size of the third dimension
  [in] | d3 | size of the fourth dimension
  [in] | ty | type

Returns
  constant 4-D array