From 45ee14a13a914fd21d00abe799de0039651edcb8 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 21 Jul 2015 22:22:12 +0200 Subject: Fix output of relative error, and add more support for long double --- test/main.h | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'test/main.h') diff --git a/test/main.h b/test/main.h index ef471acc8..0d03d4853 100644 --- a/test/main.h +++ b/test/main.h @@ -291,9 +291,10 @@ namespace Eigen { template inline typename NumTraits::Real test_precision() { return NumTraits::dummy_precision(); } template<> inline float test_precision() { return 1e-3f; } template<> inline double test_precision() { return 1e-6; } +template<> inline long double test_precision() { return 1e-6; } template<> inline float test_precision >() { return test_precision(); } template<> inline double test_precision >() { return test_precision(); } -template<> inline long double test_precision() { return 1e-6; } +template<> inline long double test_precision >() { return test_precision(); } inline bool test_isApprox(const int& a, const int& b) { return internal::isApprox(a, b, test_precision()); } @@ -326,6 +327,11 @@ inline bool test_isApprox(const std::complex& a, const std::complex >()); } inline bool test_isMuchSmallerThan(const std::complex& a, const std::complex& b) { return internal::isMuchSmallerThan(a, b, test_precision >()); } + +inline bool test_isApprox(const std::complex& a, const std::complex& b) +{ return internal::isApprox(a, b, test_precision >()); } +inline bool test_isMuchSmallerThan(const std::complex& a, const std::complex& b) +{ return internal::isMuchSmallerThan(a, b, test_precision >()); } #endif #ifndef EIGEN_TEST_NO_LONGDOUBLE @@ -349,10 +355,11 @@ inline bool test_isApproxOrLessThan(const long double& a, const long double& b) template typename T1::RealScalar test_relative_error(const EigenBase &a, const EigenBase &b) { + using std::sqrt; typedef typename T1::RealScalar RealScalar; typename internal::nested_eval::type ea(a.derived()); typename internal::nested_eval::type eb(b.derived()); - return RealScalar((ea-eb).cwiseAbs2().sum()) / RealScalar((std::min)(eb.cwiseAbs2().sum(),ea.cwiseAbs2().sum())); + return sqrt(RealScalar((ea-eb).cwiseAbs2().sum()) / RealScalar((std::min)(eb.cwiseAbs2().sum(),ea.cwiseAbs2().sum()))); } template @@ -411,7 +418,8 @@ typename NumTraits::Real test_relative_error(const T1 &a, const T2 &b, typen { typedef typename NumTraits::Real RealScalar; using std::min; - return RealScalar(numext::abs2(a-b))/RealScalar((min)(numext::abs2(a),numext::abs2(b))); + using std::sqrt; + return sqrt(RealScalar(numext::abs2(a-b))/RealScalar((min)(numext::abs2(a),numext::abs2(b)))); } template @@ -596,13 +604,15 @@ template struct GetDifferentType > // Forward declaration to avoid ICC warning template std::string type_name(); -template std::string type_name() { return "other"; } -template<> std::string type_name() { return "float"; } -template<> std::string type_name() { return "double"; } -template<> std::string type_name() { return "int"; } -template<> std::string type_name >() { return "complex"; } -template<> std::string type_name >() { return "complex"; } -template<> std::string type_name >() { return "complex"; } +template std::string type_name() { return "other"; } +template<> std::string type_name() { return "float"; } +template<> std::string type_name() { return "double"; } +template<> std::string type_name() { return "long double"; } +template<> std::string type_name() { return "int"; } +template<> std::string type_name >() { return "complex"; } +template<> std::string type_name >() { return "complex"; } +template<> std::string type_name >() { return "complex"; } +template<> std::string type_name >() { return "complex"; } // forward declaration of the main test function void EIGEN_CAT(test_,EIGEN_TEST_FUNC)(); -- cgit v1.2.3