Adapted mean to work with complex numbers.

Added regression test.
This commit is contained in:
Hauke Heibel 2010-01-29 12:12:02 +01:00
parent 42b88983ff
commit 6dee5440e4
2 changed files with 14 additions and 1 deletions

View File

@ -356,7 +356,7 @@ template<typename Derived>
EIGEN_STRONG_INLINE typename ei_traits<Derived>::Scalar
DenseBase<Derived>::mean() const
{
return this->redux(Eigen::ei_scalar_sum_op<Scalar>()) / this->size();
return this->redux(Eigen::ei_scalar_sum_op<Scalar>()) / Scalar(this->size());
}
/** \returns the product of all coefficients of *this

View File

@ -44,7 +44,11 @@ template<typename MatrixType> void matrixRedux(const MatrixType& m)
minc = std::min(ei_real(minc), ei_real(m1(i,j)));
maxc = std::max(ei_real(maxc), ei_real(m1(i,j)));
}
const Scalar mean = s/Scalar(rows*cols);
const Scalar other_mean = m1.mean();
VERIFY_IS_APPROX(m1.sum(), s);
VERIFY_IS_APPROX(m1.mean(), mean);
VERIFY_IS_APPROX(m1.prod(), p);
VERIFY_IS_APPROX(m1.real().minCoeff(), ei_real(minc));
VERIFY_IS_APPROX(m1.real().maxCoeff(), ei_real(maxc));
@ -113,15 +117,24 @@ void test_redux()
{
for(int i = 0; i < g_repeat; i++) {
CALL_SUBTEST_1( matrixRedux(Matrix<float, 1, 1>()) );
CALL_SUBTEST_1( matrixRedux(Array<float, 1, 1>()) );
CALL_SUBTEST_2( matrixRedux(Matrix2f()) );
CALL_SUBTEST_2( matrixRedux(Array2f()) );
CALL_SUBTEST_3( matrixRedux(Matrix4d()) );
CALL_SUBTEST_3( matrixRedux(Array4d()) );
CALL_SUBTEST_4( matrixRedux(MatrixXcf(3, 3)) );
CALL_SUBTEST_4( matrixRedux(ArrayXXcf(3, 3)) );
CALL_SUBTEST_5( matrixRedux(MatrixXd(8, 12)) );
CALL_SUBTEST_5( matrixRedux(ArrayXXd(8, 12)) );
CALL_SUBTEST_6( matrixRedux(MatrixXi(8, 12)) );
CALL_SUBTEST_6( matrixRedux(ArrayXXi(8, 12)) );
}
for(int i = 0; i < g_repeat; i++) {
CALL_SUBTEST_7( vectorRedux(Vector4f()) );
CALL_SUBTEST_7( vectorRedux(Array4f()) );
CALL_SUBTEST_5( vectorRedux(VectorXd(10)) );
CALL_SUBTEST_5( vectorRedux(ArrayXd(10)) );
CALL_SUBTEST_8( vectorRedux(VectorXf(33)) );
CALL_SUBTEST_8( vectorRedux(ArrayXf(33)) );
}
}