| 26 | |
| 27 | template<typename T> |
| 28 | void sort_index(Array<T> &okey, Array<uint> &oval, const Array<T> &in, |
| 29 | const uint dim, bool isAscending) { |
| 30 | // okey is values, oval is indices |
| 31 | okey = copyArray<T>(in); |
| 32 | oval = range<uint>(in.dims(), dim); |
| 33 | |
| 34 | switch (dim) { |
| 35 | case 0: |
| 36 | getQueue().enqueue(kernel::sort0ByKey<T, uint>, okey, oval, |
| 37 | isAscending); |
| 38 | break; |
| 39 | case 1: |
| 40 | case 2: |
| 41 | case 3: |
| 42 | getQueue().enqueue(kernel::sortByKeyBatched<T, uint>, okey, oval, |
| 43 | dim, isAscending); |
| 44 | break; |
| 45 | default: AF_ERROR("Not Supported", AF_ERR_NOT_SUPPORTED); |
| 46 | } |
| 47 | |
| 48 | if (dim != 0) { |
| 49 | af::dim4 preorderDims = okey.dims(); |
| 50 | af::dim4 reorderDims(0, 1, 2, 3); |
| 51 | reorderDims[dim] = 0; |
| 52 | preorderDims[0] = okey.dims()[dim]; |
| 53 | for (int i = 1; i <= static_cast<int>(dim); i++) { |
| 54 | reorderDims[i - 1] = i; |
| 55 | preorderDims[i] = okey.dims()[i - 1]; |
| 56 | } |
| 57 | |
| 58 | okey.setDataDims(preorderDims); |
| 59 | oval.setDataDims(preorderDims); |
| 60 | |
| 61 | okey = reorder<T>(okey, reorderDims); |
| 62 | oval = reorder<uint>(oval, reorderDims); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | #define INSTANTIATE(T) \ |
| 67 | template void sort_index<T>(Array<T> & val, Array<uint> & idx, \ |
nothing calls this directly
no test coverage detected