Skip to content

Commit fa6c7f4

Browse files
committed
Test refactoring: poly evaluation
1 parent 64fe019 commit fa6c7f4

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ set(XSIMD_TESTS
153153
test_hyperbolic.cpp
154154
test_interface.cpp
155155
test_memory.cpp
156+
test_poly_evaluation.cpp
156157
test_utils.hpp
157158
#[[ xsimd_api_test.hpp
158159
xsimd_api_test.cpp

test/test_poly_evaluation.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/***************************************************************************
2+
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
3+
* Martin Renou *
4+
* Copyright (c) QuantStack *
5+
* *
6+
* Distributed under the terms of the BSD 3-Clause License. *
7+
* *
8+
* The full license is in the file LICENSE, distributed with this software. *
9+
****************************************************************************/
10+
11+
#include "test_utils.hpp"
12+
13+
template <class B>
14+
class poly_evaluation_test : public testing::Test
15+
{
16+
protected:
17+
18+
using batch_type = B;
19+
using value_type = typename B::value_type;
20+
static constexpr size_t size = B::size;
21+
using vector_type = std::vector<value_type>;
22+
23+
size_t nb_input;
24+
vector_type input;
25+
vector_type horner_res;
26+
vector_type estrin_res;
27+
28+
poly_evaluation_test()
29+
{
30+
nb_input = size * 10000;
31+
input.resize(nb_input);
32+
for (size_t i = 0; i < nb_input; ++i)
33+
{
34+
input[i] = value_type(i) / 4 + value_type(1.2) * std::sqrt(value_type(i + 0.25));
35+
}
36+
horner_res.resize(nb_input);
37+
estrin_res.resize(nb_input);
38+
}
39+
40+
void test_poly_evaluation()
41+
{
42+
batch_type in, out;
43+
for (size_t i = 0; i < nb_input; i += size)
44+
{
45+
detail::load_batch(in, input, i);
46+
out = xsimd::horner<batch_type, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16>(in);
47+
detail::store_batch(out, horner_res, i);
48+
out = xsimd::estrin<batch_type, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16>(in);
49+
detail::store_batch(out, estrin_res, i);
50+
}
51+
size_t diff = detail::get_nb_diff(horner_res, estrin_res);
52+
EXPECT_EQ(diff, 0) << print_function_name("estrin");
53+
}
54+
};
55+
56+
TYPED_TEST_SUITE(poly_evaluation_test, batch_float_types, simd_test_names);
57+
58+
TYPED_TEST(poly_evaluation_test, poly_evaluation)
59+
{
60+
this->test_poly_evaluation();
61+
}

0 commit comments

Comments
 (0)