| 34 | } |
| 35 | |
| 36 | void af_wrap_common(af_array* out, const af_array in, const dim_t ox, |
| 37 | const dim_t oy, const dim_t wx, const dim_t wy, |
| 38 | const dim_t sx, const dim_t sy, const dim_t px, |
| 39 | const dim_t py, const bool is_column, bool allocate_out) { |
| 40 | ARG_ASSERT(0, out != 0); // *out (the af_array) can be null, but not out |
| 41 | ARG_ASSERT(1, in != 0); |
| 42 | |
| 43 | const ArrayInfo& info = getInfo(in); |
| 44 | const af_dtype in_type = info.getType(); |
| 45 | const dim4& in_dims = info.dims(); |
| 46 | const dim4 out_dims(ox, oy, in_dims[2], in_dims[3]); |
| 47 | |
| 48 | ARG_ASSERT(4, wx > 0); |
| 49 | ARG_ASSERT(5, wy > 0); |
| 50 | ARG_ASSERT(6, sx > 0); |
| 51 | ARG_ASSERT(7, sy > 0); |
| 52 | |
| 53 | const dim_t nx = (ox + 2 * px - wx) / sx + 1; |
| 54 | const dim_t ny = (oy + 2 * py - wy) / sy + 1; |
| 55 | |
| 56 | const dim_t patch_size = is_column ? in_dims[0] : in_dims[1]; |
| 57 | const dim_t num_patches = is_column ? in_dims[1] : in_dims[0]; |
| 58 | |
| 59 | DIM_ASSERT(1, patch_size == wx * wy); |
| 60 | DIM_ASSERT(1, num_patches == nx * ny); |
| 61 | |
| 62 | if (allocate_out) { *out = createHandleFromValue(out_dims, 0.0, in_type); } |
| 63 | |
| 64 | // The out pointer can be passed in to the function by the user |
| 65 | DIM_ASSERT(0, getInfo(*out).dims() == out_dims); |
| 66 | |
| 67 | // clang-format off |
| 68 | switch(in_type) { |
| 69 | case f32: wrap<float >(out, in, wx, wy, sx, sy, px, py, is_column); break; |
| 70 | case f64: wrap<double >(out, in, wx, wy, sx, sy, px, py, is_column); break; |
| 71 | case c32: wrap<cfloat >(out, in, wx, wy, sx, sy, px, py, is_column); break; |
| 72 | case c64: wrap<cdouble>(out, in, wx, wy, sx, sy, px, py, is_column); break; |
| 73 | case s32: wrap<int >(out, in, wx, wy, sx, sy, px, py, is_column); break; |
| 74 | case u32: wrap<uint >(out, in, wx, wy, sx, sy, px, py, is_column); break; |
| 75 | case s64: wrap<intl >(out, in, wx, wy, sx, sy, px, py, is_column); break; |
| 76 | case u64: wrap<uintl >(out, in, wx, wy, sx, sy, px, py, is_column); break; |
| 77 | case s16: wrap<short >(out, in, wx, wy, sx, sy, px, py, is_column); break; |
| 78 | case u16: wrap<ushort >(out, in, wx, wy, sx, sy, px, py, is_column); break; |
| 79 | case s8: wrap<schar >(out, in, wx, wy, sx, sy, px, py, is_column); break; |
| 80 | case u8: wrap<uchar >(out, in, wx, wy, sx, sy, px, py, is_column); break; |
| 81 | case b8: wrap<char >(out, in, wx, wy, sx, sy, px, py, is_column); break; |
| 82 | default: TYPE_ERROR(1, in_type); |
| 83 | } |
| 84 | // clang-format on |
| 85 | } |
| 86 | |
| 87 | af_err af_wrap(af_array* out, const af_array in, const dim_t ox, const dim_t oy, |
| 88 | const dim_t wx, const dim_t wy, const dim_t sx, const dim_t sy, |
no test coverage detected