MCPcopy Create free account
hub / github.com/numpy/numpy / KEY_OF

Function KEY_OF

numpy/core/src/npysort/radixsort.cpp:18–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16// Reference: https://github.com/eloj/radix-sorting#-key-derivation
17template <class T, class UT>
18UT
19KEY_OF(UT x)
20{
21 // Floating-point is currently disabled.
22 // Floating-point tests succeed for double and float on macOS but not on
23 // Windows/Linux. Basic sorting tests succeed but others relying on sort
24 // fail. Possibly related to floating-point normalisation or multiple NaN
25 // reprs? Not sure.
26 if (std::is_floating_point<T>::value) {
27 // For floats, we invert the key if the sign bit is set, else we invert
28 // the sign bit.
29 return ((x) ^ (-((x) >> (sizeof(T) * 8 - 1)) |
30 ((UT)1 << (sizeof(T) * 8 - 1))));
31 }
32 else if (std::is_signed<T>::value) {
33 // For signed ints, we flip the sign bit so the negatives are below the
34 // positives.
35 return ((x) ^ ((UT)1 << (sizeof(UT) * 8 - 1)));
36 }
37 else {
38 return x;
39 }
40}
41
42template <class T>
43static inline npy_ubyte

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected