| 30 | |
| 31 | template<typename T> |
| 32 | Array<T> index(const Array<T>& in, const af_index_t idxrs[]) { |
| 33 | vector<bool> isSeq(4); |
| 34 | vector<af_seq> seqs(4, af_span); |
| 35 | // create seq vector to retrieve output |
| 36 | // dimensions, offsets & offsets |
| 37 | for (unsigned x = 0; x < isSeq.size(); ++x) { |
| 38 | if (idxrs[x].isSeq) { |
| 39 | af_seq seq = idxrs[x].idx.seq; |
| 40 | // Handle af_span as a sequence that covers the complete axis |
| 41 | if (seq.begin == af_span.begin && seq.end == af_span.end && |
| 42 | seq.step == af_span.step) { |
| 43 | seqs[x] = af_seq{0, (double)(in.dims()[x] - 1), 1}; |
| 44 | } else { |
| 45 | seqs[x] = seq; |
| 46 | } |
| 47 | } |
| 48 | isSeq[x] = idxrs[x].isSeq; |
| 49 | } |
| 50 | |
| 51 | // retrieve |
| 52 | dim4 oDims = toDims(seqs, in.dims()); |
| 53 | |
| 54 | vector<Array<uint>> idxArrs(4, createEmptyArray<uint>(dim4())); |
| 55 | // look through indexs to read af_array indexs |
| 56 | for (unsigned x = 0; x < isSeq.size(); ++x) { |
| 57 | if (!isSeq[x]) { |
| 58 | idxArrs[x] = castArray<uint>(idxrs[x].idx.arr); |
| 59 | // set output array ith dimension value |
| 60 | oDims[x] = idxArrs[x].elements(); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | Array<T> out = createEmptyArray<T>(oDims); |
| 65 | vector<CParam<uint>> idxParams(idxArrs.begin(), idxArrs.end()); |
| 66 | |
| 67 | getQueue().enqueue(kernel::index<T>, out, in, in.getDataDims(), |
| 68 | std::move(isSeq), std::move(seqs), std::move(idxParams)); |
| 69 | |
| 70 | return out; |
| 71 | } |
| 72 | |
| 73 | #define INSTANTIATE(T) \ |
| 74 | template Array<T> index<T>(const Array<T>& in, const af_index_t idxrs[]); |
no test coverage detected