* extend Map to allow the user to specify whether the mapped data

is aligned or not. This is done using the Aligned constant:
  Map<MatrixType,Aligned>::Map(data);
* rename ForceAligned to EnforceAlignedAccess, and update its doc,
  and emphasize this is mainly an internal stuff.
This commit is contained in:
Gael Guennebaud
2009-10-23 14:26:14 +02:00
parent 83a7b7c44c
commit a382963b04
6 changed files with 63 additions and 43 deletions

View File

@@ -31,16 +31,14 @@
* \brief A matrix or vector expression mapping an existing array of data.
*
* \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.
* \param PointerAlignment specifies whether the pointer is \c Aligned, or \c Unaligned.
* The default is \c Unaligned.
*
* 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,
* such as plain C arrays or structures from other libraries.
*
* \b Tips: to change the array of data mapped by a Map object, you can use the C++
* \b Tip: to change the array of data mapped by a Map object, you can use the C++
* placement new syntax:
*
* Example: \include Map_placement_new.cpp
@@ -48,22 +46,27 @@
*
* This class is the return type of Matrix::Map() but can also be used directly.
*
* \b Note \b to \b Eigen \b developers: The template parameter \c PointerAlignment
* can also be or-ed with \c EnforceAlignedAccess in order to enforce aligned read
* in expressions such as \code A += B; \endcode. See class MapBase for further details.
*
* \sa Matrix::Map()
*/
template<typename MatrixType, int _PacketAccess>
struct ei_traits<Map<MatrixType, _PacketAccess> > : public ei_traits<MatrixType>
template<typename MatrixType, int Options>
struct ei_traits<Map<MatrixType, Options> > : public ei_traits<MatrixType>
{
enum {
PacketAccess = _PacketAccess,
Flags = ei_traits<MatrixType>::Flags & ~AlignedBit
PacketAccess = Options & EnforceAlignedAccess,
Flags = (Options&Aligned)==Aligned ? ei_traits<MatrixType>::Flags | AlignedBit
: ei_traits<MatrixType>::Flags & ~AlignedBit
};
typedef typename ei_meta_if<int(PacketAccess)==ForceAligned,
Map<MatrixType, _PacketAccess>&,
Map<MatrixType, ForceAligned> >::ret AlignedDerivedType;
typedef typename ei_meta_if<int(PacketAccess)==EnforceAlignedAccess,
Map<MatrixType, Options>&,
Map<MatrixType, Options|EnforceAlignedAccess> >::ret AlignedDerivedType;
};
template<typename MatrixType, int PacketAccess> class Map
: public MapBase<Map<MatrixType, PacketAccess> >
template<typename MatrixType, int Options> class Map
: public MapBase<Map<MatrixType, Options> >
{
public:
@@ -72,9 +75,9 @@ template<typename MatrixType, int PacketAccess> class Map
inline int stride() const { return this->innerSize(); }
AlignedDerivedType _convertToForceAligned()
AlignedDerivedType _convertToEnforceAlignedAccess()
{
return Map<MatrixType,ForceAligned>(Base::m_data, Base::m_rows.value(), Base::m_cols.value());
return AlignedDerivedType(Base::m_data, Base::m_rows.value(), Base::m_cols.value());
}
inline Map(const Scalar* data) : Base(data) {}