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,14 +221,12 @@ class Block<MatrixType,BlockRows,BlockCols,PacketAccess,HasDirectAccess>
class InnerIterator;
typedef typename ei_traits<Block>::AlignedDerivedType AlignedDerivedType;
friend class Block<MatrixType,BlockRows,BlockCols,AsRequested,HasDirectAccess>;
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Block)
AlignedDerivedType forceAligned()
AlignedDerivedType _convertToForceAligned()
{
if (PacketAccess==ForceAligned)
return *this;
else
return Block<MatrixType,BlockRows,BlockCols,ForceAligned,HasDirectAccess>
(m_matrix, Base::m_data, Base::m_rows.value(), Base::m_cols.value());
}

View File

@ -72,11 +72,8 @@ template<typename MatrixType, int PacketAccess> class Map
inline int stride() const { return this->innerSize(); }
AlignedDerivedType forceAligned()
AlignedDerivedType _convertToForceAligned()
{
if (PacketAccess==ForceAligned)
return *this;
else
return Map<MatrixType,ForceAligned>(Base::m_data, Base::m_rows.value(), Base::m_cols.value());
}

View File

@ -65,9 +65,20 @@ template<typename Derived> class MapBase
inline int stride() const { return derived().stride(); }
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
* 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
{
@ -155,6 +166,17 @@ template<typename Derived> class MapBase
&& 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>
Derived& operator+=(const MatrixBase<OtherDerived>& other)
{ return derived() = forceAligned() + other; }

View File

@ -204,18 +204,18 @@ using Eigen::ei_cos;
template<typename OtherDerived> \
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) \
{ \
return Eigen::MatrixBase<Derived>::operator Op(other); \
return Base::operator Op(other); \
}
#define EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, Op) \
template<typename Other> \
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) \