From db6c3d0197144638ced6ff97d2b6f2e8aef61cd4 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 9 Mar 2009 19:23:31 +0000 Subject: [PATCH] fix MapBase's ForceAligned concept which was not working at all.... --- Eigen/src/Core/Block.h | 10 ++++------ Eigen/src/Core/Map.h | 11 ++++------- Eigen/src/Core/MapBase.h | 24 +++++++++++++++++++++++- Eigen/src/Core/util/Macros.h | 6 +++--- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h index cfbf6da53..195533266 100644 --- a/Eigen/src/Core/Block.h +++ b/Eigen/src/Core/Block.h @@ -221,15 +221,13 @@ class Block class InnerIterator; typedef typename ei_traits::AlignedDerivedType AlignedDerivedType; + friend class Block; EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Block) - AlignedDerivedType forceAligned() + AlignedDerivedType _convertToForceAligned() { - if (PacketAccess==ForceAligned) - return *this; - else - return Block + return Block (m_matrix, Base::m_data, Base::m_rows.value(), Base::m_cols.value()); } @@ -454,7 +452,7 @@ MatrixBase::end(int size) const * \only_for_vectors * * 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 * * Example: \include MatrixBase_template_int_segment.cpp diff --git a/Eigen/src/Core/Map.h b/Eigen/src/Core/Map.h index 4c2c455ce..b41870e5d 100644 --- a/Eigen/src/Core/Map.h +++ b/Eigen/src/Core/Map.h @@ -39,7 +39,7 @@ * 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++ * placement new syntax: * @@ -72,12 +72,9 @@ template class Map inline int stride() const { return this->innerSize(); } - AlignedDerivedType forceAligned() + AlignedDerivedType _convertToForceAligned() { - 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) {} @@ -85,7 +82,7 @@ template class Map inline Map(const Scalar* data, int size) : Base(data, size) {} inline Map(const Scalar* data, int rows, int cols) : Base(data, rows, cols) {} - + inline void resize(int rows, int cols) { EIGEN_ONLY_USED_FOR_DEBUG(rows); diff --git a/Eigen/src/Core/MapBase.h b/Eigen/src/Core/MapBase.h index 7014f27f6..d4d99a167 100644 --- a/Eigen/src/Core/MapBase.h +++ b/Eigen/src/Core/MapBase.h @@ -65,9 +65,20 @@ template class MapBase inline int stride() const { return derived().stride(); } inline const Scalar* data() const { return m_data; } + template struct force_aligned_impl { + AlignedDerivedType static run(MapBase& a) { return a.derived(); } + }; + + template struct force_aligned_impl { + 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::run(*this); + } inline const Scalar& coeff(int row, int col) const { @@ -155,6 +166,17 @@ template class MapBase && cols > 0 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols))); } + Derived& operator=(const MapBase& other) + { + return Base::operator=(other); + } + + template + Derived& operator=(const MatrixBase& other) + { + return Base::operator=(other); + } + template Derived& operator+=(const MatrixBase& other) { return derived() = forceAligned() + other; } diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h index fad9a016e..de4dd06b9 100644 --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -204,18 +204,18 @@ using Eigen::ei_cos; template \ EIGEN_STRONG_INLINE Derived& operator Op(const Eigen::MatrixBase& other) \ { \ - return Eigen::MatrixBase::operator Op(other.derived()); \ + return Base::operator Op(other.derived()); \ } \ EIGEN_STRONG_INLINE Derived& operator Op(const Derived& other) \ { \ - return Eigen::MatrixBase::operator Op(other); \ + return Base::operator Op(other); \ } #define EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, Op) \ template \ EIGEN_STRONG_INLINE Derived& operator Op(const Other& scalar) \ { \ - return Eigen::MatrixBase::operator Op(scalar); \ + return Base::operator Op(scalar); \ } #define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived) \