From 95f2e7f3f5ebdda92d7c16e2aa3df291b54a4d2f Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 21 Jul 2010 10:57:01 +0200 Subject: [PATCH] introduce a new LvalueBit flag and split DenseCoeffBase into three level of accessors --- Eigen/src/Core/BandMatrix.h | 2 +- Eigen/src/Core/Block.h | 2 +- Eigen/src/Core/CwiseUnaryView.h | 2 +- Eigen/src/Core/DenseCoeffsBase.h | 28 +++++++++++++++---- Eigen/src/Core/Diagonal.h | 2 +- Eigen/src/Core/DiagonalMatrix.h | 5 +++- Eigen/src/Core/Reverse.h | 2 +- Eigen/src/Core/util/Constants.h | 12 ++++++++ Eigen/src/Core/util/ForwardDeclarations.h | 5 +++- Eigen/src/Core/util/XprHelper.h | 4 +-- .../src/Eigenvalues/HessenbergDecomposition.h | 6 ++-- Eigen/src/Sparse/DynamicSparseMatrix.h | 2 +- Eigen/src/Sparse/SparseMatrix.h | 2 +- Eigen/src/Sparse/SparseVector.h | 2 +- 14 files changed, 56 insertions(+), 20 deletions(-) diff --git a/Eigen/src/Core/BandMatrix.h b/Eigen/src/Core/BandMatrix.h index e846b38e5..2f94d12dc 100644 --- a/Eigen/src/Core/BandMatrix.h +++ b/Eigen/src/Core/BandMatrix.h @@ -55,7 +55,7 @@ struct ei_traits > ColsAtCompileTime = Cols, MaxRowsAtCompileTime = Rows, MaxColsAtCompileTime = Cols, - Flags = 0 + Flags = LvalueBit }; }; diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h index f888d5ea0..7d9ae500d 100644 --- a/Eigen/src/Core/Block.h +++ b/Eigen/src/Core/Block.h @@ -93,7 +93,7 @@ struct ei_traits > : ei_tr && (InnerStrideAtCompileTime == 1) ? PacketAccessBit : 0, FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ? LinearAccessBit : 0, - Flags0 = ei_traits::Flags & (HereditaryBits | MaskPacketAccessBit | DirectAccessBit), + Flags0 = ei_traits::Flags & (HereditaryBits | MaskPacketAccessBit | LvalueBit | DirectAccessBit), Flags1 = Flags0 | FlagsLinearAccessBit, Flags = (Flags1 & ~RowMajorBit) | (IsRowMajor ? RowMajorBit : 0) }; diff --git a/Eigen/src/Core/CwiseUnaryView.h b/Eigen/src/Core/CwiseUnaryView.h index 612b28f1f..37c58223e 100644 --- a/Eigen/src/Core/CwiseUnaryView.h +++ b/Eigen/src/Core/CwiseUnaryView.h @@ -48,7 +48,7 @@ struct ei_traits > typedef typename MatrixType::Nested MatrixTypeNested; typedef typename ei_cleantype::type _MatrixTypeNested; enum { - Flags = (ei_traits<_MatrixTypeNested>::Flags & (HereditaryBits | LinearAccessBit | DirectAccessBit)), + Flags = (ei_traits<_MatrixTypeNested>::Flags & (HereditaryBits | LvalueBit | LinearAccessBit | DirectAccessBit)), CoeffReadCost = ei_traits<_MatrixTypeNested>::CoeffReadCost + ei_functor_traits::Cost, MatrixTypeInnerStride = ei_inner_stride_at_compile_time::ret, // need to cast the sizeof's from size_t to int explicitly, otherwise: diff --git a/Eigen/src/Core/DenseCoeffsBase.h b/Eigen/src/Core/DenseCoeffsBase.h index 6802cea24..0b348c81d 100644 --- a/Eigen/src/Core/DenseCoeffsBase.h +++ b/Eigen/src/Core/DenseCoeffsBase.h @@ -25,15 +25,15 @@ #ifndef EIGEN_DENSECOEFFSBASE_H #define EIGEN_DENSECOEFFSBASE_H -template -class DenseCoeffsBase : public EigenBase +template +class DenseCoeffsBase : public EigenBase { public: typedef typename ei_traits::StorageKind StorageKind; typedef typename ei_traits::Index Index; typedef typename ei_traits::Scalar Scalar; typedef typename ei_packet_traits::type PacketScalar; - typedef typename ei_meta_if::ret, + typedef typename ei_meta_if::Flags&LvalueBit), const Scalar&, typename ei_meta_if::ret, Scalar, const Scalar>::ret >::ret CoeffReturnType; @@ -239,11 +239,11 @@ class DenseCoeffsBase : public EigenBase }; template -class DenseCoeffsBase : public DenseCoeffsBase +class DenseCoeffsBase : public DenseCoeffsBase { public: - typedef DenseCoeffsBase Base; + typedef DenseCoeffsBase Base; typedef typename ei_traits::StorageKind StorageKind; typedef typename ei_traits::Index Index; @@ -512,6 +512,23 @@ class DenseCoeffsBase : public DenseCoeffsBase } #endif +}; + +template +class DenseCoeffsBase : public DenseCoeffsBase +{ + public: + + typedef DenseCoeffsBase Base; + typedef typename ei_traits::Index Index; + typedef typename ei_traits::Scalar Scalar; + typedef typename NumTraits::Real RealScalar; + + using Base::rows; + using Base::cols; + using Base::size; + using Base::derived; + /** \returns the pointer increment between two consecutive elements within a slice in the inner direction. * * \sa outerStride(), rowStride(), colStride() @@ -531,6 +548,7 @@ class DenseCoeffsBase : public DenseCoeffsBase return derived().outerStride(); } + // FIXME shall we remove it ? inline Index stride() const { return Derived::IsVectorAtCompileTime ? innerStride() : outerStride(); diff --git a/Eigen/src/Core/Diagonal.h b/Eigen/src/Core/Diagonal.h index 8c2eacd96..0b7d14179 100644 --- a/Eigen/src/Core/Diagonal.h +++ b/Eigen/src/Core/Diagonal.h @@ -62,7 +62,7 @@ struct ei_traits > MatrixType::MaxColsAtCompileTime) : (EIGEN_SIZE_MIN_PREFER_FIXED(MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime) - AbsDiagIndex), MaxColsAtCompileTime = 1, - Flags = (unsigned int)_MatrixTypeNested::Flags & (HereditaryBits | LinearAccessBit | DirectAccessBit) & ~RowMajorBit, + Flags = (unsigned int)_MatrixTypeNested::Flags & (HereditaryBits | LinearAccessBit | LvalueBit | DirectAccessBit) & ~RowMajorBit, CoeffReadCost = _MatrixTypeNested::CoeffReadCost, MatrixTypeOuterStride = ei_outer_stride_at_compile_time::ret, InnerStrideAtCompileTime = MatrixTypeOuterStride == Dynamic ? Dynamic : MatrixTypeOuterStride+1, diff --git a/Eigen/src/Core/DiagonalMatrix.h b/Eigen/src/Core/DiagonalMatrix.h index 8c4200a6f..0c0525028 100644 --- a/Eigen/src/Core/DiagonalMatrix.h +++ b/Eigen/src/Core/DiagonalMatrix.h @@ -105,6 +105,9 @@ struct ei_traits typedef Matrix<_Scalar,SizeAtCompileTime,1,0,MaxSizeAtCompileTime,1> DiagonalVectorType; typedef Dense StorageKind; typedef DenseIndex Index; + enum { + Flags = LvalueBit + }; }; template @@ -213,7 +216,7 @@ struct ei_traits > ColsAtCompileTime = DiagonalVectorType::SizeAtCompileTime, MaxRowsAtCompileTime = DiagonalVectorType::SizeAtCompileTime, MaxColsAtCompileTime = DiagonalVectorType::SizeAtCompileTime, - Flags = 0 + Flags = ei_traits::Flags & LvalueBit }; }; diff --git a/Eigen/src/Core/Reverse.h b/Eigen/src/Core/Reverse.h index 5858e684c..6051f7366 100644 --- a/Eigen/src/Core/Reverse.h +++ b/Eigen/src/Core/Reverse.h @@ -59,7 +59,7 @@ struct ei_traits > LinearAccess = ( (Direction==BothDirections) && (int(_MatrixTypeNested::Flags)&PacketAccessBit) ) ? LinearAccessBit : 0, - Flags = int(_MatrixTypeNested::Flags) & (HereditaryBits | PacketAccessBit | LinearAccess | DirectAccessBit), + Flags = int(_MatrixTypeNested::Flags) & (HereditaryBits | LvalueBit | PacketAccessBit | LinearAccess), CoeffReadCost = _MatrixTypeNested::CoeffReadCost }; diff --git a/Eigen/src/Core/util/Constants.h b/Eigen/src/Core/util/Constants.h index d758c2a0b..2c100c809 100644 --- a/Eigen/src/Core/util/Constants.h +++ b/Eigen/src/Core/util/Constants.h @@ -139,6 +139,14 @@ const unsigned int DirectAccessBit = 0x20; * means the first coefficient packet is guaranteed to be aligned */ const unsigned int AlignedBit = 0x40; +/** \ingroup flags + * + * Means the expression is writable. Note that DirectAccessBit implies LvalueBit. + * Internaly, it is mainly used to enable the writable coeff accessors, and makes + * the read-only coeff accessors to return by const reference. + */ +const unsigned int LvalueBit = 0x80; + const unsigned int NestByRefBit = 0x100; // list of flags that are inherited by default @@ -234,6 +242,10 @@ enum { IsSparse }; +enum AccessorLevels { + ReadOnlyAccessors, WriteAccessors, DirectAccessors +}; + enum DecompositionOptions { Pivoting = 0x01, // LDLT, NoPivoting = 0x02, // LDLT, diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h index 310ffa4b3..c3ff9d7c4 100644 --- a/Eigen/src/Core/util/ForwardDeclarations.h +++ b/Eigen/src/Core/util/ForwardDeclarations.h @@ -36,7 +36,10 @@ template struct ei_has_direct_access template struct EigenBase; template class DenseBase; -template::ret> +template::Flags & DirectAccessBit) ? DirectAccessors + : (ei_traits::Flags & LvalueBit) ? WriteAccessors + : ReadOnlyAccessors> class DenseCoeffsBase; template struct ei_size_at_compile_time @@ -355,7 +355,7 @@ template::type> template struct ei_are_flags_consistent { - enum { ret = true }; + enum { ret = EIGEN_IMPLIES(bool(Flags&DirectAccessBit), bool(Flags&LvalueBit)) }; }; template::XprKind> diff --git a/Eigen/src/Eigenvalues/HessenbergDecomposition.h b/Eigen/src/Eigenvalues/HessenbergDecomposition.h index 0f2b78e27..79554187a 100644 --- a/Eigen/src/Eigenvalues/HessenbergDecomposition.h +++ b/Eigen/src/Eigenvalues/HessenbergDecomposition.h @@ -130,7 +130,7 @@ template class HessenbergDecomposition { if(matrix.rows()<2) { - m_isInitialized = true; + m_isInitialized = true; return; } m_hCoeffs.resize(matrix.rows()-1,1); @@ -160,7 +160,7 @@ template class HessenbergDecomposition m_matrix = matrix; if(matrix.rows()<2) { - m_isInitialized = true; + m_isInitialized = true; return *this; } m_hCoeffs.resize(matrix.rows()-1,1); @@ -360,7 +360,7 @@ template struct HessenbergDecompositionMatrixHReturnType result = m_hess.packedMatrix(); Index n = result.rows(); if (n>2) - result.bottomLeftCorner(n-2, n-2).template triangularView().setZero(); + result.bottomLeftCorner(n-2, n-2).template triangularView().setZero(); } Index rows() const { return m_hess.packedMatrix().rows(); } diff --git a/Eigen/src/Sparse/DynamicSparseMatrix.h b/Eigen/src/Sparse/DynamicSparseMatrix.h index 69e1f55ba..620f09289 100644 --- a/Eigen/src/Sparse/DynamicSparseMatrix.h +++ b/Eigen/src/Sparse/DynamicSparseMatrix.h @@ -54,7 +54,7 @@ struct ei_traits > ColsAtCompileTime = Dynamic, MaxRowsAtCompileTime = Dynamic, MaxColsAtCompileTime = Dynamic, - Flags = _Flags | NestByRefBit, + Flags = _Flags | NestByRefBit | LvalueBit, CoeffReadCost = NumTraits::ReadCost, SupportedAccessPatterns = OuterRandomAccessPattern }; diff --git a/Eigen/src/Sparse/SparseMatrix.h b/Eigen/src/Sparse/SparseMatrix.h index ecf8efbe7..820cf2884 100644 --- a/Eigen/src/Sparse/SparseMatrix.h +++ b/Eigen/src/Sparse/SparseMatrix.h @@ -54,7 +54,7 @@ struct ei_traits > ColsAtCompileTime = Dynamic, MaxRowsAtCompileTime = Dynamic, MaxColsAtCompileTime = Dynamic, - Flags = _Options | NestByRefBit, + Flags = _Options | NestByRefBit | LvalueBit, CoeffReadCost = NumTraits::ReadCost, SupportedAccessPatterns = InnerRandomAccessPattern }; diff --git a/Eigen/src/Sparse/SparseVector.h b/Eigen/src/Sparse/SparseVector.h index dfe79a3b2..c5d0a6981 100644 --- a/Eigen/src/Sparse/SparseVector.h +++ b/Eigen/src/Sparse/SparseVector.h @@ -48,7 +48,7 @@ struct ei_traits > ColsAtCompileTime = IsColVector ? 1 : Dynamic, MaxRowsAtCompileTime = RowsAtCompileTime, MaxColsAtCompileTime = ColsAtCompileTime, - Flags = _Options | NestByRefBit, + Flags = _Options | NestByRefBit | LvalueBit, CoeffReadCost = NumTraits::ReadCost, SupportedAccessPatterns = InnerRandomAccessPattern };