Implement evaluator for PartialReduxExpr as a dumb wrapper.

This commit is contained in:
Jitse Niesen 2011-04-13 09:49:10 +01:00
parent 11164830f5
commit 7e86324898
2 changed files with 38 additions and 0 deletions

View File

@ -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<PartialReduxExpr<XprType, MemberOp, Direction> >
{
typedef PartialReduxExpr<XprType, MemberOp, Direction> 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

View File

@ -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());
}