SparseLU (not sure whether this is limited to sparseLU) appears to take compressed RowMajor while treating it as ColMajor (i.e. skips conversion to ColMajor)
According to the online docs of Eigen 3.3.90 the sparseLU solver should convert a SparseMatrix into a compressed ColMajor sparseMatrix before atempting to solve when either the sparseMatrix is not compressed or not ColMajor.
I've created a small example (in my personal attempt to learn Eigen): A = [[1.0, 0.0001]; [0.0, 1.0]] (here the only non diagonal entry '0.0001' is in the top right corner) and b = [[1.1]; [3.14]] in two different ways as RowMajor sparseMatrix:
- this->mat = new Map<SparseMatrix<Scalar_t, RowMajor>> (2, 2, 3, &indPtr[0], &indices[0], &data[0]);
where
double data[] = {1.0, 0.0001, 1.0};
int indices[] = {0, 1, 1}; // inner indices
int indPtr[] = {0, 2, 3}; // outer indices
double b[] = {1.1, 3.14}; Note: this way this->mat automatically becomes a compressed sparseMatrix - this->mat = new SparseMatrix<Scalar_t, RowMajor>(2, 2);
this->mat->insert(0, 0) = 1.0;
this->mat->insert(0, 1) = 0.0001;
this->mat->insert(1, 1) = 1.0;
this->mat->makeCompressed();
Afterwards I've created an SparseLU solver instance:
this->LUInstance = new SparseLU<SparseMatrix<Scalar_t, RowMajor>>();
feed it with my matrix:
this->LUInstance->compute(*(this->mat));
create the RHS-vector as Eigen-data-structure:
Map<Matrix<Scalar_t, Dynamic, 1>> b2(&b[0], this->rows);
and solve my system:
Matrix<Scalar_t, Dynamic, 1> result = this->LUInstance->solve(b2);
The result 'result' then becomes: [[11000]; [3.14]] and is awfully wrong.
This does not happen when I initialize the Matrix this->mat by the 2. option, but skipping "this->mat->makeCompressed();".
This led me to the speculation that SparseLU take the RowMajor matrix without changing and copying it into ColMajor.