From 1dabd133cc7b547ded5750e3fd1a6c6701ba47b5 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Sun, 23 Jan 2011 21:53:28 -0500 Subject: [PATCH] pass eigen2's triangular test --- Eigen/src/Core/DiagonalMatrix.h | 15 ++++++++++- Eigen/src/Core/MatrixBase.h | 10 ++++++-- Eigen/src/Core/TriangularMatrix.h | 30 ++++++++++++++++++++++ Eigen/src/Eigen2Support/TriangularSolver.h | 4 +-- 4 files changed, 54 insertions(+), 5 deletions(-) diff --git a/Eigen/src/Core/DiagonalMatrix.h b/Eigen/src/Core/DiagonalMatrix.h index 7b105b299..7118db4b8 100644 --- a/Eigen/src/Core/DiagonalMatrix.h +++ b/Eigen/src/Core/DiagonalMatrix.h @@ -76,6 +76,19 @@ class DiagonalBase : public EigenBase { return diagonal().cwiseInverse(); } + + #ifdef EIGEN2_SUPPORT + template + bool isApprox(const DiagonalBase& other, typename NumTraits::Real precision = NumTraits::dummy_precision()) const + { + return diagonal().isApprox(other.diagonal(), precision); + } + template + bool isApprox(const MatrixBase& other, typename NumTraits::Real precision = NumTraits::dummy_precision()) const + { + return toDenseMatrix().isApprox(other, precision); + } + #endif }; template @@ -256,7 +269,7 @@ class DiagonalWrapper * \sa class DiagonalWrapper, class DiagonalMatrix, diagonal(), isDiagonal() **/ template -inline const DiagonalWrapper +inline const DiagonalWrapper MatrixBase::asDiagonal() const { return derived(); diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 783fdaa48..e18104b95 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -245,7 +245,13 @@ template class MatrixBase #ifdef EIGEN2_SUPPORT template TriangularView part(); template const TriangularView part() const; - #endif + + // huuuge hack. make Eigen2's matrix.part() work in eigen3. Problem: Diagonal is now a class template instead + // of an integer constant. Solution: overload the part() method template wrt template parameters list. + template class U> + const DiagonalWrapper part() const + { return diagonal().asDiagonal(); } + #endif // EIGEN2_SUPPORT template struct TriangularViewReturnType { typedef TriangularView Type; }; template struct ConstTriangularViewReturnType { typedef const TriangularView Type; }; @@ -270,7 +276,7 @@ template class MatrixBase static const BasisReturnType UnitZ(); static const BasisReturnType UnitW(); - const DiagonalWrapper asDiagonal() const; + const DiagonalWrapper asDiagonal() const; Derived& setIdentity(); Derived& setIdentity(Index rows, Index cols); diff --git a/Eigen/src/Core/TriangularMatrix.h b/Eigen/src/Core/TriangularMatrix.h index af5092a7e..3b5f5986b 100644 --- a/Eigen/src/Core/TriangularMatrix.h +++ b/Eigen/src/Core/TriangularMatrix.h @@ -295,6 +295,36 @@ template class TriangularView (lhs.derived(),rhs.m_matrix); } + + #ifdef EIGEN2_SUPPORT + + template + struct eigen2_product_return_type + { + typedef typename TriangularView::DenseMatrixType DenseMatrixType; + typedef typename TriangularView::DenseMatrixType OtherDenseMatrixType; + typedef typename ProductReturnType::Type ProdRetType; + typedef typename ProdRetType::PlainObject type; + }; + template + const typename eigen2_product_return_type::type + operator*(const TriangularView& rhs) const + { + return toDenseMatrix() * rhs.toDenseMatrix(); + } + + template + bool isApprox(const TriangularView& other, typename NumTraits::Real precision = NumTraits::dummy_precision()) const + { + return toDenseMatrix().isApprox(other.toDenseMatrix(), precision); + } + template + bool isApprox(const MatrixBase& other, typename NumTraits::Real precision = NumTraits::dummy_precision()) const + { + return toDenseMatrix().isApprox(other, precision); + } + + #endif // EIGEN2_SUPPORT template typename internal::plain_matrix_type_column_major::type diff --git a/Eigen/src/Eigen2Support/TriangularSolver.h b/Eigen/src/Eigen2Support/TriangularSolver.h index a83640e62..e94e47a50 100644 --- a/Eigen/src/Eigen2Support/TriangularSolver.h +++ b/Eigen/src/Eigen2Support/TriangularSolver.h @@ -40,14 +40,14 @@ template typename ExpressionType::PlainObject Flagged::solveTriangular(const MatrixBase& other) const { - return m_matrix.template triangularView.solve(other.derived()); + return m_matrix.template triangularView().solve(other.derived()); } template template void Flagged::solveTriangularInPlace(const MatrixBase& other) const { - m_matrix.template triangularView.solveInPlace(other.derived()); + m_matrix.template triangularView().solveInPlace(other.derived()); } #endif // EIGEN_TRIANGULAR_SOLVER2_H