diff options
author | Benoit Jacob <jacob.benoit.1@gmail.com> | 2010-05-08 16:00:05 -0400 |
---|---|---|
committer | Benoit Jacob <jacob.benoit.1@gmail.com> | 2010-05-08 16:00:05 -0400 |
commit | 7cbb84b0460e4537112273954f2efe3448df5631 (patch) | |
tree | ac2b648459302e698f4f486d48cc6685895f9697 | |
parent | 0e2a480466220ea2054b8dbe68569b3440918174 (diff) |
move the strides API to DenseCoeffsBase,
and various fixes to make stuff compile after my big changes
-rw-r--r-- | Eigen/src/Core/Coeffs.h | 54 | ||||
-rw-r--r-- | Eigen/src/Core/CwiseUnaryView.h | 9 | ||||
-rw-r--r-- | Eigen/src/Core/DenseBase.h | 51 | ||||
-rw-r--r-- | Eigen/src/Core/Functors.h | 32 | ||||
-rw-r--r-- | Eigen/src/plugins/CommonCwiseUnaryOps.h | 4 |
5 files changed, 97 insertions, 53 deletions
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<Derived> return derived().template packet<LoadMode>(index); } + protected: void coeffRef(); void coeffRefByOuterInner(); void writePacket(); @@ -221,6 +222,11 @@ class DenseCoeffsBase : public EigenBase<Derived> void copyCoeffByOuterInner(); void copyPacket(); void copyPacketByOuterInner(); + void stride(); + void innerStride(); + void outerStride(); + void rowStride(); + void colStride(); }; template<typename Derived> @@ -238,6 +244,12 @@ class DenseCoeffsBase<Derived, true> : public DenseCoeffsBase<Derived, false> 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<Derived, true> : public DenseCoeffsBase<Derived, false> derived().copyPacket<OtherDerived, StoreMode, LoadMode>(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<typename Derived, bool JustReturnZero> 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<MatrixType>::type m_matrix; - const ViewOp m_functor; + ViewOp m_functor; }; template<typename ViewOp, typename MatrixType> @@ -102,6 +102,8 @@ class CwiseUnaryViewImpl<ViewOp,MatrixType,Dense> public: + typedef typename ei_dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type Base; + inline int innerStride() const { return derived().nestedExpression().innerStride() * sizeof(typename ei_traits<MatrixType>::Scalar) / sizeof(Scalar); @@ -112,15 +114,14 @@ class CwiseUnaryViewImpl<ViewOp,MatrixType,Dense> return derived().nestedExpression().outerStride(); } - typedef typename ei_dense_xpr_base<CwiseUnaryView<ViewOp, MatrixType> >::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<typename Derived> 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<typename Derived> class DenseBase } #ifndef EIGEN_PARSED_BY_DOXYGEN - /** \internal the return type of coeff() - */ - typedef typename ei_meta_if<ei_has_direct_access<Derived>::ret, const Scalar&, Scalar>::ret CoeffReturnType; /** \internal Represents a matrix with all coefficients equal to one another*/ typedef CwiseNullaryOp<ei_scalar_constant_op<Scalar>,Derived> ConstantReturnType; @@ -301,48 +304,6 @@ template<typename Derived> class DenseBase Derived& lazyAssign(const DenseBase<OtherDerived>& 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<Derived> operator<< (const Scalar& s); template<unsigned int Added,unsigned int Removed> 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<Scalar>::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<typename Scalar> struct ei_functor_traits<ei_scalar_real_op<Scalar> > @@ -306,13 +305,42 @@ struct ei_scalar_imag_op { EIGEN_EMPTY_STRUCT_CTOR(ei_scalar_imag_op) typedef typename NumTraits<Scalar>::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<typename Scalar> struct ei_functor_traits<ei_scalar_imag_op<Scalar> > { 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<typename Scalar> +struct ei_scalar_real_ref_op { + EIGEN_EMPTY_STRUCT_CTOR(ei_scalar_real_ref_op) + typedef typename NumTraits<Scalar>::Real result_type; + EIGEN_STRONG_INLINE result_type& operator() (const Scalar& a) const { return ei_real_ref(*const_cast<Scalar*>(&a)); } +}; +template<typename Scalar> +struct ei_functor_traits<ei_scalar_real_ref_op<Scalar> > +{ 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<typename Scalar> +struct ei_scalar_imag_ref_op { + EIGEN_EMPTY_STRUCT_CTOR(ei_scalar_imag_ref_op) + typedef typename NumTraits<Scalar>::Real result_type; + EIGEN_STRONG_INLINE result_type& operator() (Scalar& a) const { return ei_imag_ref(*const_cast<Scalar*>(&a)); } +}; +template<typename Scalar> +struct ei_functor_traits<ei_scalar_imag_ref_op<Scalar> > +{ 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<NumTraits<Scalar>::IsComplex, >::ret RealReturnType; /** \internal the return type of real() */ typedef typename ei_meta_if<NumTraits<Scalar>::IsComplex, - CwiseUnaryView<ei_scalar_real_op<Scalar>, Derived>, + CwiseUnaryView<ei_scalar_real_ref_op<Scalar>, Derived>, Derived& >::ret NonConstRealReturnType; /** \internal the return type of imag() const */ typedef CwiseUnaryOp<ei_scalar_imag_op<Scalar>, Derived> ImagReturnType; /** \internal the return type of imag() */ -typedef CwiseUnaryView<ei_scalar_imag_op<Scalar>, Derived> NonConstImagReturnType; +typedef CwiseUnaryView<ei_scalar_imag_ref_op<Scalar>, Derived> NonConstImagReturnType; #endif // not EIGEN_PARSED_BY_DOXYGEN |