Workaround fixing aliasing issue in x = SparseLU::solve(x)

This commit is contained in:
Gael Guennebaud
2013-11-15 11:19:19 +01:00
parent 6b471f205e
commit 46dd1bb1be
2 changed files with 5 additions and 2 deletions

View File

@@ -229,8 +229,10 @@ class SparseLU : public internal::SparseLUImpl<typename _MatrixType::Scalar, typ
// Permute the right hand side to form X = Pr*B
// on return, X is overwritten by the computed solution
X.resize(B.rows(),B.cols());
// this ugly const_cast_derived() helps to detect aliasing when applying the permutations
for(Index j = 0; j < B.cols(); ++j)
X.col(j) = rowsPermutation() * B.col(j);
X.col(j) = rowsPermutation() * B.const_cast_derived().col(j);
//Forward substitution with L
this->matrixL().solveInPlace(X);