| 36 | } |
| 37 | |
| 38 | af_err af_transpose(af_array* out, af_array in, const bool conjugate) { |
| 39 | try { |
| 40 | const ArrayInfo& info = getInfo(in); |
| 41 | af_dtype type = info.getType(); |
| 42 | af::dim4 dims = info.dims(); |
| 43 | |
| 44 | if (dims.elements() == 0) { return af_retain_array(out, in); } |
| 45 | |
| 46 | if (dims[0] == 1 || dims[1] == 1) { |
| 47 | af::dim4 outDims(dims[1], dims[0], dims[2], dims[3]); |
| 48 | if (conjugate) { |
| 49 | af_array temp = 0; |
| 50 | AF_CHECK(af_conjg(&temp, in)); |
| 51 | AF_CHECK(af_moddims(out, temp, outDims.ndims(), outDims.get())); |
| 52 | AF_CHECK(af_release_array(temp)); |
| 53 | return AF_SUCCESS; |
| 54 | } else { |
| 55 | // for a vector OR a batch of vectors |
| 56 | // we can use modDims to transpose |
| 57 | AF_CHECK(af_moddims(out, in, outDims.ndims(), outDims.get())); |
| 58 | return AF_SUCCESS; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | af_array output; |
| 63 | switch (type) { |
| 64 | case f32: output = trs<float>(in, conjugate); break; |
| 65 | case c32: output = trs<cfloat>(in, conjugate); break; |
| 66 | case f64: output = trs<double>(in, conjugate); break; |
| 67 | case c64: output = trs<cdouble>(in, conjugate); break; |
| 68 | case b8: output = trs<char>(in, conjugate); break; |
| 69 | case s32: output = trs<int>(in, conjugate); break; |
| 70 | case u32: output = trs<uint>(in, conjugate); break; |
| 71 | case s8: output = trs<schar>(in, conjugate); break; |
| 72 | case u8: output = trs<uchar>(in, conjugate); break; |
| 73 | case s64: output = trs<intl>(in, conjugate); break; |
| 74 | case u64: output = trs<uintl>(in, conjugate); break; |
| 75 | case s16: output = trs<short>(in, conjugate); break; |
| 76 | case u16: output = trs<ushort>(in, conjugate); break; |
| 77 | case f16: output = trs<half>(in, conjugate); break; |
| 78 | default: TYPE_ERROR(1, type); |
| 79 | } |
| 80 | std::swap(*out, output); |
| 81 | } |
| 82 | CATCHALL; |
| 83 | |
| 84 | return AF_SUCCESS; |
| 85 | } |
| 86 | |
| 87 | template<typename T> |
| 88 | static inline void transpose_inplace(af_array in, const bool conjugate) { |
no test coverage detected