mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-04 18:54:00 +08:00
Implement evaluator for PartialReduxExpr as a dumb wrapper.
This commit is contained in:
parent
11164830f5
commit
7e86324898
@ -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
|
} // namespace internal
|
||||||
|
|
||||||
#endif // EIGEN_COREEVALUATORS_H
|
#endif // EIGEN_COREEVALUATORS_H
|
||||||
|
@ -176,4 +176,9 @@ void test_evaluators()
|
|||||||
matXcd.resize(12, 12);
|
matXcd.resize(12, 12);
|
||||||
VERIFY_IS_APPROX_EVALUATOR(matXcd, matXcd_ref.replicate(2,2));
|
VERIFY_IS_APPROX_EVALUATOR(matXcd, matXcd_ref.replicate(2,2));
|
||||||
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());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user