fix sum()/prod() on empty matrix making sure this does not affect fixed sized object, extend related unit tests including partial reduction

This commit is contained in:
Gael Guennebaud
2010-07-16 14:02:20 +02:00
parent 6a370f50c7
commit 044424b0e2
3 changed files with 23 additions and 1 deletions

View File

@@ -64,6 +64,10 @@ template<typename MatrixType> void matrixRedux(const MatrixType& m)
VERIFY_IS_APPROX(m1.block(r0,c0,r1,c1).prod(), m1.block(r0,c0,r1,c1).eval().prod());
VERIFY_IS_APPROX(m1.block(r0,c0,r1,c1).real().minCoeff(), m1.block(r0,c0,r1,c1).real().eval().minCoeff());
VERIFY_IS_APPROX(m1.block(r0,c0,r1,c1).real().maxCoeff(), m1.block(r0,c0,r1,c1).real().eval().maxCoeff());
// test empty objects
VERIFY_IS_APPROX(m1.block(r0,c0,0,0).sum(), Scalar(0));
VERIFY_IS_APPROX(m1.block(r0,c0,0,0).prod(), Scalar(1));
}
template<typename VectorType> void vectorRedux(const VectorType& w)
@@ -124,6 +128,13 @@ template<typename VectorType> void vectorRedux(const VectorType& w)
VERIFY_IS_APPROX(minc, v.real().segment(i, size-2*i).minCoeff());
VERIFY_IS_APPROX(maxc, v.real().segment(i, size-2*i).maxCoeff());
}
// test empty objects
VERIFY_IS_APPROX(v.head(0).sum(), Scalar(0));
VERIFY_IS_APPROX(v.tail(0).prod(), Scalar(1));
VERIFY_RAISES_ASSERT(v.head(0).mean());
VERIFY_RAISES_ASSERT(v.head(0).minCoeff());
VERIFY_RAISES_ASSERT(v.head(0).maxCoeff());
}
void test_redux()