lacking info() in PartialPivLU etc.: more consistent API?
Describe the feature you would like to be implemented.
ColPivHouseholderQR has the info member function, though it always returns Success. The documentation says this is for "compatibility with other factorization routines":
https://eigen.tuxfamily.org/dox/classEigen_1_1ColPivHouseholderQR.html#a5c756a789175197cab3eff3a3e479ef2 https://gitlab.com/libeigen/eigen/-/blob/d271a7d545f83f75755a9c2f20ec5e0e4fe5a8a8/Eigen/src/QR/ColPivHouseholderQR.h#L407-417
But, other factorization classes PartialPivLU/FullPivLU etc., or even HouseholderQR/FullPivHouseholderQR in the same QR module, do not have the info member function.
Would it be more reasonable if such classes for matrix decomposition and solvers have info() giving always Success?
Would such a feature be useful for other users? Why?
I have some helper function (I guess others may write more or less similar code), which essentially does something like
template <typename Solver, typename Matrix, typename Vector>
void solve_system(Solver& solver, const Matrix& a, const Vector& b, Vector& x) {
// This function solves a x = b with the given solver.
solver.compute(a);
if (solver.info() != Eigen::ComputationInfo::Success) {
std::cerr << "error: decomposition failed: " << solver.info() << std::endl;
std::exit(1);
}
x = solver.solve(b);
if (solver.info() != Eigen::ComputationInfo::Success) {
std::cerr << "error: solving failed: " << solver.info() << std::endl;
std::exit(1);
}
}
This was at the beginning intended for iterative solvers, but it also works with some dense matrix solvers:
using Matrix = ...;
using Vector = ...;
Matrix a{{ ... }, ..., { ... }};
Vector b{{ ...}};
Eigen::ColPivHouseholderQR<Matrix> solver;
solve_system(solver, a, b, x);
Another example:
Eigen::BDCSVD<Matrix> solver(a.cols(), a.rows(), Eigen::ComputeThinU | Eigen::ComputeThinV);
(By the way, I see no BDCSVD constructor with one argument for computationOptions and so I have to use the constructor with the memory preallocation size.)
But compiling fails with
Eigen::PartialPivLU<Matrix> solver;
due to the missing info().
As a workaround, the above solve_system can be modified with SFINAE in such a way that info() is called only if Solver has it, but it complicates the code a bit.
Any hints on how to implement the requested feature?
Implementation options might be
- to put boilerplate code of
info()for all such classes (straightforward to write/understand), - to add a default
info()givingSuccessinSolverBase(elegant but may be relatively less readable due to possible metaprogramming).
Additional resources
None.