aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Jitse Niesen <jitse@maths.leeds.ac.uk>2011-04-05 18:15:59 +0100
committerGravatar Jitse Niesen <jitse@maths.leeds.ac.uk>2011-04-05 18:15:59 +0100
commitcca7b146a2018a74aa5f83edc0797fab89b1040e (patch)
treebefd747f5994e5e408fa211f1da5038106ce0597
parenta6b5314c205a2a6257d756c1a529dfb4d56817f0 (diff)
Implement evaluator for Map
-rw-r--r--Eigen/src/Core/CoreEvaluators.h116
-rw-r--r--test/evaluators.cpp12
2 files changed, 81 insertions, 47 deletions
diff --git a/Eigen/src/Core/CoreEvaluators.h b/Eigen/src/Core/CoreEvaluators.h
index 6fe7177c6..3060ca982 100644
--- a/Eigen/src/Core/CoreEvaluators.h
+++ b/Eigen/src/Core/CoreEvaluators.h
@@ -334,32 +334,32 @@ protected:
PlainObject m_result;
};
-// -------------------- Block --------------------
+// -------------------- Map --------------------
-template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel>
-struct evaluator_impl<Block<XprType, BlockRows, BlockCols, InnerPanel, /* HasDirectAccess */ false> >
+template<typename Derived, int AccessorsType>
+struct evaluator_impl<MapBase<Derived, AccessorsType> >
{
- typedef Block<XprType, BlockRows, BlockCols, InnerPanel, false> BlockType;
-
- evaluator_impl(const BlockType& block)
- : m_argImpl(block.nestedExpression()),
- m_startRow(block.startRow()),
- m_startCol(block.startCol())
+ typedef MapBase<Derived, AccessorsType> MapType;
+ typedef typename MapType::PointerType PointerType;
+ typedef typename MapType::Index Index;
+ typedef typename MapType::Scalar Scalar;
+ typedef typename MapType::CoeffReturnType CoeffReturnType;
+ typedef typename MapType::PacketScalar PacketScalar;
+ typedef typename MapType::PacketReturnType PacketReturnType;
+
+ evaluator_impl(const MapType& map)
+ : m_data(const_cast<PointerType>(map.data())),
+ m_rowStride(map.rowStride()),
+ m_colStride(map.colStride())
{ }
- typedef typename BlockType::Index Index;
- typedef typename BlockType::Scalar Scalar;
- typedef typename BlockType::CoeffReturnType CoeffReturnType;
- typedef typename BlockType::PacketScalar PacketScalar;
- typedef typename BlockType::PacketReturnType PacketReturnType;
-
enum {
- RowsAtCompileTime = BlockType::RowsAtCompileTime
+ RowsAtCompileTime = MapType::RowsAtCompileTime
};
CoeffReturnType coeff(Index row, Index col) const
{
- return m_argImpl.coeff(m_startRow + row, m_startCol + col);
+ return m_data[col * m_colStride + row * m_rowStride];
}
CoeffReturnType coeff(Index index) const
@@ -370,7 +370,7 @@ struct evaluator_impl<Block<XprType, BlockRows, BlockCols, InnerPanel, /* HasDir
Scalar& coeffRef(Index row, Index col)
{
- return m_argImpl.coeffRef(m_startRow + row, m_startCol + col);
+ return m_data[col * m_colStride + row * m_rowStride];
}
Scalar& coeffRef(Index index)
@@ -382,7 +382,8 @@ struct evaluator_impl<Block<XprType, BlockRows, BlockCols, InnerPanel, /* HasDir
template<int LoadMode>
PacketReturnType packet(Index row, Index col) const
{
- return m_argImpl.template packet<LoadMode>(m_startRow + row, m_startCol + col);
+ PointerType ptr = m_data + row * m_rowStride + col * m_colStride;
+ return internal::ploadt<PacketScalar, LoadMode>(ptr);
}
template<int LoadMode>
@@ -395,7 +396,8 @@ struct evaluator_impl<Block<XprType, BlockRows, BlockCols, InnerPanel, /* HasDir
template<int StoreMode>
void writePacket(Index row, Index col, const PacketScalar& x)
{
- return m_argImpl.template writePacket<StoreMode>(m_startRow + row, m_startCol + col, x);
+ PointerType ptr = m_data + row * m_rowStride + col * m_colStride;
+ return internal::pstoret<Scalar, PacketScalar, StoreMode>(ptr, x);
}
template<int StoreMode>
@@ -407,41 +409,48 @@ struct evaluator_impl<Block<XprType, BlockRows, BlockCols, InnerPanel, /* HasDir
}
protected:
- typename evaluator<XprType>::type m_argImpl;
+ PointerType m_data;
+ int m_rowStride;
+ int m_colStride;
+};
- // TODO: Get rid of m_startRow, m_startCol if known at compile time
- Index m_startRow;
- Index m_startCol;
+template<typename PlainObjectType, int MapOptions, typename StrideType>
+struct evaluator_impl<Map<PlainObjectType, MapOptions, StrideType> >
+ : public evaluator_impl<MapBase<Map<PlainObjectType, MapOptions, StrideType> > >
+{
+ typedef Map<PlainObjectType, MapOptions, StrideType> MapType;
+
+ evaluator_impl(const MapType& map)
+ : evaluator_impl<MapBase<MapType> >(map)
+ { }
};
-// TODO: This evaluator does not actually use the child evaluator;
-// all action is via the data() as returned by the Block expression.
+// -------------------- Block --------------------
template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel>
-struct evaluator_impl<Block<XprType, BlockRows, BlockCols, InnerPanel, /* HasDirectAccess */ true> >
+struct evaluator_impl<Block<XprType, BlockRows, BlockCols, InnerPanel, /* HasDirectAccess */ false> >
{
- typedef Block<XprType, BlockRows, BlockCols, InnerPanel, true> BlockType;
- typedef typename BlockType::PointerType PointerType;
+ typedef Block<XprType, BlockRows, BlockCols, InnerPanel, false> BlockType;
+
+ evaluator_impl(const BlockType& block)
+ : m_argImpl(block.nestedExpression()),
+ m_startRow(block.startRow()),
+ m_startCol(block.startCol())
+ { }
+
typedef typename BlockType::Index Index;
typedef typename BlockType::Scalar Scalar;
typedef typename BlockType::CoeffReturnType CoeffReturnType;
typedef typename BlockType::PacketScalar PacketScalar;
typedef typename BlockType::PacketReturnType PacketReturnType;
-
- evaluator_impl(const BlockType& block)
- : m_argImpl(block.nestedExpression()),
- m_data(const_cast<PointerType>(block.data())),
- m_rowStride(block.rowStride()),
- m_colStride(block.colStride())
- { }
-
+
enum {
RowsAtCompileTime = BlockType::RowsAtCompileTime
};
CoeffReturnType coeff(Index row, Index col) const
{
- return m_data[col * m_colStride + row * m_rowStride];
+ return m_argImpl.coeff(m_startRow + row, m_startCol + col);
}
CoeffReturnType coeff(Index index) const
@@ -452,7 +461,7 @@ struct evaluator_impl<Block<XprType, BlockRows, BlockCols, InnerPanel, /* HasDir
Scalar& coeffRef(Index row, Index col)
{
- return m_data[col * m_colStride + row * m_rowStride];
+ return m_argImpl.coeffRef(m_startRow + row, m_startCol + col);
}
Scalar& coeffRef(Index index)
@@ -464,8 +473,7 @@ struct evaluator_impl<Block<XprType, BlockRows, BlockCols, InnerPanel, /* HasDir
template<int LoadMode>
PacketReturnType packet(Index row, Index col) const
{
- PointerType ptr = m_data + row * m_rowStride + col * m_colStride;
- return internal::ploadt<PacketScalar, LoadMode>(ptr);
+ return m_argImpl.template packet<LoadMode>(m_startRow + row, m_startCol + col);
}
template<int LoadMode>
@@ -478,8 +486,7 @@ struct evaluator_impl<Block<XprType, BlockRows, BlockCols, InnerPanel, /* HasDir
template<int StoreMode>
void writePacket(Index row, Index col, const PacketScalar& x)
{
- PointerType ptr = m_data + row * m_rowStride + col * m_colStride;
- return internal::pstoret<Scalar, PacketScalar, StoreMode>(ptr, x);
+ return m_argImpl.template writePacket<StoreMode>(m_startRow + row, m_startCol + col, x);
}
template<int StoreMode>
@@ -491,10 +498,25 @@ struct evaluator_impl<Block<XprType, BlockRows, BlockCols, InnerPanel, /* HasDir
}
protected:
- typename evaluator<XprType>::type m_argImpl;
- PointerType m_data;
- int m_rowStride;
- int m_colStride;
+ typename evaluator<XprType>::type m_argImpl;
+
+ // TODO: Get rid of m_startRow, m_startCol if known at compile time
+ Index m_startRow;
+ Index m_startCol;
+};
+
+// TODO: This evaluator does not actually use the child evaluator;
+// all action is via the data() as returned by the Block expression.
+
+template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel>
+struct evaluator_impl<Block<XprType, BlockRows, BlockCols, InnerPanel, /* HasDirectAccess */ true> >
+ : evaluator_impl<MapBase<Block<XprType, BlockRows, BlockCols, InnerPanel, true> > >
+{
+ typedef Block<XprType, BlockRows, BlockCols, InnerPanel, true> BlockType;
+
+ evaluator_impl(const BlockType& block)
+ : evaluator_impl<MapBase<BlockType> >(block)
+ { }
};
diff --git a/test/evaluators.cpp b/test/evaluators.cpp
index e3fe53215..b2bc42840 100644
--- a/test/evaluators.cpp
+++ b/test/evaluators.cpp
@@ -142,4 +142,16 @@ void test_evaluators()
copy_using_evaluator(mX.block(4, 4, 9, 12), mXsrc);
mXref.block(4, 4, 9, 12) = mXsrc;
VERIFY_IS_APPROX(mX, mXref);
+
+ // Testing Map
+ const float raw[3] = {1,2,3};
+ float buffer[3] = {0,0,0};
+ Vector3f v3;
+ Array3f a3f;
+ VERIFY_IS_APPROX_EVALUATOR(v3, Map<const Vector3f>(raw));
+ VERIFY_IS_APPROX_EVALUATOR(a3f, Map<const Array3f>(raw));
+ Vector3f::Map(buffer) = 2*v3;
+ VERIFY(buffer[0] == 2);
+ VERIFY(buffer[1] == 4);
+ VERIFY(buffer[2] == 6);
}