Eigenvalues from SelfAdjointEigenSolver are not sorted with -ffinite-math-only
Summary
When compiling with -ffinite-math-only, the vector of eigenvalues returned from SelfAdjointEigenSolver is not sorted in increasing order, as expected per the documentation.
Environment
- Operating System : Linux
- Architecture : x86-64
- Eigen Version : master(dd563675)
- Compiler Version : clang (trunk)
- Compile Flags : -O2 -ffinite-math-only
Minimal Example
https://godbolt.org/z/Khrvs3vob
const Eigen::Matrix3d A{
{0.76669696185107039, -0.30136429161212552, 0.97174865518595022},
{0.25272530616350553, 0.044219304710036322, 0.85537920641446874},
{-0.73693255780683664, 0.500251164429387, -0.6416854079510852},
};
const Eigen::Matrix3d P = A.transpose()*A;
Eigen::SelfAdjointEigenSolver<Eigen::Matrix3d> solver;
solver.compute(P);
const Eigen::Vector3d eigenvalues = solver.eigenvalues();
// Alternatively
// const Eigen::Vector3d eigenvalues = P.selfAdjointView<Eigen::Lower>().eigenvalues();
// eigenvalues is not sorted in increasing order, as it should according to
// https://libeigen.gitlab.io/docs/classEigen_1_1SelfAdjointEigenSolver.html#ac7ed3481c19457b9b2f6e5c9fbfa1f88
std::cout << eigenvalues << std::endl; // Outputs: 0.259736, 0.00336527, 3.36242
Edited by Fredrik Bjerkås