| 29 | |
| 30 | template <typename T, typename Cmp = std::less<T>> |
| 31 | std::vector<int64_t> ArgSort(const std::vector<T>& values, Cmp&& cmp = {}) { |
| 32 | std::vector<int64_t> indices(values.size()); |
| 33 | std::iota(indices.begin(), indices.end(), 0); |
| 34 | std::sort(indices.begin(), indices.end(), |
| 35 | [&](int64_t i, int64_t j) -> bool { return cmp(values[i], values[j]); }); |
| 36 | return indices; |
| 37 | } |
| 38 | |
| 39 | template <typename T> |
| 40 | size_t Permute(const std::vector<int64_t>& indices, std::vector<T>* values) { |