Initial commit
This commit is contained in:
68
tests/test_utils.hpp
Normal file
68
tests/test_utils.hpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
|
||||
#include <catch2/matchers/catch_matchers_floating_point.hpp>
|
||||
#include <trigdx/reference.hpp>
|
||||
|
||||
const size_t N = 1e7;
|
||||
|
||||
template <typename Backend> inline void test_sinf(float tol) {
|
||||
std::vector<float> x(N), s_ref(N), s(N);
|
||||
|
||||
for (size_t i = 0; i < N; ++i) {
|
||||
x[i] = float(i) * 0.01f;
|
||||
}
|
||||
|
||||
ReferenceBackend ref;
|
||||
Backend backend;
|
||||
backend.init();
|
||||
|
||||
ref.compute_sinf(N, x.data(), s_ref.data());
|
||||
backend.compute_sinf(N, x.data(), s.data());
|
||||
|
||||
for (size_t i = 0; i < N; ++i) {
|
||||
REQUIRE_THAT(s[i], Catch::Matchers::WithinAbs(s_ref[i], tol));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Backend> inline void test_cosf(float tol) {
|
||||
std::vector<float> x(N), c_ref(N), c(N);
|
||||
|
||||
for (size_t i = 0; i < N; ++i) {
|
||||
x[i] = float(i) * 0.01f;
|
||||
}
|
||||
|
||||
ReferenceBackend ref;
|
||||
Backend backend;
|
||||
backend.init();
|
||||
|
||||
ref.compute_cosf(N, x.data(), c_ref.data());
|
||||
backend.compute_cosf(N, x.data(), c.data());
|
||||
|
||||
for (size_t i = 0; i < N; ++i) {
|
||||
REQUIRE_THAT(c[i], Catch::Matchers::WithinAbs(c_ref[i], tol));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Backend> inline void test_sincosf(float tol) {
|
||||
std::vector<float> x(N), s_ref(N), c_ref(N), s(N), c(N);
|
||||
|
||||
for (size_t i = 0; i < N; ++i) {
|
||||
x[i] = float(i) * 0.01f;
|
||||
}
|
||||
|
||||
ReferenceBackend ref;
|
||||
Backend backend;
|
||||
backend.init();
|
||||
|
||||
ref.compute_sincosf(N, x.data(), s_ref.data(), c_ref.data());
|
||||
backend.compute_sincosf(N, x.data(), s.data(), c.data());
|
||||
|
||||
for (size_t i = 0; i < N; ++i) {
|
||||
REQUIRE_THAT(s[i], Catch::Matchers::WithinAbs(s_ref[i], tol));
|
||||
REQUIRE_THAT(c[i], Catch::Matchers::WithinAbs(c_ref[i], tol));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user