diff --git a/Eigen/src/Core/Coeffs.h b/Eigen/src/Core/Coeffs.h index 661e57e74..faebc0b14 100644 --- a/Eigen/src/Core/Coeffs.h +++ b/Eigen/src/Core/Coeffs.h @@ -213,6 +213,7 @@ class DenseCoeffsBase : public EigenBase return derived().template packet(index); } + protected: void coeffRef(); void coeffRefByOuterInner(); void writePacket(); @@ -221,6 +222,11 @@ class DenseCoeffsBase : public EigenBase void copyCoeffByOuterInner(); void copyPacket(); void copyPacketByOuterInner(); + void stride(); + void innerStride(); + void outerStride(); + void rowStride(); + void colStride(); }; template @@ -238,6 +244,12 @@ class DenseCoeffsBase : public DenseCoeffsBase using Base::derived; using Base::rowIndexByOuterInner; using Base::colIndexByOuterInner; + using Base::operator[]; + using Base::operator(); + using Base::x; + using Base::y; + using Base::z; + using Base::w; /** Short version: don't use this function, use * \link operator()(int,int) \endlink instead. @@ -485,6 +497,48 @@ class DenseCoeffsBase : public DenseCoeffsBase derived().copyPacket(row, col, other); } #endif + + /** \returns the pointer increment between two consecutive elements within a slice in the inner direction. + * + * \sa outerStride(), rowStride(), colStride() + */ + inline int innerStride() const + { + return derived().innerStride(); + } + + /** \returns the pointer increment between two consecutive inner slices (for example, between two consecutive columns + * in a column-major matrix). + * + * \sa innerStride(), rowStride(), colStride() + */ + inline int outerStride() const + { + return derived().outerStride(); + } + + inline int stride() const + { + return Derived::IsVectorAtCompileTime ? innerStride() : outerStride(); + } + + /** \returns the pointer increment between two consecutive rows. + * + * \sa innerStride(), outerStride(), colStride() + */ + inline int rowStride() const + { + return Derived::IsRowMajor ? outerStride() : innerStride(); + } + + /** \returns the pointer increment between two consecutive columns. + * + * \sa innerStride(), outerStride(), rowStride() + */ + inline int colStride() const + { + return Derived::IsRowMajor ? innerStride() : outerStride(); + } }; template diff --git a/Eigen/src/Core/CwiseUnaryView.h b/Eigen/src/Core/CwiseUnaryView.h index 036bff8fb..9cdd03477 100644 --- a/Eigen/src/Core/CwiseUnaryView.h +++ b/Eigen/src/Core/CwiseUnaryView.h @@ -91,7 +91,7 @@ class CwiseUnaryView : ei_no_assignment_operator, protected: // FIXME changed from MatrixType::Nested because of a weird compilation error with sun CC const typename ei_nested::type m_matrix; - const ViewOp m_functor; + ViewOp m_functor; }; template @@ -102,6 +102,8 @@ class CwiseUnaryViewImpl public: + typedef typename ei_dense_xpr_base< CwiseUnaryView >::type Base; + inline int innerStride() const { return derived().nestedExpression().innerStride() * sizeof(typename ei_traits::Scalar) / sizeof(Scalar); @@ -112,15 +114,14 @@ class CwiseUnaryViewImpl return derived().nestedExpression().outerStride(); } - typedef typename ei_dense_xpr_base >::type Base; EIGEN_DENSE_PUBLIC_INTERFACE(Derived) - EIGEN_STRONG_INLINE const Scalar coeff(int row, int col) const + EIGEN_STRONG_INLINE CoeffReturnType coeff(int row, int col) const { return derived().functor()(derived().nestedExpression().coeff(row, col)); } - EIGEN_STRONG_INLINE const Scalar coeff(int index) const + EIGEN_STRONG_INLINE CoeffReturnType coeff(int index) const { return derived().functor()(derived().nestedExpression().coeff(index)); } diff --git a/Eigen/src/Core/DenseBase.h b/Eigen/src/Core/DenseBase.h index f686885b3..046c46e4e 100644 --- a/Eigen/src/Core/DenseBase.h +++ b/Eigen/src/Core/DenseBase.h @@ -102,6 +102,12 @@ template class DenseBase using Base::y; using Base::z; using Base::w; + using Base::stride; + using Base::innerStride; + using Base::outerStride; + using Base::rowStride; + using Base::colStride; + using Base::CoeffReturnType; #endif // not EIGEN_PARSED_BY_DOXYGEN @@ -246,9 +252,6 @@ template class DenseBase } #ifndef EIGEN_PARSED_BY_DOXYGEN - /** \internal the return type of coeff() - */ - typedef typename ei_meta_if::ret, const Scalar&, Scalar>::ret CoeffReturnType; /** \internal Represents a matrix with all coefficients equal to one another*/ typedef CwiseNullaryOp,Derived> ConstantReturnType; @@ -301,48 +304,6 @@ template class DenseBase Derived& lazyAssign(const DenseBase& other); #endif // not EIGEN_PARSED_BY_DOXYGEN - /** \returns the pointer increment between two consecutive elements within a slice in the inner direction. - * - * \sa outerStride(), rowStride(), colStride() - */ - inline int innerStride() const - { - return derived().innerStride(); - } - - /** \returns the pointer increment between two consecutive inner slices (for example, between two consecutive columns - * in a column-major matrix). - * - * \sa innerStride(), rowStride(), colStride() - */ - inline int outerStride() const - { - return derived().outerStride(); - } - - inline int stride() const - { - return IsVectorAtCompileTime ? innerStride() : outerStride(); - } - - /** \returns the pointer increment between two consecutive rows. - * - * \sa innerStride(), outerStride(), colStride() - */ - inline int rowStride() const - { - return IsRowMajor ? outerStride() : innerStride(); - } - - /** \returns the pointer increment between two consecutive columns. - * - * \sa innerStride(), outerStride(), rowStride() - */ - inline int colStride() const - { - return IsRowMajor ? innerStride() : outerStride(); - } - CommaInitializer operator<< (const Scalar& s); template diff --git a/Eigen/src/Core/Functors.h b/Eigen/src/Core/Functors.h index bdceb9bb5..494a56fca 100644 --- a/Eigen/src/Core/Functors.h +++ b/Eigen/src/Core/Functors.h @@ -290,7 +290,6 @@ struct ei_scalar_real_op { EIGEN_EMPTY_STRUCT_CTOR(ei_scalar_real_op) typedef typename NumTraits::Real result_type; EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const { return ei_real(a); } - EIGEN_STRONG_INLINE result_type& operator() (Scalar& a) const { return ei_real_ref(a); } }; template struct ei_functor_traits > @@ -306,12 +305,41 @@ struct ei_scalar_imag_op { EIGEN_EMPTY_STRUCT_CTOR(ei_scalar_imag_op) typedef typename NumTraits::Real result_type; EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const { return ei_imag(a); } - EIGEN_STRONG_INLINE result_type& operator() (Scalar& a) const { return ei_imag_ref(a); } }; template struct ei_functor_traits > { enum { Cost = 0, PacketAccess = false }; }; +/** \internal + * \brief Template functor to extract the real part of a complex as a reference + * + * \sa class CwiseUnaryOp, MatrixBase::real() + */ +template +struct ei_scalar_real_ref_op { + EIGEN_EMPTY_STRUCT_CTOR(ei_scalar_real_ref_op) + typedef typename NumTraits::Real result_type; + EIGEN_STRONG_INLINE result_type& operator() (const Scalar& a) const { return ei_real_ref(*const_cast(&a)); } +}; +template +struct ei_functor_traits > +{ enum { Cost = 0, PacketAccess = false }; }; + +/** \internal + * \brief Template functor to extract the imaginary part of a complex as a reference + * + * \sa class CwiseUnaryOp, MatrixBase::imag() + */ +template +struct ei_scalar_imag_ref_op { + EIGEN_EMPTY_STRUCT_CTOR(ei_scalar_imag_ref_op) + typedef typename NumTraits::Real result_type; + EIGEN_STRONG_INLINE result_type& operator() (Scalar& a) const { return ei_imag_ref(*const_cast(&a)); } +}; +template +struct ei_functor_traits > +{ enum { Cost = 0, PacketAccess = false }; }; + /** \internal * * \brief Template functor to compute the exponential of a scalar diff --git a/Eigen/src/plugins/CommonCwiseUnaryOps.h b/Eigen/src/plugins/CommonCwiseUnaryOps.h index 74601c2d2..0cdb5ffd8 100644 --- a/Eigen/src/plugins/CommonCwiseUnaryOps.h +++ b/Eigen/src/plugins/CommonCwiseUnaryOps.h @@ -43,13 +43,13 @@ typedef typename ei_meta_if::IsComplex, >::ret RealReturnType; /** \internal the return type of real() */ typedef typename ei_meta_if::IsComplex, - CwiseUnaryView, Derived>, + CwiseUnaryView, Derived>, Derived& >::ret NonConstRealReturnType; /** \internal the return type of imag() const */ typedef CwiseUnaryOp, Derived> ImagReturnType; /** \internal the return type of imag() */ -typedef CwiseUnaryView, Derived> NonConstImagReturnType; +typedef CwiseUnaryView, Derived> NonConstImagReturnType; #endif // not EIGEN_PARSED_BY_DOXYGEN