aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/vectorwiseop.cpp
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2018-10-09 22:54:54 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2018-10-09 22:54:54 +0200
commitc0c3be26ed0093a03316219783992b2bc9f8a226 (patch)
tree6a1854921403ba37e93338c6ac20d637e90bb259 /test/vectorwiseop.cpp
parent3f2c8b7ff067c4a6cf00688a171c5a05154ee39b (diff)
Extend unit tests for partial reductions
Diffstat (limited to 'test/vectorwiseop.cpp')
-rw-r--r--test/vectorwiseop.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/test/vectorwiseop.cpp b/test/vectorwiseop.cpp
index 2d7ddbed1..96a9bb0ee 100644
--- a/test/vectorwiseop.cpp
+++ b/test/vectorwiseop.cpp
@@ -197,11 +197,24 @@ template<typename MatrixType> void vectorwiseop_matrix(const MatrixType& m)
VERIFY_RAISES_ASSERT(m1.rowwise() - rowvec.transpose());
}
+ // ------ partial reductions ------
+
// test norm
- rrres = m1.colwise().norm();
- VERIFY_IS_APPROX(rrres(c), m1.col(c).norm());
- rcres = m1.rowwise().norm();
- VERIFY_IS_APPROX(rcres(r), m1.row(r).norm());
+ #define TEST_PARTIAL_REDUX_BASIC(FUNC,ROW,COL,PREPROCESS) { \
+ ROW = m1 PREPROCESS .colwise().FUNC ; \
+ for(Index k=0; k<cols; ++k) VERIFY_IS_APPROX(ROW(k), m1.col(k) PREPROCESS .FUNC ); \
+ COL = m1 PREPROCESS .rowwise().FUNC ; \
+ for(Index k=0; k<rows; ++k) VERIFY_IS_APPROX(COL(k), m1.row(k) PREPROCESS .FUNC ); \
+ }
+
+ TEST_PARTIAL_REDUX_BASIC(sum(),rowvec,colvec,);
+ TEST_PARTIAL_REDUX_BASIC(prod(),rowvec,colvec,);
+ TEST_PARTIAL_REDUX_BASIC(mean(),rowvec,colvec,);
+ TEST_PARTIAL_REDUX_BASIC(minCoeff(),rrres,rcres,.real());
+ TEST_PARTIAL_REDUX_BASIC(maxCoeff(),rrres,rcres,.real());
+ TEST_PARTIAL_REDUX_BASIC(norm(),rrres,rcres,);
+ TEST_PARTIAL_REDUX_BASIC(squaredNorm(),rrres,rcres,);
+ TEST_PARTIAL_REDUX_BASIC(redux(internal::scalar_sum_op<Scalar,Scalar>()),rowvec,colvec,);
VERIFY_IS_APPROX(m1.cwiseAbs().colwise().sum(), m1.colwise().template lpNorm<1>());
VERIFY_IS_APPROX(m1.cwiseAbs().rowwise().sum(), m1.rowwise().template lpNorm<1>());