diff options
author | Benoit Jacob <jacob.benoit.1@gmail.com> | 2010-12-22 17:45:37 -0500 |
---|---|---|
committer | Benoit Jacob <jacob.benoit.1@gmail.com> | 2010-12-22 17:45:37 -0500 |
commit | 75b7d98665dd144c44d7a113c6613f5f998be626 (patch) | |
tree | bc75d316e2ed8e679e744bc34f159dcb0f285243 /Eigen/src/Core | |
parent | 3b6d97b51a7e7a4b0c69ae6be44b1c16d72c2e80 (diff) |
bug #54 - really fix const correctness except in Sparse
Diffstat (limited to 'Eigen/src/Core')
34 files changed, 334 insertions, 222 deletions
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<typename Derived> 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<BandMatrix<_Scalar,Rows,Cols,Supers,Subs,Opt { return Block<DataType,1,SizeAtCompileTime>(m_data,supers(),0,1,std::min(rows(),cols())); } /** \returns a vector expression of the main diagonal (const version) */ - inline const Block<DataType,1,SizeAtCompileTime> diagonal() const - { return Block<DataType,1,SizeAtCompileTime>(m_data,supers(),0,1,std::min(rows(),cols())); } + inline const Block<const DataType,1,SizeAtCompileTime> diagonal() const + { return Block<const DataType,1,SizeAtCompileTime>(m_data,supers(),0,1,std::min(rows(),cols())); } template<int Index> struct DiagonalIntReturnType { enum { @@ -172,10 +172,10 @@ class BandMatrix : public EigenBase<BandMatrix<_Scalar,Rows,Cols,Supers,Subs,Opt } /** \returns a vector expression of the \a i -th sub or super diagonal */ - inline const Block<DataType,1,Dynamic> diagonal(Index i) const + inline const Block<const DataType,1,Dynamic> diagonal(Index i) const { eigen_assert((i<0 && -i<=subs()) || (i>=0 && i<=supers())); - return Block<DataType,1,Dynamic>(m_data, supers()-i, std::max<Index>(0,i), 1, diagonalLength(i)); + return Block<const DataType,1,Dynamic>(m_data, supers()-i, std::max<Index>(0,i), 1, diagonalLength(i)); } template<typename Dest> 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<Block<XprType, BlockRows, BlockCols, InnerPanel, HasDirectAccess> ? PacketAccessBit : 0, MaskAlignedBit = (InnerPanel && (OuterStrideAtCompileTime!=Dynamic) && ((OuterStrideAtCompileTime % packet_traits<Scalar>::size) == 0)) ? AlignedBit : 0, FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ? LinearAccessBit : 0, - Flags0 = traits<XprType>::Flags & (HereditaryBits | MaskPacketAccessBit | LvalueBit | DirectAccessBit | MaskAlignedBit), - Flags1 = Flags0 | FlagsLinearAccessBit, - Flags = (Flags1 & ~RowMajorBit) | (IsRowMajor ? RowMajorBit : 0) + FlagsLvalueBit = is_lvalue<XprType>::value ? LvalueBit : 0, + FlagsRowMajorBit = IsRowMajor ? RowMajorBit : 0, + Flags0 = traits<XprType>::Flags & ( (HereditaryBits & ~RowMajorBit) | + DirectAccessBit | + MaskPacketAccessBit | + MaskAlignedBit), + Flags = Flags0 | FlagsLinearAccessBit | FlagsLvalueBit | FlagsRowMajorBit }; }; } @@ -163,6 +167,13 @@ template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel, bool H inline Scalar& coeffRef(Index row, Index col) { + EIGEN_STATIC_ASSERT_LVALUE(XprType) + return m_xpr.const_cast_derived() + .coeffRef(row + m_startRow.value(), col + m_startCol.value()); + } + + inline const Scalar& coeffRef(Index row, Index col) const + { return m_xpr.const_cast_derived() .coeffRef(row + m_startRow.value(), col + m_startCol.value()); } @@ -174,6 +185,14 @@ template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel, bool H inline Scalar& coeffRef(Index index) { + EIGEN_STATIC_ASSERT_LVALUE(XprType) + return m_xpr.const_cast_derived() + .coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index), + m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0)); + } + + inline const Scalar& coeffRef(Index index) const + { return m_xpr.const_cast_derived() .coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index), m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0)); @@ -246,8 +265,8 @@ class Block<XprType,BlockRows,BlockCols, InnerPanel,true> /** 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<XprType,BlockRows,BlockCols, InnerPanel,true> /** 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<XprType,BlockRows,BlockCols, InnerPanel,true> /** 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<typename Derived> class DenseBase OuterStrideAtCompileTime = internal::outer_stride_at_compile_time<Derived>::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<typename Derived> class DenseBase CommaInitializer<Derived> operator<< (const DenseBase<OtherDerived>& other); Eigen::Transpose<Derived> transpose(); - const Eigen::Transpose<Derived> transpose() const; + typedef const Transpose<const Derived> ConstTransposeReturnType; + ConstTransposeReturnType transpose() const; void transposeInPlace(); #ifndef EIGEN_NO_DEBUG protected: @@ -282,41 +285,28 @@ template<typename Derived> class DenseBase public: #endif - VectorBlock<Derived> segment(Index start, Index size); - const VectorBlock<Derived> segment(Index start, Index size) const; - - VectorBlock<Derived> head(Index size); - const VectorBlock<Derived> head(Index size) const; - - VectorBlock<Derived> tail(Index size); - const VectorBlock<Derived> tail(Index size) const; - - template<int Size> VectorBlock<Derived,Size> head(void); - template<int Size> const VectorBlock<Derived,Size> head() const; - - template<int Size> VectorBlock<Derived,Size> tail(); - template<int Size> const VectorBlock<Derived,Size> tail() const; + typedef VectorBlock<Derived> SegmentReturnType; + typedef const VectorBlock<const Derived> ConstSegmentReturnType; + template<int Size> struct FixedSegmentReturnType { typedef VectorBlock<Derived, Size> Type; }; + template<int Size> struct ConstFixedSegmentReturnType { typedef const VectorBlock<const Derived, Size> Type; }; + + SegmentReturnType segment(Index start, Index size); + ConstSegmentReturnType segment(Index start, Index size) const; - template<int Size> VectorBlock<Derived,Size> segment(Index start); - template<int Size> const VectorBlock<Derived,Size> segment(Index start) const; + SegmentReturnType head(Index size); + ConstSegmentReturnType head(Index size) const; - Diagonal<Derived,0> diagonal(); - const Diagonal<Derived,0> diagonal() const; + SegmentReturnType tail(Index size); + ConstSegmentReturnType tail(Index size) const; - template<int Index> Diagonal<Derived,Index> diagonal(); - template<int Index> const Diagonal<Derived,Index> diagonal() const; + template<int Size> typename FixedSegmentReturnType<Size>::Type head(); + template<int Size> typename ConstFixedSegmentReturnType<Size>::Type head() const; - Diagonal<Derived, Dynamic> diagonal(Index index); - const Diagonal<Derived, Dynamic> diagonal(Index index) const; + template<int Size> typename FixedSegmentReturnType<Size>::Type tail(); + template<int Size> typename ConstFixedSegmentReturnType<Size>::Type tail() const; - template<unsigned int Mode> TriangularView<Derived, Mode> part(); - template<unsigned int Mode> const TriangularView<Derived, Mode> part() const; - - template<unsigned int Mode> TriangularView<Derived, Mode> triangularView(); - template<unsigned int Mode> const TriangularView<Derived, Mode> triangularView() const; - - template<unsigned int UpLo> SelfAdjointView<Derived, UpLo> selfadjointView(); - template<unsigned int UpLo> const SelfAdjointView<Derived, UpLo> selfadjointView() const; + template<int Size> typename FixedSegmentReturnType<Size>::Type segment(Index start); + template<int Size> typename ConstFixedSegmentReturnType<Size>::Type segment(Index start) const; static const ConstantReturnType Constant(Index rows, Index cols, const Scalar& value); @@ -389,8 +379,25 @@ template<typename Derived> class DenseBase return typename internal::eval<Derived>::type(derived()); } + /** swaps *this with the expression \a other. + * + */ template<typename OtherDerived> - void swap(DenseBase<OtherDerived> EIGEN_REF_TO_TEMPORARY other); + void swap(const DenseBase<OtherDerived>& other, + int = OtherDerived::ThisConstantIsPrivateInPlainObjectBase) + { + SwapWrapper<Derived>(derived()).lazyAssign(other.derived()); + } + + /** swaps *this with the matrix or array \a other. + * + */ + template<typename OtherDerived> + void swap(PlainObjectBase<OtherDerived>& other) + { + SwapWrapper<Derived>(derived()).lazyAssign(other.derived()); + } + inline const NestByValue<Derived> nestByValue() const; inline const ForceAlignedAccess<Derived> forceAlignedAccess() const; @@ -436,10 +443,15 @@ template<typename Derived> class DenseBase bool any(void) const; Index count() const; - const VectorwiseOp<Derived,Horizontal> rowwise() const; - VectorwiseOp<Derived,Horizontal> rowwise(); - const VectorwiseOp<Derived,Vertical> colwise() const; - VectorwiseOp<Derived,Vertical> colwise(); + typedef VectorwiseOp<Derived, Horizontal> RowwiseReturnType; + typedef const VectorwiseOp<const Derived, Horizontal> ConstRowwiseReturnType; + typedef VectorwiseOp<Derived, Vertical> ColwiseReturnType; + typedef const VectorwiseOp<const Derived, Vertical> ConstColwiseReturnType; + + ConstRowwiseReturnType rowwise() const; + RowwiseReturnType rowwise(); + ConstColwiseReturnType colwise() const; + ColwiseReturnType colwise(); static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random(Index rows, Index cols); static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random(Index size); @@ -464,8 +476,10 @@ template<typename Derived> class DenseBase const Replicate<Derived,RowFactor,ColFactor> replicate() const; const Replicate<Derived,Dynamic,Dynamic> replicate(Index rowFacor,Index colFactor) const; - Eigen::Reverse<Derived, BothDirections> reverse(); - const Eigen::Reverse<Derived, BothDirections> reverse() const; + typedef Reverse<Derived, BothDirections> ReverseReturnType; + typedef const Reverse<const Derived, BothDirections> 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<Diagonal<MatrixType,DiagIndex> > 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<MatrixType>::value ? LvalueBit : 0, + Flags = (unsigned int)_MatrixTypeNested::Flags & (HereditaryBits | LinearAccessBit | MaskLvalueBit | DirectAccessBit) & ~RowMajorBit, CoeffReadCost = _MatrixTypeNested::CoeffReadCost, MatrixTypeOuterStride = outer_stride_at_compile_time<MatrixType>::ret, InnerStrideAtCompileTime = MatrixTypeOuterStride == Dynamic ? Dynamic : MatrixTypeOuterStride+1, @@ -105,6 +106,11 @@ template<typename MatrixType, int DiagIndex> 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<typename MatrixType, int DiagIndex> 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<typename MatrixType, int DiagIndex> class Diagonal * * \sa class Diagonal */ template<typename Derived> -inline Diagonal<Derived, 0> +inline typename MatrixBase<Derived>::DiagonalReturnType MatrixBase<Derived>::diagonal() { - return Diagonal<Derived, 0>(derived()); + return derived(); } /** This is the const version of diagonal(). */ template<typename Derived> -inline const Diagonal<Derived, 0> +inline const typename MatrixBase<Derived>::ConstDiagonalReturnType MatrixBase<Derived>::diagonal() const { - return Diagonal<Derived, 0>(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<Derived>::diagonal() const * * \sa MatrixBase::diagonal(), class Diagonal */ template<typename Derived> -inline Diagonal<Derived, Dynamic> +inline typename MatrixBase<Derived>::template DiagonalIndexReturnType<Dynamic>::Type MatrixBase<Derived>::diagonal(Index index) { - return Diagonal<Derived, Dynamic>(derived(), index); + return typename DiagonalIndexReturnType<Dynamic>::Type(derived(), index); } /** This is the const version of diagonal(Index). */ template<typename Derived> -inline const Diagonal<Derived, Dynamic> +inline typename MatrixBase<Derived>::template ConstDiagonalIndexReturnType<Dynamic>::Type MatrixBase<Derived>::diagonal(Index index) const { - return Diagonal<Derived, Dynamic>(derived(), index); + return typename ConstDiagonalIndexReturnType<Dynamic>::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<Derived>::diagonal(Index index) const * * \sa MatrixBase::diagonal(), class Diagonal */ template<typename Derived> -template<int DiagIndex> -inline Diagonal<Derived,DiagIndex> +template<int Index> +inline typename MatrixBase<Derived>::template DiagonalIndexReturnType<Index>::Type MatrixBase<Derived>::diagonal() { - return Diagonal<Derived,DiagIndex>(derived()); + return derived(); } /** This is the const version of diagonal<int>(). */ template<typename Derived> -template<int DiagIndex> -inline const Diagonal<Derived,DiagIndex> +template<int Index> +inline typename MatrixBase<Derived>::template ConstDiagonalIndexReturnType<Index>::Type MatrixBase<Derived>::diagonal() const { - return Diagonal<Derived,DiagIndex>(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<typename Derived> struct EigenBase inline Derived& const_cast_derived() const { return *static_cast<Derived*>(const_cast<EigenBase*>(this)); } + inline const Derived& const_derived() const + { return *static_cast<const Derived*>(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<typename PlainObjectType, int MapOptions, typename StrideType> struct traits<Map<PlainObjectType, MapOptions, StrideType> > - : public traits<typename internal::remove_const<PlainObjectType>::type> + : public traits<PlainObjectType> { - typedef traits<typename internal::remove_const<PlainObjectType>::type> TraitsBase; + typedef traits<PlainObjectType> TraitsBase; typedef typename PlainObjectType::Index Index; typedef typename PlainObjectType::Scalar Scalar; enum { @@ -106,7 +106,7 @@ struct traits<Map<PlainObjectType, MapOptions, StrideType> > Flags1 = IsAligned ? (int(Flags0) | AlignedBit) : (int(Flags0) & ~AlignedBit), Flags2 = (bool(HasNoStride) || bool(PlainObjectType::IsVectorAtCompileTime)) ? int(Flags1) : int(Flags1 & ~LinearAccessBit), - Flags3 = internal::is_const<PlainObjectType>::value ? (int(Flags2) & ~LvalueBit) : int(Flags2), + Flags3 = is_lvalue<PlainObjectType>::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<typename Derived> class MapBase<Derived, ReadOnlyAccessors> typedef typename internal::packet_traits<Scalar>::type PacketScalar; typedef typename NumTraits<Scalar>::Real RealScalar; typedef typename internal::conditional< - bool(int(internal::traits<Derived>::Flags) & LvalueBit), + bool(internal::is_lvalue<Derived>::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<typename Derived> 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<typename Derived> class MatrixBase typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,Derived> ConstantReturnType; /** \internal the return type of MatrixBase::adjoint() */ typedef typename internal::conditional<NumTraits<Scalar>::IsComplex, - CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, Eigen::Transpose<Derived> >, - Transpose<Derived> + CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, ConstTransposeReturnType>, + ConstTransposeReturnType >::type AdjointReturnType; /** \internal Return type of eigenvalues() */ typedef Matrix<std::complex<RealScalar>, internal::traits<Derived>::ColsAtCompileTime, 1, ColMajor> EigenvaluesReturnType; @@ -212,23 +213,34 @@ template<typename Derived> class MatrixBase const AdjointReturnType adjoint() const; void adjointInPlace(); - Diagonal<Derived,0> diagonal(); - const Diagonal<Derived,0> diagonal() const; + typedef Diagonal<Derived> DiagonalReturnType; + DiagonalReturnType diagonal(); + typedef const Diagonal<const Derived> ConstDiagonalReturnType; + ConstDiagonalReturnType diagonal() const; - template<int Index> Diagonal<Derived,Index> diagonal(); - template<int Index> const Diagonal<Derived,Index> diagonal() const; + template<int Index> struct DiagonalIndexReturnType { typedef Diagonal<Derived,Index> Type; }; + template<int Index> struct ConstDiagonalIndexReturnType { typedef const Diagonal<const Derived,Index> Type; }; - Diagonal<Derived, Dynamic> diagonal(Index index); - const Diagonal<Derived, Dynamic> diagonal(Index index) const; + template<int Index> typename DiagonalIndexReturnType<Index>::Type diagonal(); + template<int Index> typename ConstDiagonalIndexReturnType<Index>::Type diagonal() const; + + typename DiagonalIndexReturnType<Dynamic>::Type diagonal(Index index); + typename ConstDiagonalIndexReturnType<Dynamic>::Type diagonal(Index index) const; template<unsigned int Mode> TriangularView<Derived, Mode> part(); template<unsigned int Mode> const TriangularView<Derived, Mode> part() const; - template<unsigned int Mode> TriangularView<Derived, Mode> triangularView(); - template<unsigned int Mode> const TriangularView<Derived, Mode> triangularView() const; + template<unsigned int Mode> struct TriangularViewReturnType { typedef TriangularView<Derived, Mode> Type; }; + template<unsigned int Mode> struct ConstTriangularViewReturnType { typedef const TriangularView<const Derived, Mode> Type; }; + + template<unsigned int Mode> typename TriangularViewReturnType<Mode>::Type triangularView(); + template<unsigned int Mode> typename ConstTriangularViewReturnType<Mode>::Type triangularView() const; + + template<unsigned int UpLo> struct SelfAdjointViewReturnType { typedef SelfAdjointView<Derived, UpLo> Type; }; + template<unsigned int UpLo> struct ConstSelfAdjointViewReturnType { typedef const SelfAdjointView<const Derived, UpLo> Type; }; - template<unsigned int UpLo> SelfAdjointView<Derived, UpLo> selfadjointView(); - template<unsigned int UpLo> const SelfAdjointView<Derived, UpLo> selfadjointView() const; + template<unsigned int UpLo> typename SelfAdjointViewReturnType<UpLo>::Type selfadjointView(); + template<unsigned int UpLo> typename ConstSelfAdjointViewReturnType<UpLo>::Type selfadjointView() const; const SparseView<Derived> sparseView(const Scalar& m_reference = Scalar(0), typename NumTraits<Scalar>::Real m_epsilon = NumTraits<Scalar>::dummy_precision()) const; @@ -345,13 +357,13 @@ template<typename Derived> class MatrixBase enum { SizeMinusOne = SizeAtCompileTime==Dynamic ? Dynamic : SizeAtCompileTime-1 }; - typedef Block<Derived, + typedef Block<const Derived, internal::traits<Derived>::ColsAtCompileTime==1 ? SizeMinusOne : 1, - internal::traits<Derived>::ColsAtCompileTime==1 ? 1 : SizeMinusOne> StartMinusOne; + internal::traits<Derived>::ColsAtCompileTime==1 ? 1 : SizeMinusOne> ConstStartMinusOne; typedef CwiseUnaryOp<internal::scalar_quotient1_op<typename internal::traits<Derived>::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<MatrixTypeNestedCleaned,Side==OnTheLeft ? 1 : MatrixType::RowsAtCompileTime,Side==OnTheRight ? 1 : MatrixType::ColsAtCompileTime> + Block<const MatrixTypeNestedCleaned,Side==OnTheLeft ? 1 : MatrixType::RowsAtCompileTime,Side==OnTheRight ? 1 : MatrixType::ColsAtCompileTime> (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<Derived>::type using Base::IsVectorAtCompileTime; using Base::Flags; - typedef typename internal::add_const<Derived>::type ConstDerived; friend class Eigen::Map<Derived, Unaligned>; - typedef class Eigen::Map<Derived, Unaligned> MapType; - friend class Eigen::Map<ConstDerived, Unaligned>; - typedef class Eigen::Map<ConstDerived, Unaligned> ConstMapType; + typedef Eigen::Map<Derived, Unaligned> MapType; + friend class Eigen::Map<const Derived, Unaligned>; + typedef const Eigen::Map<const Derived, Unaligned> ConstMapType; friend class Eigen::Map<Derived, Aligned>; - typedef class Eigen::Map<Derived, Aligned> AlignedMapType; - friend class Eigen::Map<ConstDerived, Aligned>; - typedef class Eigen::Map<ConstDerived, Aligned> ConstAlignedMapType; + typedef Eigen::Map<Derived, Aligned> AlignedMapType; + friend class Eigen::Map<const Derived, Aligned>; + typedef const Eigen::Map<const Derived, Aligned> ConstAlignedMapType; protected: DenseStorage<Scalar, Base::MaxSizeAtCompileTime, Base::RowsAtCompileTime, Base::ColsAtCompileTime, Options> m_storage; @@ -116,6 +115,19 @@ class PlainObjectBase : public internal::dense_xpr_base<Derived>::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<int LoadMode> EIGEN_STRONG_INLINE PacketScalar packet(Index row, Index col) const { @@ -381,28 +393,28 @@ class PlainObjectBase : public internal::dense_xpr_base<Derived>::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<Derived>::type INVALID_MATRIX_TEMPLATE_PARAMETERS) } #endif + +private: + enum { ThisConstantIsPrivateInPlainObjectBase }; }; template <typename Derived, typename OtherDerived, bool IsVector> 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<OnTheLeft,StorageOrder,BlasCompatible> Transpose<Dest> destT(dest); enum { OtherStorageOrder = StorageOrder == RowMajor ? ColMajor : RowMajor }; gemv_selector<OnTheRight,OtherStorageOrder,BlasCompatible> - ::run(GeneralProduct<Transpose<typename ProductType::_RhsNested>,Transpose<typename ProductType::_LhsNested>, GemvProduct> + ::run(GeneralProduct<Transpose<const typename ProductType::_RhsNested>,Transpose<const typename ProductType::_LhsNested>, GemvProduct> (prod.rhs().transpose(), prod.lhs().transpose()), destT, alpha); } }; @@ -442,8 +442,8 @@ template<> struct gemv_selector<OnTheRight,RowMajor,true> 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<ActualLhsType>::type actualLhs = LhsBlasTraits::extract(prod.lhs()); + typename add_const<ActualRhsType>::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<OnTheRight,RowMajor,true> RhsScalar* rhs_data; if (DirectlyUseRhs) - rhs_data = &actualRhs.const_cast_derived().coeffRef(0); + rhs_data = const_cast<RhsScalar*>(&actualRhs.coeffRef(0)); else { rhs_data = ei_aligned_stack_new(RhsScalar, actualRhs.size()); @@ -467,7 +467,7 @@ template<> struct gemv_selector<OnTheRight,RowMajor,true> general_matrix_vector_product <Index,LhsScalar,RowMajor,LhsBlasTraits::NeedToConjugate,RhsScalar,RhsBlasTraits::NeedToConjugate>::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<typename MatrixType,int RowFactor,int ColFactor> class Replicate inline explicit Replicate(const OriginalMatrixType& matrix) : m_matrix(matrix), m_rowFactor(RowFactor), m_colFactor(ColFactor) { - EIGEN_STATIC_ASSERT((internal::is_same<MatrixType,OriginalMatrixType>::value), + EIGEN_STATIC_ASSERT((internal::is_same<typename internal::remove_const<MatrixType>::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<typename MatrixType,int RowFactor,int ColFactor> 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<MatrixType,OriginalMatrixType>::value), + EIGEN_STATIC_ASSERT((internal::is_same<typename internal::remove_const<MatrixType>::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<typename MatrixType, int Direction> class Reverse * */ template<typename Derived> -inline Reverse<Derived, BothDirections> +inline typename DenseBase<Derived>::ReverseReturnType DenseBase<Derived>::reverse() { return derived(); @@ -202,7 +202,7 @@ DenseBase<Derived>::reverse() /** This is the const version of reverse(). */ template<typename Derived> -inline const Reverse<Derived, BothDirections> +inline const typename DenseBase<Derived>::ConstReverseReturnType DenseBase<Derived>::reverse() const { return derived(); @@ -216,7 +216,7 @@ DenseBase<Derived>::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<Derived1, Derived2, SelfAdjoint|Lower, Dyn template<typename Derived> template<unsigned int UpLo> -const SelfAdjointView<Derived, UpLo> MatrixBase<Derived>::selfadjointView() const +typename MatrixBase<Derived>::template ConstSelfAdjointViewReturnType<UpLo>::Type +MatrixBase<Derived>::selfadjointView() const { return derived(); } template<typename Derived> template<unsigned int UpLo> -SelfAdjointView<Derived, UpLo> MatrixBase<Derived>::selfadjointView() +typename MatrixBase<Derived>::template SelfAdjointViewReturnType<UpLo>::Type +MatrixBase<Derived>::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,13 +77,23 @@ template<typename BinaryOp, typename Lhs, typename Rhs> 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<Lhs,Rhs,Side,Mode,NoUnrolling,Dynamic> const ActualLhsType actualLhs = LhsProductTraits::extract(lhs); triangular_solve_matrix<Scalar,Index,Side,Mode,LhsProductTraits::NeedToConjugate,(int(Lhs::Flags) & RowMajorBit) ? RowMajor : ColMajor, (Rhs::Flags&RowMajorBit) ? RowMajor : ColMajor> - ::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<typename ExpressionType> 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<typename OtherDerived> void copyCoeff(Index row, Index col, const DenseBase<OtherDerived>& other) { @@ -113,18 +123,4 @@ template<typename ExpressionType> 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<typename Derived> -template<typename OtherDerived> -void DenseBase<Derived>::swap(DenseBase<OtherDerived> EIGEN_REF_TO_TEMPORARY other) -{ - (SwapWrapper<Derived>(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<Transpose<MatrixType> > : traits<MatrixType> { typedef typename MatrixType::Scalar Scalar; typedef typename nested<MatrixType>::type MatrixTypeNested; - typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested; + typedef typename remove_reference<MatrixTypeNested>::type MatrixTypeNestedPlain; typedef typename traits<MatrixType>::StorageKind StorageKind; typedef typename traits<MatrixType>::XprKind XprKind; enum { @@ -54,8 +54,11 @@ struct traits<Transpose<MatrixType> > : traits<MatrixType> ColsAtCompileTime = MatrixType::RowsAtCompileTime, MaxRowsAtCompileTime = MatrixType::MaxColsAtCompileTime, MaxColsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - Flags = int(_MatrixTypeNested::Flags & ~NestByRefBit) ^ RowMajorBit, - CoeffReadCost = _MatrixTypeNested::CoeffReadCost, + FlagsLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0, + Flags0 = MatrixTypeNestedPlain::Flags & ~(LvalueBit | NestByRefBit), + Flags1 = Flags0 | FlagsLvalueBit, + Flags = Flags1 ^ RowMajorBit, + CoeffReadCost = MatrixTypeNestedPlain::CoeffReadCost, InnerStrideAtCompileTime = inner_stride_at_compile_time<MatrixType>::ret, OuterStrideAtCompileTime = outer_stride_at_compile_time<MatrixType>::ret }; @@ -122,12 +125,24 @@ template<typename MatrixType> class TransposeImpl<MatrixType,Dense> 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<typename MatrixType> class TransposeImpl<MatrixType,Dense> template<int LoadMode> inline void writePacket(Index row, Index col, const PacketScalar& x) { - const_cast_derived().nestedExpression().template writePacket<LoadMode>(col, row, x); + derived().nestedExpression().const_cast_derived().template writePacket<LoadMode>(col, row, x); } template<int LoadMode> @@ -161,7 +176,7 @@ template<typename MatrixType> class TransposeImpl<MatrixType,Dense> template<int LoadMode> inline void writePacket(Index index, const PacketScalar& x) { - const_cast_derived().nestedExpression().template writePacket<LoadMode>(index, x); + derived().nestedExpression().const_cast_derived().template writePacket<LoadMode>(index, x); } }; @@ -197,7 +212,7 @@ DenseBase<Derived>::transpose() * * \sa transposeInPlace(), adjoint() */ template<typename Derived> -inline const Transpose<Derived> +inline const typename DenseBase<Derived>::ConstTransposeReturnType DenseBase<Derived>::transpose() const { return derived(); @@ -226,7 +241,8 @@ template<typename Derived> inline const typename MatrixBase<Derived>::AdjointReturnType MatrixBase<Derived>::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<typename Derived> class TriangularBase : public EigenBase<Derived> EIGEN_ONLY_USED_FOR_DEBUG(row); EIGEN_ONLY_USED_FOR_DEBUG(col); eigen_assert(col>=0 && col<cols() && row>=0 && row<rows()); - eigen_assert( (Mode==Upper && col>=row) - || (Mode==Lower && col<=row) - || ((Mode==StrictlyUpper || Mode==UnitUpper) && col>row) - || ((Mode==StrictlyLower || Mode==UnitLower) && col<row)); + const int mode = int(Mode) & ~SelfAdjoint; + eigen_assert((mode==Upper && col>=row) + || (mode==Lower && col<=row) + || ((mode==StrictlyUpper || mode==UnitUpper) && col>row) + || ((mode==StrictlyLower || mode==UnitLower) && col<row)); } #ifdef EIGEN_INTERNAL_DEBUGGING @@ -260,7 +261,10 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView /** \sa MatrixBase::transpose() */ inline TriangularView<Transpose<MatrixType>,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<Transpose<MatrixType>,TransposeMode> transpose() const { return m_matrix.transpose(); } @@ -701,7 +705,8 @@ EIGEN_DEPRECATED TriangularView<Derived, Mode> MatrixBase<Derived>::part() */ template<typename Derived> template<unsigned int Mode> -TriangularView<Derived, Mode> MatrixBase<Derived>::triangularView() +typename MatrixBase<Derived>::template TriangularViewReturnType<Mode>::Type +MatrixBase<Derived>::triangularView() { return derived(); } @@ -709,7 +714,8 @@ TriangularView<Derived, Mode> MatrixBase<Derived>::triangularView() /** This is the const version of MatrixBase::triangularView() */ template<typename Derived> template<unsigned int Mode> -const TriangularView<Derived, Mode> MatrixBase<Derived>::triangularView() const +typename MatrixBase<Derived>::template ConstTriangularViewReturnType<Mode>::Type +MatrixBase<Derived>::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<typename VectorType, int Size> 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<typename VectorType, int Size> 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<typename VectorType, int Size> class VectorBlock * \sa class Block, segment(Index) */ template<typename Derived> -inline VectorBlock<Derived> DenseBase<Derived> - ::segment(Index start, Index size) +inline typename DenseBase<Derived>::SegmentReturnType +DenseBase<Derived>::segment(Index start, Index size) { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return VectorBlock<Derived>(derived(), start, size); + return SegmentReturnType(derived(), start, size); } /** This is the const version of segment(Index,Index).*/ template<typename Derived> -inline const VectorBlock<Derived> +inline typename DenseBase<Derived>::ConstSegmentReturnType DenseBase<Derived>::segment(Index start, Index size) const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return VectorBlock<Derived>(derived(), start, size); + return ConstSegmentReturnType(derived(), start, size); } /** \returns a dynamic-size expression of the first coefficients of *this. @@ -152,20 +152,20 @@ DenseBase<Derived>::segment(Index start, Index size) const * \sa class Block, block(Index,Index) */ template<typename Derived> -inline VectorBlock<Derived> +inline typename DenseBase<Derived>::SegmentReturnType DenseBase<Derived>::head(Index size) { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return VectorBlock<Derived>(derived(), 0, size); + return SegmentReturnType(derived(), 0, size); } /** This is the const version of head(Index).*/ template<typename Derived> -inline const VectorBlock<Derived> +inline typename DenseBase<Derived>::ConstSegmentReturnType DenseBase<Derived>::head(Index size) const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return VectorBlock<Derived>(derived(), 0, size); + return ConstSegmentReturnType(derived(), 0, size); } /** \returns a dynamic-size expression of the last coefficients of *this. @@ -184,20 +184,20 @@ DenseBase<Derived>::head(Index size) const * \sa class Block, block(Index,Index) */ template<typename Derived> -inline VectorBlock<Derived> +inline typename DenseBase<Derived>::SegmentReturnType DenseBase<Derived>::tail(Index size) { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return VectorBlock<Derived>(derived(), this->size() - size, size); + return SegmentReturnType(derived(), this->size() - size, size); } /** This is the const version of tail(Index).*/ template<typename Derived> -inline const VectorBlock<Derived> +inline typename DenseBase<Derived>::ConstSegmentReturnType DenseBase<Derived>::tail(Index size) const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return VectorBlock<Derived>(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<Derived>::tail(Index size) const */ template<typename Derived> template<int Size> -inline VectorBlock<Derived,Size> +inline typename DenseBase<Derived>::template FixedSegmentReturnType<Size>::Type DenseBase<Derived>::segment(Index start) { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return VectorBlock<Derived,Size>(derived(), start); + return typename FixedSegmentReturnType<Size>::Type(derived(), start); } /** This is the const version of segment<int>(Index).*/ template<typename Derived> template<int Size> -inline const VectorBlock<Derived,Size> +inline typename DenseBase<Derived>::template ConstFixedSegmentReturnType<Size>::Type DenseBase<Derived>::segment(Index start) const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return VectorBlock<Derived,Size>(derived(), start); + return typename ConstFixedSegmentReturnType<Size>::Type(derived(), start); } /** \returns a fixed-size expression of the first coefficients of *this. @@ -245,21 +245,21 @@ DenseBase<Derived>::segment(Index start) const */ template<typename Derived> template<int Size> -inline VectorBlock<Derived,Size> +inline typename DenseBase<Derived>::template FixedSegmentReturnType<Size>::Type DenseBase<Derived>::head() { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return VectorBlock<Derived,Size>(derived(), 0); + return typename FixedSegmentReturnType<Size>::Type(derived(), 0); } /** This is the const version of head<int>().*/ template<typename Derived> template<int Size> -inline const VectorBlock<Derived,Size> +inline typename DenseBase<Derived>::template ConstFixedSegmentReturnType<Size>::Type DenseBase<Derived>::head() const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return VectorBlock<Derived,Size>(derived(), 0); + return typename ConstFixedSegmentReturnType<Size>::Type(derived(), 0); } /** \returns a fixed-size expression of the last coefficients of *this. @@ -275,21 +275,21 @@ DenseBase<Derived>::head() const */ template<typename Derived> template<int Size> -inline VectorBlock<Derived,Size> +inline typename DenseBase<Derived>::template FixedSegmentReturnType<Size>::Type DenseBase<Derived>::tail() { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return VectorBlock<Derived, Size>(derived(), size() - Size); + return typename FixedSegmentReturnType<Size>::Type(derived(), size() - Size); } /** This is the const version of tail<int>.*/ template<typename Derived> template<int Size> -inline const VectorBlock<Derived,Size> +inline typename DenseBase<Derived>::template ConstFixedSegmentReturnType<Size>::Type DenseBase<Derived>::tail() const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return VectorBlock<Derived, Size>(derived(), size() - Size); + return typename ConstFixedSegmentReturnType<Size>::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<typename ExpressionType, int Direction> class VectorwiseOp typedef typename ExpressionType::RealScalar RealScalar; typedef typename ExpressionType::Index Index; typedef typename internal::conditional<internal::must_nest_by_value<ExpressionType>::ret, - ExpressionType, const ExpressionType&>::type ExpressionTypeNested; + ExpressionType, ExpressionType&>::type ExpressionTypeNested; + typedef typename internal::remove_all<ExpressionTypeNested>::type ExpressionTypeNestedCleaned; template<template<typename _Scalar> class Functor, typename Scalar=typename internal::traits<ExpressionType>::Scalar> struct ReturnType @@ -245,7 +246,7 @@ template<typename ExpressionType, int Direction> 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<typename ExpressionType, int Direction> class VectorwiseOp } /** Returns the expression of the sum of the vector \a other to each subvector of \c *this */ - template<typename OtherDerived> EIGEN_STRONG_INLINE + template<typename OtherDerived> EIGEN_STRONG_INLINE CwiseBinaryOp<internal::scalar_sum_op<Scalar>, - ExpressionType, + ExpressionTypeNestedCleaned, typename ExtendedType<OtherDerived>::Type> operator+(const DenseBase<OtherDerived>& other) const { @@ -457,7 +458,7 @@ template<typename ExpressionType, int Direction> class VectorwiseOp /** Returns the expression of the difference between each subvector of \c *this and the vector \a other */ template<typename OtherDerived> CwiseBinaryOp<internal::scalar_difference_op<Scalar>, - ExpressionType, + ExpressionTypeNestedCleaned, typename ExtendedType<OtherDerived>::Type> operator-(const DenseBase<OtherDerived>& other) const { @@ -478,13 +479,13 @@ template<typename ExpressionType, int Direction> class VectorwiseOp : internal::traits<ExpressionType>::ColsAtCompileTime, HNormalized_SizeMinusOne = HNormalized_Size==Dynamic ? Dynamic : HNormalized_Size-1 }; - typedef Block<ExpressionType, + typedef Block<const ExpressionType, Direction==Vertical ? int(HNormalized_SizeMinusOne) : int(internal::traits<ExpressionType>::RowsAtCompileTime), Direction==Horizontal ? int(HNormalized_SizeMinusOne) : int(internal::traits<ExpressionType>::ColsAtCompileTime)> HNormalized_Block; - typedef Block<ExpressionType, + typedef Block<const ExpressionType, Direction==Vertical ? 1 : int(internal::traits<ExpressionType>::RowsAtCompileTime), Direction==Horizontal ? 1 : int(internal::traits<ExpressionType>::ColsAtCompileTime)> HNormalized_Factors; @@ -495,7 +496,7 @@ template<typename ExpressionType, int Direction> class VectorwiseOp Direction==Horizontal ? HNormalized_SizeMinusOne : 1> > HNormalizedReturnType; - HNormalizedReturnType hnormalized() const; + const HNormalizedReturnType hnormalized() const; protected: ExpressionTypeNested m_matrix; @@ -509,7 +510,7 @@ template<typename ExpressionType, int Direction> class VectorwiseOp * \sa rowwise(), class VectorwiseOp */ template<typename Derived> -inline const VectorwiseOp<Derived,Vertical> +inline const typename DenseBase<Derived>::ConstColwiseReturnType DenseBase<Derived>::colwise() const { return derived(); @@ -520,7 +521,7 @@ DenseBase<Derived>::colwise() const * \sa rowwise(), class VectorwiseOp */ template<typename Derived> -inline VectorwiseOp<Derived,Vertical> +inline typename DenseBase<Derived>::ColwiseReturnType DenseBase<Derived>::colwise() { return derived(); @@ -534,7 +535,7 @@ DenseBase<Derived>::colwise() * \sa colwise(), class VectorwiseOp */ template<typename Derived> -inline const VectorwiseOp<Derived,Horizontal> +inline const typename DenseBase<Derived>::ConstRowwiseReturnType DenseBase<Derived>::rowwise() const { return derived(); @@ -545,7 +546,7 @@ DenseBase<Derived>::rowwise() const * \sa colwise(), class VectorwiseOp */ template<typename Derived> -inline VectorwiseOp<Derived,Horizontal> +inline typename DenseBase<Derived>::RowwiseReturnType DenseBase<Derived>::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<MatrixType,UpLo>& TriangularView<MatrixType,UpLo>::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<Scalar*>(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<Lhs,LhsMode,false,Rhs,RhsMode,false> internal::traits<Dest>::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<Lhs,LhsMode,false,Rhs,0,true> internal::product_selfadjoint_vector<Scalar, Index, (internal::traits<_ActualLhsType>::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<Lhs,0,true,Rhs,RhsMode,false> 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<MatrixType,UpLo>& SelfAdjointView<MatrixType,UpLo> Scalar, _ActualUType::Flags&RowMajorBit ? ColMajor : RowMajor, (!UBlasTraits::NeedToConjugate) && NumTraits<Scalar>::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<Mode,LhsIsTriangular,Lhs,false,Rhs,false> (internal::traits<Dest >::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<Index,Mode,LhsScalar,ConjLhs,RhsScalar,C Index s = IsLower ? pi+actualPanelWidth : 0; general_matrix_vector_product<Index,LhsScalar,ColMajor,ConjLhs,RhsScalar,ConjRhs>::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<Index,Mode,LhsScalar,ConjLhs,RhsScalar,C Index s = IsLower ? 0 : pi + actualPanelWidth; general_matrix_vector_product<Index,LhsScalar,RowMajor,ConjLhs,RhsScalar,ConjRhs>::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<LhsScalar, RhsScalar, Index, OnTheLeft, Mode, Con general_matrix_vector_product<Index,LhsScalar,RowMajor,Conjugate,RhsScalar,false>::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<LhsScalar, RhsScalar, Index, OnTheLeft, Mode, Con // 2 - it is slighlty faster at runtime general_matrix_vector_product<Index,LhsScalar,ColMajor,Conjugate,RhsScalar,false>::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<typename XprType> 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<CwiseUnaryOp<scalar_conjugate_op<Scalar>, NestedXpr> > IsComplex = NumTraits<Scalar>::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<CwiseUnaryOp<scalar_multiple_op<Scalar>, NestedXpr> > typedef blas_traits<NestedXpr> Base; typedef CwiseUnaryOp<scalar_multiple_op<Scalar>, 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<CwiseUnaryOp<scalar_opposite_op<Scalar>, NestedXpr> > typedef blas_traits<NestedXpr> Base; typedef CwiseUnaryOp<scalar_opposite_op<Scalar>, 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<Transpose<NestedXpr> > static inline Scalar extractScalarFactor(const XprType& x) { return Base::extractScalarFactor(x.nestedExpression()); } }; +template<typename T> +struct blas_traits<const T> + : blas_traits<T> +{}; + template<typename T, bool HasUsableDirectAccess=blas_traits<T>::HasUsableDirectAccess> struct extract_data_selector { static const typename T::Scalar* run(const T& m) { - return &blas_traits<T>::extract(m).const_cast_derived().coeffRef(0,0); // FIXME this should be .data() + return const_cast<typename T::Scalar*>(&blas_traits<T>::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<typename T> struct traits; +// here we say once and for all that traits<const T> == traits<T> +// When constness must affect traits, it has to be constness on template parameters on which T itself depends. +// For example, traits<Map<const T> > != traits<Map<T> >, but +// traits<const Map<T> > == traits<Map<T> > +template<typename T> struct traits<const T> : traits<T> {}; + template<typename Derived> struct has_direct_access { enum { ret = (traits<Derived>::Flags & DirectAccessBit) ? 1 : 0 }; @@ -49,6 +56,7 @@ template<typename T> struct NumTraits; template<typename Derived> struct EigenBase; template<typename Derived> class DenseBase; +template<typename Derived> class PlainObjectBase; template<typename Derived, @@ -92,7 +100,7 @@ template<typename Derived> class DiagonalBase; template<typename _DiagonalVectorType> class DiagonalWrapper; template<typename _Scalar, int SizeAtCompileTime, int MaxSizeAtCompileTime=SizeAtCompileTime> class DiagonalMatrix; template<typename MatrixType, typename DiagonalType, int ProductOrder> class DiagonalProduct; -template<typename MatrixType, int Index> class Diagonal; +template<typename MatrixType, int Index = 0> class Diagonal; template<int SizeAtCompileTime, int MaxSizeAtCompileTime = SizeAtCompileTime> class PermutationMatrix; template<int SizeAtCompileTime, int MaxSizeAtCompileTime = SizeAtCompileTime> 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<Derived>::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<Derived,Scalar,OtherScalar,true> : public DenseCo { return static_cast<const special_scalar_op_base&>(matrix).operator*(scalar); } }; -template<typename ExpressionType> struct HNormalizedReturnType { - - enum { - SizeAtCompileTime = ExpressionType::SizeAtCompileTime, - SizeMinusOne = SizeAtCompileTime==Dynamic ? Dynamic : SizeAtCompileTime-1 - }; - typedef Block<ExpressionType, - traits<ExpressionType>::ColsAtCompileTime==1 ? SizeMinusOne : 1, - traits<ExpressionType>::ColsAtCompileTime==1 ? 1 : SizeMinusOne> StartMinusOne; - typedef CwiseUnaryOp<scalar_quotient1_op<typename traits<ExpressionType>::Scalar>, - StartMinusOne > Type; -}; - template<typename XprType, typename CastType> struct cast_return_type { typedef typename XprType::Scalar CurrentScalarType; @@ -455,6 +442,13 @@ struct plain_diag_type >::type type; }; +template<typename ExpressionType> +struct is_lvalue +{ + enum { value = !bool(is_const<ExpressionType>::value) && + bool(traits<ExpressionType>::Flags & LvalueBit) }; +}; + } // end namespace internal #endif // EIGEN_XPRHELPER_H |