diff options
author | Benoit Jacob <jacob.benoit.1@gmail.com> | 2011-01-25 21:22:04 -0500 |
---|---|---|
committer | Benoit Jacob <jacob.benoit.1@gmail.com> | 2011-01-25 21:22:04 -0500 |
commit | 1d98cc5e5da88254c784c4f02517bf5a47f007bc (patch) | |
tree | de9bc9696892cf0bfa35a820b19b34524f4c954d /Eigen/src/Core/TriangularMatrix.h | |
parent | 4fbadfd230af9859c5e82c09a4974396af45473f (diff) |
eigen2 support: implement part<SelfAdjoint>, mimic eigen2 behavior braindeadness-for-braindeadness
Diffstat (limited to 'Eigen/src/Core/TriangularMatrix.h')
-rw-r--r-- | Eigen/src/Core/TriangularMatrix.h | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/Eigen/src/Core/TriangularMatrix.h b/Eigen/src/Core/TriangularMatrix.h index ce5b53631..714d56a5b 100644 --- a/Eigen/src/Core/TriangularMatrix.h +++ b/Eigen/src/Core/TriangularMatrix.h @@ -48,6 +48,7 @@ template<typename Derived> class TriangularBase : public EigenBase<Derived> typedef typename internal::traits<Derived>::Scalar Scalar; typedef typename internal::traits<Derived>::StorageKind StorageKind; typedef typename internal::traits<Derived>::Index Index; + typedef typename internal::traits<Derived>::DenseMatrixType DenseMatrixType; inline TriangularBase() { eigen_assert(!((Mode&UnitDiag) && (Mode&ZeroDiag))); } @@ -88,6 +89,13 @@ template<typename Derived> class TriangularBase : public EigenBase<Derived> template<typename DenseDerived> void evalToLazy(MatrixBase<DenseDerived> &other) const; + DenseMatrixType toDenseMatrix() const + { + DenseMatrixType res(rows(), cols()); + evalToLazy(res); + return res; + } + protected: void check_coordinates(Index row, Index col) const @@ -137,6 +145,7 @@ struct traits<TriangularView<MatrixType, _Mode> > : traits<MatrixType> typedef typename nested<MatrixType>::type MatrixTypeNested; typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested; typedef MatrixType ExpressionType; + typedef typename MatrixType::PlainObject DenseMatrixType; enum { Mode = _Mode, Flags = (_MatrixTypeNested::Flags & (HereditaryBits) & (~(PacketAccessBit | DirectAccessBit | LinearAccessBit))) | Mode, @@ -159,7 +168,7 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView typedef typename internal::traits<TriangularView>::Scalar Scalar; typedef _MatrixType MatrixType; - typedef typename MatrixType::PlainObject DenseMatrixType; + typedef typename internal::traits<TriangularView>::DenseMatrixType DenseMatrixType; protected: typedef typename MatrixType::Nested MatrixTypeNested; @@ -269,13 +278,6 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView inline const TriangularView<Transpose<MatrixType>,TransposeMode> transpose() const { return m_matrix.transpose(); } - DenseMatrixType toDenseMatrix() const - { - DenseMatrixType res(rows(), cols()); - evalToLazy(res); - return res; - } - /** Efficient triangular matrix times vector/matrix product */ template<typename OtherDerived> TriangularProduct<Mode,true,MatrixType,false,OtherDerived,OtherDerived::IsVectorAtCompileTime> @@ -310,18 +312,18 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView const typename eigen2_product_return_type<OtherMatrixType>::type operator*(const TriangularView<OtherMatrixType, Mode>& rhs) const { - return toDenseMatrix() * rhs.toDenseMatrix(); + return this->toDenseMatrix() * rhs.toDenseMatrix(); } template<typename OtherMatrixType> bool isApprox(const TriangularView<OtherMatrixType, Mode>& other, typename NumTraits<Scalar>::Real precision = NumTraits<Scalar>::dummy_precision()) const { - return toDenseMatrix().isApprox(other.toDenseMatrix(), precision); + return this->toDenseMatrix().isApprox(other.toDenseMatrix(), precision); } template<typename OtherDerived> bool isApprox(const MatrixBase<OtherDerived>& other, typename NumTraits<Scalar>::Real precision = NumTraits<Scalar>::dummy_precision()) const { - return toDenseMatrix().isApprox(other, precision); + return this->toDenseMatrix().isApprox(other, precision); } #endif // EIGEN2_SUPPORT @@ -707,10 +709,27 @@ void TriangularBase<Derived>::evalToLazy(MatrixBase<DenseDerived> &other) const ***************************************************************************/ #ifdef EIGEN2_SUPPORT + +// implementation of part<>(), including the SelfAdjoint case. + +namespace internal { +template<typename MatrixType, unsigned int Mode> +struct eigen2_part_return_type +{ + typedef TriangularView<MatrixType, Mode> type; +}; + +template<typename MatrixType> +struct eigen2_part_return_type<MatrixType, SelfAdjoint> +{ + typedef SelfAdjointView<MatrixType, Upper> type; +}; +} + /** \deprecated use MatrixBase::triangularView() */ template<typename Derived> template<unsigned int Mode> -const TriangularView<Derived, Mode> MatrixBase<Derived>::part() const +const typename internal::eigen2_part_return_type<Derived, Mode>::type MatrixBase<Derived>::part() const { return derived(); } @@ -718,7 +737,7 @@ const TriangularView<Derived, Mode> MatrixBase<Derived>::part() const /** \deprecated use MatrixBase::triangularView() */ template<typename Derived> template<unsigned int Mode> -TriangularView<Derived, Mode> MatrixBase<Derived>::part() +typename internal::eigen2_part_return_type<Derived, Mode>::type MatrixBase<Derived>::part() { return derived(); } |