aboutsummaryrefslogtreecommitdiffhomepage
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
parent3f2c8b7ff067c4a6cf00688a171c5a05154ee39b (diff)
Extend unit tests for partial reductions
-rw-r--r--test/array_for_matrix.cpp9
-rw-r--r--test/vectorwiseop.cpp21
2 files changed, 25 insertions, 5 deletions
diff --git a/test/array_for_matrix.cpp b/test/array_for_matrix.cpp
index 6b03abb10..fb6be351e 100644
--- a/test/array_for_matrix.cpp
+++ b/test/array_for_matrix.cpp
@@ -57,7 +57,14 @@ template<typename MatrixType> void array_for_matrix(const MatrixType& m)
VERIFY_IS_APPROX(m3.rowwise() -= rv1, m1.rowwise() - rv1);
// empty objects
- VERIFY_IS_APPROX(m1.block(0,0,0,cols).colwise().sum(), RowVectorType::Zero(cols));
+ VERIFY_IS_APPROX((m1.template block<0,Dynamic>(0,0,0,cols).colwise().sum()), RowVectorType::Zero(cols));
+ VERIFY_IS_APPROX((m1.template block<Dynamic,0>(0,0,rows,0).rowwise().sum()), ColVectorType::Zero(rows));
+ VERIFY_IS_APPROX((m1.template block<0,Dynamic>(0,0,0,cols).colwise().prod()), RowVectorType::Ones(cols));
+ VERIFY_IS_APPROX((m1.template block<Dynamic,0>(0,0,rows,0).rowwise().prod()), ColVectorType::Ones(rows));
+
+ VERIFY_IS_APPROX(m1.block(0,0,0,cols).colwise().sum(), RowVectorType::Zero(cols));
+ VERIFY_IS_APPROX(m1.block(0,0,rows,0).rowwise().sum(), ColVectorType::Zero(rows));
+ VERIFY_IS_APPROX(m1.block(0,0,0,cols).colwise().prod(), RowVectorType::Ones(cols));
VERIFY_IS_APPROX(m1.block(0,0,rows,0).rowwise().prod(), ColVectorType::Ones(rows));
// verify the const accessors exist
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>());