I want to use SparseQR or SparseLU method for solving linear systems with sparse matrices. I am using Eigen Library for that purpose. The problem is that this methods gives error an the code doesnt work. I am programing in Eclipse C++, with MinGW compiler
I have used the bicgstab method from the Eigen Library and it is working, but now with the Sparse methods errors appear.
This is the code I want to use for solving linear systems, just changing the method name and one of the parameters it works for other methods, but not for sparse methods
SparseQR<MatrixXd, NaturalOrdering<int>> solver;
solver.analyzePattern(A);
solver.factorize(A);
x = solver.solve(y);
x,A and y are of the class MatrixXd.
This code works for the method bicgstab, and the syntaxis is the same. The problem is that the following error appears:
src\/src/SparseQR/SparseQR.h:381:66: error: 'const class Eigen::SparseQR<Eigen::Matrix<double, -0x000000001, -0x000000001>,Eigen::NaturalOrdering<int> >::MatrixType' has no member named 'isCompressed' src\/src/SparseQR/SparseQR.h:381:66: error: 'const class Eigen::SparseQR<Eigen::Matrix<double, -0x000000001, -0x000000001>,Eigen::NaturalOrdering<int> >::MatrixType' has no member named 'outerIndexPtr'
and I dont know hot fix it.
If you have any idea of a possible solution I would really appreciate it. Thanks for your time
As said in the comments, SparseQR
only works with sparse matrices. If for some reason your input matrix A
is passed as a dense matrix, you could convert it using A.sparseView()
, but you should really prefer storing it as a (compressed) sparse matrix in the first place. Also notice that the template parameter of SparseQR
must be a SparseMatrix
:
void foo(Eigen::MatrixXd const &A, Eigen::VectorXd const &y, Eigen::VectorXd& x)
{
Eigen::SparseQR<Eigen::SparseMatrix<double>, Eigen::NaturalOrdering<int> > solver;
solver.compute(A.sparseView());
x = solver.solve(y);
}
If your matrix A
in fact is dense (or "not very sparse") it is usually much more efficient to just use a dense solver, e.g.
void foo(Eigen::MatrixXd const &A, Eigen::VectorXd const &y, Eigen::VectorXd& x)
{
Eigen::FullPivHouseholderQR<Eigen::MatrixXd> solver;
solver.compute(A);
x = solver.solve(y);
}