| 60 | } |
| 61 | |
| 62 | void af_transform_common(af_array *out, const af_array in, const af_array tf, |
| 63 | const dim_t odim0, const dim_t odim1, |
| 64 | const af_interp_type method, const bool inverse, |
| 65 | bool allocate_out) { |
| 66 | ARG_ASSERT(0, out != 0); // *out (the af_array) can be null, but not out |
| 67 | ARG_ASSERT(1, in != 0); |
| 68 | ARG_ASSERT(2, tf != 0); |
| 69 | |
| 70 | const ArrayInfo &t_info = getInfo(tf); |
| 71 | const ArrayInfo &i_info = getInfo(in); |
| 72 | |
| 73 | const dim4 &idims = i_info.dims(); |
| 74 | const dim4 &tdims = t_info.dims(); |
| 75 | const af_dtype itype = i_info.getType(); |
| 76 | |
| 77 | // Assert type and interpolation |
| 78 | ARG_ASSERT(2, t_info.getType() == f32); |
| 79 | ARG_ASSERT(5, method == AF_INTERP_NEAREST || method == AF_INTERP_BILINEAR || |
| 80 | method == AF_INTERP_BILINEAR_COSINE || |
| 81 | method == AF_INTERP_BICUBIC || |
| 82 | method == AF_INTERP_BICUBIC_SPLINE || |
| 83 | method == AF_INTERP_LOWER); |
| 84 | |
| 85 | // Assert dimesions |
| 86 | // Image can be 2D or higher |
| 87 | DIM_ASSERT(1, idims.elements() > 0); |
| 88 | DIM_ASSERT(1, idims.ndims() >= 2); |
| 89 | |
| 90 | // Transform can be 3x2 for affine transform or 3x3 for perspective |
| 91 | // transform |
| 92 | DIM_ASSERT(2, (tdims[0] == 3 && (tdims[1] == 2 || tdims[1] == 3))); |
| 93 | |
| 94 | // If transform is batched, the output dimensions must be specified |
| 95 | if (tdims[2] * tdims[3] > 1) { |
| 96 | ARG_ASSERT(3, odim0 > 0); |
| 97 | ARG_ASSERT(4, odim1 > 0); |
| 98 | } |
| 99 | |
| 100 | // If idims[2] > 1 and tdims[2] > 1, then both must be equal |
| 101 | // else at least one of them must be 1 |
| 102 | if (tdims[2] != 1 && idims[2] != 1) { |
| 103 | DIM_ASSERT(2, idims[2] == tdims[2]); |
| 104 | } else { |
| 105 | DIM_ASSERT(2, idims[2] == 1 || tdims[2] == 1); |
| 106 | } |
| 107 | |
| 108 | // If idims[3] > 1 and tdims[3] > 1, then both must be equal |
| 109 | // else at least one of them must be 1 |
| 110 | if (tdims[3] != 1 && idims[3] != 1) { |
| 111 | DIM_ASSERT(2, idims[3] == tdims[3]); |
| 112 | } else { |
| 113 | DIM_ASSERT(2, idims[3] == 1 || tdims[3] == 1); |
| 114 | } |
| 115 | |
| 116 | const bool perspective = (tdims[1] == 3); |
| 117 | dim_t o0 = odim0, o1 = odim1, o2 = 0, o3 = 0; |
| 118 | if (odim0 * odim1 == 0) { |
| 119 | o0 = idims[0]; |
no test coverage detected