1 #ifndef STAN_MATH_PRIM_MAT_FUN_SORT_INDICES_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_SORT_INDICES_HPP
22 template <
bool ascending,
typename C>
23 class index_comparator {
33 explicit index_comparator(
const C& xs) : xs_(xs) { }
43 bool operator()(
int i,
int j)
const {
45 return xs_[i-1] < xs_[j-1];
47 return xs_[i-1] > xs_[j-1];
61 template <
bool ascending,
typename C>
62 std::vector<int> sort_indices(
const C& xs) {
63 typedef typename index_type<C>::type idx_t;
64 idx_t
size = xs.size();
65 std::vector<int> idxs;
67 for (idx_t i = 0; i <
size; ++i)
69 index_comparator<ascending, C> comparator(xs);
70 std::sort(idxs.begin(), idxs.end(), comparator);
int size(const std::vector< T > &x)
Return the size of the specified standard vector.