From 113fc3a2606997533287921ccec49e320bf9f79b Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Wed, 1 Apr 2009 00:39:56 +0000 Subject: [PATCH] now if Derived has the DirectAccess flag, then MatrixBase::coeff() const returns a const Scalar& and not a Scalar as before. useful for people doing direct access. + 1 bugfix thanks to Patrick Mihelich, forgot a & in MapBase::coeff(int). --- Eigen/src/Core/Coeffs.h | 18 +++++++++--------- Eigen/src/Core/MapBase.h | 2 +- Eigen/src/Core/MatrixBase.h | 22 +++++++++++++--------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/Eigen/src/Core/Coeffs.h b/Eigen/src/Core/Coeffs.h index 23a84228b..b514dcd17 100644 --- a/Eigen/src/Core/Coeffs.h +++ b/Eigen/src/Core/Coeffs.h @@ -40,7 +40,7 @@ * \sa operator()(int,int) const, coeffRef(int,int), coeff(int) const */ template -EIGEN_STRONG_INLINE const typename ei_traits::Scalar MatrixBase +EIGEN_STRONG_INLINE const typename MatrixBase::CoeffReturnType MatrixBase ::coeff(int row, int col) const { ei_internal_assert(row >= 0 && row < rows() @@ -53,7 +53,7 @@ EIGEN_STRONG_INLINE const typename ei_traits::Scalar MatrixBase -EIGEN_STRONG_INLINE const typename ei_traits::Scalar MatrixBase +EIGEN_STRONG_INLINE const typename MatrixBase::CoeffReturnType MatrixBase ::operator()(int row, int col) const { ei_assert(row >= 0 && row < rows() @@ -112,7 +112,7 @@ EIGEN_STRONG_INLINE typename ei_traits::Scalar& MatrixBase * \sa operator[](int) const, coeffRef(int), coeff(int,int) const */ template -EIGEN_STRONG_INLINE const typename ei_traits::Scalar MatrixBase +EIGEN_STRONG_INLINE const typename MatrixBase::CoeffReturnType MatrixBase ::coeff(int index) const { ei_internal_assert(index >= 0 && index < size()); @@ -127,7 +127,7 @@ EIGEN_STRONG_INLINE const typename ei_traits::Scalar MatrixBase -EIGEN_STRONG_INLINE const typename ei_traits::Scalar MatrixBase +EIGEN_STRONG_INLINE const typename MatrixBase::CoeffReturnType MatrixBase ::operator[](int index) const { ei_assert(index >= 0 && index < size()); @@ -144,7 +144,7 @@ EIGEN_STRONG_INLINE const typename ei_traits::Scalar MatrixBase -EIGEN_STRONG_INLINE const typename ei_traits::Scalar MatrixBase +EIGEN_STRONG_INLINE const typename MatrixBase::CoeffReturnType MatrixBase ::operator()(int index) const { ei_assert(index >= 0 && index < size()); @@ -205,22 +205,22 @@ EIGEN_STRONG_INLINE typename ei_traits::Scalar& MatrixBase /** equivalent to operator[](0). */ template -EIGEN_STRONG_INLINE const typename ei_traits::Scalar MatrixBase +EIGEN_STRONG_INLINE const typename MatrixBase::CoeffReturnType MatrixBase ::x() const { return (*this)[0]; } /** equivalent to operator[](1). */ template -EIGEN_STRONG_INLINE const typename ei_traits::Scalar MatrixBase +EIGEN_STRONG_INLINE const typename MatrixBase::CoeffReturnType MatrixBase ::y() const { return (*this)[1]; } /** equivalent to operator[](2). */ template -EIGEN_STRONG_INLINE const typename ei_traits::Scalar MatrixBase +EIGEN_STRONG_INLINE const typename MatrixBase::CoeffReturnType MatrixBase ::z() const { return (*this)[2]; } /** equivalent to operator[](3). */ template -EIGEN_STRONG_INLINE const typename ei_traits::Scalar MatrixBase +EIGEN_STRONG_INLINE const typename MatrixBase::CoeffReturnType MatrixBase ::w() const { return (*this)[3]; } /** equivalent to operator[](0). */ diff --git a/Eigen/src/Core/MapBase.h b/Eigen/src/Core/MapBase.h index ed3d2cbf8..bc666878a 100644 --- a/Eigen/src/Core/MapBase.h +++ b/Eigen/src/Core/MapBase.h @@ -96,7 +96,7 @@ template class MapBase return const_cast(m_data)[row + col * stride()]; } - inline const Scalar coeff(int index) const + inline const Scalar& coeff(int index) const { ei_assert(Derived::IsVectorAtCompileTime || (ei_traits::Flags & LinearAccessBit)); if ( ((RowsAtCompileTime == 1) == IsRowMajor) ) diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index dfe17c526..2d6b3d85b 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -199,6 +199,10 @@ template class MatrixBase */ typedef typename ei_plain_matrix_type::type PlainMatrixType_ColMajor; + /** \internal the return type of coeff() + */ + typedef typename ei_meta_if::ret CoeffReturnType; + /** \internal Represents a matrix with all coefficients equal to one another*/ typedef CwiseNullaryOp,Derived> ConstantReturnType; /** \internal Represents a scalar multiple of a matrix */ @@ -264,15 +268,15 @@ template class MatrixBase template CommaInitializer operator<< (const MatrixBase& other); - const Scalar coeff(int row, int col) const; - const Scalar operator()(int row, int col) const; + const CoeffReturnType coeff(int row, int col) const; + const CoeffReturnType operator()(int row, int col) const; Scalar& coeffRef(int row, int col); Scalar& operator()(int row, int col); - const Scalar coeff(int index) const; - const Scalar operator[](int index) const; - const Scalar operator()(int index) const; + const CoeffReturnType coeff(int index) const; + const CoeffReturnType operator[](int index) const; + const CoeffReturnType operator()(int index) const; Scalar& coeffRef(int index); Scalar& operator[](int index); @@ -299,10 +303,10 @@ template class MatrixBase template void writePacket(int index, const PacketScalar& x); - const Scalar x() const; - const Scalar y() const; - const Scalar z() const; - const Scalar w() const; + const CoeffReturnType x() const; + const CoeffReturnType y() const; + const CoeffReturnType z() const; + const CoeffReturnType w() const; Scalar& x(); Scalar& y(); Scalar& z();