3 #ifndef FORPY_UTIL_ARGSORT_H_ 4 #define FORPY_UTIL_ARGSORT_H_ 11 #include "../global.h" 24 static std::vector<size_t>
argsort(
const T *v,
const size_t n) {
26 std::vector<size_t> idx(n);
27 std::iota(idx.begin(), idx.end(), 0);
30 std::sort(idx.begin(), idx.end(),
31 [&v](
size_t i1,
size_t i2) {
return v[i1] < v[i2]; });
45 static std::vector<size_t>
argsort(
const std::vector<T> &v) {
46 return argsort(&v[0], v.size());
49 #endif // FORPY_UTIL_ARGSORT_H_
static std::vector< size_t > argsort(const T *v, const size_t n)
Highly efficient argsort realized with few STL commands.