From 7f824dd613fe79e68efc4691972c30a5956bc0e6 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Thu, 25 Jun 2015 17:17:38 +0200 Subject: [PATCH] Optimize CG to enable faster spare row-major * dense vector products when the input matrix is complete (Upper|Lower) but column major. --- Eigen/src/IterativeLinearSolvers/ConjugateGradient.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Eigen/src/IterativeLinearSolvers/ConjugateGradient.h b/Eigen/src/IterativeLinearSolvers/ConjugateGradient.h index de576edc9..5f0159e52 100644 --- a/Eigen/src/IterativeLinearSolvers/ConjugateGradient.h +++ b/Eigen/src/IterativeLinearSolvers/ConjugateGradient.h @@ -185,10 +185,13 @@ public: template void _solve_with_guess_impl(const Rhs& b, Dest& x) const { + typedef Ref MatRef; + typedef typename internal::conditional::IsComplex), + Transpose, MatRef const&>::type RowMajorWrapper; typedef typename internal::conditional&, - typename Ref::template ConstSelfAdjointViewReturnType::Type - >::type MatrixWrapperType; + RowMajorWrapper, + typename MatRef::template ConstSelfAdjointViewReturnType::Type + >::type SelfAdjointWrapper; m_iterations = Base::maxIterations(); m_error = Base::m_tolerance; @@ -198,7 +201,8 @@ public: m_error = Base::m_tolerance; typename Dest::ColXpr xj(x,j); - internal::conjugate_gradient(MatrixWrapperType(mp_matrix), b.col(j), xj, Base::m_preconditioner, m_iterations, m_error); + RowMajorWrapper row_mat(mp_matrix); + internal::conjugate_gradient(SelfAdjointWrapper(row_mat), b.col(j), xj, Base::m_preconditioner, m_iterations, m_error); } m_isInitialized = true;