https://github.com/HTDerekLiu/surface_multigrid_code
Revision db5c7fa56b977d3f1ac0ac11ed875f75229f2d27 authored by eriszhang on 08 August 2021, 03:27:39 UTC, committed by eriszhang on 08 August 2021, 03:27:39 UTC
1 parent d366192
Tip revision: db5c7fa56b977d3f1ac0ac11ed875f75229f2d27 authored by eriszhang on 08 August 2021, 03:27:39 UTC
add
add
Tip revision: db5c7fa
sort_vec.cpp
#include "sort_vec.h"
void sort_vec(
const Eigen::VectorXd & vec,
Eigen::VectorXd & sorted_vec,
Eigen::VectorXi & ind)
{
// https://www.programmersought.com/article/343692646/
using namespace Eigen;
using namespace std;
ind=VectorXi::LinSpaced(vec.size(),0,vec.size()-1);//[0 1 2 3 ... N-1]
auto rule=[vec](int i, int j)->bool{
return vec(i)<vec(j);
}; // regular expression, as a predicate of sort
std::sort(ind.data(),ind.data()+ind.size(),rule);
//The data member function returns a pointer to the first element of VectorXd, similar to begin()
sorted_vec.resize(vec.size());
for(int i=0;i<vec.size();i++){
sorted_vec(i)=vec(ind(i));
}
}
void sort_vec(
const Eigen::VectorXi & vec,
Eigen::VectorXi & sorted_vec,
Eigen::VectorXi & ind)
{
// https://www.programmersought.com/article/343692646/
using namespace Eigen;
using namespace std;
ind=VectorXi::LinSpaced(vec.size(),0,vec.size()-1);//[0 1 2 3 ... N-1]
auto rule=[vec](int i, int j)->bool{
return vec(i)<vec(j);
}; // regular expression, as a predicate of sort
std::sort(ind.data(),ind.data()+ind.size(),rule);
//The data member function returns a pointer to the first element of VectorXd, similar to begin()
sorted_vec.resize(vec.size());
for(int i=0;i<vec.size();i++){
sorted_vec(i)=vec(ind(i));
}
}
Computing file changes ...