From fb6e32a62fe288aa7236394fc16eb57f3fc40335 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 29 Nov 2013 16:45:47 +0100 Subject: [PATCH] Get rid of evalautor_impl --- Eigen/src/Core/CoreEvaluators.h | 181 +++++++++++++++-------------- Eigen/src/Core/ProductEvaluators.h | 13 ++- 2 files changed, 102 insertions(+), 92 deletions(-) diff --git a/Eigen/src/Core/CoreEvaluators.h b/Eigen/src/Core/CoreEvaluators.h index c998c37cb..c63ff8acd 100644 --- a/Eigen/src/Core/CoreEvaluators.h +++ b/Eigen/src/Core/CoreEvaluators.h @@ -17,33 +17,33 @@ namespace Eigen { namespace internal { -// evaluator_traits contains traits for evaluator_impl +template struct evaluator; -template -struct evaluator_traits +// evaluator_traits contains traits for evaluator + + template +struct evaluator_traits_base { + // TODO check whether these two indirections are really needed. + // Basically, if nobody overwrite type and nestedType, then, they can be dropped + typedef evaluator type; + typedef evaluator nestedType; + // 1 if assignment A = B assumes aliasing when B is of type T and thus B needs to be evaluated into a // temporary; 0 if not. static const int AssumeAliasing = 0; }; +template +struct evaluator_traits : public evaluator_traits_base +{ +}; + // expression class for evaluating nested expression to a temporary template class EvalToTemp; -// evaluator::type is type of evaluator for T - -template -struct evaluator_impl -{ }; - -template -struct evaluator -{ - typedef evaluator_impl type; - typedef evaluator_impl nestedType; -}; // TODO: Think about const-correctness @@ -56,26 +56,24 @@ struct evaluator // TODO this class does not seem to be necessary anymore template -struct evaluator_impl_base +struct evaluator_base { + typedef typename evaluator_traits::type type; + typedef typename evaluator_traits::nestedType nestedType; + typedef typename ExpressionType::Index Index; // TODO that's not very nice to have to propagate all these traits. They are currently only needed to handle outer,inner indices. typedef traits ExpressionTraits; - - evaluator_impl& derived() - { - return *static_cast*>(this); - } }; // -------------------- Matrix and Array -------------------- // -// evaluator_impl is a common base class for the +// evaluator is a common base class for the // Matrix and Array evaluators. template -struct evaluator_impl > - : evaluator_impl_base +struct evaluator > + : evaluator_base { typedef PlainObjectBase PlainObjectType; @@ -86,14 +84,14 @@ struct evaluator_impl > ColsAtCompileTime = PlainObjectType::ColsAtCompileTime }; - evaluator_impl() + evaluator() : m_data(0), m_outerStride(IsVectorAtCompileTime ? 0 : int(IsRowMajor) ? ColsAtCompileTime : RowsAtCompileTime) {} - evaluator_impl(const PlainObjectType& m) + evaluator(const PlainObjectType& m) : m_data(m.data()), m_outerStride(IsVectorAtCompileTime ? 0 : m.outerStride()) { } @@ -171,28 +169,28 @@ protected: }; template -struct evaluator_impl > - : evaluator_impl > > +struct evaluator > + : evaluator > > { typedef Matrix XprType; - evaluator_impl() {} + evaluator() {} - evaluator_impl(const XprType& m) - : evaluator_impl >(m) + evaluator(const XprType& m) + : evaluator >(m) { } }; template -struct evaluator_impl > - : evaluator_impl > > +struct evaluator > + : evaluator > > { typedef Array XprType; - evaluator_impl() {} + evaluator() {} - evaluator_impl(const XprType& m) - : evaluator_impl >(m) + evaluator(const XprType& m) + : evaluator >(m) { } }; @@ -236,14 +234,17 @@ class EvalToTemp }; template -struct evaluator_impl > +struct evaluator > : public evaluator::type { typedef EvalToTemp XprType; typedef typename ArgType::PlainObject PlainObject; typedef typename evaluator::type Base; + + typedef evaluator type; + typedef evaluator nestedType; - evaluator_impl(const XprType& xpr) + evaluator(const XprType& xpr) : m_result(xpr.rows(), xpr.cols()) { ::new (static_cast(this)) Base(m_result); @@ -252,7 +253,7 @@ struct evaluator_impl > } // This constructor is used when nesting an EvalTo evaluator in another evaluator - evaluator_impl(const ArgType& arg) + evaluator(const ArgType& arg) : m_result(arg.rows(), arg.cols()) { ::new (static_cast(this)) Base(m_result); @@ -267,12 +268,12 @@ protected: // -------------------- Transpose -------------------- template -struct evaluator_impl > - : evaluator_impl_base > +struct evaluator > + : evaluator_base > { typedef Transpose XprType; - evaluator_impl(const XprType& t) : m_argImpl(t.nestedExpression()) {} + evaluator(const XprType& t) : m_argImpl(t.nestedExpression()) {} typedef typename XprType::Index Index; typedef typename XprType::Scalar Scalar; @@ -331,11 +332,12 @@ protected: // -------------------- CwiseNullaryOp -------------------- template -struct evaluator_impl > +struct evaluator > + : evaluator_base > { typedef CwiseNullaryOp XprType; - evaluator_impl(const XprType& n) + evaluator(const XprType& n) : m_functor(n.functor()) { } @@ -372,11 +374,12 @@ protected: // -------------------- CwiseUnaryOp -------------------- template -struct evaluator_impl > +struct evaluator > + : evaluator_base > { typedef CwiseUnaryOp XprType; - evaluator_impl(const XprType& op) + evaluator(const XprType& op) : m_functor(op.functor()), m_argImpl(op.nestedExpression()) { } @@ -415,11 +418,12 @@ protected: // -------------------- CwiseBinaryOp -------------------- template -struct evaluator_impl > +struct evaluator > + : evaluator_base > { typedef CwiseBinaryOp XprType; - evaluator_impl(const XprType& xpr) + evaluator(const XprType& xpr) : m_functor(xpr.functor()), m_lhsImpl(xpr.lhs()), m_rhsImpl(xpr.rhs()) @@ -462,12 +466,12 @@ protected: // -------------------- CwiseUnaryView -------------------- template -struct evaluator_impl > - : evaluator_impl_base > +struct evaluator > + : evaluator_base > { typedef CwiseUnaryView XprType; - evaluator_impl(const XprType& op) + evaluator(const XprType& op) : m_unaryOp(op.functor()), m_argImpl(op.nestedExpression()) { } @@ -504,8 +508,8 @@ protected: // -------------------- Map -------------------- template -struct evaluator_impl > - : evaluator_impl_base +struct evaluator > + : evaluator_base { typedef MapBase MapType; typedef Derived XprType; @@ -517,7 +521,7 @@ struct evaluator_impl > typedef typename XprType::PacketScalar PacketScalar; typedef typename XprType::PacketReturnType PacketReturnType; - evaluator_impl(const XprType& map) + evaluator(const XprType& map) : m_data(const_cast(map.data())), m_rowStride(map.rowStride()), m_colStride(map.colStride()) @@ -585,13 +589,13 @@ protected: }; template -struct evaluator_impl > - : public evaluator_impl > > +struct evaluator > + : public evaluator > > { typedef Map XprType; - evaluator_impl(const XprType& map) - : evaluator_impl >(map) + evaluator(const XprType& map) + : evaluator >(map) { } }; @@ -601,17 +605,17 @@ template::ret> struct block_evaluator; template -struct evaluator_impl > +struct evaluator > : block_evaluator { typedef Block XprType; typedef block_evaluator block_evaluator_type; - evaluator_impl(const XprType& block) : block_evaluator_type(block) {} + evaluator(const XprType& block) : block_evaluator_type(block) {} }; template struct block_evaluator - : evaluator_impl_base > + : evaluator_base > { typedef Block XprType; @@ -691,12 +695,12 @@ protected: template struct block_evaluator - : evaluator_impl > > + : evaluator > > { typedef Block XprType; block_evaluator(const XprType& block) - : evaluator_impl >(block) + : evaluator >(block) { } }; @@ -704,11 +708,12 @@ struct block_evaluator -struct evaluator_impl > +struct evaluator > + : evaluator_base > { typedef Select XprType; - evaluator_impl(const XprType& select) + evaluator(const XprType& select) : m_conditionImpl(select.conditionMatrix()), m_thenImpl(select.thenMatrix()), m_elseImpl(select.elseMatrix()) @@ -743,11 +748,12 @@ protected: // -------------------- Replicate -------------------- template -struct evaluator_impl > +struct evaluator > + : evaluator_base > { typedef Replicate XprType; - evaluator_impl(const XprType& replicate) + evaluator(const XprType& replicate) : m_argImpl(replicate.nestedExpression()), m_rows(replicate.nestedExpression().rows()), m_cols(replicate.nestedExpression().cols()) @@ -797,11 +803,12 @@ protected: // the row() and col() member functions. template< typename ArgType, typename MemberOp, int Direction> -struct evaluator_impl > +struct evaluator > + : evaluator_base > { typedef PartialReduxExpr XprType; - evaluator_impl(const XprType expr) + evaluator(const XprType expr) : m_expr(expr) { } @@ -825,16 +832,16 @@ protected: // -------------------- MatrixWrapper and ArrayWrapper -------------------- // -// evaluator_impl_wrapper_base is a common base class for the +// evaluator_wrapper_base is a common base class for the // MatrixWrapper and ArrayWrapper evaluators. template -struct evaluator_impl_wrapper_base - : evaluator_impl_base +struct evaluator_wrapper_base + : evaluator_base { typedef typename remove_all::type ArgType; - evaluator_impl_wrapper_base(const ArgType& arg) : m_argImpl(arg) {} + evaluator_wrapper_base(const ArgType& arg) : m_argImpl(arg) {} typedef typename ArgType::Index Index; typedef typename ArgType::Scalar Scalar; @@ -891,24 +898,24 @@ protected: }; template -struct evaluator_impl > - : evaluator_impl_wrapper_base > +struct evaluator > + : evaluator_wrapper_base > { typedef MatrixWrapper XprType; - evaluator_impl(const XprType& wrapper) - : evaluator_impl_wrapper_base >(wrapper.nestedExpression()) + evaluator(const XprType& wrapper) + : evaluator_wrapper_base >(wrapper.nestedExpression()) { } }; template -struct evaluator_impl > - : evaluator_impl_wrapper_base > +struct evaluator > + : evaluator_wrapper_base > { typedef ArrayWrapper XprType; - evaluator_impl(const XprType& wrapper) - : evaluator_impl_wrapper_base >(wrapper.nestedExpression()) + evaluator(const XprType& wrapper) + : evaluator_wrapper_base >(wrapper.nestedExpression()) { } }; @@ -919,8 +926,8 @@ struct evaluator_impl > template struct reverse_packet_cond; template -struct evaluator_impl > - : evaluator_impl_base > +struct evaluator > + : evaluator_base > { typedef Reverse XprType; typedef typename XprType::Index Index; @@ -943,7 +950,7 @@ struct evaluator_impl > }; typedef internal::reverse_packet_cond reverse_packet; - evaluator_impl(const XprType& reverse) + evaluator(const XprType& reverse) : m_argImpl(reverse.nestedExpression()), m_rows(ReverseRow ? reverse.nestedExpression().rows() : 0), m_cols(ReverseCol ? reverse.nestedExpression().cols() : 0) @@ -1013,12 +1020,12 @@ protected: // -------------------- Diagonal -------------------- template -struct evaluator_impl > - : evaluator_impl_base > +struct evaluator > + : evaluator_base > { typedef Diagonal XprType; - evaluator_impl(const XprType& diagonal) + evaluator(const XprType& diagonal) : m_argImpl(diagonal.nestedExpression()), m_index(diagonal.index()) { } diff --git a/Eigen/src/Core/ProductEvaluators.h b/Eigen/src/Core/ProductEvaluators.h index 42dd3c7ac..9f5f6eb0c 100644 --- a/Eigen/src/Core/ProductEvaluators.h +++ b/Eigen/src/Core/ProductEvaluators.h @@ -27,14 +27,17 @@ struct dense_product_impl; // The evaluator for default dense products creates a temporary and call dense_product_impl template -struct evaluator_impl > +struct evaluator > : public evaluator::PlainObject>::type { typedef Product XprType; typedef typename XprType::PlainObject PlainObject; typedef typename evaluator::type Base; + + typedef evaluator type; + typedef evaluator nestedType; - evaluator_impl(const XprType& xpr) + evaluator(const XprType& xpr) : m_result(xpr.rows(), xpr.cols()) { ::new (static_cast(this)) Base(m_result); @@ -196,13 +199,13 @@ template -struct evaluator_impl > - : evaluator_impl_base > +struct evaluator > + : evaluator_base > { typedef Product XprType; typedef CoeffBasedProduct CoeffBasedProductType; - evaluator_impl(const XprType& xpr) + evaluator(const XprType& xpr) : m_lhsImpl(xpr.lhs()), m_rhsImpl(xpr.rhs()), m_innerDim(xpr.lhs().cols())