If someone needs this, here how I did it
Eigen::EigenSolver<Eigen::MatrixXf> eigensolver;
eigensolver.compute(covmat);
Eigen::VectorXf eigen_values = eigensolver.eigenvalues().real();
Eigen::MatrixXf eigen_vectors = eigensolver.eigenvectors().real();
std::vector<std::tuple<float, Eigen::VectorXf>> eigen_vectors_and_values;
for(int i=0; i<eigen_values.size(); i++){
std::tuple<float, Eigen::VectorXf> vec_and_val(eigen_values[i], eigen_vectors.row(i));
eigen_vectors_and_values.push_back(vec_and_val);
}
std::sort(eigen_vectors_and_values.begin(), eigen_vectors_and_values.end(),
[&](const std::tuple<float, Eigen::VectorXf>& a, const std::tuple<float, Eigen::VectorXf>& b) -> bool{
return std::get<0>(a) <= std::get<0>(b);
});
int index = 0;
for(auto const vect : eigen_vectors_and_values){
eigen_values(index) = std::get<0>(vect);
eigen_vectors.row(index) = std::get<1>(vect);
index++;
}
Here covmat in which eigenvectors and eigenvalues to be found out. Also, I sort them according to descending order which we do the most of the times. One important thing is that when you selecting which eigendecomposition technique is to be used to be careful because those are not doing the same way. You may find out more information here [https://eigen.tuxfamily.org/dox/group__Eigenvalues__Module.html ]
Eigen
is a headers only package ( so technically, you won't need to link to any library ) and here is an example from the documentation for calculating eigenvalues. – user6764549