MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / cast

Function cast

src/api/c/cast.cpp:37–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35using detail::ushort;
36
37static af_array cast(const af_array in, const af_dtype type) {
38 const ArrayInfo& info = getInfo(in, false);
39
40 if (info.getType() == type) { return retain(in); }
41
42 if (info.isSparse()) {
43 switch (type) {
44 case f32: return getHandle(castSparse<float>(in));
45 case f64: return getHandle(castSparse<double>(in));
46 case c32: return getHandle(castSparse<cfloat>(in));
47 case c64: return getHandle(castSparse<cdouble>(in));
48 default: TYPE_ERROR(2, type);
49 }
50 } else {
51 switch (type) {
52 case f32: return getHandle(castArray<float>(in));
53 case f64: return getHandle(castArray<double>(in));
54 case c32: return getHandle(castArray<cfloat>(in));
55 case c64: return getHandle(castArray<cdouble>(in));
56 case s32: return getHandle(castArray<int>(in));
57 case u32: return getHandle(castArray<uint>(in));
58 case s8: return getHandle(castArray<schar>(in));
59 case u8: return getHandle(castArray<uchar>(in));
60 case b8: return getHandle(castArray<char>(in));
61 case s64: return getHandle(castArray<intl>(in));
62 case u64: return getHandle(castArray<uintl>(in));
63 case s16: return getHandle(castArray<short>(in));
64 case u16: return getHandle(castArray<ushort>(in));
65 case f16: return getHandle(castArray<half>(in));
66 default: TYPE_ERROR(2, type);
67 }
68 }
69}
70
71af_err af_cast(af_array* out, const af_array in, const af_dtype type) {
72 try {

Callers 2

af_castFunction · 0.70
half_castFunction · 0.50

Calls 4

retainFunction · 0.85
isSparseMethod · 0.80
getHandleFunction · 0.70
getTypeMethod · 0.45

Tested by

no test coverage detected