diff options
author | Hauke Heibel <hauke.heibel@gmail.com> | 2010-01-29 12:12:02 +0100 |
---|---|---|
committer | Hauke Heibel <hauke.heibel@gmail.com> | 2010-01-29 12:12:02 +0100 |
commit | 6dee5440e4971781077769913586e9748b1d6dbf (patch) | |
tree | 06641abffa1adb278a3bf78c8d1c067e84666863 | |
parent | 42b88983ff846624ff335e2a60f7435acb7cb9cf (diff) |
Adapted mean to work with complex numbers.
Added regression test.
-rw-r--r-- | Eigen/src/Core/Redux.h | 2 | ||||
-rw-r--r-- | test/redux.cpp | 13 |
2 files changed, 14 insertions, 1 deletions
diff --git a/Eigen/src/Core/Redux.h b/Eigen/src/Core/Redux.h index 1643f13b2..09538a3bd 100644 --- a/Eigen/src/Core/Redux.h +++ b/Eigen/src/Core/Redux.h @@ -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 diff --git a/test/redux.cpp b/test/redux.cpp index 3293fd54e..f95e8b29c 100644 --- a/test/redux.cpp +++ b/test/redux.cpp @@ -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)) ); } } |