Registered Member
|
Hello,
Is it possible to cast the result of eigen solvers to real (double or float) ? For example, in the above example, m_solved_val if of type EigenvalueType which is a matrix of complex numbers. But it appears that the matrix contains only real numbers. For your information, this is the example of function "eigen" in R. Best Regards, R. Trépos
|
Moderator
|
you can simply do:
VectorXd m_solved_val = m_solve.eigenvalues().cast<double>(); also note that the eigen solver m_solve already stores the eigenvalues/vectors for you, so you can directly use them in expressions without overhead, e.g.: smallest_abs_eigenvalue = m_solve.eigenvalues().cwise().abs().minCoeff(); |
Registered Member
|
Thanks you for your answer
However, with this line : VectorXd m_solved_val_d = m_solve.eigenvalues().cast<double>(); I have the compile error : ... /home/rtrepos/usr/src/vle_dev/eigen_utils/src/test_eigen_utils.cpp:77: instantiated from here /usr/include/eigen2/Eigen/src/Core/Functors.h:225: error: invalid static_cast from type ‘const std::complex<double>’ to type ‘double’ make[2]: *** [src/CMakeFiles/test_eigen_utils.dir/test_eigen_utils.cpp.o] Erreur 1 make[1]: *** [src/CMakeFiles/test_eigen_utils.dir/all] Erreur 2 Could this be a problem of a "const" ? |
Registered Member
|
For the moment I think you can try
In the future it would be great if we were able to cast from complex<double> to double by stripping the imaginary part. - Hauke |
Registered Member
|
Ok it works,
thank you for your time.. I have other questions but I have to create new topics for that R. Trépos |
Moderator
|
sorry I'm stupid ! Actually you can already strip the imaginary part:
m_solve.eigenvalues().real(); that's faster than constructing the "pseudoEigenvalueMatrix". |
Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]