Skip to content
Snippets Groups Projects
Commit 3126f59d authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

new function sorted_indices to replace gsl_sort

parent 9917fd15
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,8 @@
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
......@@ -69,3 +71,13 @@ bool triv::is_equidist( double *step, const vector<double>& V )
return false;
return true;
}
//! Compute array of sorted indices.
vector<size_t> triv::sorted_indices(vector<double> const& V)
{
vector<size_t> I(V.size());
iota(begin(I), end(I), static_cast<size_t>(0));
sort( begin(I), end(I), [&](size_t a, size_t b) { return V[a] < V[b]; } );
return I;
}
......@@ -14,4 +14,5 @@ namespace triv {
double tolabs=1e-100, double tolrel=1e-10 );
bool is_ascending( const vector<double>& V );
bool is_equidist( double *step, const vector<double>& V );
vector<size_t> sorted_indices(vector<double> const& V);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment