constant

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

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

Create a array from a scalar input value. More...

## Functions
template<typename T >
array | constant (T val, const dim4 &dims, const dtype ty=(af_dtype) dtype_traits< T >::ctype)
template<typename T >
array | constant (T val, const dim_t d0, const af_dtype ty=(af_dtype) dtype_traits< T >::ctype)
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)
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)
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)
AFAPI af_err | af_constant (af_array *arr, const double val, const unsigned ndims, const dim_t *const dims, const af_dtype type)
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)
AFAPI af_err | af_constant_long (af_array *arr, const intl val, const unsigned ndims, const dim_t *const dims)
AFAPI af_err | af_constant_ulong (af_array *arr, const uintl val, const unsigned ndims, const dim_t *const dims)

## Detailed Description

Create a array from a scalar input value.

The array created has the same value at all locations

## Function Documentation

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

Parameters

  [out] | arr | is the generated array of given type
  [in] | val | is the value of each element in the generated array
  [in] | ndims | is size of dimension array `dims`
  [in] | dims | is the array containing sizes of the dimension
  [in] | type | is the type of array to generate

Examples:
  basic.cpp.

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

Parameters

  [out] | arr | is the generated array of type c32 or c64
  [in] | real | is the real value of each element in the generated array
  [in] | imag | is the imaginary value of each element in the generated array
  [in] | ndims | is size of dimension array `dims`
  [in] | dims | is the array containing sizes of the dimension
  [in] | type | is the type of array to generate

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

Parameters

  [out] | arr | is the generated array of type s64
  [in] | val | is a complex value of each element in the generated array
  [in] | ndims | is size of dimension array `dims`
  [in] | dims | is the array containing sizes of the dimension

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

Parameters

  [out] | arr | is the generated array of type u64
  [in] | val | is a complex value of each element in the generated array
  [in] | ndims | is size of dimension array `dims`
  [in] | dims | is the array containing sizes of the dimension

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

Parameters

  [in] | val | is the value of each element of the array be genrated
  [in] | dims | is the dimensions of the array to be generated
  [in] | ty | is the type of the array

Returns
  array of size `dims`

Examples:
  adaptive_thresholding.cpp, bagging.cpp, basic.cpp, brain_segmentation.cpp, convolve.cpp, deep_belief_net.cpp, fft.cpp, filters.cpp, fractal.cpp, heston_model.cpp, histogram.cpp, image_editing.cpp, kmeans.cpp, knn.cpp, logistic_regression.cpp, monte_carlo_options.cpp, morphing.cpp, naive_bayes.cpp, neural_network.cpp, optical_flow.cpp, perceptron.cpp, plot3.cpp, pyramids.cpp, rainfall.cpp, rbm.cpp, softmax_regression.cpp, swe.cpp, and vectorize.cpp.

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

Parameters

  [in] | val | is the value of each element of the array to be generated
  [in] | d0 | is the size of the array to be generated
  [in] | ty | is the type of the array

Returns
  array of size `d0`

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

Parameters

  [in] | val | is the value of each element of the array to be generated
  [in] | d0 | is the number of rows of the array to be generated
  [in] | d1 | is the number of columns of the array to be generated
  [in] | ty | is the type of the array

Returns
  array of size `d0` x d1

array af::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`
| ) |  |

Parameters

  [in] | val | is the value of each element of the array to be generated
  [in] | d0 | is the size of the 1st dimension of the array to be generated
  [in] | d1 | is the size of the 2nd dimension of the array to be generated
  [in] | d2 | is the size of the 3rd dimension of the array to be generated
  [in] | ty | is the type of the array

Returns
  array of size `d0` x d1 x d2

array af::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`
| ) |  |

Parameters

  [in] | val | is the value of each element of the array to be generated
  [in] | d0 | is the size of the 1st dimension of the array to be generated
  [in] | d1 | is the size of the 2nd dimension of the array to be generated
  [in] | d2 | is the size of the 3rd dimension of the array to be generated
  [in] | d3 | is the size of the 4rd dimension of the array to be generated
  [in] | ty | is the type of the array

Returns
  array of size `d0` x d1 x d2 x d3