From e26742c62993892deffbd44e68f3769423330cbb Mon Sep 17 00:00:00 2001 From: CNugteren Date: Sat, 20 Jun 2015 10:58:21 +0200 Subject: Added additional absolute error checking when testing --- test/correctness/testabc.cc | 2 +- test/correctness/testabc.h | 1 - test/correctness/testaxy.cc | 2 +- test/correctness/testaxy.h | 1 - test/correctness/tester.cc | 23 +++++++++++------------ test/correctness/tester.h | 5 +++-- test/correctness/testxy.cc | 2 +- test/correctness/testxy.h | 1 - 8 files changed, 17 insertions(+), 20 deletions(-) (limited to 'test') diff --git a/test/correctness/testabc.cc b/test/correctness/testabc.cc index f2880f50..0d78a24d 100644 --- a/test/correctness/testabc.cc +++ b/test/correctness/testabc.cc @@ -133,7 +133,7 @@ void TestABC::TestRegular(Arguments &args, const std::string &name) { auto index = (args.layout == Layout::kRowMajor) ? idm*args.c_ld + idn + args.c_offset: idn*args.c_ld + idm + args.c_offset; - if (!TestSimilarity(r_result[index], s_result[index], kErrorMargin)) { + if (!TestSimilarity(r_result[index], s_result[index])) { errors++; } } diff --git a/test/correctness/testabc.h b/test/correctness/testabc.h index f1e9e7f0..e995ba5b 100644 --- a/test/correctness/testabc.h +++ b/test/correctness/testabc.h @@ -31,7 +31,6 @@ class TestABC: public Tester { // Uses several variables from the Tester class using Tester::context_; using Tester::queue_; - using Tester::kErrorMargin; using Tester::kLayouts; using Tester::kTransposes; diff --git a/test/correctness/testaxy.cc b/test/correctness/testaxy.cc index ed0b06ab..50591613 100644 --- a/test/correctness/testaxy.cc +++ b/test/correctness/testaxy.cc @@ -125,7 +125,7 @@ void TestAXY::TestRegular(Arguments &args, const std::string &name) { auto errors = size_t{0}; for (auto idm=size_t{0}; idm { // Uses several variables from the Tester class using Tester::context_; using Tester::queue_; - using Tester::kErrorMargin; using Tester::kLayouts; using Tester::kTransposes; diff --git a/test/correctness/tester.cc b/test/correctness/tester.cc index f55af842..5fd9da92 100644 --- a/test/correctness/tester.cc +++ b/test/correctness/tester.cc @@ -17,7 +17,6 @@ #include #include #include -#include namespace clblast { // ================================================================================================= @@ -168,34 +167,34 @@ void Tester::TestEnd() { // Compares two floating point values and returns whether they are within an acceptable error // margin. This replaces GTest's EXPECT_NEAR(). template -bool Tester::TestSimilarity(const T val1, const T val2, const double margin) { +bool Tester::TestSimilarity(const T val1, const T val2) { const auto difference = std::fabs(val1 - val2); // Shortcut, handles infinities if (val1 == val2) { return true; } - // The values are zero or both are extremely close to it relative error is less meaningful - else if (val1 == 0 || val2 == 0 || difference < std::numeric_limits::min()) { - return difference < (static_cast(margin) * std::numeric_limits::min()); + // The values are zero or very small: the relative error is less meaningful + else if (val1 == 0 || val2 == 0 || difference < static_cast(kErrorMarginAbsolute)) { + return (difference < static_cast(kErrorMarginAbsolute)); } // Use relative error else { - return (difference / (std::fabs(val1) + std::fabs(val2))) < static_cast(margin); + return (difference / (std::fabs(val1)+std::fabs(val2))) < static_cast(kErrorMarginRelative); } } // Specialisations for complex data-types template <> -bool Tester::TestSimilarity(const float2 val1, const float2 val2, const double margin) { - auto real = Tester::TestSimilarity(val1.real(), val2.real(), margin); - auto imag = Tester::TestSimilarity(val1.imag(), val2.imag(), margin); +bool Tester::TestSimilarity(const float2 val1, const float2 val2) { + auto real = Tester::TestSimilarity(val1.real(), val2.real()); + auto imag = Tester::TestSimilarity(val1.imag(), val2.imag()); return (real && imag); } template <> -bool Tester::TestSimilarity(const double2 val1, const double2 val2, const double margin) { - auto real = Tester::TestSimilarity(val1.real(), val2.real(), margin); - auto imag = Tester::TestSimilarity(val1.imag(), val2.imag(), margin); +bool Tester::TestSimilarity(const double2 val1, const double2 val2) { + auto real = Tester::TestSimilarity(val1.real(), val2.real()); + auto imag = Tester::TestSimilarity(val1.imag(), val2.imag()); return (real && imag); } diff --git a/test/correctness/tester.h b/test/correctness/tester.h index 934141d2..e6815fce 100644 --- a/test/correctness/tester.h +++ b/test/correctness/tester.h @@ -44,7 +44,8 @@ class Tester { static constexpr auto kStatusError = -1.0f; // Set the allowed error margin for floating-point comparisons - static constexpr auto kErrorMargin = 1.0e-2; + static constexpr auto kErrorMarginRelative = 1.0e-2; + static constexpr auto kErrorMarginAbsolute = 1.0e-10; // Constants holding start and end strings for terminal-output in colour const std::string kPrintError{"\x1b[31m"}; @@ -84,7 +85,7 @@ class Tester { void TestEnd(); // Compares two floating point values for similarity. Allows for a certain relative error margin. - static bool TestSimilarity(const T val1, const T val2, const double margin); + static bool TestSimilarity(const T val1, const T val2); // Tests either an error count (should be zero) or two error codes (must match) void TestErrorCount(const size_t errors, const size_t size, const Arguments &args); diff --git a/test/correctness/testxy.cc b/test/correctness/testxy.cc index 49ae5d7d..b88600b7 100644 --- a/test/correctness/testxy.cc +++ b/test/correctness/testxy.cc @@ -100,7 +100,7 @@ void TestXY::TestRegular(Arguments &args, const std::string &name) { auto errors = size_t{0}; for (auto idn=size_t{0}; idn { // Uses several variables from the Tester class using Tester::context_; using Tester::queue_; - using Tester::kErrorMargin; // Uses several helper functions from the Tester class using Tester::TestStart; -- cgit v1.2.3