From b6b8578a678c0ebe8ed80bdd975882d37902952f Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Thu, 19 May 2016 11:36:38 +0200 Subject: [PATCH] bug #1230: add support for SelfadjointView::triangularView. --- Eigen/src/Core/SelfAdjointView.h | 23 +++++++++++++++++++++++ test/triangular.cpp | 6 ++++++ 2 files changed, 29 insertions(+) diff --git a/Eigen/src/Core/SelfAdjointView.h b/Eigen/src/Core/SelfAdjointView.h index 9fda02691..3a8cc221f 100644 --- a/Eigen/src/Core/SelfAdjointView.h +++ b/Eigen/src/Core/SelfAdjointView.h @@ -162,6 +162,29 @@ template class SelfAdjointView EIGEN_DEVICE_FUNC SelfAdjointView& rankUpdate(const MatrixBase& u, const Scalar& alpha = Scalar(1)); + /** \returns an expression of a triangular view extracted from the current selfadjoint view of a given triangular part + * + * The parameter \a TriMode can have the following values: \c #Upper, \c #StrictlyUpper, \c #UnitUpper, + * \c #Lower, \c #StrictlyLower, \c #UnitLower. + * + * If \c TriMode references the same triangular part than \c *this, then this method simply return a \c TriangularView of the nested expression, + * otherwise, the nested expression is first transposed, thus returning a \c TriangularView> object. + * + * \sa MatrixBase::triangularView(), class TriangularView + */ + template + EIGEN_DEVICE_FUNC + typename internal::conditional<(TriMode&(Upper|Lower))==(UpLo&(Upper|Lower)), + TriangularView, + TriangularView,TriMode> >::type + triangularView() const + { + typename internal::conditional<(TriMode&(Upper|Lower))==(UpLo&(Upper|Lower)), MatrixType&, Transpose >::type tmp(m_matrix); + return typename internal::conditional<(TriMode&(Upper|Lower))==(UpLo&(Upper|Lower)), + TriangularView, + TriangularView,TriMode> >::type(tmp); + } + /////////// Cholesky module /////////// const LLT llt() const; diff --git a/test/triangular.cpp b/test/triangular.cpp index 3e120f406..519916dc9 100644 --- a/test/triangular.cpp +++ b/test/triangular.cpp @@ -121,6 +121,12 @@ template void triangular_square(const MatrixType& m) VERIFY_IS_APPROX(m1.template triangularView() * m5, m3*m5); VERIFY_IS_APPROX(m6*m1.template triangularView(), m6*m3); + m1up = m1.template triangularView(); + VERIFY_IS_APPROX(m1.template selfadjointView().template triangularView().toDenseMatrix(), m1up); + VERIFY_IS_APPROX(m1up.template selfadjointView().template triangularView().toDenseMatrix(), m1up); + VERIFY_IS_APPROX(m1.template selfadjointView().template triangularView().toDenseMatrix(), m1up.adjoint()); + VERIFY_IS_APPROX(m1up.template selfadjointView().template triangularView().toDenseMatrix(), m1up.adjoint()); + }