diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h index c2c9606a5..917175bfd 100644 --- a/Eigen/src/Core/Block.h +++ b/Eigen/src/Core/Block.h @@ -33,7 +33,10 @@ * \param MatrixType the type of the object in which we are taking a block * \param BlockRows the number of rows of the block we are taking at compile time (optional) * \param BlockCols the number of columns of the block we are taking at compile time (optional) - * \param _PacketAccess + * \param _PacketAccess allows to enforce aligned loads and stores if set to ForceAligned. + * The default is AsRequested. This parameter is internaly used by Eigen + * in expressions such as \code mat.block() += other; \endcode and most of + * the time this is the only way it is used. * \param _DirectAccessStatus \internal used for partial specialization * * This class represents an expression of either a fixed-size or dynamic-size block. It is the return @@ -84,9 +87,9 @@ struct ei_traits&, - Block >::ret AlignedDerivedType; + Block >::ret AlignedDerivedType; }; template class Block @@ -223,12 +226,12 @@ class Block EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Block) - AlignedDerivedType allowAligned() + AlignedDerivedType forceAligned() { - if (PacketAccess==Aligned) + if (PacketAccess==ForceAligned) return *this; else - return Block + return Block (m_matrix, Base::m_data, Base::m_rows.value(), Base::m_cols.value()); } diff --git a/Eigen/src/Core/Map.h b/Eigen/src/Core/Map.h index a1953993f..85fbcc0f0 100644 --- a/Eigen/src/Core/Map.h +++ b/Eigen/src/Core/Map.h @@ -30,8 +30,11 @@ * * \brief A matrix or vector expression mapping an existing array of data. * - * \param _PacketAccess controls whether vectorized aligned loads or stores are allowed (Aligned) - * or forced to unaligned (Unaligned). Defaults to Unaligned. + * \param MatrixType the equivalent matrix type of the mapped data + * \param _PacketAccess allows to enforce aligned loads and stores if set to ForceAligned. + * The default is AsRequested. This parameter is internaly used by Eigen + * in expressions such as \code Map<...>(...) += other; \endcode and most + * of the time this is the only way it is used. * * This class represents a matrix or vector expression mapping an existing array of data. * It can be used to let Eigen interface without any overhead with non-Eigen data structures, @@ -48,9 +51,9 @@ struct ei_traits > : public ei_traits PacketAccess = _PacketAccess, Flags = ei_traits::Flags & ~AlignedBit }; - typedef typename ei_meta_if&, - Map >::ret AlignedDerivedType; + Map >::ret AlignedDerivedType; }; template class Map @@ -63,12 +66,12 @@ template class Map inline int stride() const { return this->innerSize(); } - AlignedDerivedType allowAligned() + AlignedDerivedType forceAligned() { - if (PacketAccess==Aligned) + if (PacketAccess==ForceAligned) return *this; else - return Map(Base::m_data, Base::m_rows.value(), Base::m_cols.value()); + return Map(Base::m_data, Base::m_rows.value(), Base::m_cols.value()); } inline Map(const Scalar* data) : Base(data) {} diff --git a/Eigen/src/Core/MapBase.h b/Eigen/src/Core/MapBase.h index 0b54ca7b8..4c1a0cf2f 100644 --- a/Eigen/src/Core/MapBase.h +++ b/Eigen/src/Core/MapBase.h @@ -26,12 +26,18 @@ #ifndef EIGEN_MAPBASE_H #define EIGEN_MAPBASE_H -/** \internal - * - * \class MapBase +/** \class MapBase * * \brief Base class for Map and Block expression with direct access * + * Expression classes inheriting MapBase must define the constant \c PacketAccess, + * and type \c AlignedDerivedType in their respective ei_traits<> specialization structure. + * The value of \c PacketAccess can be either: + * - \b ForceAligned which enforces both aligned loads and stores + * - \b AsRequested which is the default behavior + * The type \c AlignedDerivedType should correspond to the equivalent expression type + * with \c PacketAccess being \c ForceAligned. + * * \sa class Map, class Block */ template class MapBase @@ -57,7 +63,10 @@ template class MapBase inline int cols() const { return m_cols.value(); } inline int stride() const { return derived().stride(); } - AlignedDerivedType allowAligned() { return derived().allowAligned(); } + + /** \Returns an expression equivalent to \c *this but having the \c PacketAccess constant + * set to \c ForceAligned. Must be reimplemented by the derived class. */ + AlignedDerivedType forceAligned() { return derived().forceAligned(); } inline const Scalar& coeff(int row, int col) const { @@ -92,7 +101,7 @@ template class MapBase template inline PacketScalar packet(int row, int col) const { - return ei_ploadt + return ei_ploadt (m_data + (IsRowMajor ? col + row * stride() : row + col * stride())); } @@ -100,13 +109,13 @@ template class MapBase template inline PacketScalar packet(int index) const { - return ei_ploadt(m_data + index); + return ei_ploadt(m_data + index); } template inline void writePacket(int row, int col, const PacketScalar& x) { - ei_pstoret + ei_pstoret (const_cast(m_data) + (IsRowMajor ? col + row * stride() : row + col * stride()), x); } @@ -114,7 +123,7 @@ template class MapBase template inline void writePacket(int index, const PacketScalar& x) { - ei_pstoret + ei_pstoret (const_cast(m_data) + index, x); } @@ -142,21 +151,19 @@ template class MapBase EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MapBase) -// EIGEN_INHERIT_ASSIGNMENT_OPERATOR(MapBase, =) - template Derived& operator+=(const MatrixBase& other) - { return derived() = allowAligned() + other; } + { return derived() = forceAligned() + other; } template Derived& operator-=(const MatrixBase& other) - { return derived() = allowAligned() - other; } + { return derived() = forceAligned() - other; } Derived& operator*=(const Scalar& other) - { return derived() = allowAligned() * other; } + { return derived() = forceAligned() * other; } Derived& operator/=(const Scalar& other) - { return derived() = allowAligned() / other; } + { return derived() = forceAligned() / other; } protected: const Scalar* __restrict__ m_data; diff --git a/Eigen/src/Core/util/Constants.h b/Eigen/src/Core/util/Constants.h index ea3994544..2885a41fc 100644 --- a/Eigen/src/Core/util/Constants.h +++ b/Eigen/src/Core/util/Constants.h @@ -180,7 +180,8 @@ const unsigned int UnitUpper = UpperTriangularBit | UnitDiagBit; const unsigned int UnitLower = LowerTriangularBit | UnitDiagBit; const unsigned int Diagonal = Upper | Lower; -enum { Aligned=0, Unaligned=1, Unknown=2 }; +enum { Aligned, Unaligned }; +enum { ForceAligned, AsRequested }; enum { ConditionalJumpCost = 5 }; enum CornerType { TopLeft, TopRight, BottomLeft, BottomRight }; enum DirectionType { Vertical, Horizontal }; diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h index 7a1f95443..77c6f297a 100644 --- a/Eigen/src/Core/util/ForwardDeclarations.h +++ b/Eigen/src/Core/util/ForwardDeclarations.h @@ -43,7 +43,7 @@ template clas template class NestByValue; template class SwapWrapper; template class Minor; -template::Flags&DirectAccessBit> class Block; template class Transpose; template class Conjugate; @@ -53,7 +53,7 @@ template class CwiseBinaryOp; template class Product; template class DiagonalMatrix; template class DiagonalCoeffs; -template class Map; +template class Map; template class Part; template class Extract; template class Cwise;