diff options
author | Yi Kong <yikong@google.com> | 2022-02-25 16:17:02 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-02-25 16:17:02 +0000 |
commit | 7cb50013986f04dce5fac87bebf319bb8db37a36 (patch) | |
tree | fb979fb4cf4f8052c8cc66b1ec9516d91fcd859b /test/redux.cpp | |
parent | 26a30e76965432e5088c271df90759e49d9636a2 (diff) | |
parent | 10f298fc4175c1b8537c674f654a070c871960e5 (diff) | |
download | eigen-7cb50013986f04dce5fac87bebf319bb8db37a36.tar.gz |
Merge changes Iee153445,Iee274471 am: 79df15ea88 am: 10f298fc41
Original change: https://android-review.googlesource.com/c/platform/external/eigen/+/1999079
Change-Id: I3dd349f9a45d37f37441ff7a7742ebe953b70516
Diffstat (limited to 'test/redux.cpp')
-rw-r--r-- | test/redux.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/test/redux.cpp b/test/redux.cpp index 989e1057b..fdbab7714 100644 --- a/test/redux.cpp +++ b/test/redux.cpp @@ -9,12 +9,13 @@ // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. #define TEST_ENABLE_TEMPORARY_TRACKING +#define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 8 +// ^^ see bug 1449 #include "main.h" template<typename MatrixType> void matrixRedux(const MatrixType& m) { - typedef typename MatrixType::Index Index; typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::RealScalar RealScalar; @@ -27,6 +28,9 @@ template<typename MatrixType> void matrixRedux(const MatrixType& m) // failures if we underflow into denormals. Thus, we scale so that entries are close to 1. MatrixType m1_for_prod = MatrixType::Ones(rows, cols) + RealScalar(0.2) * m1; + Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> m2(rows,rows); + m2.setRandom(); + VERIFY_IS_MUCH_SMALLER_THAN(MatrixType::Zero(rows, cols).sum(), Scalar(1)); VERIFY_IS_APPROX(MatrixType::Ones(rows, cols).sum(), Scalar(float(rows*cols))); // the float() here to shut up excessive MSVC warning about int->complex conversion being lossy Scalar s(0), p(1), minc(numext::real(m1.coeff(0))), maxc(numext::real(m1.coeff(0))); @@ -45,6 +49,10 @@ template<typename MatrixType> void matrixRedux(const MatrixType& m) VERIFY_IS_APPROX(m1_for_prod.prod(), p); VERIFY_IS_APPROX(m1.real().minCoeff(), numext::real(minc)); VERIFY_IS_APPROX(m1.real().maxCoeff(), numext::real(maxc)); + + // test that partial reduction works if nested expressions is forced to evaluate early + VERIFY_IS_APPROX((m1.matrix() * m1.matrix().transpose()) .cwiseProduct(m2.matrix()).rowwise().sum().sum(), + (m1.matrix() * m1.matrix().transpose()).eval().cwiseProduct(m2.matrix()).rowwise().sum().sum()); // test slice vectorization assuming assign is ok Index r0 = internal::random<Index>(0,rows-1); @@ -71,15 +79,12 @@ template<typename MatrixType> void matrixRedux(const MatrixType& m) // test nesting complex expression VERIFY_EVALUATION_COUNT( (m1.matrix()*m1.matrix().transpose()).sum(), (MatrixType::IsVectorAtCompileTime && MatrixType::SizeAtCompileTime!=1 ? 0 : 1) ); - Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> m2(rows,rows); - m2.setRandom(); VERIFY_EVALUATION_COUNT( ((m1.matrix()*m1.matrix().transpose())+m2).sum(),(MatrixType::IsVectorAtCompileTime && MatrixType::SizeAtCompileTime!=1 ? 0 : 1)); } template<typename VectorType> void vectorRedux(const VectorType& w) { using std::abs; - typedef typename VectorType::Index Index; typedef typename VectorType::Scalar Scalar; typedef typename NumTraits<Scalar>::Real RealScalar; Index size = w.size(); @@ -146,7 +151,7 @@ template<typename VectorType> void vectorRedux(const VectorType& w) VERIFY_RAISES_ASSERT(v.head(0).maxCoeff()); } -void test_redux() +EIGEN_DECLARE_TEST(redux) { // the max size cannot be too large, otherwise reduxion operations obviously generate large errors. int maxsize = (std::min)(100,EIGEN_TEST_MAX_SIZE); |