| 16 | |
| 17 | template<typename To, typename Ti> |
| 18 | void packData(Param<To> out, const af::dim4 od, const af::dim4 os, |
| 19 | CParam<Ti> in) { |
| 20 | To* out_ptr = out.get(); |
| 21 | |
| 22 | const af::dim4 id = in.dims(); |
| 23 | const af::dim4 is = in.strides(); |
| 24 | const Ti* in_ptr = in.get(); |
| 25 | |
| 26 | int id0_half = divup(id[0], 2); |
| 27 | bool odd_id0 = (id[0] % 2 == 1); |
| 28 | |
| 29 | for (int d3 = 0; d3 < (int)od[3]; d3++) { |
| 30 | for (int d2 = 0; d2 < (int)od[2]; d2++) { |
| 31 | for (int d1 = 0; d1 < (int)od[1]; d1++) { |
| 32 | for (int d0 = 0; d0 < (int)od[0] / 2; d0++) { |
| 33 | const dim_t oidx = |
| 34 | d3 * os[3] + d2 * os[2] + d1 * os[1] + d0 * 2; |
| 35 | |
| 36 | if (d0 < (int)id0_half && d1 < (int)id[1] && |
| 37 | d2 < (int)id[2] && d3 < (int)id[3]) { |
| 38 | const dim_t iidx = |
| 39 | d3 * is[3] + d2 * is[2] + d1 * is[1] + d0; |
| 40 | out_ptr[oidx] = (To)in_ptr[iidx]; |
| 41 | if (d0 == id0_half - 1 && odd_id0) |
| 42 | out_ptr[oidx + 1] = (To)0; |
| 43 | else |
| 44 | out_ptr[oidx + 1] = (To)in_ptr[iidx + id0_half]; |
| 45 | } else { |
| 46 | // Pad remaining elements with 0s |
| 47 | out_ptr[oidx] = (To)0; |
| 48 | out_ptr[oidx + 1] = (To)0; |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | template<typename To, typename Ti> |
| 57 | void padArray(Param<To> out, const af::dim4 od, const af::dim4 os, |
no test coverage detected