Skip to content

Commit 9717ffa

Browse files
committed
Test refactoring: complex hyperbolic
1 parent eeb8232 commit 9717ffa

File tree

2 files changed

+174
-0
lines changed

2 files changed

+174
-0
lines changed

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ set(XSIMD_TESTS
149149
test_batch_float.cpp
150150
test_batch_int.cpp
151151
test_complex_exponential.cpp
152+
test_complex_hyperbolic.cpp
152153
test_error_gamma.cpp
153154
test_exponential.cpp
154155
test_fp_manipulation.cpp

test/test_complex_hyperbolic.cpp

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
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 complex_hyperbolic_test : public testing::Test
15+
{
16+
protected:
17+
18+
using batch_type = B;
19+
using real_batch_type = typename B::real_batch;
20+
using value_type = typename B::value_type;
21+
using real_value_type = typename value_type::value_type;
22+
static constexpr size_t size = B::size;
23+
using vector_type = std::vector<value_type>;
24+
25+
size_t nb_input;
26+
vector_type input;
27+
vector_type acosh_input;
28+
vector_type atanh_input;
29+
vector_type expected;
30+
vector_type res;
31+
32+
complex_hyperbolic_test()
33+
{
34+
nb_input = 10000 * size;
35+
input.resize(nb_input);
36+
acosh_input.resize(nb_input);
37+
atanh_input.resize(nb_input);
38+
for (size_t i = 0; i < nb_input; ++i)
39+
{
40+
input[i] = value_type(real_value_type(-1.5) + i * real_value_type(3) / nb_input,
41+
real_value_type(-1.3) + i * real_value_type(2.5) / nb_input);
42+
acosh_input[i] = value_type(real_value_type(1.) + i * real_value_type(3) / nb_input,
43+
real_value_type(1.2) + i * real_value_type(2.7) / nb_input);
44+
atanh_input[i] = value_type(real_value_type(-0.95) + i * real_value_type(1.9) / nb_input,
45+
real_value_type(-0.94) + i * real_value_type(1.8) / nb_input);
46+
}
47+
expected.resize(nb_input);
48+
res.resize(nb_input);
49+
}
50+
51+
void test_sinh()
52+
{
53+
std::transform(input.cbegin(), input.cend(), expected.begin(),
54+
[](const value_type& v) { using std::sinh; return sinh(v); });
55+
batch_type in, out;
56+
for (size_t i = 0; i < nb_input; i += size)
57+
{
58+
detail::load_batch(in, input, i);
59+
out = sinh(in);
60+
detail::store_batch(out, res, i);
61+
}
62+
size_t diff = detail::get_nb_diff(res, expected);
63+
EXPECT_EQ(diff, 0) << print_function_name("sinh");
64+
}
65+
66+
void test_cosh()
67+
{
68+
std::transform(input.cbegin(), input.cend(), expected.begin(),
69+
[](const value_type& v) { using std::cosh; return cosh(v); });
70+
batch_type in, out;
71+
for (size_t i = 0; i < nb_input; i += size)
72+
{
73+
detail::load_batch(in, input, i);
74+
out = cosh(in);
75+
detail::store_batch(out, res, i);
76+
}
77+
size_t diff = detail::get_nb_diff(res, expected);
78+
EXPECT_EQ(diff, 0) << print_function_name("cosh");
79+
}
80+
81+
void test_tanh()
82+
{
83+
std::transform(input.cbegin(), input.cend(), expected.begin(),
84+
[](const value_type& v) { using std::tanh; return tanh(v); });
85+
batch_type in, out;
86+
for (size_t i = 0; i < nb_input; i += size)
87+
{
88+
detail::load_batch(in, input, i);
89+
out = tanh(in);
90+
detail::store_batch(out, res, i);
91+
}
92+
size_t diff = detail::get_nb_diff(res, expected);
93+
EXPECT_EQ(diff, 0) << print_function_name("tanh");
94+
}
95+
96+
void test_asinh()
97+
{
98+
std::transform(input.cbegin(), input.cend(), expected.begin(),
99+
[](const value_type& v) { using std::asinh; return asinh(v); });
100+
batch_type in, out;
101+
for (size_t i = 0; i < nb_input; i += size)
102+
{
103+
detail::load_batch(in, input, i);
104+
out = asinh(in);
105+
detail::store_batch(out, res, i);
106+
}
107+
size_t diff = detail::get_nb_diff(res, expected);
108+
EXPECT_EQ(diff, 0) << print_function_name("asinh");
109+
}
110+
111+
void test_acosh()
112+
{
113+
std::transform(acosh_input.cbegin(), acosh_input.cend(), expected.begin(),
114+
[](const value_type& v) { using std::acosh; return acosh(v); });
115+
batch_type in, out;
116+
for (size_t i = 0; i < nb_input; i += size)
117+
{
118+
detail::load_batch(in, acosh_input, i);
119+
out = acosh(in);
120+
detail::store_batch(out, res, i);
121+
}
122+
size_t diff = detail::get_nb_diff(res, expected);
123+
EXPECT_EQ(diff, 0) << print_function_name("acosh");
124+
}
125+
126+
void test_atanh()
127+
{
128+
std::transform(atanh_input.cbegin(), atanh_input.cend(), expected.begin(),
129+
[](const value_type& v) { using std::atanh; return atanh(v); });
130+
batch_type in, out;
131+
for (size_t i = 0; i < nb_input; i += size)
132+
{
133+
detail::load_batch(in, atanh_input, i);
134+
out = atanh(in);
135+
detail::store_batch(out, res, i);
136+
}
137+
size_t diff = detail::get_nb_diff(res, expected);
138+
EXPECT_EQ(diff, 0) << print_function_name("atanh");
139+
}
140+
};
141+
142+
TYPED_TEST_SUITE(complex_hyperbolic_test, batch_complex_types, simd_test_names);
143+
144+
TYPED_TEST(complex_hyperbolic_test, sinh)
145+
{
146+
this->test_sinh();
147+
}
148+
149+
TYPED_TEST(complex_hyperbolic_test, cosh)
150+
{
151+
this->test_cosh();
152+
}
153+
154+
TYPED_TEST(complex_hyperbolic_test, tanh)
155+
{
156+
this->test_tanh();
157+
}
158+
159+
TYPED_TEST(complex_hyperbolic_test, asinh)
160+
{
161+
this->test_asinh();
162+
}
163+
164+
TYPED_TEST(complex_hyperbolic_test, acosh)
165+
{
166+
this->test_acosh();
167+
}
168+
169+
TYPED_TEST(complex_hyperbolic_test, atanh)
170+
{
171+
this->test_atanh();
172+
}
173+

0 commit comments

Comments
 (0)