fix MapBase's ForceAligned concept which was not working at all....

This commit is contained in:
Gael Guennebaud 2009-03-09 19:23:31 +00:00
parent 3f80c68be5
commit db6c3d0197
4 changed files with 34 additions and 17 deletions

View File

@ -221,15 +221,13 @@ class Block<MatrixType,BlockRows,BlockCols,PacketAccess,HasDirectAccess>
class InnerIterator; class InnerIterator;
typedef typename ei_traits<Block>::AlignedDerivedType AlignedDerivedType; typedef typename ei_traits<Block>::AlignedDerivedType AlignedDerivedType;
friend class Block<MatrixType,BlockRows,BlockCols,AsRequested,HasDirectAccess>;
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Block) EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Block)
AlignedDerivedType forceAligned() AlignedDerivedType _convertToForceAligned()
{ {
if (PacketAccess==ForceAligned) return Block<MatrixType,BlockRows,BlockCols,ForceAligned,HasDirectAccess>
return *this;
else
return Block<MatrixType,BlockRows,BlockCols,ForceAligned,HasDirectAccess>
(m_matrix, Base::m_data, Base::m_rows.value(), Base::m_cols.value()); (m_matrix, Base::m_data, Base::m_rows.value(), Base::m_cols.value());
} }
@ -454,7 +452,7 @@ MatrixBase<Derived>::end(int size) const
* \only_for_vectors * \only_for_vectors
* *
* The template parameter \a Size is the number of coefficients in the block * The template parameter \a Size is the number of coefficients in the block
* *
* \param start the index of the first element of the sub-vector * \param start the index of the first element of the sub-vector
* *
* Example: \include MatrixBase_template_int_segment.cpp * Example: \include MatrixBase_template_int_segment.cpp

View File

@ -39,7 +39,7 @@
* This class represents a matrix or vector expression mapping an existing array of data. * 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, * 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. * 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 Tips: to change the array of data mapped by a Map object, you can use the C++
* placement new syntax: * placement new syntax:
* *
@ -72,12 +72,9 @@ template<typename MatrixType, int PacketAccess> class Map
inline int stride() const { return this->innerSize(); } inline int stride() const { return this->innerSize(); }
AlignedDerivedType forceAligned() AlignedDerivedType _convertToForceAligned()
{ {
if (PacketAccess==ForceAligned) return Map<MatrixType,ForceAligned>(Base::m_data, Base::m_rows.value(), Base::m_cols.value());
return *this;
else
return Map<MatrixType,ForceAligned>(Base::m_data, Base::m_rows.value(), Base::m_cols.value());
} }
inline Map(const Scalar* data) : Base(data) {} inline Map(const Scalar* data) : Base(data) {}
@ -85,7 +82,7 @@ template<typename MatrixType, int PacketAccess> class Map
inline Map(const Scalar* data, int size) : Base(data, size) {} inline Map(const Scalar* data, int size) : Base(data, size) {}
inline Map(const Scalar* data, int rows, int cols) : Base(data, rows, cols) {} inline Map(const Scalar* data, int rows, int cols) : Base(data, rows, cols) {}
inline void resize(int rows, int cols) inline void resize(int rows, int cols)
{ {
EIGEN_ONLY_USED_FOR_DEBUG(rows); EIGEN_ONLY_USED_FOR_DEBUG(rows);

View File

@ -65,9 +65,20 @@ template<typename Derived> class MapBase
inline int stride() const { return derived().stride(); } inline int stride() const { return derived().stride(); }
inline const Scalar* data() const { return m_data; } inline const Scalar* data() const { return m_data; }
template<bool IsForceAligned,typename Dummy> struct force_aligned_impl {
AlignedDerivedType static run(MapBase& a) { return a.derived(); }
};
template<typename Dummy> struct force_aligned_impl<false,Dummy> {
AlignedDerivedType static run(MapBase& a) { return a.derived()._convertToForceAligned(); }
};
/** \returns an expression equivalent to \c *this but having the \c PacketAccess constant /** \returns an expression equivalent to \c *this but having the \c PacketAccess constant
* set to \c ForceAligned. Must be reimplemented by the derived class. */ * set to \c ForceAligned. Must be reimplemented by the derived class. */
AlignedDerivedType forceAligned() { return derived().forceAligned(); } AlignedDerivedType forceAligned()
{
return force_aligned_impl<int(PacketAccess)==int(ForceAligned),Derived>::run(*this);
}
inline const Scalar& coeff(int row, int col) const inline const Scalar& coeff(int row, int col) const
{ {
@ -155,6 +166,17 @@ template<typename Derived> class MapBase
&& cols > 0 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols))); && cols > 0 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols)));
} }
Derived& operator=(const MapBase& other)
{
return Base::operator=(other);
}
template<typename OtherDerived>
Derived& operator=(const MatrixBase<OtherDerived>& other)
{
return Base::operator=(other);
}
template<typename OtherDerived> template<typename OtherDerived>
Derived& operator+=(const MatrixBase<OtherDerived>& other) Derived& operator+=(const MatrixBase<OtherDerived>& other)
{ return derived() = forceAligned() + other; } { return derived() = forceAligned() + other; }

View File

@ -204,18 +204,18 @@ using Eigen::ei_cos;
template<typename OtherDerived> \ template<typename OtherDerived> \
EIGEN_STRONG_INLINE Derived& operator Op(const Eigen::MatrixBase<OtherDerived>& other) \ EIGEN_STRONG_INLINE Derived& operator Op(const Eigen::MatrixBase<OtherDerived>& other) \
{ \ { \
return Eigen::MatrixBase<Derived>::operator Op(other.derived()); \ return Base::operator Op(other.derived()); \
} \ } \
EIGEN_STRONG_INLINE Derived& operator Op(const Derived& other) \ EIGEN_STRONG_INLINE Derived& operator Op(const Derived& other) \
{ \ { \
return Eigen::MatrixBase<Derived>::operator Op(other); \ return Base::operator Op(other); \
} }
#define EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, Op) \ #define EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, Op) \
template<typename Other> \ template<typename Other> \
EIGEN_STRONG_INLINE Derived& operator Op(const Other& scalar) \ EIGEN_STRONG_INLINE Derived& operator Op(const Other& scalar) \
{ \ { \
return Eigen::MatrixBase<Derived>::operator Op(scalar); \ return Base::operator Op(scalar); \
} }
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived) \ #define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived) \