From 0182695204292540931d4b180a8cb58038f1c735 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Tue, 3 Nov 2009 11:34:45 -0500 Subject: [PATCH] move cholesky to ei_xxx_return_value --- Eigen/Cholesky | 1 + Eigen/src/Cholesky/LDLT.h | 47 ++++++++++-------------------------- Eigen/src/Cholesky/LLT.h | 51 ++++++++++++--------------------------- test/cholesky.cpp | 3 +++ 4 files changed, 32 insertions(+), 70 deletions(-) diff --git a/Eigen/Cholesky b/Eigen/Cholesky index f1806f726..634dc156f 100644 --- a/Eigen/Cholesky +++ b/Eigen/Cholesky @@ -30,6 +30,7 @@ namespace Eigen { * \endcode */ +#include "src/misc/Solve.h" #include "src/Array/CwiseOperators.h" #include "src/Array/Functors.h" #include "src/Cholesky/LLT.h" diff --git a/Eigen/src/Cholesky/LDLT.h b/Eigen/src/Cholesky/LDLT.h index 04c02d4fc..761a4a8e8 100644 --- a/Eigen/src/Cholesky/LDLT.h +++ b/Eigen/src/Cholesky/LDLT.h @@ -27,8 +27,6 @@ #ifndef EIGEN_LDLT_H #define EIGEN_LDLT_H -template struct ei_ldlt_solve_impl; - /** \ingroup cholesky_Module * * \class LDLT @@ -54,10 +52,10 @@ template struct ei_ldlt_solve_impl; * Note that during the decomposition, only the upper triangular part of A is considered. Therefore, * the strict lower part does not have to store correct values. */ -template class LDLT +template class LDLT { public: - + typedef _MatrixType MatrixType; typedef typename MatrixType::Scalar Scalar; typedef typename NumTraits::Real RealScalar; typedef Matrix VectorType; @@ -126,13 +124,13 @@ template class LDLT * \sa solveInPlace(), MatrixBase::ldlt() */ template - inline const ei_ldlt_solve_impl + inline const ei_solve_return_value solve(const MatrixBase& b) const { ei_assert(m_isInitialized && "LDLT is not initialized."); ei_assert(m_matrix.rows()==b.rows() && "LDLT::solve(): invalid number of rows of the right hand side matrix b"); - return ei_ldlt_solve_impl(*this, b.derived()); + return ei_solve_return_value(*this, b.derived()); } template @@ -149,6 +147,9 @@ template class LDLT ei_assert(m_isInitialized && "LDLT is not initialized."); return m_matrix; } + + inline int rows() const { return m_matrix.rows(); } + inline int cols() const { return m_matrix.cols(); } protected: /** \internal @@ -263,36 +264,14 @@ LDLT& LDLT::compute(const MatrixType& a) return *this; } -template -struct ei_traits > +template +struct ei_solve_impl, Rhs, Dest> + : ei_solve_return_value, Rhs> { - typedef Matrix ReturnMatrixType; -}; - -template -struct ei_ldlt_solve_impl : public ReturnByValue > -{ - typedef typename ei_cleantype::type RhsNested; - typedef LDLT LDLTType; - const LDLTType& m_ldlt; - const typename Rhs::Nested m_rhs; - - ei_ldlt_solve_impl(const LDLTType& ldlt, const Rhs& rhs) - : m_ldlt(ldlt), m_rhs(rhs) - {} - - inline int rows() const { return m_ldlt.matrixLDLT().cols(); } - inline int cols() const { return m_rhs.cols(); } - - template void evalTo(Dest& dst) const + void evalTo(Dest& dst) const { - dst = m_rhs; - m_ldlt.solveInPlace(dst); + dst = this->m_rhs; + this->m_dec.solveInPlace(dst); } }; diff --git a/Eigen/src/Cholesky/LLT.h b/Eigen/src/Cholesky/LLT.h index d6fd514cc..0ad67aa5f 100644 --- a/Eigen/src/Cholesky/LLT.h +++ b/Eigen/src/Cholesky/LLT.h @@ -26,7 +26,6 @@ #define EIGEN_LLT_H template struct LLT_Traits; -template struct ei_llt_solve_impl; /** \ingroup cholesky_Module * @@ -54,9 +53,10 @@ template struct ei_llt_solve_impl; * Note that during the decomposition, only the upper triangular part of A is considered. Therefore, * the strict lower part does not have to store correct values. */ -template class LLT +template class LLT { - private: + public: + typedef _MatrixType MatrixType; typedef typename MatrixType::Scalar Scalar; typedef typename NumTraits::Real RealScalar; typedef Matrix VectorType; @@ -69,8 +69,6 @@ template class LLT typedef LLT_Traits Traits; - public: - /** * \brief Default Constructor. * @@ -111,13 +109,13 @@ template class LLT * \sa solveInPlace(), MatrixBase::llt() */ template - inline const ei_llt_solve_impl + inline const ei_solve_return_value solve(const MatrixBase& b) const { ei_assert(m_isInitialized && "LLT is not initialized."); ei_assert(m_matrix.rows()==b.rows() && "LLT::solve(): invalid number of rows of the right hand side matrix b"); - return ei_llt_solve_impl(*this, b.derived()); + return ei_solve_return_value(*this, b.derived()); } template @@ -134,7 +132,10 @@ template class LLT ei_assert(m_isInitialized && "LLT is not initialized."); return m_matrix; } - + + inline int rows() const { return m_matrix.rows(); } + inline int cols() const { return m_matrix.cols(); } + protected: /** \internal * Used to compute and store L @@ -257,36 +258,14 @@ LLT& LLT::compute(const MatrixType& a) return *this; } -template -struct ei_traits > +template +struct ei_solve_impl, Rhs, Dest> + : ei_solve_return_value, Rhs> { - typedef Matrix ReturnMatrixType; -}; - -template -struct ei_llt_solve_impl : public ReturnByValue > -{ - typedef typename ei_cleantype::type RhsNested; - typedef LLT LLTType; - const LLTType& m_llt; - const typename Rhs::Nested m_rhs; - - ei_llt_solve_impl(const LLTType& llt, const Rhs& rhs) - : m_llt(llt), m_rhs(rhs) - {} - - inline int rows() const { return m_llt.matrixLLT().cols(); } - inline int cols() const { return m_rhs.cols(); } - - template void evalTo(Dest& dst) const + void evalTo(Dest& dst) const { - dst = m_rhs; - m_llt.solveInPlace(dst); + dst = this->m_rhs; + this->m_dec.solveInPlace(dst); } }; diff --git a/test/cholesky.cpp b/test/cholesky.cpp index 83f7e0492..c3ef96752 100644 --- a/test/cholesky.cpp +++ b/test/cholesky.cpp @@ -22,7 +22,10 @@ // License and a copy of the GNU General Public License along with // Eigen. If not, see . +#ifndef EIGEN_NO_ASSERTION_CHECKING #define EIGEN_NO_ASSERTION_CHECKING +#endif + #include "main.h" #include #include