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/Diagonal.h | |
parent | 3b6d97b51a7e7a4b0c69ae6be44b1c16d72c2e80 (diff) |
bug #54 - really fix const correctness except in Sparse
Diffstat (limited to 'Eigen/src/Core/Diagonal.h')
-rw-r--r-- | Eigen/src/Core/Diagonal.h | 41 |
1 files changed, 26 insertions, 15 deletions
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 |