MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / sort_index

Function sort_index

src/backend/oneapi/sort_index.cpp:24–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22namespace oneapi {
23template<typename T>
24void sort_index(Array<T> &okey, Array<uint> &oval, const Array<T> &in,
25 const uint dim, bool isAscending) {
26 try {
27 // okey contains values, oval contains indices
28 okey = copyArray<T>(in);
29 oval = range<uint>(in.dims(), dim);
30 oval.eval();
31
32 switch (dim) {
33 case 0: kernel::sort0ByKey<T, uint>(okey, oval, isAscending); break;
34 case 1:
35 case 2:
36 case 3:
37 kernel::sortByKeyBatched<T, uint>(okey, oval, dim, isAscending);
38 break;
39 default: AF_ERROR("Not Supported", AF_ERR_NOT_SUPPORTED);
40 }
41
42 if (dim != 0) {
43 af::dim4 preorderDims = okey.dims();
44 af::dim4 reorderDims(0, 1, 2, 3);
45 reorderDims[dim] = 0;
46 preorderDims[0] = okey.dims()[dim];
47 for (uint i = 1; i <= dim; i++) {
48 reorderDims[i - 1] = i;
49 preorderDims[i] = okey.dims()[i - 1];
50 }
51
52 okey.setDataDims(preorderDims);
53 oval.setDataDims(preorderDims);
54
55 okey = reorder<T>(okey, reorderDims);
56 oval = reorder<uint>(oval, reorderDims);
57 }
58 } catch (const std::exception &ex) { AF_ERROR(ex.what(), AF_ERR_INTERNAL); }
59}
60
61#define INSTANTIATE(T) \
62 template void sort_index<T>(Array<T> & val, Array<uint> & idx, \

Callers 1

topkFunction · 0.70

Calls 3

dimsMethod · 0.45
evalMethod · 0.45
setDataDimsMethod · 0.45

Tested by

no test coverage detected