| 69 | } |
| 70 | |
| 71 | af_err af_cast(af_array* out, const af_array in, const af_dtype type) { |
| 72 | try { |
| 73 | const ArrayInfo& info = getInfo(in, false); |
| 74 | |
| 75 | af_dtype inType = info.getType(); |
| 76 | if ((inType == c32 || inType == c64) && |
| 77 | (type == f32 || type == f64 || type == f16)) { |
| 78 | AF_ERROR( |
| 79 | "Casting is not allowed from complex (c32/c64) to real " |
| 80 | "(f16/f32/f64) types.\n" |
| 81 | "Use abs, real, imag etc to convert complex to floating type.", |
| 82 | AF_ERR_TYPE); |
| 83 | } |
| 84 | |
| 85 | dim4 idims = info.dims(); |
| 86 | if (idims.elements() == 0) { |
| 87 | return af_create_handle(out, 0, nullptr, type); |
| 88 | } |
| 89 | |
| 90 | af_array res = cast(in, type); |
| 91 | |
| 92 | std::swap(*out, res); |
| 93 | } |
| 94 | CATCHALL; |
| 95 | |
| 96 | return AF_SUCCESS; |
| 97 | } |
no test coverage detected