From 7e863248987b06440742b1a02feaeb35cb1d75b6 Mon Sep 17 00:00:00 2001 From: Jitse Niesen Date: Wed, 13 Apr 2011 09:49:10 +0100 Subject: [PATCH] Implement evaluator for PartialReduxExpr as a dumb wrapper. --- Eigen/src/Core/CoreEvaluators.h | 33 +++++++++++++++++++++++++++++++++ test/evaluators.cpp | 5 +++++ 2 files changed, 38 insertions(+) diff --git a/Eigen/src/Core/CoreEvaluators.h b/Eigen/src/Core/CoreEvaluators.h index ef6913add..db6faca10 100644 --- a/Eigen/src/Core/CoreEvaluators.h +++ b/Eigen/src/Core/CoreEvaluators.h @@ -665,6 +665,39 @@ protected: }; +// -------------------- PartialReduxExpr -------------------- +// +// This is a wrapper around the expression object. +// TODO: Find out how to write a proper evaluator without duplicating +// the row() and col() member functions. + +template< typename XprType, typename MemberOp, int Direction> +struct evaluator_impl > +{ + typedef PartialReduxExpr PartialReduxExprType; + + evaluator_impl(const PartialReduxExprType expr) + : m_expr(expr) + { } + + typedef typename PartialReduxExprType::Index Index; + typedef typename PartialReduxExprType::CoeffReturnType CoeffReturnType; + + CoeffReturnType coeff(Index row, Index col) const + { + return m_expr.coeff(row, col); + } + + CoeffReturnType coeff(Index index) const + { + return m_expr.coeff(index); + } + +protected: + const PartialReduxExprType& m_expr; +}; + + } // namespace internal #endif // EIGEN_COREEVALUATORS_H diff --git a/test/evaluators.cpp b/test/evaluators.cpp index 8e0dadb06..aa57e4ad5 100644 --- a/test/evaluators.cpp +++ b/test/evaluators.cpp @@ -176,4 +176,9 @@ void test_evaluators() matXcd.resize(12, 12); VERIFY_IS_APPROX_EVALUATOR(matXcd, matXcd_ref.replicate(2,2)); VERIFY_IS_APPROX_EVALUATOR(matXcd, (matXcd_ref.replicate<2,2>())); + + // test partial reductions + VectorXd vec1(6); + VERIFY_IS_APPROX_EVALUATOR(vec1, mat1.rowwise().sum()); + VERIFY_IS_APPROX_EVALUATOR(vec1, mat1.colwise().sum().transpose()); }