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

Function sort0Iterative

src/backend/cpu/kernel/sort.hpp:24–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22// Based off of http://stackoverflow.com/a/12399290
23template<typename T>
24void sort0Iterative(Param<T> val, bool isAscending) {
25 // initialize original index locations
26 T *val_ptr = val.get();
27
28 std::function<bool(T, T)> op = std::greater<T>();
29 if (isAscending) { op = std::less<T>(); }
30
31 T *comp_ptr = nullptr;
32 for (dim_t w = 0; w < val.dims(3); w++) {
33 dim_t valW = w * val.strides(3);
34 for (dim_t z = 0; z < val.dims(2); z++) {
35 dim_t valWZ = valW + z * val.strides(2);
36 for (dim_t y = 0; y < val.dims(1); y++) {
37 dim_t valOffset = valWZ + y * val.strides(1);
38
39 comp_ptr = val_ptr + valOffset;
40 std::sort(comp_ptr, comp_ptr + val.dims(0), op);
41 }
42 }
43 }
44 return;
45}
46
47} // namespace kernel
48} // namespace cpu

Callers

nothing calls this directly

Calls 4

sortFunction · 0.50
getMethod · 0.45
dimsMethod · 0.45
stridesMethod · 0.45

Tested by

no test coverage detected