From 18429156a145c1adddcb313512f9f1179a9141cf Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 31 Jul 2009 17:35:55 +0200 Subject: add selfadjointView from a trinagularView --- Eigen/src/Core/TriangularMatrix.h | 21 +++++++++++-- test/product_trsm.cpp | 65 ++++++++++----------------------------- 2 files changed, 36 insertions(+), 50 deletions(-) diff --git a/Eigen/src/Core/TriangularMatrix.h b/Eigen/src/Core/TriangularMatrix.h index a41adb190..8b6c9a23b 100644 --- a/Eigen/src/Core/TriangularMatrix.h +++ b/Eigen/src/Core/TriangularMatrix.h @@ -156,7 +156,9 @@ template class TriangularView typedef typename ei_traits::Scalar Scalar; typedef _MatrixType MatrixType; typedef typename MatrixType::PlainMatrixType PlainMatrixType; - + typedef typename MatrixType::Nested MatrixTypeNested; + typedef typename ei_cleantype::type _MatrixTypeNested; + enum { Mode = _Mode, TransposeMode = (Mode & UpperTriangularBit ? LowerTriangularBit : 0) @@ -286,6 +288,17 @@ template class TriangularView void solveInPlace(const MatrixBase& other) const { return solveInPlace(other); } + const SelfAdjointView<_MatrixTypeNested,Mode> selfadjointView() const + { + EIGEN_STATIC_ASSERT((Mode&UnitDiagBit)==0,PROGRAMMING_ERROR); + return SelfAdjointView<_MatrixTypeNested,Mode>(m_matrix); + } + SelfAdjointView<_MatrixTypeNested,Mode> selfadjointView() + { + EIGEN_STATIC_ASSERT((Mode&UnitDiagBit)==0,PROGRAMMING_ERROR); + return SelfAdjointView<_MatrixTypeNested,Mode>(m_matrix); + } + template void swap(const TriangularBase& other) { @@ -300,7 +313,7 @@ template class TriangularView protected: - const typename MatrixType::Nested m_matrix; + const MatrixTypeNested m_matrix; }; /*************************************************************************** @@ -562,6 +575,10 @@ void TriangularBase::evalToDenseLazy(MatrixBase &other) c >::run(other.derived(), derived()._expression()); } +/*************************************************************************** +* Implementation of TriangularView methods +***************************************************************************/ + /*************************************************************************** * Implementation of MatrixBase methods ***************************************************************************/ diff --git a/test/product_trsm.cpp b/test/product_trsm.cpp index bda158048..4f0fd15be 100644 --- a/test/product_trsm.cpp +++ b/test/product_trsm.cpp @@ -24,12 +24,11 @@ #include "main.h" -template -void solve_ref(const Lhs& lhs, Rhs& rhs) -{ - for (int j=0; j void trsm(int size,int cols) { @@ -37,53 +36,23 @@ template void trsm(int size,int cols) Matrix cmLhs(size,size); Matrix rmLhs(size,size); - - Matrix cmRef(size,cols), cmRhs(size,cols); - Matrix rmRef(size,cols), rmRhs(size,cols); - - cmLhs.setRandom(); cmLhs.diagonal().cwise() += 10; - rmLhs.setRandom(); rmLhs.diagonal().cwise() += 10; - - cmRhs.setRandom(); cmRef = cmRhs; - cmLhs.conjugate().template triangularView().solveInPlace(cmRhs); - solve_ref(cmLhs.conjugate().template triangularView(),cmRef); - VERIFY_IS_APPROX(cmRhs, cmRef); - - cmRhs.setRandom(); cmRef = cmRhs; - cmLhs.conjugate().template triangularView().solveInPlace(cmRhs); - solve_ref(cmLhs.conjugate().template triangularView(),cmRef); - VERIFY_IS_APPROX(cmRhs, cmRef); - - rmRhs.setRandom(); rmRef = rmRhs; - cmLhs.template triangularView().solveInPlace(rmRhs); - solve_ref(cmLhs.template triangularView(),rmRef); - VERIFY_IS_APPROX(rmRhs, rmRef); - - rmRhs.setRandom(); rmRef = rmRhs; - cmLhs.template triangularView().solveInPlace(rmRhs); - solve_ref(cmLhs.template triangularView(),rmRef); - VERIFY_IS_APPROX(rmRhs, rmRef); + Matrix cmRhs(size,cols), ref(size,cols); + Matrix rmRhs(size,cols); - cmRhs.setRandom(); cmRef = cmRhs; - rmLhs.template triangularView().solveInPlace(cmRhs); - solve_ref(rmLhs.template triangularView(),cmRef); - VERIFY_IS_APPROX(cmRhs, cmRef); + cmLhs.setRandom(); cmLhs *= 0.1; cmLhs.diagonal().cwise() += 1; + rmLhs.setRandom(); rmLhs *= 0.1; rmLhs.diagonal().cwise() += 1; - cmRhs.setRandom(); cmRef = cmRhs; - rmLhs.template triangularView().solveInPlace(cmRhs); - solve_ref(rmLhs.template triangularView(),cmRef); - VERIFY_IS_APPROX(cmRhs, cmRef); + VERIFY_TRSM(cmLhs.conjugate().template triangularView(), cmRhs); + VERIFY_TRSM(cmLhs .template triangularView(), cmRhs); + VERIFY_TRSM(cmLhs .template triangularView(), rmRhs); + VERIFY_TRSM(cmLhs.conjugate().template triangularView(), rmRhs); - rmRhs.setRandom(); rmRef = rmRhs; - rmLhs.template triangularView().solveInPlace(rmRhs); - solve_ref(rmLhs.template triangularView(),rmRef); - VERIFY_IS_APPROX(rmRhs, rmRef); + VERIFY_TRSM(cmLhs.conjugate().template triangularView(), cmRhs); + VERIFY_TRSM(cmLhs .template triangularView(), rmRhs); - rmRhs.setRandom(); rmRef = rmRhs; - rmLhs.template triangularView().solveInPlace(rmRhs); - solve_ref(rmLhs.template triangularView(),rmRef); - VERIFY_IS_APPROX(rmRhs, rmRef); + VERIFY_TRSM(rmLhs .template triangularView(), cmRhs); + VERIFY_TRSM(rmLhs.conjugate().template triangularView(), rmRhs); } void test_product_trsm() -- cgit v1.2.3