aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2010-02-26 20:12:51 -0500
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2010-02-26 20:12:51 -0500
commitb1f666d007ee4dc22f48dd65f900ee3659dd1f7d (patch)
tree29c6de6cb4b2bf92a9f54b1f67c7ef5aa2773b24 /Eigen/src
parent32115bff1e2b99641e09e0fe182d2d5cc11413ec (diff)
Fix Map-with-Stride and cover it by new unit tests.
Diffstat (limited to 'Eigen/src')
-rw-r--r--Eigen/src/Core/DenseStorageBase.h3
-rw-r--r--Eigen/src/Core/Map.h35
-rw-r--r--Eigen/src/Core/Stride.h30
-rw-r--r--Eigen/src/Core/util/Constants.h10
-rw-r--r--Eigen/src/Core/util/ForwardDeclarations.h2
5 files changed, 39 insertions, 41 deletions
diff --git a/Eigen/src/Core/DenseStorageBase.h b/Eigen/src/Core/DenseStorageBase.h
index 89e6e7112..12ffd2e43 100644
--- a/Eigen/src/Core/DenseStorageBase.h
+++ b/Eigen/src/Core/DenseStorageBase.h
@@ -362,6 +362,9 @@ class DenseStorageBase : public _Base<Derived>
* while the AlignedMap() functions return aligned Map objects and thus should be called only with 16-byte-aligned
* \a data pointers.
*
+ * These methods do not allow to specify strides. If you need to specify strides, you have to
+ * use the Map class directly.
+ *
* \see class Map
*/
//@{
diff --git a/Eigen/src/Core/Map.h b/Eigen/src/Core/Map.h
index d9ccb1b20..f8b70b866 100644
--- a/Eigen/src/Core/Map.h
+++ b/Eigen/src/Core/Map.h
@@ -52,11 +52,23 @@ template<typename MatrixType, int Options, typename StrideType>
struct ei_traits<Map<MatrixType, Options, StrideType> >
: public ei_traits<MatrixType>
{
+ typedef typename MatrixType::Scalar Scalar;
enum {
+ InnerStride = StrideType::InnerStrideAtCompileTime,
+ OuterStride = StrideType::OuterStrideAtCompileTime,
+ HasNoInnerStride = InnerStride <= 1,
+ HasNoOuterStride = OuterStride == 0,
+ HasNoStride = HasNoInnerStride && HasNoOuterStride,
+ IsAligned = int(int(Options)&Aligned)==Aligned,
+ IsDynamicSize = MatrixType::SizeAtCompileTime==Dynamic,
+ KeepsPacketAccess = bool(HasNoInnerStride)
+ && ( bool(IsDynamicSize)
+ || HasNoOuterStride
+ || ( OuterStride!=Dynamic && ((int(OuterStride)*sizeof(Scalar))%16)==0 ) ),
Flags0 = ei_traits<MatrixType>::Flags,
- Flags1 = ((Options&Aligned)==Aligned ? Flags0 | AlignedBit
- : Flags0 & ~AlignedBit),
- Flags = int(StrideType::InnerStrideAtCompileTime)==1 ? Flags1 : (Flags1 & ~PacketAccessBit)
+ Flags1 = IsAligned ? int(Flags0) | AlignedBit : int(Flags0) & ~AlignedBit,
+ Flags2 = HasNoStride ? int(Flags1) : int(Flags1 & ~LinearAccessBit),
+ Flags = KeepsPacketAccess ? int(Flags2) : (int(Flags2) & ~PacketAccessBit)
};
};
@@ -94,23 +106,6 @@ template<typename MatrixType, int Options, typename StrideType> class Map
inline Map(const Scalar* data, int rows, int cols, const StrideType& stride = StrideType())
: Base(data, rows, cols), m_stride(stride) {}
-/*
- inline void resize(int rows, int cols)
- {
- EIGEN_ONLY_USED_FOR_DEBUG(rows);
- EIGEN_ONLY_USED_FOR_DEBUG(cols);
- ei_assert(rows == this->rows());
- ei_assert(cols == this->cols());
- }
-
- inline void resize(int size)
- {
- EIGEN_STATIC_ASSERT_VECTOR_ONLY(MatrixType)
- EIGEN_ONLY_USED_FOR_DEBUG(size);
- ei_assert(size == this->size());
- }
-*/
-
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Map)
protected:
diff --git a/Eigen/src/Core/Stride.h b/Eigen/src/Core/Stride.h
index 7982035fd..f04039e7d 100644
--- a/Eigen/src/Core/Stride.h
+++ b/Eigen/src/Core/Stride.h
@@ -25,7 +25,7 @@
#ifndef EIGEN_STRIDE_H
#define EIGEN_STRIDE_H
-template<int _InnerStrideAtCompileTime, int _OuterStrideAtCompileTime>
+template<int _OuterStrideAtCompileTime, int _InnerStrideAtCompileTime>
class Stride
{
public:
@@ -36,45 +36,45 @@ class Stride
};
Stride()
- : m_inner(InnerStrideAtCompileTime), m_outer(OuterStrideAtCompileTime)
+ : m_outer(OuterStrideAtCompileTime), m_inner(InnerStrideAtCompileTime)
{
ei_assert(InnerStrideAtCompileTime != Dynamic && OuterStrideAtCompileTime != Dynamic);
}
- Stride(int innerStride, int outerStride)
- : m_inner(innerStride), m_outer(outerStride)
+ Stride(int outerStride, int innerStride)
+ : m_outer(outerStride), m_inner(innerStride)
{
ei_assert(innerStride>=0 && outerStride>=0);
}
Stride(const Stride& other)
- : m_inner(other.inner()), m_outer(other.outer())
+ : m_outer(other.outer()), m_inner(other.inner())
{}
- inline int inner() const { return m_inner.value(); }
inline int outer() const { return m_outer.value(); }
+ inline int inner() const { return m_inner.value(); }
protected:
- ei_int_if_dynamic<InnerStrideAtCompileTime> m_inner;
ei_int_if_dynamic<OuterStrideAtCompileTime> m_outer;
+ ei_int_if_dynamic<InnerStrideAtCompileTime> m_inner;
};
-template<int Value = Dynamic>
-class InnerStride : public Stride<Value, 0>
+template<int Value>
+class InnerStride : public Stride<0, Value>
{
- typedef Stride<Value,0> Base;
+ typedef Stride<0, Value> Base;
public:
InnerStride() : Base() {}
- InnerStride(int v) : Base(v,0) {}
+ InnerStride(int v) : Base(0, v) {}
};
-template<int Value = Dynamic>
-class OuterStride : public Stride<0, Value>
+template<int Value>
+class OuterStride : public Stride<Value, 0>
{
- typedef Stride<0,Value> Base;
+ typedef Stride<Value, 0> Base;
public:
OuterStride() : Base() {}
- OuterStride(int v) : Base(0,v) {}
+ OuterStride(int v) : Base(v,0) {}
};
#endif // EIGEN_STRIDE_H
diff --git a/Eigen/src/Core/util/Constants.h b/Eigen/src/Core/util/Constants.h
index c27c979a6..c167df697 100644
--- a/Eigen/src/Core/util/Constants.h
+++ b/Eigen/src/Core/util/Constants.h
@@ -86,11 +86,11 @@ const unsigned int EvalBeforeAssigningBit = 0x4;
* Long version: means that the coefficients can be handled by packets
* and start at a memory location whose alignment meets the requirements
* of the present CPU architecture for optimized packet access. In the fixed-size
- * case, there is the additional condition that the total size of the coefficients
- * array is a multiple of the packet size, so that it is possible to access all the
- * coefficients by packets. In the dynamic-size case, there is no such condition
- * on the total size, so it might not be possible to access the few last coeffs
- * by packets.
+ * case, there is the additional condition that it be possible to access all the
+ * coefficients by packets (this implies the requirement that the size be a multiple of 16 bytes,
+ * and that any nontrivial strides don't break the alignment). In the dynamic-size case,
+ * there is no such condition on the total size and strides, so it might not be possible to access
+ * all coeffs by packets.
*
* \note This bit can be set regardless of whether vectorization is actually enabled.
* To check for actual vectorizability, see \a ActualPacketAccessBit.
diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h
index 6096272fa..8451d0ebe 100644
--- a/Eigen/src/Core/util/ForwardDeclarations.h
+++ b/Eigen/src/Core/util/ForwardDeclarations.h
@@ -61,7 +61,7 @@ template<typename _Scalar, int SizeAtCompileTime, int MaxSizeAtCompileTime=SizeA
template<typename MatrixType, typename DiagonalType, int ProductOrder> class DiagonalProduct;
template<typename MatrixType, int Index> class Diagonal;
-template<int InnerStrideAtCompileTime = Dynamic, int OuterStrideAtCompileTime = Dynamic> class Stride;
+template<int InnerStrideAtCompileTime, int OuterStrideAtCompileTime> class Stride;
template<typename MatrixType, int Options=Unaligned, typename StrideType = Stride<0,0> > class Map;
template<typename Derived> class TriangularBase;