Are there aliasing issues when using Eigen’s SparseLU to solve in place?

  aliasing, c++, eigen

I’m using Eigen, trying to minimize memory allocations and would like to do something like this:

Eigen::SparseMatrix A(...);
A.setFromTriplets(...);
Eigen::MatrixXd X = <here some data>;
Eigen::SparseLU<Eigen::SparseMatrix<double>> solver;
solver.compute(A);


// here comes the crucial thing I want to do:
X = solver.solve(X);

The documentation doesn’t say much about it. I’ve tested it with many matrices A and vectors for X, which seems to work, but not yet for matrices X.
I also havn’t tested whether Eigen detects this and then silently allocates a temporary.

Also I would feel much safer knowing that this is supposed to work or not supposed to work.

As SparseLU has methods matrixL() and matrixU() which in turn have methods solveInPlace(), I guess the answer is yes. But unfortunately I cannot simply use these methods as I would have to also apply the permutations.

Source: Windows Questions C++

LEAVE A COMMENT