A high-performance general-purpose compute library

Cast an array from one type to another. More...

Functions

AFAPI af_err af_cast (af_array *out, const af_array in, const af_dtype type)
 C Interface to cast an array from one type to another. More...
 

Detailed Description

Cast an array from one type to another.

Function Documentation

◆ af_cast()

AFAPI af_err af_cast ( af_array out,
const af_array  in,
const af_dtype  type 
)

C Interface to cast an array from one type to another.

This function casts an af_array object from one type to another. If the type of the original array is the same as type then the same array is returned.

Consecutive casting operations may be may be optimized out if the original type of the af_array is the same as the final type. For example if the original type is f64, which is cast to f32 and then back to f64, then the cast to f32 is skipped and that operation will NOT be performed by ArrayFire. The following table shows which casts will be optimized out. outer -> inner -> outer

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

If you want to avoid this behavior use, af_eval after the first cast operation. This will ensure that the cast operation is performed on the af_array.

Parameters
[out]outvalues in the specified type
[in]ininput
[in]typetarget data type af_dtype
Returns
AF_SUCCESS, if function returns successfully, else an af_err code is given