summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCNugteren <web@cedricnugteren.nl>2015-06-20 10:58:21 +0200
committerCNugteren <web@cedricnugteren.nl>2015-06-20 10:58:21 +0200
commite26742c62993892deffbd44e68f3769423330cbb (patch)
tree1ee472facfd4c9fe47979a98261973d488c6d939 /test
parentd7097a063ad7eca9aa3982c3c63eba91cd2271c5 (diff)
Added additional absolute error checking when testing
Diffstat (limited to 'test')
-rw-r--r--test/correctness/testabc.cc2
-rw-r--r--test/correctness/testabc.h1
-rw-r--r--test/correctness/testaxy.cc2
-rw-r--r--test/correctness/testaxy.h1
-rw-r--r--test/correctness/tester.cc23
-rw-r--r--test/correctness/tester.h5
-rw-r--r--test/correctness/testxy.cc2
-rw-r--r--test/correctness/testxy.h1
8 files changed, 17 insertions, 20 deletions
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<T>::TestRegular(Arguments<T> &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<T> {
// Uses several variables from the Tester class
using Tester<T>::context_;
using Tester<T>::queue_;
- using Tester<T>::kErrorMargin;
using Tester<T>::kLayouts;
using Tester<T>::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<T>::TestRegular(Arguments<T> &args, const std::string &name) {
auto errors = size_t{0};
for (auto idm=size_t{0}; idm<m_real; ++idm) {
auto index = idm*y_inc + y_offset;
- if (!TestSimilarity(r_result[index], s_result[index], kErrorMargin)) {
+ if (!TestSimilarity(r_result[index], s_result[index])) {
errors++;
}
}
diff --git a/test/correctness/testaxy.h b/test/correctness/testaxy.h
index 927477ed..97155d69 100644
--- a/test/correctness/testaxy.h
+++ b/test/correctness/testaxy.h
@@ -31,7 +31,6 @@ class TestAXY: public Tester<T> {
// Uses several variables from the Tester class
using Tester<T>::context_;
using Tester<T>::queue_;
- using Tester<T>::kErrorMargin;
using Tester<T>::kLayouts;
using Tester<T>::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 <vector>
#include <iostream>
#include <cmath>
-#include <limits>
namespace clblast {
// =================================================================================================
@@ -168,34 +167,34 @@ void Tester<T>::TestEnd() {
// Compares two floating point values and returns whether they are within an acceptable error
// margin. This replaces GTest's EXPECT_NEAR().
template <typename T>
-bool Tester<T>::TestSimilarity(const T val1, const T val2, const double margin) {
+bool Tester<T>::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<T>::min()) {
- return difference < (static_cast<T>(margin) * std::numeric_limits<T>::min());
+ // The values are zero or very small: the relative error is less meaningful
+ else if (val1 == 0 || val2 == 0 || difference < static_cast<T>(kErrorMarginAbsolute)) {
+ return (difference < static_cast<T>(kErrorMarginAbsolute));
}
// Use relative error
else {
- return (difference / (std::fabs(val1) + std::fabs(val2))) < static_cast<T>(margin);
+ return (difference / (std::fabs(val1)+std::fabs(val2))) < static_cast<T>(kErrorMarginRelative);
}
}
// Specialisations for complex data-types
template <>
-bool Tester<float2>::TestSimilarity(const float2 val1, const float2 val2, const double margin) {
- auto real = Tester<float>::TestSimilarity(val1.real(), val2.real(), margin);
- auto imag = Tester<float>::TestSimilarity(val1.imag(), val2.imag(), margin);
+bool Tester<float2>::TestSimilarity(const float2 val1, const float2 val2) {
+ auto real = Tester<float>::TestSimilarity(val1.real(), val2.real());
+ auto imag = Tester<float>::TestSimilarity(val1.imag(), val2.imag());
return (real && imag);
}
template <>
-bool Tester<double2>::TestSimilarity(const double2 val1, const double2 val2, const double margin) {
- auto real = Tester<double>::TestSimilarity(val1.real(), val2.real(), margin);
- auto imag = Tester<double>::TestSimilarity(val1.imag(), val2.imag(), margin);
+bool Tester<double2>::TestSimilarity(const double2 val1, const double2 val2) {
+ auto real = Tester<double>::TestSimilarity(val1.real(), val2.real());
+ auto imag = Tester<double>::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<T> &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<T>::TestRegular(Arguments<T> &args, const std::string &name) {
auto errors = size_t{0};
for (auto idn=size_t{0}; idn<n; ++idn) {
auto index = idn*y_inc + y_offset;
- if (!TestSimilarity(r_result[index], s_result[index], kErrorMargin)) {
+ if (!TestSimilarity(r_result[index], s_result[index])) {
errors++;
}
}
diff --git a/test/correctness/testxy.h b/test/correctness/testxy.h
index 32cd91fa..2a9dcab9 100644
--- a/test/correctness/testxy.h
+++ b/test/correctness/testxy.h
@@ -31,7 +31,6 @@ class TestXY: public Tester<T> {
// Uses several variables from the Tester class
using Tester<T>::context_;
using Tester<T>::queue_;
- using Tester<T>::kErrorMargin;
// Uses several helper functions from the Tester class
using Tester<T>::TestStart;