'Eigen householderQr gives nan/infs on specific singular matrix
I tried to solve linear system using colPivHouseholderQr, but received nans/infs for some specific matrices.
Here is example:
Eigen::MatrixXd lhs {
{0. , 0. , 0. , 0. , 0. , 0.293596,
0.32315 , 0. },
{0. , 0. , 0. , 0. , 0. , 0.293596,
0.32315 , 0. },
{0. , 0. , 0. , 0. , 0. , 0.293596,
0.32315 , 0. },
{0. , 0. , 0. , 0. , 0. , 0.293596,
0.32315 , 0. },
{0. , 0. , 0. , 0. , 0. , 0.293596,
0.32315 , 0. },
{0.293596, 0.293596, 0.293596, 0.293596, 0.293596, 0. ,
0.31533 , 0.293596},
{0.32315 , 0.32315 , 0.32315 , 0.32315 , 0.32315 , 0.31533 ,
0. , 0.32315 },
{0. , 0. , 0. , 0. , 0. , 0.293596,
0.32315 , 0. }
};
Eigen::VectorXd rhs = Eigen::VectorXd::Ones(lhs.rows());
const Eigen::VectorXd solution = lhs.householderQr().solve(rhs);
std::cout << solution << std::endl;
This code prints something like:
-nan -nan -nan -nan -nan -nan -nan inf
If i change solver to, for example, colPivHouseholderQr i get valid solution. I also tried to perform SVD on my original matrix, and to run householderQr only on diagonal system with singular values on diagonal (including zeros), and householderQr works ok, so at least it able to deal with singular matrices.
According to documentation householderQr should work with any matrix. So my question is - is it intended behaviour, or my mistake or bug in documentation/implementation?
My Eigen version is 3.4.0, my compiler is GCC 11.2.0
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
