From c910c517b34b147894e7fa62cb9602cc19e0669b Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sun, 6 Jul 2008 19:02:03 +0000 Subject: [PATCH] fix issues in previously added additionnal product tests --- test/product.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/test/product.cpp b/test/product.cpp index f432e411a..7e859fb1f 100644 --- a/test/product.cpp +++ b/test/product.cpp @@ -23,6 +23,13 @@ // Eigen. If not, see . #include "main.h" +#include + +template +bool areNotApprox(const MatrixBase& m1, const MatrixBase& m2, typename Derived1::Scalar epsilon = precision()) +{ + return !((m1-m2).matrixNorm() < epsilon * std::max(m1.matrixNorm(), m2.matrixNorm())); +} template void product(const MatrixType& m) { @@ -89,18 +96,28 @@ template void product(const MatrixType& m) VERIFY_RAISES_ASSERT(m3 = m1*m1); // test the previous tests were not screwed up because operator* returns 0 - VERIFY_IS_NOT_APPROX((m1.transpose()*m2).template cast(), (m2.transpose()*m1).template cast()); + // (we use the more accurate default epsilon) + if (NumTraits::HasFloatingPoint && std::min(rows,cols)>1) + { + VERIFY(areNotApprox(m1.transpose()*m2,m2.transpose()*m1)); + } // test optimized operator+= path res = square; res += (m1 * m2.transpose()).lazy(); VERIFY_IS_APPROX(res, square + m1 * m2.transpose()); - VERIFY_IS_NOT_APPROX(res.template cast(), (square + m2 * m1.transpose()).template cast()); + if (NumTraits::HasFloatingPoint && std::min(rows,cols)>1) + { + VERIFY(areNotApprox(res,square + m2 * m1.transpose())); + } res2 = square2; res2 += (m1.transpose() * m2).lazy(); VERIFY_IS_APPROX(res2, square2 + m1.transpose() * m2); - VERIFY_IS_NOT_APPROX(res2.template cast(), (square2 + m2.transpose() * m1).template cast()); + if (NumTraits::HasFloatingPoint && std::min(rows,cols)>1) + { + VERIFY(areNotApprox(res2,square2 + m2.transpose() * m1)); + } } void test_product()