summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/internal/utilities.h4
-rw-r--r--src/utilities.cc12
-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
10 files changed, 30 insertions, 23 deletions
diff --git a/include/internal/utilities.h b/include/internal/utilities.h
index af04dfdb..600605c7 100644
--- a/include/internal/utilities.h
+++ b/include/internal/utilities.h
@@ -143,6 +143,10 @@ bool CheckArgument(const int argc, char *argv[], std::string &help, const std::s
// Returns a random number to be used as a seed
unsigned int GetRandomSeed();
+// Test/example data lower and upper limit
+constexpr auto kTestDataLowerLimit = -2.0;
+constexpr auto kTestDataUpperLimit = 2.0;
+
// Populates a vector with random data
template <typename T>
void PopulateVector(std::vector<T> &vector);
diff --git a/src/utilities.cc b/src/utilities.cc
index 80cea852..3fc33502 100644
--- a/src/utilities.cc
+++ b/src/utilities.cc
@@ -182,8 +182,10 @@ unsigned int GetRandomSeed() {
// Create a random number generator and populates a vector with samples from a random distribution
template <typename T>
void PopulateVector(std::vector<T> &vector) {
+ auto lower_limit = static_cast<T>(kTestDataLowerLimit);
+ auto upper_limit = static_cast<T>(kTestDataUpperLimit);
std::mt19937 mt(GetRandomSeed());
- std::uniform_real_distribution<T> dist(static_cast<T>(-2.0), static_cast<T>(2.0));
+ std::uniform_real_distribution<T> dist(lower_limit, upper_limit);
for (auto &element: vector) { element = dist(mt); }
}
template void PopulateVector<float>(std::vector<float>&);
@@ -192,14 +194,18 @@ template void PopulateVector<double>(std::vector<double>&);
// Specialized versions of the above for complex data-types
template <>
void PopulateVector(std::vector<float2> &vector) {
+ auto lower_limit = static_cast<float>(kTestDataLowerLimit);
+ auto upper_limit = static_cast<float>(kTestDataUpperLimit);
std::mt19937 mt(GetRandomSeed());
- std::uniform_real_distribution<float> dist(-2.0f, 2.0f);
+ std::uniform_real_distribution<float> dist(lower_limit, upper_limit);
for (auto &element: vector) { element.real(dist(mt)); element.imag(dist(mt)); }
}
template <>
void PopulateVector(std::vector<double2> &vector) {
+ auto lower_limit = static_cast<double>(kTestDataLowerLimit);
+ auto upper_limit = static_cast<double>(kTestDataUpperLimit);
std::mt19937 mt(GetRandomSeed());
- std::uniform_real_distribution<double> dist(-2.0, 2.0);
+ std::uniform_real_distribution<double> dist(lower_limit, upper_limit);
for (auto &element: vector) { element.real(dist(mt)); element.imag(dist(mt)); }
}
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;