diff --git a/Eigen/src/Cholesky/LDLT.h b/Eigen/src/Cholesky/LDLT.h index 15925ba5d..635fb1586 100644 --- a/Eigen/src/Cholesky/LDLT.h +++ b/Eigen/src/Cholesky/LDLT.h @@ -130,7 +130,7 @@ template class LDLT } /** \returns the coefficients of the diagonal matrix D */ - inline Diagonal vectorD(void) const + inline Diagonal vectorD(void) const { eigen_assert(m_isInitialized && "LDLT is not initialized."); return m_matrix.diagonal(); diff --git a/Eigen/src/Core/ArrayBase.h b/Eigen/src/Core/ArrayBase.h index 394f09958..f85178374 100644 --- a/Eigen/src/Core/ArrayBase.h +++ b/Eigen/src/Core/ArrayBase.h @@ -91,6 +91,7 @@ template class ArrayBase using Base::operator/=; typedef typename Base::CoeffReturnType CoeffReturnType; + #endif // not EIGEN_PARSED_BY_DOXYGEN #ifndef EIGEN_PARSED_BY_DOXYGEN diff --git a/Eigen/src/Core/BandMatrix.h b/Eigen/src/Core/BandMatrix.h index 649adb542..5c9ee1a44 100644 --- a/Eigen/src/Core/BandMatrix.h +++ b/Eigen/src/Core/BandMatrix.h @@ -132,8 +132,8 @@ class BandMatrix : public EigenBase(m_data,supers(),0,1,std::min(rows(),cols())); } /** \returns a vector expression of the main diagonal (const version) */ - inline const Block diagonal() const - { return Block(m_data,supers(),0,1,std::min(rows(),cols())); } + inline const Block diagonal() const + { return Block(m_data,supers(),0,1,std::min(rows(),cols())); } template struct DiagonalIntReturnType { enum { @@ -172,10 +172,10 @@ class BandMatrix : public EigenBase diagonal(Index i) const + inline const Block diagonal(Index i) const { eigen_assert((i<0 && -i<=subs()) || (i>=0 && i<=supers())); - return Block(m_data, supers()-i, std::max(0,i), 1, diagonalLength(i)); + return Block(m_data, supers()-i, std::max(0,i), 1, diagonalLength(i)); } template inline void evalTo(Dest& dst) const diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h index 3ab242537..00d5d8b4e 100644 --- a/Eigen/src/Core/Block.h +++ b/Eigen/src/Core/Block.h @@ -96,9 +96,13 @@ struct traits ? PacketAccessBit : 0, MaskAlignedBit = (InnerPanel && (OuterStrideAtCompileTime!=Dynamic) && ((OuterStrideAtCompileTime % packet_traits::size) == 0)) ? AlignedBit : 0, FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ? LinearAccessBit : 0, - Flags0 = traits::Flags & (HereditaryBits | MaskPacketAccessBit | LvalueBit | DirectAccessBit | MaskAlignedBit), - Flags1 = Flags0 | FlagsLinearAccessBit, - Flags = (Flags1 & ~RowMajorBit) | (IsRowMajor ? RowMajorBit : 0) + FlagsLvalueBit = is_lvalue::value ? LvalueBit : 0, + FlagsRowMajorBit = IsRowMajor ? RowMajorBit : 0, + Flags0 = traits::Flags & ( (HereditaryBits & ~RowMajorBit) | + DirectAccessBit | + MaskPacketAccessBit | + MaskAlignedBit), + Flags = Flags0 | FlagsLinearAccessBit | FlagsLvalueBit | FlagsRowMajorBit }; }; } @@ -162,6 +166,13 @@ template /** Column or Row constructor */ - inline Block(const XprType& xpr, Index i) - : Base(&xpr.const_cast_derived().coeffRef( + inline Block(XprType& xpr, Index i) + : Base(&xpr.coeffRef( (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ? i : 0, (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0), BlockRows==1 ? 1 : xpr.rows(), @@ -262,8 +281,8 @@ class Block /** Fixed-size constructor */ - inline Block(const XprType& xpr, Index startRow, Index startCol) - : Base(&xpr.const_cast_derived().coeffRef(startRow,startCol)), m_xpr(xpr) + inline Block(XprType& xpr, Index startRow, Index startCol) + : Base(&xpr.coeffRef(startRow,startCol)), m_xpr(xpr) { eigen_assert(startRow >= 0 && BlockRows >= 1 && startRow + BlockRows <= xpr.rows() && startCol >= 0 && BlockCols >= 1 && startCol + BlockCols <= xpr.cols()); @@ -272,10 +291,10 @@ class Block /** Dynamic-size constructor */ - inline Block(const XprType& xpr, + inline Block(XprType& xpr, Index startRow, Index startCol, Index blockRows, Index blockCols) - : Base(&xpr.const_cast_derived().coeffRef(startRow,startCol), blockRows, blockCols), + : Base(&xpr.coeffRef(startRow,startCol), blockRows, blockCols), m_xpr(xpr) { eigen_assert((RowsAtCompileTime==Dynamic || RowsAtCompileTime==blockRows) diff --git a/Eigen/src/Core/DenseBase.h b/Eigen/src/Core/DenseBase.h index 1d7ceb9a0..c5da1c6b0 100644 --- a/Eigen/src/Core/DenseBase.h +++ b/Eigen/src/Core/DenseBase.h @@ -172,6 +172,8 @@ template class DenseBase OuterStrideAtCompileTime = internal::outer_stride_at_compile_time::ret }; + enum { ThisConstantIsPrivateInPlainObjectBase }; + /** \returns the number of nonzero coefficients which is in practice the number * of stored coefficients. */ inline Index nonZeros() const { return size(); } @@ -273,7 +275,8 @@ template class DenseBase CommaInitializer operator<< (const DenseBase& other); Eigen::Transpose transpose(); - const Eigen::Transpose transpose() const; + typedef const Transpose ConstTransposeReturnType; + ConstTransposeReturnType transpose() const; void transposeInPlace(); #ifndef EIGEN_NO_DEBUG protected: @@ -282,41 +285,28 @@ template class DenseBase public: #endif - VectorBlock segment(Index start, Index size); - const VectorBlock segment(Index start, Index size) const; + typedef VectorBlock SegmentReturnType; + typedef const VectorBlock ConstSegmentReturnType; + template struct FixedSegmentReturnType { typedef VectorBlock Type; }; + template struct ConstFixedSegmentReturnType { typedef const VectorBlock Type; }; + + SegmentReturnType segment(Index start, Index size); + ConstSegmentReturnType segment(Index start, Index size) const; - VectorBlock head(Index size); - const VectorBlock head(Index size) const; + SegmentReturnType head(Index size); + ConstSegmentReturnType head(Index size) const; - VectorBlock tail(Index size); - const VectorBlock tail(Index size) const; + SegmentReturnType tail(Index size); + ConstSegmentReturnType tail(Index size) const; - template VectorBlock head(void); - template const VectorBlock head() const; + template typename FixedSegmentReturnType::Type head(); + template typename ConstFixedSegmentReturnType::Type head() const; - template VectorBlock tail(); - template const VectorBlock tail() const; + template typename FixedSegmentReturnType::Type tail(); + template typename ConstFixedSegmentReturnType::Type tail() const; - template VectorBlock segment(Index start); - template const VectorBlock segment(Index start) const; - - Diagonal diagonal(); - const Diagonal diagonal() const; - - template Diagonal diagonal(); - template const Diagonal diagonal() const; - - Diagonal diagonal(Index index); - const Diagonal diagonal(Index index) const; - - template TriangularView part(); - template const TriangularView part() const; - - template TriangularView triangularView(); - template const TriangularView triangularView() const; - - template SelfAdjointView selfadjointView(); - template const SelfAdjointView selfadjointView() const; + template typename FixedSegmentReturnType::Type segment(Index start); + template typename ConstFixedSegmentReturnType::Type segment(Index start) const; static const ConstantReturnType Constant(Index rows, Index cols, const Scalar& value); @@ -389,8 +379,25 @@ template class DenseBase return typename internal::eval::type(derived()); } + /** swaps *this with the expression \a other. + * + */ template - void swap(DenseBase EIGEN_REF_TO_TEMPORARY other); + void swap(const DenseBase& other, + int = OtherDerived::ThisConstantIsPrivateInPlainObjectBase) + { + SwapWrapper(derived()).lazyAssign(other.derived()); + } + + /** swaps *this with the matrix or array \a other. + * + */ + template + void swap(PlainObjectBase& other) + { + SwapWrapper(derived()).lazyAssign(other.derived()); + } + inline const NestByValue nestByValue() const; inline const ForceAlignedAccess forceAlignedAccess() const; @@ -436,10 +443,15 @@ template class DenseBase bool any(void) const; Index count() const; - const VectorwiseOp rowwise() const; - VectorwiseOp rowwise(); - const VectorwiseOp colwise() const; - VectorwiseOp colwise(); + typedef VectorwiseOp RowwiseReturnType; + typedef const VectorwiseOp ConstRowwiseReturnType; + typedef VectorwiseOp ColwiseReturnType; + typedef const VectorwiseOp ConstColwiseReturnType; + + ConstRowwiseReturnType rowwise() const; + RowwiseReturnType rowwise(); + ConstColwiseReturnType colwise() const; + ColwiseReturnType colwise(); static const CwiseNullaryOp,Derived> Random(Index rows, Index cols); static const CwiseNullaryOp,Derived> Random(Index size); @@ -464,8 +476,10 @@ template class DenseBase const Replicate replicate() const; const Replicate replicate(Index rowFacor,Index colFactor) const; - Eigen::Reverse reverse(); - const Eigen::Reverse reverse() const; + typedef Reverse ReverseReturnType; + typedef const Reverse ConstReverseReturnType; + ReverseReturnType reverse(); + ConstReverseReturnType reverse() const; void reverseInPlace(); #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::DenseBase diff --git a/Eigen/src/Core/Diagonal.h b/Eigen/src/Core/Diagonal.h index 158bc6df7..30818f6d1 100644 --- a/Eigen/src/Core/Diagonal.h +++ b/Eigen/src/Core/Diagonal.h @@ -64,7 +64,8 @@ struct traits > MatrixType::MaxColsAtCompileTime) : (EIGEN_SIZE_MIN_PREFER_FIXED(MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime) - AbsDiagIndex), MaxColsAtCompileTime = 1, - Flags = (unsigned int)_MatrixTypeNested::Flags & (HereditaryBits | LinearAccessBit | LvalueBit | DirectAccessBit) & ~RowMajorBit, + MaskLvalueBit = is_lvalue::value ? LvalueBit : 0, + Flags = (unsigned int)_MatrixTypeNested::Flags & (HereditaryBits | LinearAccessBit | MaskLvalueBit | DirectAccessBit) & ~RowMajorBit, CoeffReadCost = _MatrixTypeNested::CoeffReadCost, MatrixTypeOuterStride = outer_stride_at_compile_time::ret, InnerStrideAtCompileTime = MatrixTypeOuterStride == Dynamic ? Dynamic : MatrixTypeOuterStride+1, @@ -105,6 +106,11 @@ template class Diagonal return m_matrix.const_cast_derived().coeffRef(row+rowOffset(), row+colOffset()); } + inline const Scalar& coeffRef(Index row, Index) const + { + return m_matrix.const_cast_derived().coeffRef(row+rowOffset(), row+colOffset()); + } + inline CoeffReturnType coeff(Index row, Index) const { return m_matrix.coeff(row+rowOffset(), row+colOffset()); @@ -115,6 +121,11 @@ template class Diagonal return m_matrix.const_cast_derived().coeffRef(index+rowOffset(), index+colOffset()); } + inline const Scalar& coeffRef(Index index) const + { + return m_matrix.const_cast_derived().coeffRef(index+rowOffset(), index+colOffset()); + } + inline CoeffReturnType coeff(Index index) const { return m_matrix.coeff(index+rowOffset(), index+colOffset()); @@ -143,18 +154,18 @@ template class Diagonal * * \sa class Diagonal */ template -inline Diagonal +inline typename MatrixBase::DiagonalReturnType MatrixBase::diagonal() { - return Diagonal(derived()); + return derived(); } /** This is the const version of diagonal(). */ template -inline const Diagonal +inline const typename MatrixBase::ConstDiagonalReturnType MatrixBase::diagonal() const { - return Diagonal(derived()); + return derived(); } /** \returns an expression of the \a DiagIndex-th sub or super diagonal of the matrix \c *this @@ -169,18 +180,18 @@ MatrixBase::diagonal() const * * \sa MatrixBase::diagonal(), class Diagonal */ template -inline Diagonal +inline typename MatrixBase::template DiagonalIndexReturnType::Type MatrixBase::diagonal(Index index) { - return Diagonal(derived(), index); + return typename DiagonalIndexReturnType::Type(derived(), index); } /** This is the const version of diagonal(Index). */ template -inline const Diagonal +inline typename MatrixBase::template ConstDiagonalIndexReturnType::Type MatrixBase::diagonal(Index index) const { - return Diagonal(derived(), index); + return typename ConstDiagonalIndexReturnType::Type(derived(), index); } /** \returns an expression of the \a DiagIndex-th sub or super diagonal of the matrix \c *this @@ -195,20 +206,20 @@ MatrixBase::diagonal(Index index) const * * \sa MatrixBase::diagonal(), class Diagonal */ template -template -inline Diagonal +template +inline typename MatrixBase::template DiagonalIndexReturnType::Type MatrixBase::diagonal() { - return Diagonal(derived()); + return derived(); } /** This is the const version of diagonal(). */ template -template -inline const Diagonal +template +inline typename MatrixBase::template ConstDiagonalIndexReturnType::Type MatrixBase::diagonal() const { - return Diagonal(derived()); + return derived(); } #endif // EIGEN_DIAGONAL_H diff --git a/Eigen/src/Core/EigenBase.h b/Eigen/src/Core/EigenBase.h index 69e964350..0472539af 100644 --- a/Eigen/src/Core/EigenBase.h +++ b/Eigen/src/Core/EigenBase.h @@ -51,6 +51,8 @@ template struct EigenBase inline Derived& const_cast_derived() const { return *static_cast(const_cast(this)); } + inline const Derived& const_derived() const + { return *static_cast(this); } /** \returns the number of rows. \sa cols(), RowsAtCompileTime */ inline Index rows() const { return derived().rows(); } diff --git a/Eigen/src/Core/Map.h b/Eigen/src/Core/Map.h index b38b2f048..e9534b6bb 100644 --- a/Eigen/src/Core/Map.h +++ b/Eigen/src/Core/Map.h @@ -80,9 +80,9 @@ namespace internal { template struct traits > - : public traits::type> + : public traits { - typedef traits::type> TraitsBase; + typedef traits TraitsBase; typedef typename PlainObjectType::Index Index; typedef typename PlainObjectType::Scalar Scalar; enum { @@ -106,7 +106,7 @@ struct traits > Flags1 = IsAligned ? (int(Flags0) | AlignedBit) : (int(Flags0) & ~AlignedBit), Flags2 = (bool(HasNoStride) || bool(PlainObjectType::IsVectorAtCompileTime)) ? int(Flags1) : int(Flags1 & ~LinearAccessBit), - Flags3 = internal::is_const::value ? (int(Flags2) & ~LvalueBit) : int(Flags2), + Flags3 = is_lvalue::value ? int(Flags2) : (int(Flags2) & ~LvalueBit), Flags = KeepsPacketAccess ? int(Flags3) : (int(Flags3) & ~PacketAccessBit) }; private: diff --git a/Eigen/src/Core/MapBase.h b/Eigen/src/Core/MapBase.h index b5bd7f964..d8ecdf2f4 100644 --- a/Eigen/src/Core/MapBase.h +++ b/Eigen/src/Core/MapBase.h @@ -56,7 +56,7 @@ template class MapBase typedef typename internal::packet_traits::type PacketScalar; typedef typename NumTraits::Real RealScalar; typedef typename internal::conditional< - bool(int(internal::traits::Flags) & LvalueBit), + bool(internal::is_lvalue::value), Scalar *, const Scalar *>::type PointerType; diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 0dca72dbd..6fb10de9d 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -93,6 +93,7 @@ template class MatrixBase using Base::operator/=; typedef typename Base::CoeffReturnType CoeffReturnType; + typedef typename Base::ConstTransposeReturnType ConstTransposeReturnType; typedef typename Base::RowXpr RowXpr; typedef typename Base::ColXpr ColXpr; #endif // not EIGEN_PARSED_BY_DOXYGEN @@ -128,8 +129,8 @@ template class MatrixBase typedef CwiseNullaryOp,Derived> ConstantReturnType; /** \internal the return type of MatrixBase::adjoint() */ typedef typename internal::conditional::IsComplex, - CwiseUnaryOp, Eigen::Transpose >, - Transpose + CwiseUnaryOp, ConstTransposeReturnType>, + ConstTransposeReturnType >::type AdjointReturnType; /** \internal Return type of eigenvalues() */ typedef Matrix, internal::traits::ColsAtCompileTime, 1, ColMajor> EigenvaluesReturnType; @@ -212,23 +213,34 @@ template class MatrixBase const AdjointReturnType adjoint() const; void adjointInPlace(); - Diagonal diagonal(); - const Diagonal diagonal() const; + typedef Diagonal DiagonalReturnType; + DiagonalReturnType diagonal(); + typedef const Diagonal ConstDiagonalReturnType; + ConstDiagonalReturnType diagonal() const; - template Diagonal diagonal(); - template const Diagonal diagonal() const; + template struct DiagonalIndexReturnType { typedef Diagonal Type; }; + template struct ConstDiagonalIndexReturnType { typedef const Diagonal Type; }; - Diagonal diagonal(Index index); - const Diagonal diagonal(Index index) const; + template typename DiagonalIndexReturnType::Type diagonal(); + template typename ConstDiagonalIndexReturnType::Type diagonal() const; + + typename DiagonalIndexReturnType::Type diagonal(Index index); + typename ConstDiagonalIndexReturnType::Type diagonal(Index index) const; template TriangularView part(); template const TriangularView part() const; - template TriangularView triangularView(); - template const TriangularView triangularView() const; + template struct TriangularViewReturnType { typedef TriangularView Type; }; + template struct ConstTriangularViewReturnType { typedef const TriangularView Type; }; - template SelfAdjointView selfadjointView(); - template const SelfAdjointView selfadjointView() const; + template typename TriangularViewReturnType::Type triangularView(); + template typename ConstTriangularViewReturnType::Type triangularView() const; + + template struct SelfAdjointViewReturnType { typedef SelfAdjointView Type; }; + template struct ConstSelfAdjointViewReturnType { typedef const SelfAdjointView Type; }; + + template typename SelfAdjointViewReturnType::Type selfadjointView(); + template typename ConstSelfAdjointViewReturnType::Type selfadjointView() const; const SparseView sparseView(const Scalar& m_reference = Scalar(0), typename NumTraits::Real m_epsilon = NumTraits::dummy_precision()) const; @@ -345,13 +357,13 @@ template class MatrixBase enum { SizeMinusOne = SizeAtCompileTime==Dynamic ? Dynamic : SizeAtCompileTime-1 }; - typedef Block::ColsAtCompileTime==1 ? SizeMinusOne : 1, - internal::traits::ColsAtCompileTime==1 ? 1 : SizeMinusOne> StartMinusOne; + internal::traits::ColsAtCompileTime==1 ? 1 : SizeMinusOne> ConstStartMinusOne; typedef CwiseUnaryOp::Scalar>, - StartMinusOne > HNormalizedReturnType; + ConstStartMinusOne > HNormalizedReturnType; - HNormalizedReturnType hnormalized() const; + const HNormalizedReturnType hnormalized() const; // put this as separate enum value to work around possible GCC 4.3 bug (?) enum { HomogeneousReturnTypeDirection = ColsAtCompileTime==1?Vertical:Horizontal }; diff --git a/Eigen/src/Core/PermutationMatrix.h b/Eigen/src/Core/PermutationMatrix.h index 1f333adea..f53dd8772 100644 --- a/Eigen/src/Core/PermutationMatrix.h +++ b/Eigen/src/Core/PermutationMatrix.h @@ -389,7 +389,7 @@ struct permut_matrix_product_retval = - Block + Block (m_matrix, ((Side==OnTheRight) ^ Transposed) ? m_permutation.indices().coeff(i) : i); } } diff --git a/Eigen/src/Core/PlainObjectBase.h b/Eigen/src/Core/PlainObjectBase.h index 4df262d16..5b0169f72 100644 --- a/Eigen/src/Core/PlainObjectBase.h +++ b/Eigen/src/Core/PlainObjectBase.h @@ -66,15 +66,14 @@ class PlainObjectBase : public internal::dense_xpr_base::type using Base::IsVectorAtCompileTime; using Base::Flags; - typedef typename internal::add_const::type ConstDerived; friend class Eigen::Map; - typedef class Eigen::Map MapType; - friend class Eigen::Map; - typedef class Eigen::Map ConstMapType; + typedef Eigen::Map MapType; + friend class Eigen::Map; + typedef const Eigen::Map ConstMapType; friend class Eigen::Map; - typedef class Eigen::Map AlignedMapType; - friend class Eigen::Map; - typedef class Eigen::Map ConstAlignedMapType; + typedef Eigen::Map AlignedMapType; + friend class Eigen::Map; + typedef const Eigen::Map ConstAlignedMapType; protected: DenseStorage m_storage; @@ -116,6 +115,19 @@ class PlainObjectBase : public internal::dense_xpr_base::type return m_storage.data()[index]; } + EIGEN_STRONG_INLINE const Scalar& coeffRef(Index row, Index col) const + { + if(Flags & RowMajorBit) + return m_storage.data()[col + row * m_storage.cols()]; + else // column-major + return m_storage.data()[row + col * m_storage.rows()]; + } + + EIGEN_STRONG_INLINE const Scalar& coeffRef(Index index) const + { + return m_storage.data()[index]; + } + template EIGEN_STRONG_INLINE PacketScalar packet(Index row, Index col) const { @@ -381,28 +393,28 @@ class PlainObjectBase : public internal::dense_xpr_base::type * \see class Map */ //@{ - inline static const ConstMapType Map(const Scalar* data) + inline static ConstMapType Map(const Scalar* data) { return ConstMapType(data); } inline static MapType Map(Scalar* data) { return MapType(data); } - inline static const ConstMapType Map(const Scalar* data, Index size) + inline static ConstMapType Map(const Scalar* data, Index size) { return ConstMapType(data, size); } inline static MapType Map(Scalar* data, Index size) { return MapType(data, size); } - inline static const ConstMapType Map(const Scalar* data, Index rows, Index cols) + inline static ConstMapType Map(const Scalar* data, Index rows, Index cols) { return ConstMapType(data, rows, cols); } inline static MapType Map(Scalar* data, Index rows, Index cols) { return MapType(data, rows, cols); } - inline static const ConstAlignedMapType MapAligned(const Scalar* data) + inline static ConstAlignedMapType MapAligned(const Scalar* data) { return ConstAlignedMapType(data); } inline static AlignedMapType MapAligned(Scalar* data) { return AlignedMapType(data); } - inline static const ConstAlignedMapType MapAligned(const Scalar* data, Index size) + inline static ConstAlignedMapType MapAligned(const Scalar* data, Index size) { return ConstAlignedMapType(data, size); } inline static AlignedMapType MapAligned(Scalar* data, Index size) { return AlignedMapType(data, size); } - inline static const ConstAlignedMapType MapAligned(const Scalar* data, Index rows, Index cols) + inline static ConstAlignedMapType MapAligned(const Scalar* data, Index rows, Index cols) { return ConstAlignedMapType(data, rows, cols); } inline static AlignedMapType MapAligned(Scalar* data, Index rows, Index cols) { return AlignedMapType(data, rows, cols); } @@ -536,6 +548,9 @@ class PlainObjectBase : public internal::dense_xpr_base::type INVALID_MATRIX_TEMPLATE_PARAMETERS) } #endif + +private: + enum { ThisConstantIsPrivateInPlainObjectBase }; }; template diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h index eacdccb9a..49e27a448 100644 --- a/Eigen/src/Core/Product.h +++ b/Eigen/src/Core/Product.h @@ -353,7 +353,7 @@ struct gemv_selector Transpose destT(dest); enum { OtherStorageOrder = StorageOrder == RowMajor ? ColMajor : RowMajor }; gemv_selector - ::run(GeneralProduct,Transpose, GemvProduct> + ::run(GeneralProduct,Transpose, GemvProduct> (prod.rhs().transpose(), prod.lhs().transpose()), destT, alpha); } }; @@ -442,8 +442,8 @@ template<> struct gemv_selector typedef typename ProductType::LhsBlasTraits LhsBlasTraits; typedef typename ProductType::RhsBlasTraits RhsBlasTraits; - ActualLhsType actualLhs = LhsBlasTraits::extract(prod.lhs()); - ActualRhsType actualRhs = RhsBlasTraits::extract(prod.rhs()); + typename add_const::type actualLhs = LhsBlasTraits::extract(prod.lhs()); + typename add_const::type actualRhs = RhsBlasTraits::extract(prod.rhs()); ResScalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(prod.lhs()) * RhsBlasTraits::extractScalarFactor(prod.rhs()); @@ -457,7 +457,7 @@ template<> struct gemv_selector RhsScalar* rhs_data; if (DirectlyUseRhs) - rhs_data = &actualRhs.const_cast_derived().coeffRef(0); + rhs_data = const_cast(&actualRhs.coeffRef(0)); else { rhs_data = ei_aligned_stack_new(RhsScalar, actualRhs.size()); @@ -467,7 +467,7 @@ template<> struct gemv_selector general_matrix_vector_product ::run( actualLhs.rows(), actualLhs.cols(), - &actualLhs.const_cast_derived().coeffRef(0,0), actualLhs.outerStride(), + &actualLhs.coeffRef(0,0), actualLhs.outerStride(), rhs_data, 1, &dest.coeffRef(0,0), dest.innerStride(), actualAlpha); diff --git a/Eigen/src/Core/Replicate.h b/Eigen/src/Core/Replicate.h index 87fcfccdd..d2f9712db 100644 --- a/Eigen/src/Core/Replicate.h +++ b/Eigen/src/Core/Replicate.h @@ -81,7 +81,7 @@ template class Replicate inline explicit Replicate(const OriginalMatrixType& matrix) : m_matrix(matrix), m_rowFactor(RowFactor), m_colFactor(ColFactor) { - EIGEN_STATIC_ASSERT((internal::is_same::value), + EIGEN_STATIC_ASSERT((internal::is_same::type,OriginalMatrixType>::value), THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE) eigen_assert(RowFactor!=Dynamic && ColFactor!=Dynamic); } @@ -90,7 +90,7 @@ template class Replicate inline Replicate(const OriginalMatrixType& matrix, int rowFactor, int colFactor) : m_matrix(matrix), m_rowFactor(rowFactor), m_colFactor(colFactor) { - EIGEN_STATIC_ASSERT((internal::is_same::value), + EIGEN_STATIC_ASSERT((internal::is_same::type,OriginalMatrixType>::value), THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE) } diff --git a/Eigen/src/Core/Reverse.h b/Eigen/src/Core/Reverse.h index ed32b17fc..600744ae7 100644 --- a/Eigen/src/Core/Reverse.h +++ b/Eigen/src/Core/Reverse.h @@ -194,7 +194,7 @@ template class Reverse * */ template -inline Reverse +inline typename DenseBase::ReverseReturnType DenseBase::reverse() { return derived(); @@ -202,7 +202,7 @@ DenseBase::reverse() /** This is the const version of reverse(). */ template -inline const Reverse +inline const typename DenseBase::ConstReverseReturnType DenseBase::reverse() const { return derived(); @@ -216,7 +216,7 @@ DenseBase::reverse() const * the following additional features: * - less error prone: doing the same operation with .reverse() requires special care: * \code m = m.reverse().eval(); \endcode - * - no temporary object is created (currently there is one created but could be avoided using swap) + * - this API allows to avoid creating a temporary (the current implementation creates a temporary, but that could be avoided using swap) * - it allows future optimizations (cache friendliness, etc.) * * \sa reverse() */ diff --git a/Eigen/src/Core/SelfAdjointView.h b/Eigen/src/Core/SelfAdjointView.h index dd1757aea..5d8468884 100644 --- a/Eigen/src/Core/SelfAdjointView.h +++ b/Eigen/src/Core/SelfAdjointView.h @@ -282,14 +282,16 @@ struct triangular_assignment_selector template -const SelfAdjointView MatrixBase::selfadjointView() const +typename MatrixBase::template ConstSelfAdjointViewReturnType::Type +MatrixBase::selfadjointView() const { return derived(); } template template -SelfAdjointView MatrixBase::selfadjointView() +typename MatrixBase::template SelfAdjointViewReturnType::Type +MatrixBase::selfadjointView() { return derived(); } diff --git a/Eigen/src/Core/SelfCwiseBinaryOp.h b/Eigen/src/Core/SelfCwiseBinaryOp.h index 213983588..4e9ca8874 100644 --- a/Eigen/src/Core/SelfCwiseBinaryOp.h +++ b/Eigen/src/Core/SelfCwiseBinaryOp.h @@ -77,12 +77,22 @@ template class SelfCwiseBinaryOp // TODO make Assign use .data() inline Scalar& coeffRef(Index row, Index col) { + EIGEN_STATIC_ASSERT_LVALUE(Lhs) return m_matrix.const_cast_derived().coeffRef(row, col); } + inline const Scalar& coeffRef(Index row, Index col) const + { + return m_matrix.coeffRef(row, col); + } // note that this function is needed by assign to correctly align loads/stores // TODO make Assign use .data() inline Scalar& coeffRef(Index index) + { + EIGEN_STATIC_ASSERT_LVALUE(Lhs) + return m_matrix.const_cast_derived().coeffRef(index); + } + inline const Scalar& coeffRef(Index index) const { return m_matrix.const_cast_derived().coeffRef(index); } diff --git a/Eigen/src/Core/SolveTriangular.h b/Eigen/src/Core/SolveTriangular.h index 63f08e9fb..d186b5a4b 100644 --- a/Eigen/src/Core/SolveTriangular.h +++ b/Eigen/src/Core/SolveTriangular.h @@ -110,7 +110,7 @@ struct triangular_solver_selector const ActualLhsType actualLhs = LhsProductTraits::extract(lhs); triangular_solve_matrix - ::run(lhs.rows(), Side==OnTheLeft? rhs.cols() : rhs.rows(), &actualLhs.coeff(0,0), actualLhs.outerStride(), &rhs.coeffRef(0,0), rhs.outerStride()); + ::run(lhs.rows(), Side==OnTheLeft? rhs.cols() : rhs.rows(), &actualLhs.coeffRef(0,0), actualLhs.outerStride(), &rhs.coeffRef(0,0), rhs.outerStride()); } }; diff --git a/Eigen/src/Core/Swap.h b/Eigen/src/Core/Swap.h index abbef4443..5fb032866 100644 --- a/Eigen/src/Core/Swap.h +++ b/Eigen/src/Core/Swap.h @@ -63,6 +63,16 @@ template class SwapWrapper return m_expression.const_cast_derived().coeffRef(index); } + inline Scalar& coeffRef(Index row, Index col) const + { + return m_expression.coeffRef(row, col); + } + + inline Scalar& coeffRef(Index index) const + { + return m_expression.coeffRef(index); + } + template void copyCoeff(Index row, Index col, const DenseBase& other) { @@ -113,18 +123,4 @@ template class SwapWrapper ExpressionType& m_expression; }; -/** swaps *this with the expression \a other. - * - * \note \a other is only marked for internal reasons, but of course - * it gets const-casted. One reason is that one will often call swap - * on temporary objects (hence non-const references are forbidden). - * Another reason is that lazyAssign takes a const argument anyway. - */ -template -template -void DenseBase::swap(DenseBase EIGEN_REF_TO_TEMPORARY other) -{ - (SwapWrapper(derived())).lazyAssign(other); -} - #endif // EIGEN_SWAP_H diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h index 394b375ab..1c9403eba 100644 --- a/Eigen/src/Core/Transpose.h +++ b/Eigen/src/Core/Transpose.h @@ -46,7 +46,7 @@ struct traits > : traits { typedef typename MatrixType::Scalar Scalar; typedef typename nested::type MatrixTypeNested; - typedef typename remove_reference::type _MatrixTypeNested; + typedef typename remove_reference::type MatrixTypeNestedPlain; typedef typename traits::StorageKind StorageKind; typedef typename traits::XprKind XprKind; enum { @@ -54,8 +54,11 @@ struct traits > : traits ColsAtCompileTime = MatrixType::RowsAtCompileTime, MaxRowsAtCompileTime = MatrixType::MaxColsAtCompileTime, MaxColsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - Flags = int(_MatrixTypeNested::Flags & ~NestByRefBit) ^ RowMajorBit, - CoeffReadCost = _MatrixTypeNested::CoeffReadCost, + FlagsLvalueBit = is_lvalue::value ? LvalueBit : 0, + Flags0 = MatrixTypeNestedPlain::Flags & ~(LvalueBit | NestByRefBit), + Flags1 = Flags0 | FlagsLvalueBit, + Flags = Flags1 ^ RowMajorBit, + CoeffReadCost = MatrixTypeNestedPlain::CoeffReadCost, InnerStrideAtCompileTime = inner_stride_at_compile_time::ret, OuterStrideAtCompileTime = outer_stride_at_compile_time::ret }; @@ -122,12 +125,24 @@ template class TransposeImpl inline Scalar& coeffRef(Index row, Index col) { - return const_cast_derived().nestedExpression().coeffRef(col, row); + EIGEN_STATIC_ASSERT_LVALUE(MatrixType) + return derived().nestedExpression().const_cast_derived().coeffRef(col, row); } inline Scalar& coeffRef(Index index) { - return const_cast_derived().nestedExpression().coeffRef(index); + EIGEN_STATIC_ASSERT_LVALUE(MatrixType) + return derived().nestedExpression().const_cast_derived().coeffRef(index); + } + + inline const Scalar& coeffRef(Index row, Index col) const + { + return derived().nestedExpression().coeffRef(col, row); + } + + inline const Scalar& coeffRef(Index index) const + { + return derived().nestedExpression().coeffRef(index); } inline const CoeffReturnType coeff(Index row, Index col) const @@ -149,7 +164,7 @@ template class TransposeImpl template inline void writePacket(Index row, Index col, const PacketScalar& x) { - const_cast_derived().nestedExpression().template writePacket(col, row, x); + derived().nestedExpression().const_cast_derived().template writePacket(col, row, x); } template @@ -161,7 +176,7 @@ template class TransposeImpl template inline void writePacket(Index index, const PacketScalar& x) { - const_cast_derived().nestedExpression().template writePacket(index, x); + derived().nestedExpression().const_cast_derived().template writePacket(index, x); } }; @@ -197,7 +212,7 @@ DenseBase::transpose() * * \sa transposeInPlace(), adjoint() */ template -inline const Transpose +inline const typename DenseBase::ConstTransposeReturnType DenseBase::transpose() const { return derived(); @@ -226,7 +241,8 @@ template inline const typename MatrixBase::AdjointReturnType MatrixBase::adjoint() const { - return this->transpose(); + return this->transpose(); // in the complex case, the .conjugate() is be implicit here + // due to implicit conversion to return type } /*************************************************************************** diff --git a/Eigen/src/Core/TriangularMatrix.h b/Eigen/src/Core/TriangularMatrix.h index 328aac611..575681620 100644 --- a/Eigen/src/Core/TriangularMatrix.h +++ b/Eigen/src/Core/TriangularMatrix.h @@ -95,10 +95,11 @@ template class TriangularBase : public EigenBase EIGEN_ONLY_USED_FOR_DEBUG(row); EIGEN_ONLY_USED_FOR_DEBUG(col); eigen_assert(col>=0 && col=0 && row=row) - || (Mode==Lower && col<=row) - || ((Mode==StrictlyUpper || Mode==UnitUpper) && col>row) - || ((Mode==StrictlyLower || Mode==UnitLower) && col=row) + || (mode==Lower && col<=row) + || ((mode==StrictlyUpper || mode==UnitUpper) && col>row) + || ((mode==StrictlyLower || mode==UnitLower) && col class TriangularView /** \sa MatrixBase::transpose() */ inline TriangularView,TransposeMode> transpose() - { return m_matrix.transpose(); } + { + EIGEN_STATIC_ASSERT_LVALUE(MatrixType) + return m_matrix.const_cast_derived().transpose(); + } /** \sa MatrixBase::transpose() const */ inline const TriangularView,TransposeMode> transpose() const { return m_matrix.transpose(); } @@ -701,7 +705,8 @@ EIGEN_DEPRECATED TriangularView MatrixBase::part() */ template template -TriangularView MatrixBase::triangularView() +typename MatrixBase::template TriangularViewReturnType::Type +MatrixBase::triangularView() { return derived(); } @@ -709,7 +714,8 @@ TriangularView MatrixBase::triangularView() /** This is the const version of MatrixBase::triangularView() */ template template -const TriangularView MatrixBase::triangularView() const +typename MatrixBase::template ConstTriangularViewReturnType::Type +MatrixBase::triangularView() const { return derived(); } diff --git a/Eigen/src/Core/VectorBlock.h b/Eigen/src/Core/VectorBlock.h index 912277633..858e4c786 100644 --- a/Eigen/src/Core/VectorBlock.h +++ b/Eigen/src/Core/VectorBlock.h @@ -85,7 +85,7 @@ template class VectorBlock /** Dynamic-size constructor */ - inline VectorBlock(const VectorType& vector, Index start, Index size) + inline VectorBlock(VectorType& vector, Index start, Index size) : Base(vector, IsColVector ? start : 0, IsColVector ? 0 : start, IsColVector ? size : 1, IsColVector ? 1 : size) @@ -95,7 +95,7 @@ template class VectorBlock /** Fixed-size constructor */ - inline VectorBlock(const VectorType& vector, Index start) + inline VectorBlock(VectorType& vector, Index start) : Base(vector, IsColVector ? start : 0, IsColVector ? 0 : start) { EIGEN_STATIC_ASSERT_VECTOR_ONLY(VectorBlock); @@ -120,20 +120,20 @@ template class VectorBlock * \sa class Block, segment(Index) */ template -inline VectorBlock DenseBase - ::segment(Index start, Index size) +inline typename DenseBase::SegmentReturnType +DenseBase::segment(Index start, Index size) { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return VectorBlock(derived(), start, size); + return SegmentReturnType(derived(), start, size); } /** This is the const version of segment(Index,Index).*/ template -inline const VectorBlock +inline typename DenseBase::ConstSegmentReturnType DenseBase::segment(Index start, Index size) const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return VectorBlock(derived(), start, size); + return ConstSegmentReturnType(derived(), start, size); } /** \returns a dynamic-size expression of the first coefficients of *this. @@ -152,20 +152,20 @@ DenseBase::segment(Index start, Index size) const * \sa class Block, block(Index,Index) */ template -inline VectorBlock +inline typename DenseBase::SegmentReturnType DenseBase::head(Index size) { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return VectorBlock(derived(), 0, size); + return SegmentReturnType(derived(), 0, size); } /** This is the const version of head(Index).*/ template -inline const VectorBlock +inline typename DenseBase::ConstSegmentReturnType DenseBase::head(Index size) const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return VectorBlock(derived(), 0, size); + return ConstSegmentReturnType(derived(), 0, size); } /** \returns a dynamic-size expression of the last coefficients of *this. @@ -184,20 +184,20 @@ DenseBase::head(Index size) const * \sa class Block, block(Index,Index) */ template -inline VectorBlock +inline typename DenseBase::SegmentReturnType DenseBase::tail(Index size) { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return VectorBlock(derived(), this->size() - size, size); + return SegmentReturnType(derived(), this->size() - size, size); } /** This is the const version of tail(Index).*/ template -inline const VectorBlock +inline typename DenseBase::ConstSegmentReturnType DenseBase::tail(Index size) const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return VectorBlock(derived(), this->size() - size, size); + return ConstSegmentReturnType(derived(), this->size() - size, size); } /** \returns a fixed-size expression of a segment (i.e. a vector block) in \c *this @@ -215,21 +215,21 @@ DenseBase::tail(Index size) const */ template template -inline VectorBlock +inline typename DenseBase::template FixedSegmentReturnType::Type DenseBase::segment(Index start) { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return VectorBlock(derived(), start); + return typename FixedSegmentReturnType::Type(derived(), start); } /** This is the const version of segment(Index).*/ template template -inline const VectorBlock +inline typename DenseBase::template ConstFixedSegmentReturnType::Type DenseBase::segment(Index start) const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return VectorBlock(derived(), start); + return typename ConstFixedSegmentReturnType::Type(derived(), start); } /** \returns a fixed-size expression of the first coefficients of *this. @@ -245,21 +245,21 @@ DenseBase::segment(Index start) const */ template template -inline VectorBlock +inline typename DenseBase::template FixedSegmentReturnType::Type DenseBase::head() { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return VectorBlock(derived(), 0); + return typename FixedSegmentReturnType::Type(derived(), 0); } /** This is the const version of head().*/ template template -inline const VectorBlock +inline typename DenseBase::template ConstFixedSegmentReturnType::Type DenseBase::head() const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return VectorBlock(derived(), 0); + return typename ConstFixedSegmentReturnType::Type(derived(), 0); } /** \returns a fixed-size expression of the last coefficients of *this. @@ -275,21 +275,21 @@ DenseBase::head() const */ template template -inline VectorBlock +inline typename DenseBase::template FixedSegmentReturnType::Type DenseBase::tail() { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return VectorBlock(derived(), size() - Size); + return typename FixedSegmentReturnType::Type(derived(), size() - Size); } /** This is the const version of tail.*/ template template -inline const VectorBlock +inline typename DenseBase::template ConstFixedSegmentReturnType::Type DenseBase::tail() const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return VectorBlock(derived(), size() - Size); + return typename ConstFixedSegmentReturnType::Type(derived(), size() - Size); } diff --git a/Eigen/src/Core/VectorwiseOp.h b/Eigen/src/Core/VectorwiseOp.h index ab6089794..8e1a337ee 100644 --- a/Eigen/src/Core/VectorwiseOp.h +++ b/Eigen/src/Core/VectorwiseOp.h @@ -183,7 +183,8 @@ template class VectorwiseOp typedef typename ExpressionType::RealScalar RealScalar; typedef typename ExpressionType::Index Index; typedef typename internal::conditional::ret, - ExpressionType, const ExpressionType&>::type ExpressionTypeNested; + ExpressionType, ExpressionType&>::type ExpressionTypeNested; + typedef typename internal::remove_all::type ExpressionTypeNestedCleaned; template class Functor, typename Scalar=typename internal::traits::Scalar> struct ReturnType @@ -245,7 +246,7 @@ template class VectorwiseOp public: - inline VectorwiseOp(const ExpressionType& matrix) : m_matrix(matrix) {} + inline VectorwiseOp(ExpressionType& matrix) : m_matrix(matrix) {} /** \internal */ inline const ExpressionType& _expression() const { return m_matrix; } @@ -444,9 +445,9 @@ template class VectorwiseOp } /** Returns the expression of the sum of the vector \a other to each subvector of \c *this */ - template EIGEN_STRONG_INLINE + template EIGEN_STRONG_INLINE CwiseBinaryOp, - ExpressionType, + ExpressionTypeNestedCleaned, typename ExtendedType::Type> operator+(const DenseBase& other) const { @@ -457,7 +458,7 @@ template class VectorwiseOp /** Returns the expression of the difference between each subvector of \c *this and the vector \a other */ template CwiseBinaryOp, - ExpressionType, + ExpressionTypeNestedCleaned, typename ExtendedType::Type> operator-(const DenseBase& other) const { @@ -478,13 +479,13 @@ template class VectorwiseOp : internal::traits::ColsAtCompileTime, HNormalized_SizeMinusOne = HNormalized_Size==Dynamic ? Dynamic : HNormalized_Size-1 }; - typedef Block::RowsAtCompileTime), Direction==Horizontal ? int(HNormalized_SizeMinusOne) : int(internal::traits::ColsAtCompileTime)> HNormalized_Block; - typedef Block::RowsAtCompileTime), Direction==Horizontal ? 1 : int(internal::traits::ColsAtCompileTime)> HNormalized_Factors; @@ -495,7 +496,7 @@ template class VectorwiseOp Direction==Horizontal ? HNormalized_SizeMinusOne : 1> > HNormalizedReturnType; - HNormalizedReturnType hnormalized() const; + const HNormalizedReturnType hnormalized() const; protected: ExpressionTypeNested m_matrix; @@ -509,7 +510,7 @@ template class VectorwiseOp * \sa rowwise(), class VectorwiseOp */ template -inline const VectorwiseOp +inline const typename DenseBase::ConstColwiseReturnType DenseBase::colwise() const { return derived(); @@ -520,7 +521,7 @@ DenseBase::colwise() const * \sa rowwise(), class VectorwiseOp */ template -inline VectorwiseOp +inline typename DenseBase::ColwiseReturnType DenseBase::colwise() { return derived(); @@ -534,7 +535,7 @@ DenseBase::colwise() * \sa colwise(), class VectorwiseOp */ template -inline const VectorwiseOp +inline const typename DenseBase::ConstRowwiseReturnType DenseBase::rowwise() const { return derived(); @@ -545,7 +546,7 @@ DenseBase::rowwise() const * \sa colwise(), class VectorwiseOp */ template -inline VectorwiseOp +inline typename DenseBase::RowwiseReturnType DenseBase::rowwise() { return derived(); diff --git a/Eigen/src/Core/products/GeneralMatrixMatrix.h b/Eigen/src/Core/products/GeneralMatrixMatrix.h index d1bee31cc..7736a4b29 100644 --- a/Eigen/src/Core/products/GeneralMatrixMatrix.h +++ b/Eigen/src/Core/products/GeneralMatrixMatrix.h @@ -238,8 +238,8 @@ struct gemm_functor cols = m_rhs.cols(); Gemm::run(rows, cols, m_lhs.cols(), - /*(const Scalar*)*/&(m_lhs.const_cast_derived().coeffRef(row,0)), m_lhs.outerStride(), - /*(const Scalar*)*/&(m_rhs.const_cast_derived().coeffRef(0,col)), m_rhs.outerStride(), + /*(const Scalar*)*/&m_lhs.coeffRef(row,0), m_lhs.outerStride(), + /*(const Scalar*)*/&m_rhs.coeffRef(0,col), m_rhs.outerStride(), (Scalar*)&(m_dest.coeffRef(row,col)), m_dest.outerStride(), m_actualAlpha, m_blocking, info); } diff --git a/Eigen/src/Core/products/GeneralMatrixMatrixTriangular.h b/Eigen/src/Core/products/GeneralMatrixMatrixTriangular.h index c31bb48db..39495c1a2 100644 --- a/Eigen/src/Core/products/GeneralMatrixMatrixTriangular.h +++ b/Eigen/src/Core/products/GeneralMatrixMatrixTriangular.h @@ -218,7 +218,7 @@ TriangularView& TriangularView::assignProduct( typename Rhs::Scalar, _ActualRhs::Flags&RowMajorBit ? RowMajor : ColMajor, RhsBlasTraits::NeedToConjugate, MatrixType::Flags&RowMajorBit ? RowMajor : ColMajor, UpLo> ::run(m_matrix.cols(), actualLhs.cols(), - &actualLhs.coeff(0,0), actualLhs.outerStride(), &actualRhs.coeff(0,0), actualRhs.outerStride(), + &actualLhs.coeffRef(0,0), actualLhs.outerStride(), &actualRhs.coeffRef(0,0), actualRhs.outerStride(), const_cast(m_matrix.data()), m_matrix.outerStride(), actualAlpha); return *this; diff --git a/Eigen/src/Core/products/SelfadjointMatrixMatrix.h b/Eigen/src/Core/products/SelfadjointMatrixMatrix.h index 741c5f630..cfebcf426 100644 --- a/Eigen/src/Core/products/SelfadjointMatrixMatrix.h +++ b/Eigen/src/Core/products/SelfadjointMatrixMatrix.h @@ -423,8 +423,8 @@ struct SelfadjointProductMatrix internal::traits::Flags&RowMajorBit ? RowMajor : ColMajor> ::run( lhs.rows(), rhs.cols(), // sizes - &lhs.coeff(0,0), lhs.outerStride(), // lhs info - &rhs.coeff(0,0), rhs.outerStride(), // rhs info + &lhs.coeffRef(0,0), lhs.outerStride(), // lhs info + &rhs.coeffRef(0,0), rhs.outerStride(), // rhs info &dst.coeffRef(0,0), dst.outerStride(), // result info actualAlpha // alpha ); diff --git a/Eigen/src/Core/products/SelfadjointMatrixVector.h b/Eigen/src/Core/products/SelfadjointMatrixVector.h index 59c77705b..7d0f6c975 100644 --- a/Eigen/src/Core/products/SelfadjointMatrixVector.h +++ b/Eigen/src/Core/products/SelfadjointMatrixVector.h @@ -203,8 +203,8 @@ struct SelfadjointProductMatrix internal::product_selfadjoint_vector::Flags&RowMajorBit) ? RowMajor : ColMajor, int(LhsUpLo), bool(LhsBlasTraits::NeedToConjugate), bool(RhsBlasTraits::NeedToConjugate)> ( lhs.rows(), // size - &lhs.coeff(0,0), lhs.outerStride(), // lhs info - &rhs.coeff(0), rhs.innerStride(), // rhs info + &lhs.coeffRef(0,0), lhs.outerStride(), // lhs info + &rhs.coeffRef(0), rhs.innerStride(), // rhs info &dst.coeffRef(0), // result info actualAlpha // scale factor ); @@ -247,8 +247,8 @@ struct SelfadjointProductMatrix bool(RhsBlasTraits::NeedToConjugate), bool(LhsBlasTraits::NeedToConjugate)> ( rhs.rows(), // size - &rhs.coeff(0,0), rhs.outerStride(), // lhs info - &lhs.coeff(0), lhs.innerStride(), // rhs info + &rhs.coeffRef(0,0), rhs.outerStride(), // lhs info + &lhs.coeffRef(0), lhs.innerStride(), // rhs info &dst.coeffRef(0), // result info actualAlpha // scale factor ); diff --git a/Eigen/src/Core/products/SelfadjointProduct.h b/Eigen/src/Core/products/SelfadjointProduct.h index 0bf5b72fc..faefc9668 100644 --- a/Eigen/src/Core/products/SelfadjointProduct.h +++ b/Eigen/src/Core/products/SelfadjointProduct.h @@ -52,7 +52,7 @@ SelfAdjointView& SelfAdjointView Scalar, _ActualUType::Flags&RowMajorBit ? ColMajor : RowMajor, (!UBlasTraits::NeedToConjugate) && NumTraits::IsComplex, MatrixType::Flags&RowMajorBit ? RowMajor : ColMajor, UpLo> ::run(_expression().cols(), actualU.cols(), - &actualU.coeff(0,0), actualU.outerStride(), &actualU.coeff(0,0), actualU.outerStride(), + &actualU.coeffRef(0,0), actualU.outerStride(), &actualU.coeffRef(0,0), actualU.outerStride(), _expression().const_cast_derived().data(), _expression().outerStride(), actualAlpha); return *this; diff --git a/Eigen/src/Core/products/TriangularMatrixMatrix.h b/Eigen/src/Core/products/TriangularMatrixMatrix.h index e35399243..66a2515d0 100644 --- a/Eigen/src/Core/products/TriangularMatrixMatrix.h +++ b/Eigen/src/Core/products/TriangularMatrixMatrix.h @@ -387,8 +387,8 @@ struct TriangularProduct (internal::traits::Flags&RowMajorBit) ? RowMajor : ColMajor> ::run( lhs.rows(), rhs.cols(), lhs.cols(),// LhsIsTriangular ? rhs.cols() : lhs.rows(), // sizes - &lhs.coeff(0,0), lhs.outerStride(), // lhs info - &rhs.coeff(0,0), rhs.outerStride(), // rhs info + &lhs.coeffRef(0,0), lhs.outerStride(), // lhs info + &rhs.coeffRef(0,0), rhs.outerStride(), // rhs info &dst.coeffRef(0,0), dst.outerStride(), // result info actualAlpha // alpha ); diff --git a/Eigen/src/Core/products/TriangularMatrixVector.h b/Eigen/src/Core/products/TriangularMatrixVector.h index 3694be73a..03b2ad3fd 100644 --- a/Eigen/src/Core/products/TriangularMatrixVector.h +++ b/Eigen/src/Core/products/TriangularMatrixVector.h @@ -76,8 +76,8 @@ struct product_triangular_matrix_vector::run( r, actualPanelWidth, - &lhs.coeff(s,pi), lhsStride, - &rhs.coeff(pi), rhsIncr, + &lhs.coeffRef(s,pi), lhsStride, + &rhs.coeffRef(pi), rhsIncr, &res.coeffRef(s), resIncr, alpha); } } @@ -130,8 +130,8 @@ struct product_triangular_matrix_vector::run( actualPanelWidth, r, - &(lhs.coeff(pi,s)), lhsStride, - &(rhs.coeff(s)), rhsIncr, + &lhs.coeffRef(pi,s), lhsStride, + &rhs.coeffRef(s), rhsIncr, &res.coeffRef(pi), resIncr, alpha); } } diff --git a/Eigen/src/Core/products/TriangularSolverVector.h b/Eigen/src/Core/products/TriangularSolverVector.h index 0342bb356..e87f6fb0c 100644 --- a/Eigen/src/Core/products/TriangularSolverVector.h +++ b/Eigen/src/Core/products/TriangularSolverVector.h @@ -73,7 +73,7 @@ struct triangular_solve_vector::run( actualPanelWidth, r, - &(lhs.coeff(startRow,startCol)), lhsStride, + &lhs.coeffRef(startRow,startCol), lhsStride, rhs + startCol, 1, rhs + startRow, 1, RhsScalar(-1)); @@ -137,7 +137,7 @@ struct triangular_solve_vector::run( r, actualPanelWidth, - &(lhs.coeff(endBlock,startBlock)), lhsStride, + &lhs.coeffRef(endBlock,startBlock), lhsStride, rhs+startBlock, 1, rhs+endBlock, 1, RhsScalar(-1)); } diff --git a/Eigen/src/Core/util/BlasUtil.h b/Eigen/src/Core/util/BlasUtil.h index d776c4507..b15110baa 100644 --- a/Eigen/src/Core/util/BlasUtil.h +++ b/Eigen/src/Core/util/BlasUtil.h @@ -177,8 +177,8 @@ template struct blas_traits ExtractType, typename _ExtractType::PlainObject >::type DirectLinearAccessType; - static inline ExtractType extract(const XprType& x) { return x; } - static inline Scalar extractScalarFactor(const XprType&) { return Scalar(1); } + static inline const ExtractType extract(const XprType& x) { return x; } + static inline const Scalar extractScalarFactor(const XprType&) { return Scalar(1); } }; // pop conjugate @@ -194,7 +194,7 @@ struct blas_traits, NestedXpr> > IsComplex = NumTraits::IsComplex, NeedToConjugate = Base::NeedToConjugate ? 0 : IsComplex }; - static inline ExtractType extract(const XprType& x) { return Base::extract(x.nestedExpression()); } + static inline const ExtractType extract(const XprType& x) { return Base::extract(x.nestedExpression()); } static inline Scalar extractScalarFactor(const XprType& x) { return conj(Base::extractScalarFactor(x.nestedExpression())); } }; @@ -206,7 +206,7 @@ struct blas_traits, NestedXpr> > typedef blas_traits Base; typedef CwiseUnaryOp, NestedXpr> XprType; typedef typename Base::ExtractType ExtractType; - static inline ExtractType extract(const XprType& x) { return Base::extract(x.nestedExpression()); } + static inline const ExtractType extract(const XprType& x) { return Base::extract(x.nestedExpression()); } static inline Scalar extractScalarFactor(const XprType& x) { return x.functor().m_other * Base::extractScalarFactor(x.nestedExpression()); } }; @@ -219,7 +219,7 @@ struct blas_traits, NestedXpr> > typedef blas_traits Base; typedef CwiseUnaryOp, NestedXpr> XprType; typedef typename Base::ExtractType ExtractType; - static inline ExtractType extract(const XprType& x) { return Base::extract(x.nestedExpression()); } + static inline const ExtractType extract(const XprType& x) { return Base::extract(x.nestedExpression()); } static inline Scalar extractScalarFactor(const XprType& x) { return - Base::extractScalarFactor(x.nestedExpression()); } }; @@ -245,11 +245,16 @@ struct blas_traits > static inline Scalar extractScalarFactor(const XprType& x) { return Base::extractScalarFactor(x.nestedExpression()); } }; +template +struct blas_traits + : blas_traits +{}; + template::HasUsableDirectAccess> struct extract_data_selector { static const typename T::Scalar* run(const T& m) { - return &blas_traits::extract(m).const_cast_derived().coeffRef(0,0); // FIXME this should be .data() + return const_cast(&blas_traits::extract(m).coeffRef(0,0)); // FIXME this should be .data() } }; diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h index c84401fa8..355bacffe 100644 --- a/Eigen/src/Core/util/ForwardDeclarations.h +++ b/Eigen/src/Core/util/ForwardDeclarations.h @@ -27,8 +27,15 @@ #define EIGEN_FORWARDDECLARATIONS_H namespace internal { + template struct traits; +// here we say once and for all that traits == traits +// When constness must affect traits, it has to be constness on template parameters on which T itself depends. +// For example, traits > != traits >, but +// traits > == traits > +template struct traits : traits {}; + template struct has_direct_access { enum { ret = (traits::Flags & DirectAccessBit) ? 1 : 0 }; @@ -49,6 +56,7 @@ template struct NumTraits; template struct EigenBase; template class DenseBase; +template class PlainObjectBase; template class DiagonalBase; template class DiagonalWrapper; template class DiagonalMatrix; template class DiagonalProduct; -template class Diagonal; +template class Diagonal; template class PermutationMatrix; template class Transpositions; diff --git a/Eigen/src/Core/util/StaticAssert.h b/Eigen/src/Core/util/StaticAssert.h index 3637b7c0a..e7904dee7 100644 --- a/Eigen/src/Core/util/StaticAssert.h +++ b/Eigen/src/Core/util/StaticAssert.h @@ -93,7 +93,7 @@ THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS, YOU_CANNOT_MIX_ARRAYS_AND_MATRICES, YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION, - YOU_ARE_TRYING_TO_WRITE_INTO_A_READ_ONLY_EXPRESSION, + THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY, YOU_ARE_TRYING_TO_USE_AN_INDEX_BASED_ACCESSOR_ON_AN_EXPRESSION_THAT_DOES_NOT_SUPPORT_THAT, THIS_METHOD_IS_ONLY_FOR_1x1_EXPRESSIONS }; @@ -187,6 +187,6 @@ #define EIGEN_STATIC_ASSERT_LVALUE(Derived) \ EIGEN_STATIC_ASSERT(int(internal::traits::Flags) & LvalueBit, \ - YOU_ARE_TRYING_TO_WRITE_INTO_A_READ_ONLY_EXPRESSION) + THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY) #endif // EIGEN_STATIC_ASSERT_H diff --git a/Eigen/src/Core/util/XprHelper.h b/Eigen/src/Core/util/XprHelper.h index 46ade2ba1..424aa0423 100644 --- a/Eigen/src/Core/util/XprHelper.h +++ b/Eigen/src/Core/util/XprHelper.h @@ -377,19 +377,6 @@ struct special_scalar_op_base : public DenseCo { return static_cast(matrix).operator*(scalar); } }; -template struct HNormalizedReturnType { - - enum { - SizeAtCompileTime = ExpressionType::SizeAtCompileTime, - SizeMinusOne = SizeAtCompileTime==Dynamic ? Dynamic : SizeAtCompileTime-1 - }; - typedef Block::ColsAtCompileTime==1 ? SizeMinusOne : 1, - traits::ColsAtCompileTime==1 ? 1 : SizeMinusOne> StartMinusOne; - typedef CwiseUnaryOp::Scalar>, - StartMinusOne > Type; -}; - template struct cast_return_type { typedef typename XprType::Scalar CurrentScalarType; @@ -455,6 +442,13 @@ struct plain_diag_type >::type type; }; +template +struct is_lvalue +{ + enum { value = !bool(is_const::value) && + bool(traits::Flags & LvalueBit) }; +}; + } // end namespace internal #endif // EIGEN_XPRHELPER_H diff --git a/Eigen/src/Geometry/Homogeneous.h b/Eigen/src/Geometry/Homogeneous.h index 5a1e0aa4a..24ec66249 100644 --- a/Eigen/src/Geometry/Homogeneous.h +++ b/Eigen/src/Geometry/Homogeneous.h @@ -113,23 +113,11 @@ template class Homogeneous } template friend - inline const internal::homogeneous_left_product_impl::AffinePartNested> - operator* (const Transform& tr, const Homogeneous& rhs) + inline const internal::homogeneous_left_product_impl > + operator* (const Transform& lhs, const Homogeneous& rhs) { eigen_assert(int(Direction)==Vertical); - return internal::homogeneous_left_product_impl::AffinePartNested > - (tr.affine(),rhs.m_matrix); - } - - template friend - inline const internal::homogeneous_left_product_impl::MatrixType> - operator* (const Transform& tr, const Homogeneous& rhs) - { - eigen_assert(int(Direction)==Vertical); - return internal::homogeneous_left_product_impl::MatrixType> - (tr.matrix(),rhs.m_matrix); + return internal::homogeneous_left_product_impl >(lhs,rhs.m_matrix); } protected: @@ -179,11 +167,11 @@ VectorwiseOp::homogeneous() const * * \sa VectorwiseOp::hnormalized() */ template -inline typename MatrixBase::HNormalizedReturnType +inline const typename MatrixBase::HNormalizedReturnType MatrixBase::hnormalized() const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); - return StartMinusOne(derived(),0,0, + return ConstStartMinusOne(derived(),0,0, ColsAtCompileTime==1?size()-1:1, ColsAtCompileTime==1?1:size()-1) / coeff(size()-1); } @@ -197,7 +185,7 @@ MatrixBase::hnormalized() const * * \sa MatrixBase::hnormalized() */ template -inline typename VectorwiseOp::HNormalizedReturnType +inline const typename VectorwiseOp::HNormalizedReturnType VectorwiseOp::hnormalized() const { return HNormalized_Block(_expression(),0,0, @@ -217,15 +205,39 @@ VectorwiseOp::hnormalized() const namespace internal { +template +struct take_matrix_for_product +{ + typedef MatrixOrTransformType type; + static const type& run(const type &x) { return x; } +}; + +template +struct take_matrix_for_product > +{ + typedef Transform TransformType; + typedef typename TransformType::ConstAffinePart type; + static const type run (const TransformType& x) { return x.affine(); } +}; + +template +struct take_matrix_for_product > +{ + typedef Transform TransformType; + typedef typename TransformType::MatrixType type; + static const type& run (const TransformType& x) { return x.matrix(); } +}; + template struct traits,Lhs> > { + typedef typename take_matrix_for_product::type LhsMatrixType; typedef typename make_proper_matrix_type< typename traits::Scalar, - Lhs::RowsAtCompileTime, + LhsMatrixType::RowsAtCompileTime, MatrixType::ColsAtCompileTime, MatrixType::PlainObject::Options, - Lhs::MaxRowsAtCompileTime, + LhsMatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime>::type ReturnType; }; @@ -233,10 +245,12 @@ template struct homogeneous_left_product_impl,Lhs> : public ReturnByValue,Lhs> > { - typedef typename remove_all::type LhsNested; + typedef typename traits::LhsMatrixType LhsMatrixType; + typedef typename remove_all::type LhsMatrixTypeNested; typedef typename MatrixType::Index Index; homogeneous_left_product_impl(const Lhs& lhs, const MatrixType& rhs) - : m_lhs(lhs), m_rhs(rhs) + : m_lhs(take_matrix_for_product::run(lhs)), + m_rhs(rhs) {} inline Index rows() const { return m_lhs.rows(); } @@ -245,15 +259,15 @@ struct homogeneous_left_product_impl,Lhs> template void evalTo(Dest& dst) const { // FIXME investigate how to allow lazy evaluation of this product when possible - dst = Block + dst = Block (m_lhs,0,0,m_lhs.rows(),m_lhs.cols()-1) * m_rhs; dst += m_lhs.col(m_lhs.cols()-1).rowwise() .template replicate(m_rhs.cols()); } - const typename Lhs::Nested m_lhs; + const typename LhsMatrixType::Nested m_lhs; const typename MatrixType::Nested m_rhs; }; @@ -284,7 +298,7 @@ struct homogeneous_right_product_impl,Rhs> template void evalTo(Dest& dst) const { // FIXME investigate how to allow lazy evaluation of this product when possible - dst = m_lhs * Block (m_rhs,0,0,m_rhs.rows()-1,m_rhs.cols()); diff --git a/Eigen/src/Geometry/Hyperplane.h b/Eigen/src/Geometry/Hyperplane.h index 852aef185..b532cad04 100644 --- a/Eigen/src/Geometry/Hyperplane.h +++ b/Eigen/src/Geometry/Hyperplane.h @@ -57,6 +57,7 @@ public: ? Dynamic : Index(AmbientDimAtCompileTime)+1,1> Coefficients; typedef Block NormalReturnType; + typedef const Block ConstNormalReturnType; /** Default constructor without initialization */ inline explicit Hyperplane() {} @@ -148,7 +149,7 @@ public: /** \returns a constant reference to the unit normal vector of the plane, which corresponds * to the linear part of the implicit equation. */ - inline const NormalReturnType normal() const { return NormalReturnType(m_coeffs,0,0,dim(),1); } + inline ConstNormalReturnType normal() const { return ConstNormalReturnType(m_coeffs,0,0,dim(),1); } /** \returns a non-constant reference to the unit normal vector of the plane, which corresponds * to the linear part of the implicit equation. diff --git a/Eigen/src/Geometry/Quaternion.h b/Eigen/src/Geometry/Quaternion.h index 2c4098fc1..d9b34a385 100644 --- a/Eigen/src/Geometry/Quaternion.h +++ b/Eigen/src/Geometry/Quaternion.h @@ -79,7 +79,7 @@ public: inline Scalar& w() { return this->derived().coeffs().coeffRef(3); } /** \returns a read-only vector expression of the imaginary part (x,y,z) */ - inline const VectorBlock vec() const { return coeffs().template head<3>(); } + inline const VectorBlock vec() const { return coeffs().template head<3>(); } /** \returns a vector expression of the imaginary part (x,y,z) */ inline VectorBlock vec() { return coeffs().template head<3>(); } diff --git a/Eigen/src/Geometry/Transform.h b/Eigen/src/Geometry/Transform.h index f7c3bd376..0d169abb6 100644 --- a/Eigen/src/Geometry/Transform.h +++ b/Eigen/src/Geometry/Transform.h @@ -193,22 +193,28 @@ public: typedef DenseIndex Index; /** type of the matrix used to represent the transformation */ typedef Matrix MatrixType; + /** constified MatrixType */ + typedef const MatrixType ConstMatrixType; /** type of the matrix used to represent the linear part of the transformation */ typedef Matrix LinearMatrixType; /** type of read/write reference to the linear part of the transformation */ typedef Block LinearPart; + /** type of read reference to the linear part of the transformation */ + typedef const Block ConstLinearPart; /** type of read/write reference to the affine part of the transformation */ typedef typename internal::conditional >::type AffinePart; - /** type of read/write reference to the affine part of the transformation */ + /** type of read reference to the affine part of the transformation */ typedef typename internal::conditional >::type AffinePartNested; + const MatrixType&, + const Block >::type ConstAffinePart; /** type of a vector */ typedef Matrix VectorType; /** type of a read/write reference to the translation part of the rotation */ typedef Block TranslationPart; + /** type of a read reference to the translation part of the rotation */ + typedef const Block ConstTranslationPart; /** corresponding translation type */ typedef Translation TranslationType; @@ -336,17 +342,17 @@ public: inline MatrixType& matrix() { return m_matrix; } /** \returns a read-only expression of the linear part of the transformation */ - inline const LinearPart linear() const { return m_matrix.template block(0,0); } + inline ConstLinearPart linear() const { return m_matrix.template block(0,0); } /** \returns a writable expression of the linear part of the transformation */ inline LinearPart linear() { return m_matrix.template block(0,0); } /** \returns a read-only expression of the Dim x HDim affine part of the transformation */ - inline const AffinePart affine() const { return take_affine_part::run(m_matrix); } + inline ConstAffinePart affine() const { return take_affine_part::run(m_matrix); } /** \returns a writable expression of the Dim x HDim affine part of the transformation */ inline AffinePart affine() { return take_affine_part::run(m_matrix); } /** \returns a read-only expression of the translation vector of the transformation */ - inline const TranslationPart translation() const { return m_matrix.template block(0,Dim); } + inline ConstTranslationPart translation() const { return m_matrix.template block(0,Dim); } /** \returns a writable expression of the translation vector of the transformation */ inline TranslationPart translation() { return m_matrix.template block(0,Dim); } @@ -1083,9 +1089,10 @@ namespace internal { template struct transform_take_affine_part { typedef typename TransformType::MatrixType MatrixType; typedef typename TransformType::AffinePart AffinePart; + typedef typename TransformType::ConstAffinePart ConstAffinePart; static inline AffinePart run(MatrixType& m) { return m.template block(0,0); } - static inline const AffinePart run(const MatrixType& m) + static inline ConstAffinePart run(const MatrixType& m) { return m.template block(0,0); } }; @@ -1180,7 +1187,7 @@ struct transform_right_product_impl< TransformType, MatrixType, false > EIGEN_STATIC_ASSERT(OtherRows==Dim || OtherRows==HDim, YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES); typedef Block TopLeftLhs; - typedef Block TopLeftRhs; + typedef Block TopLeftRhs; ResultType res(other.rows(),other.cols()); diff --git a/Eigen/src/Householder/Householder.h b/Eigen/src/Householder/Householder.h index 7d77cd6e6..9ade04c19 100644 --- a/Eigen/src/Householder/Householder.h +++ b/Eigen/src/Householder/Householder.h @@ -65,7 +65,7 @@ void MatrixBase::makeHouseholder( RealScalar& beta) const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(EssentialPart) - VectorBlock tail(derived(), 1, size()-1); + VectorBlock tail(derived(), 1, size()-1); RealScalar tailSqNorm = size()==1 ? RealScalar(0) : tail.squaredNorm(); Scalar c0 = coeff(0); diff --git a/Eigen/src/Householder/HouseholderSequence.h b/Eigen/src/Householder/HouseholderSequence.h index 3b740a4fb..d6260cf77 100644 --- a/Eigen/src/Householder/HouseholderSequence.h +++ b/Eigen/src/Householder/HouseholderSequence.h @@ -71,26 +71,26 @@ struct traits > template struct hseq_side_dependent_impl { - typedef Block EssentialVectorType; + typedef Block EssentialVectorType; typedef HouseholderSequence HouseholderSequenceType; typedef typename VectorsType::Index Index; static inline const EssentialVectorType essentialVector(const HouseholderSequenceType& h, Index k) { Index start = k+1+h.m_shift; - return Block(h.m_vectors, start, k, h.rows()-start, 1); + return Block(h.m_vectors, start, k, h.rows()-start, 1); } }; template struct hseq_side_dependent_impl { - typedef Transpose > EssentialVectorType; + typedef Transpose > EssentialVectorType; typedef HouseholderSequence HouseholderSequenceType; typedef typename VectorsType::Index Index; static inline const EssentialVectorType essentialVector(const HouseholderSequenceType& h, Index k) { Index start = k+1+h.m_shift; - return Block(h.m_vectors, k, start, 1, h.rows()-start).transpose(); + return Block(h.m_vectors, k, start, 1, h.rows()-start).transpose(); } }; diff --git a/Eigen/src/SVD/UpperBidiagonalization.h b/Eigen/src/SVD/UpperBidiagonalization.h index 1009f5fe1..5503356d3 100644 --- a/Eigen/src/SVD/UpperBidiagonalization.h +++ b/Eigen/src/SVD/UpperBidiagonalization.h @@ -48,12 +48,12 @@ template class UpperBidiagonalization typedef Matrix DiagVectorType; typedef Matrix SuperDiagVectorType; typedef HouseholderSequence< - MatrixType, - CwiseUnaryOp, Diagonal > + const MatrixType, + CwiseUnaryOp, Diagonal > > HouseholderUSequenceType; typedef HouseholderSequence< - MatrixType, - Diagonal, + const MatrixType, + Diagonal, OnTheRight > HouseholderVSequenceType; @@ -78,16 +78,16 @@ template class UpperBidiagonalization const MatrixType& householder() const { return m_householder; } const BidiagonalType& bidiagonal() const { return m_bidiagonal; } - HouseholderUSequenceType householderU() const + const HouseholderUSequenceType householderU() const { eigen_assert(m_isInitialized && "UpperBidiagonalization is not initialized."); return HouseholderUSequenceType(m_householder, m_householder.diagonal().conjugate()); } - HouseholderVSequenceType householderV() // const here gives nasty errors and i'm lazy + const HouseholderVSequenceType householderV() // const here gives nasty errors and i'm lazy { eigen_assert(m_isInitialized && "UpperBidiagonalization is not initialized."); - return HouseholderVSequenceType(m_householder, m_householder.template diagonal<1>(), + return HouseholderVSequenceType(m_householder, m_householder.const_derived().template diagonal<1>(), false, m_householder.cols()-1, 1); } diff --git a/Eigen/src/Sparse/SparseDiagonalProduct.h b/Eigen/src/Sparse/SparseDiagonalProduct.h index 6c0a03363..82b2dff25 100644 --- a/Eigen/src/Sparse/SparseDiagonalProduct.h +++ b/Eigen/src/Sparse/SparseDiagonalProduct.h @@ -176,7 +176,8 @@ class sparse_diagonal_product_inner_iterator_selector public: inline sparse_diagonal_product_inner_iterator_selector( const SparseDiagonalProductType& expr, Index outer) - : Base(expr.lhs().innerVector(outer) .cwiseProduct(expr.rhs().diagonal().transpose()), 0) + : Base(expr.lhs().innerVector(outer) .cwiseProduct(expr.rhs().const_cast_derived().diagonal().transpose()), 0) + // the const_cast_derived above is to get it to compile. once Sparse is const correct, that shouldn't be needed anymore. {} }; diff --git a/Eigen/src/plugins/BlockMethods.h b/Eigen/src/plugins/BlockMethods.h index 2a0e508e8..4eba93338 100644 --- a/Eigen/src/plugins/BlockMethods.h +++ b/Eigen/src/plugins/BlockMethods.h @@ -30,16 +30,22 @@ /** \internal expression type of a column */ typedef Block::RowsAtCompileTime, 1, !IsRowMajor> ColXpr; +typedef const Block::RowsAtCompileTime, 1, !IsRowMajor> ConstColXpr; /** \internal expression type of a row */ typedef Block::ColsAtCompileTime, IsRowMajor> RowXpr; +typedef const Block::ColsAtCompileTime, IsRowMajor> ConstRowXpr; /** \internal expression type of a block of whole columns */ typedef Block::RowsAtCompileTime, Dynamic, !IsRowMajor> ColsBlockXpr; +typedef const Block::RowsAtCompileTime, Dynamic, !IsRowMajor> ConstColsBlockXpr; /** \internal expression type of a block of whole rows */ typedef Block::ColsAtCompileTime, IsRowMajor> RowsBlockXpr; +typedef const Block::ColsAtCompileTime, IsRowMajor> ConstRowsBlockXpr; /** \internal expression type of a block of whole columns */ template struct NColsBlockXpr { typedef Block::RowsAtCompileTime, N, !IsRowMajor> Type; }; +template struct ConstNColsBlockXpr { typedef const Block::RowsAtCompileTime, N, !IsRowMajor> Type; }; /** \internal expression type of a block of whole rows */ template struct NRowsBlockXpr { typedef Block::ColsAtCompileTime, IsRowMajor> Type; }; +template struct ConstNRowsBlockXpr { typedef const Block::ColsAtCompileTime, IsRowMajor> Type; }; #endif // not EIGEN_PARSED_BY_DOXYGEN @@ -66,9 +72,9 @@ inline Block block(Index startRow, Index startCol, Index blockRows, Ind } /** This is the const version of block(Index,Index,Index,Index). */ -inline const Block block(Index startRow, Index startCol, Index blockRows, Index blockCols) const +inline const Block block(Index startRow, Index startCol, Index blockRows, Index blockCols) const { - return Block(derived(), startRow, startCol, blockRows, blockCols); + return Block(derived(), startRow, startCol, blockRows, blockCols); } @@ -90,9 +96,9 @@ inline Block topRightCorner(Index cRows, Index cCols) } /** This is the const version of topRightCorner(Index, Index).*/ -inline const Block topRightCorner(Index cRows, Index cCols) const +inline const Block topRightCorner(Index cRows, Index cCols) const { - return Block(derived(), 0, cols() - cCols, cRows, cCols); + return Block(derived(), 0, cols() - cCols, cRows, cCols); } /** \returns an expression of a fixed-size top-right corner of *this. @@ -112,9 +118,9 @@ inline Block topRightCorner() /** This is the const version of topRightCorner().*/ template -inline const Block topRightCorner() const +inline const Block topRightCorner() const { - return Block(derived(), 0, cols() - CCols); + return Block(derived(), 0, cols() - CCols); } @@ -136,9 +142,9 @@ inline Block topLeftCorner(Index cRows, Index cCols) } /** This is the const version of topLeftCorner(Index, Index).*/ -inline const Block topLeftCorner(Index cRows, Index cCols) const +inline const Block topLeftCorner(Index cRows, Index cCols) const { - return Block(derived(), 0, 0, cRows, cCols); + return Block(derived(), 0, 0, cRows, cCols); } /** \returns an expression of a fixed-size top-left corner of *this. @@ -158,9 +164,9 @@ inline Block topLeftCorner() /** This is the const version of topLeftCorner().*/ template -inline const Block topLeftCorner() const +inline const Block topLeftCorner() const { - return Block(derived(), 0, 0); + return Block(derived(), 0, 0); } @@ -181,9 +187,9 @@ inline Block bottomRightCorner(Index cRows, Index cCols) } /** This is the const version of bottomRightCorner(Index, Index).*/ -inline const Block bottomRightCorner(Index cRows, Index cCols) const +inline const Block bottomRightCorner(Index cRows, Index cCols) const { - return Block(derived(), rows() - cRows, cols() - cCols, cRows, cCols); + return Block(derived(), rows() - cRows, cols() - cCols, cRows, cCols); } /** \returns an expression of a fixed-size bottom-right corner of *this. @@ -203,9 +209,9 @@ inline Block bottomRightCorner() /** This is the const version of bottomRightCorner().*/ template -inline const Block bottomRightCorner() const +inline const Block bottomRightCorner() const { - return Block(derived(), rows() - CRows, cols() - CCols); + return Block(derived(), rows() - CRows, cols() - CCols); } @@ -226,9 +232,9 @@ inline Block bottomLeftCorner(Index cRows, Index cCols) } /** This is the const version of bottomLeftCorner(Index, Index).*/ -inline const Block bottomLeftCorner(Index cRows, Index cCols) const +inline const Block bottomLeftCorner(Index cRows, Index cCols) const { - return Block(derived(), rows() - cRows, 0, cRows, cCols); + return Block(derived(), rows() - cRows, 0, cRows, cCols); } /** \returns an expression of a fixed-size bottom-left corner of *this. @@ -248,9 +254,9 @@ inline Block bottomLeftCorner() /** This is the const version of bottomLeftCorner().*/ template -inline const Block bottomLeftCorner() const +inline const Block bottomLeftCorner() const { - return Block(derived(), rows() - CRows, 0); + return Block(derived(), rows() - CRows, 0); } @@ -270,9 +276,9 @@ inline RowsBlockXpr topRows(Index n) } /** This is the const version of topRows(Index).*/ -inline const RowsBlockXpr topRows(Index n) const +inline ConstRowsBlockXpr topRows(Index n) const { - return RowsBlockXpr(derived(), 0, 0, n, cols()); + return ConstRowsBlockXpr(derived(), 0, 0, n, cols()); } /** \returns a block consisting of the top rows of *this. @@ -292,9 +298,9 @@ inline typename NRowsBlockXpr::Type topRows() /** This is the const version of topRows().*/ template -inline const typename NRowsBlockXpr::Type topRows() const +inline typename ConstNRowsBlockXpr::Type topRows() const { - return typename NRowsBlockXpr::Type(derived(), 0, 0, N, cols()); + return typename ConstNRowsBlockXpr::Type(derived(), 0, 0, N, cols()); } @@ -314,9 +320,9 @@ inline RowsBlockXpr bottomRows(Index n) } /** This is the const version of bottomRows(Index).*/ -inline const RowsBlockXpr bottomRows(Index n) const +inline ConstRowsBlockXpr bottomRows(Index n) const { - return RowsBlockXpr(derived(), rows() - n, 0, n, cols()); + return ConstRowsBlockXpr(derived(), rows() - n, 0, n, cols()); } /** \returns a block consisting of the bottom rows of *this. @@ -336,9 +342,9 @@ inline typename NRowsBlockXpr::Type bottomRows() /** This is the const version of bottomRows().*/ template -inline const typename NRowsBlockXpr::Type bottomRows() const +inline typename ConstNRowsBlockXpr::Type bottomRows() const { - return typename NRowsBlockXpr::Type(derived(), rows() - N, 0, N, cols()); + return typename ConstNRowsBlockXpr::Type(derived(), rows() - N, 0, N, cols()); } @@ -359,9 +365,9 @@ inline RowsBlockXpr middleRows(Index startRow, Index numRows) } /** This is the const version of middleRows(Index,Index).*/ -inline const RowsBlockXpr middleRows(Index startRow, Index numRows) const +inline ConstRowsBlockXpr middleRows(Index startRow, Index numRows) const { - return RowsBlockXpr(derived(), startRow, 0, numRows, cols()); + return ConstRowsBlockXpr(derived(), startRow, 0, numRows, cols()); } /** \returns a block consisting of a range of rows of *this. @@ -382,9 +388,9 @@ inline typename NRowsBlockXpr::Type middleRows(Index startRow) /** This is the const version of middleRows().*/ template -inline const typename NRowsBlockXpr::Type middleRows(Index startRow) const +inline typename ConstNRowsBlockXpr::Type middleRows(Index startRow) const { - return typename NRowsBlockXpr::Type(derived(), startRow, 0, N, cols()); + return typename ConstNRowsBlockXpr::Type(derived(), startRow, 0, N, cols()); } @@ -404,9 +410,9 @@ inline ColsBlockXpr leftCols(Index n) } /** This is the const version of leftCols(Index).*/ -inline const ColsBlockXpr leftCols(Index n) const +inline ConstColsBlockXpr leftCols(Index n) const { - return ColsBlockXpr(derived(), 0, 0, rows(), n); + return ConstColsBlockXpr(derived(), 0, 0, rows(), n); } /** \returns a block consisting of the left columns of *this. @@ -426,9 +432,9 @@ inline typename NColsBlockXpr::Type leftCols() /** This is the const version of leftCols().*/ template -inline const typename NColsBlockXpr::Type leftCols() const +inline typename ConstNColsBlockXpr::Type leftCols() const { - return typename NColsBlockXpr::Type(derived(), 0, 0, rows(), N); + return typename ConstNColsBlockXpr::Type(derived(), 0, 0, rows(), N); } @@ -448,9 +454,9 @@ inline ColsBlockXpr rightCols(Index n) } /** This is the const version of rightCols(Index).*/ -inline const ColsBlockXpr rightCols(Index n) const +inline ConstColsBlockXpr rightCols(Index n) const { - return ColsBlockXpr(derived(), 0, cols() - n, rows(), n); + return ConstColsBlockXpr(derived(), 0, cols() - n, rows(), n); } /** \returns a block consisting of the right columns of *this. @@ -470,9 +476,9 @@ inline typename NColsBlockXpr::Type rightCols() /** This is the const version of rightCols().*/ template -inline const typename NColsBlockXpr::Type rightCols() const +inline typename ConstNColsBlockXpr::Type rightCols() const { - return typename NColsBlockXpr::Type(derived(), 0, cols() - N, rows(), N); + return typename ConstNColsBlockXpr::Type(derived(), 0, cols() - N, rows(), N); } @@ -493,9 +499,9 @@ inline ColsBlockXpr middleCols(Index startCol, Index numCols) } /** This is the const version of middleCols(Index,Index).*/ -inline const ColsBlockXpr middleCols(Index startCol, Index numCols) const +inline ConstColsBlockXpr middleCols(Index startCol, Index numCols) const { - return ColsBlockXpr(derived(), 0, startCol, rows(), numCols); + return ConstColsBlockXpr(derived(), 0, startCol, rows(), numCols); } /** \returns a block consisting of a range of columns of *this. @@ -516,9 +522,9 @@ inline typename NColsBlockXpr::Type middleCols(Index startCol) /** This is the const version of middleCols().*/ template -inline const typename NColsBlockXpr::Type middleCols(Index startCol) const +inline typename ConstNColsBlockXpr::Type middleCols(Index startCol) const { - return typename NColsBlockXpr::Type(derived(), 0, startCol, rows(), N); + return typename ConstNColsBlockXpr::Type(derived(), 0, startCol, rows(), N); } @@ -547,9 +553,9 @@ inline Block block(Index startRow, Index startCol /** This is the const version of block<>(Index, Index). */ template -inline const Block block(Index startRow, Index startCol) const +inline const Block block(Index startRow, Index startCol) const { - return Block(derived(), startRow, startCol); + return Block(derived(), startRow, startCol); } /** \returns an expression of the \a i-th column of *this. Note that the numbering starts at 0. @@ -564,9 +570,9 @@ inline ColXpr col(Index i) } /** This is the const version of col(). */ -inline const ColXpr col(Index i) const +inline ConstColXpr col(Index i) const { - return ColXpr(derived(), i); + return ConstColXpr(derived(), i); } /** \returns an expression of the \a i-th row of *this. Note that the numbering starts at 0. @@ -581,9 +587,9 @@ inline RowXpr row(Index i) } /** This is the const version of row(). */ -inline const RowXpr row(Index i) const +inline ConstRowXpr row(Index i) const { - return RowXpr(derived(), i); + return ConstRowXpr(derived(), i); } #endif // EIGEN_BLOCKMETHODS_H diff --git a/test/block.cpp b/test/block.cpp index 6c5681683..70852ee48 100644 --- a/test/block.cpp +++ b/test/block.cpp @@ -39,6 +39,7 @@ template void block(const MatrixType& m) Index cols = m.cols(); MatrixType m1 = MatrixType::Random(rows, cols), + m1_copy = m1, m2 = MatrixType::Random(rows, cols), m3(rows, cols), mzero = MatrixType::Zero(rows, cols), @@ -58,8 +59,17 @@ template void block(const MatrixType& m) //check row() and col() VERIFY_IS_EQUAL(m1.col(c1).transpose(), m1.transpose().row(c1)); //check operator(), both constant and non-constant, on row() and col() - m1.row(r1) += s1 * m1.row(r2); - m1.col(c1) += s1 * m1.col(c2); + m1 = m1_copy; + m1.row(r1) += s1 * m1_copy.row(r2); + VERIFY_IS_APPROX(m1.row(r1), m1_copy.row(r1) + s1 * m1_copy.row(r2)); + // check nested block xpr on lhs + m1.row(r1).row(0) += s1 * m1_copy.row(r2); + VERIFY_IS_APPROX(m1.row(r1), m1_copy.row(r1) + Scalar(2) * s1 * m1_copy.row(r2)); + m1 = m1_copy; + m1.col(c1) += s1 * m1_copy.col(c2); + VERIFY_IS_APPROX(m1.col(c1), m1_copy.col(c1) + s1 * m1_copy.col(c2)); + m1.col(c1).col(0) += s1 * m1_copy.col(c2); + VERIFY_IS_APPROX(m1.col(c1), m1_copy.col(c1) + Scalar(2) * s1 * m1_copy.col(c2)); //check block() Matrix b1(1,1); b1(0,0) = m1(r1,c1); diff --git a/test/product_notemporary.cpp b/test/product_notemporary.cpp index e5dd964c0..f4f846602 100644 --- a/test/product_notemporary.cpp +++ b/test/product_notemporary.cpp @@ -24,7 +24,13 @@ static int nb_temporaries; -#define EIGEN_DEBUG_MATRIX_CTOR { if(size!=0) nb_temporaries++; } +void on_temporary_creation(int size) { + // here's a great place to set a breakpoint when debugging failures in this test! + if(size!=0) nb_temporaries++; +} + + +#define EIGEN_DEBUG_MATRIX_CTOR { on_temporary_creation(size); } #include "main.h" diff --git a/unsupported/Eigen/src/MatrixFunctions/MatrixFunction.h b/unsupported/Eigen/src/MatrixFunctions/MatrixFunction.h index a4aa9baa7..4b9d8a102 100644 --- a/unsupported/Eigen/src/MatrixFunctions/MatrixFunction.h +++ b/unsupported/Eigen/src/MatrixFunctions/MatrixFunction.h @@ -163,7 +163,7 @@ class MatrixFunction void permuteSchur(); void swapEntriesInSchur(Index index); void computeBlockAtomic(); - Block block(const MatrixType& A, Index i, Index j); + Block block(MatrixType& A, Index i, Index j); void computeOffDiagonal(); DynMatrixType solveTriangularSylvester(const DynMatrixType& A, const DynMatrixType& B, const DynMatrixType& C); @@ -385,7 +385,7 @@ void MatrixFunction::computeBlockAtomic() /** \brief Return block of matrix according to blocking given by #m_blockStart */ template -Block MatrixFunction::block(const MatrixType& A, Index i, Index j) +Block MatrixFunction::block(MatrixType& A, Index i, Index j) { return A.block(m_blockStart(i), m_blockStart(j), m_clusterSize(i), m_clusterSize(j)); }