diff --git a/Eigen/src/SparseLU/SparseLU.h b/Eigen/src/SparseLU/SparseLU.h index 0e4bd7c69..0b1347f87 100644 --- a/Eigen/src/SparseLU/SparseLU.h +++ b/Eigen/src/SparseLU/SparseLU.h @@ -8,8 +8,8 @@ // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -#ifndef EIGEN_SPARSE_LU -#define EIGEN_SPARSE_LU +#ifndef EIGEN_SPARSE_LU_H +#define EIGEN_SPARSE_LU_H namespace Eigen { @@ -111,14 +111,14 @@ class SparseLU * * \sa compute() */ -// template -// inline const solve_retval solve(const MatrixBase& B) const -// { -// eigen_assert(m_factorizationIsOk && "SparseLU is not initialized."); -// eigen_assert(rows()==B.rows() -// && "SparseLU::solve(): invalid number of rows of the right hand side matrix B"); -// return solve_retval(*this, B.derived()); -// } + template + inline const internal::solve_retval solve(const MatrixBase& B) const + { + eigen_assert(m_factorizationIsOk && "SparseLU is not initialized."); + eigen_assert(rows()==B.rows() + && "SparseLU::solve(): invalid number of rows of the right hand side matrix B"); + return internal::solve_retval(*this, B.derived()); + } /** \brief Reports whether previous computation was successful. @@ -150,7 +150,8 @@ class SparseLU // Permute the right hand side to form X = Pr*B // on return, X is overwritten by the computed solution X.resize(n,nrhs); - X = m_perm_r * B; + for(int j = 0; j < nrhs; ++j) + X.col(j) = m_perm_r * B.col(j); // Forward solve PLy = Pb; Index fsupc; // First column of the current supernode @@ -172,12 +173,12 @@ class SparseLU nsupr = m_Lstore.rowIndexPtr()[fsupc+1] - istart; nsupc = m_Lstore.supToCol()[k+1] - fsupc; nrow = nsupr - nsupc; - luptr = m_Lstore.colIndexPtr()[fsupc]; if (nsupc == 1 ) { for (j = 0; j < nrhs; j++) { + luptr = m_Lstore.colIndexPtr()[fsupc]; for (iptr = istart+1; iptr < m_Lstore.rowIndexPtr()[fsupc+1]; iptr++) { irow = m_Lstore.rowIndex()[iptr]; @@ -189,10 +190,11 @@ class SparseLU else { // The supernode has more than one column + luptr = m_Lstore.colIndexPtr()[fsupc]; // Triangular solve Map, 0, OuterStride<> > A( &(Lval[luptr]), nsupc, nsupc, OuterStride<>(nsupr) ); - Map< Matrix, 0, OuterStride<> > U (&(X.data()[fsupc]), nsupc, nrhs, OuterStride<>(X.rows()) ); + Map< Matrix, 0, OuterStride<> > U (&(X.data()[fsupc]), nsupc, nrhs, OuterStride<>(n) ); U = A.template triangularView().solve(U); // Matrix-vector product @@ -233,7 +235,7 @@ class SparseLU else { Map, 0, OuterStride<> > A( &(Lval[luptr]), nsupc, nsupc, OuterStride<>(nsupr) ); - Map< Matrix, 0, OuterStride<> > U (&(X.data()[fsupc]), nsupc, nrhs, OuterStride<>(X.rows()) ); + Map< Matrix, 0, OuterStride<> > U (&(X.data()[fsupc]), nsupc, nrhs, OuterStride<>(n) ); U = A.template triangularView().solve(U); } @@ -251,12 +253,12 @@ class SparseLU } // End For U-solve // Permute back the solution - X = m_perm_c.inverse() * X; + for (j = 0; j < nrhs; ++j) + X.col(j) = m_perm_c.inverse() * X.col(j); return true; } - protected: // Functions void initperfvalues() @@ -344,7 +346,7 @@ void SparseLU::analyzePattern(const MatrixType& mat) } // Compute the column elimination tree of the permuted matrix - if (m_etree.size() == 0) m_etree.resize(m_mat.cols()); + /*if (m_etree.size() == 0) */m_etree.resize(m_mat.cols()); LU_sp_coletree(m_mat, m_etree); @@ -654,7 +656,7 @@ void SparseLU::factorize(const MatrixType& matrix) } -/*namespace internal { +namespace internal { template struct solve_retval, Rhs> @@ -665,11 +667,11 @@ struct solve_retval, Rhs> template void evalTo(Dest& dst) const { - dec().derived()._solve(rhs(),dst); + dec()._solve(rhs(),dst); } }; -}*/ // end namespace internal +} // end namespace internal