This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Sparse Matrix decomposition (row-major) + solve A*X=B

Tags: None
(comma "," separated)
daco
Registered Member
Posts
1
Karma
0
Dear all,

I'am trying to solve the system A*X=B, where A and B are sparse matrices in row-major format. I would expect the "SimplicialLDLT" decomposition of A to work in such cases, since the documentation requires only that
_MatrixType : the type of the sparse matrix A, it must be a SparseMatrix<>
.

Below a simple test-case leading to compiling errors.
Is something wrong with the syntax used? or is it a bug? Or simply, is the row-major format NOT supported for the decomposition of sparse matrices?

Thanks in advance for any suggestions!


Code: Select all
#define EIGEN_DEFAULT_TO_ROW_MAJOR

#include <iostream>
#include <Eigen/Dense>
#include <Eigen/Sparse>

using Eigen::SparseMatrix;
using Eigen::MatrixXd;
int main()
{
//SOLVING A * X = B

//row major A
SparseMatrix<double, Eigen::RowMajor> A_rM(2,2);
A_rM.coeffRef(0,0)=2;
A_rM.coeffRef(0,1)=1;
A_rM.coeffRef(1,0)=1;
A_rM.coeffRef(1,1)=2;

//col major A
SparseMatrix<double> A_cM;
A_cM=A_rM;

// Dense Matrices are row-major... using #define EIGEN_DEFAULT_TO_ROW_MAJOR
MatrixXd Xd, Bd;
Bd=MatrixXd::Random(2,2);

// rhs and solution - row major
SparseMatrix<double, Eigen::RowMajor> B_rM(2,2),X_rM(2,2);//(2,2);
B_rM=Bd.sparseView();

// rhs and solution - col major
SparseMatrix<double> B_cM(2,2),X_cM(2,2);//(2,2);
B_cM=Bd.sparseView();

// decompositions
Eigen::SimplicialLDLT< SparseMatrix<double,Eigen::RowMajor> > solver_rM(A_rM);
Eigen::SimplicialLDLT< SparseMatrix<double> > solver_cM(A_cM);

solver_rM.solve(B_rM);       //compiling;
X_rM=solver_rM.solve(B_rM);   //not compiling;
//X_rM=solver_cM.solve(B_rM);   //not compiling, as expected;

X_cM=solver_cM.solve(B_cM);   //compiling;
//X_cM=solver_rM.solve(B_cM);   //not compiling, as expected;

//Xd=solver_rM.solve(Bd);    //not compiling;
Xd=solver_cM.solve(Bd);      //compiling;

std::cout<<A_cM*X_cM-B_cM;

std::cout<<" end "<<std::endl;

return 0;

}




Compiling error:

‘THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES’ is not a member of ‘Eigen::internal::static_assertion<false>’ line 356, /..../SparseBlock.h
‘THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES’ is not a member of ‘Eigen::internal::static_assertion<false>’ line 365, /..../SparseBlock.h

could not convert ‘(& m)->Eigen::SparseMatrix<double, 1>::<anonymous>.Eigen::SparseMatrixBase<Derived>::adjoint [with Derived = Eigen::SparseMatrix<double, 1>, Eigen::SparseMatrixBase<Derived>::AdjointReturnType = Eigen::Transpose<const Eigen::SparseMatrix<double, 1> >]()’ from ‘const AdjointReturnType {aka const Eigen::Transpose<const Eigen::SparseMatrix<double, 1> >}’ to ‘Eigen::internal::traits<Eigen::SimplicialLDLT<Eigen::SparseMatrix<double, 1> > >::MatrixU {aka Eigen::SparseTriangularView<Eigen::Transpose<const Eigen::SparseMatrix<double> >, 6>}’ line 333, /..../SimplicialCholesky.h

could not convert ‘m’ from ‘const MatrixType {aka const Eigen::SparseMatrix<double, 1>}’ to ‘Eigen::internal::traits<Eigen::SimplicialLDLT<Eigen::SparseMatrix<double, 1> > >::MatrixL {aka Eigen::SparseTriangularView<Eigen::SparseMatrix<double>, 5>}’ line 332, /..../SimplicialCholesky.h
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
when solving with a sparse right hand side, the rhs matrix must be column major.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]