Commit eb6452fa authored by Scott Thornton's avatar Scott Thornton
Browse files

Fixed up CPU tests

parent 63da1249
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include <rtg/operators.hpp> #include <rtg/operators.hpp>
#include <rtg/cpu/cpu_target.hpp> #include <rtg/cpu/cpu_target.hpp>
#include "test.hpp" #include "test.hpp"
#include "verify.hpp"
void exp_test() { void exp_test() {
rtg::program p; rtg::program p;
...@@ -15,10 +17,7 @@ void exp_test() { ...@@ -15,10 +17,7 @@ void exp_test() {
std::vector<float> results_vector(3); std::vector<float> results_vector(3);
result.visit([&] (auto output){ results_vector.assign(output.begin(), output.end()); }); result.visit([&] (auto output){ results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {0.36787944f,1.f,2.71828183f}; std::vector<float> gold = {0.36787944f,1.f,2.71828183f};
float tol = 1e-6; EXPECT(test::verify_range(results_vector, gold));
for (int i = 0; i < results_vector.size(); i++) {
EXPECT(std::abs(results_vector[i]-gold[i]) < tol);
}
} }
void sin_test() { void sin_test() {
...@@ -31,10 +30,7 @@ void sin_test() { ...@@ -31,10 +30,7 @@ void sin_test() {
std::vector<float> results_vector(3); std::vector<float> results_vector(3);
result.visit([&] (auto output){ results_vector.assign(output.begin(), output.end()); }); result.visit([&] (auto output){ results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {-0.84147098f,0.f,0.84147098f}; std::vector<float> gold = {-0.84147098f,0.f,0.84147098f};
float tol = 1e-6; EXPECT(test::verify_range(results_vector, gold));
for (int i = 0; i < results_vector.size(); i++) {
EXPECT(std::abs(results_vector[i]-gold[i]) < tol);
}
} }
void cos_test() { void cos_test() {
...@@ -47,10 +43,7 @@ void cos_test() { ...@@ -47,10 +43,7 @@ void cos_test() {
std::vector<float> results_vector(3); std::vector<float> results_vector(3);
result.visit([&] (auto output){ results_vector.assign(output.begin(), output.end()); }); result.visit([&] (auto output){ results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {0.54030231f,1.f,0.54030231f}; std::vector<float> gold = {0.54030231f,1.f,0.54030231f};
float tol = 1e-6; EXPECT(test::verify_range(results_vector, gold));
for (int i = 0; i < results_vector.size(); i++) {
EXPECT(std::abs(results_vector[i]-gold[i]) < tol);
}
} }
void tan_test() { void tan_test() {
...@@ -63,10 +56,7 @@ void tan_test() { ...@@ -63,10 +56,7 @@ void tan_test() {
std::vector<float> results_vector(3); std::vector<float> results_vector(3);
result.visit([&] (auto output){ results_vector.assign(output.begin(), output.end()); }); result.visit([&] (auto output){ results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {-1.55740772f,0.0f,1.55740772f}; std::vector<float> gold = {-1.55740772f,0.0f,1.55740772f};
float tol = 1e-6; EXPECT(test::verify_range(results_vector, gold));
for (int i = 0; i < results_vector.size(); i++) {
EXPECT(std::abs(results_vector[i]-gold[i]) < tol);
}
} }
void reshape_test() { void reshape_test() {
...@@ -82,10 +72,7 @@ void reshape_test() { ...@@ -82,10 +72,7 @@ void reshape_test() {
auto result = p.eval({}); auto result = p.eval({});
std::vector<float> results_vector(3); std::vector<float> results_vector(3);
result.visit([&] (auto output){ results_vector.assign(output.begin(), output.end()); }); result.visit([&] (auto output){ results_vector.assign(output.begin(), output.end()); });
float tol = 1e-8; EXPECT(test::verify_range(results_vector, data));
for (int i = 0; i < results_vector.size(); i++) {
EXPECT(std::abs(results_vector[i]-data[i]) < tol);
}
} }
{ {
rtg::program p; rtg::program p;
...@@ -96,10 +83,7 @@ void reshape_test() { ...@@ -96,10 +83,7 @@ void reshape_test() {
auto result = p.eval({}); auto result = p.eval({});
std::vector<float> results_vector(3); std::vector<float> results_vector(3);
result.visit([&] (auto output){ results_vector.assign(output.begin(), output.end()); }); result.visit([&] (auto output){ results_vector.assign(output.begin(), output.end()); });
float tol = 1e-8; EXPECT(test::verify_range(results_vector, data));
for (int i = 0; i < results_vector.size(); i++) {
EXPECT(std::abs(results_vector[i]-data[i]) < tol);
}
} }
{ {
rtg::program p; rtg::program p;
...@@ -110,10 +94,7 @@ void reshape_test() { ...@@ -110,10 +94,7 @@ void reshape_test() {
auto result = p.eval({}); auto result = p.eval({});
std::vector<float> results_vector(3); std::vector<float> results_vector(3);
result.visit([&] (auto output){ results_vector.assign(output.begin(), output.end()); }); result.visit([&] (auto output){ results_vector.assign(output.begin(), output.end()); });
float tol = 1e-8; EXPECT(test::verify_range(results_vector, data));
for (int i = 0; i < results_vector.size(); i++) {
EXPECT(std::abs(results_vector[i]-data[i]) < tol);
}
} }
} }
...@@ -223,10 +204,7 @@ void softmax_test() { ...@@ -223,10 +204,7 @@ void softmax_test() {
auto result = p.eval({}); auto result = p.eval({});
std::vector<float> results_vector(120); std::vector<float> results_vector(120);
result.visit([&] (auto output){ results_vector.assign(output.begin(), output.end()); }); result.visit([&] (auto output){ results_vector.assign(output.begin(), output.end()); });
float tol = 1e-6; EXPECT(test::verify_range(results_vector, s));
for (int i = 0; i < results_vector.size(); i++) {
EXPECT(std::abs(results_vector[i]-s[i]) < tol);
}
} }
void conv2d_test() { void conv2d_test() {
...@@ -288,10 +266,7 @@ void conv2d_test() { ...@@ -288,10 +266,7 @@ void conv2d_test() {
std::vector<float> results_vector(16); std::vector<float> results_vector(16);
result.visit([&] (auto output){ results_vector.assign(output.begin(), output.end()); }); result.visit([&] (auto output){ results_vector.assign(output.begin(), output.end()); });
float tol = 1e-6; EXPECT(test::verify_range(results_vector, s));
for (int i = 0; i < results_vector.size(); i++) {
EXPECT(std::abs(results_vector[i]-s[i]) < tol);
}
} }
void conv2d_padding_test() { void conv2d_padding_test() {
...@@ -355,10 +330,7 @@ void conv2d_padding_test() { ...@@ -355,10 +330,7 @@ void conv2d_padding_test() {
std::vector<float> results_vector(64); std::vector<float> results_vector(64);
result.visit([&] (auto output){ results_vector.assign(output.begin(), output.end()); }); result.visit([&] (auto output){ results_vector.assign(output.begin(), output.end()); });
float tol = 1e-6; EXPECT(test::verify_range(results_vector, s));
for (int i = 0; i < results_vector.size(); i++) {
EXPECT(std::abs(results_vector[i]-s[i]) < tol);
}
} }
void conv2d_padding_stride_test() { void conv2d_padding_stride_test() {
...@@ -413,10 +385,7 @@ void conv2d_padding_stride_test() { ...@@ -413,10 +385,7 @@ void conv2d_padding_stride_test() {
std::vector<float> results_vector(16); std::vector<float> results_vector(16);
result.visit([&] (auto output){ results_vector.assign(output.begin(), output.end()); }); result.visit([&] (auto output){ results_vector.assign(output.begin(), output.end()); });
float tol = 1e-6; EXPECT(test::verify_range(results_vector, s));
for (int i = 0; i < results_vector.size(); i++) {
EXPECT(std::abs(results_vector[i]-s[i]) < tol);
}
} }
int main() int main()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment