-
Notifications
You must be signed in to change notification settings - Fork 298
Expand file tree
/
Copy pathtest_complex_hyperbolic.cpp
More file actions
175 lines (158 loc) · 5.52 KB
/
test_complex_hyperbolic.cpp
File metadata and controls
175 lines (158 loc) · 5.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#include "xsimd/xsimd.hpp"
#ifndef XSIMD_NO_SUPPORTED_ARCHITECTURE
#include "test_utils.hpp"
template <class B>
struct complex_hyperbolic_test
{
using batch_type = B;
using real_batch_type = typename B::real_batch;
using value_type = typename B::value_type;
using real_value_type = typename value_type::value_type;
static constexpr size_t size = B::size;
using vector_type = std::vector<value_type>;
size_t nb_input;
vector_type input;
vector_type acosh_input;
vector_type atanh_input;
vector_type expected;
complex_hyperbolic_test()
{
nb_input = 10000 * size;
input.resize(nb_input);
acosh_input.resize(nb_input);
atanh_input.resize(nb_input);
for (size_t i = 0; i < nb_input; ++i)
{
input[i] = value_type(real_value_type(-1.5) + i * real_value_type(3) / nb_input,
real_value_type(-1.3) + i * real_value_type(2.5) / nb_input);
acosh_input[i] = value_type(real_value_type(1.) + i * real_value_type(3) / nb_input,
real_value_type(1.2) + i * real_value_type(2.7) / nb_input);
atanh_input[i] = value_type(real_value_type(-0.95) + i * real_value_type(1.9) / nb_input,
real_value_type(-0.94) + i * real_value_type(1.8) / nb_input);
}
expected.resize(nb_input);
}
void test_sinh()
{
std::transform(input.cbegin(), input.cend(), expected.begin(),
[](const value_type& v)
{ using std::sinh; return sinh(v); });
for (size_t i = 0; i < nb_input; i += size)
{
batch_type in, out, ref;
detail::load_batch(in, input, i);
out = sinh(in);
detail::load_batch(ref, expected, i);
CHECK_BATCH_EQ(ref, out);
}
}
void test_cosh()
{
std::transform(input.cbegin(), input.cend(), expected.begin(),
[](const value_type& v)
{ using std::cosh; return cosh(v); });
for (size_t i = 0; i < nb_input; i += size)
{
batch_type in, out, ref;
detail::load_batch(in, input, i);
out = cosh(in);
detail::load_batch(ref, expected, i);
CHECK_BATCH_EQ(ref, out);
}
}
void test_tanh()
{
std::transform(input.cbegin(), input.cend(), expected.begin(),
[](const value_type& v)
{ using std::tanh; return tanh(v); });
for (size_t i = 0; i < nb_input; i += size)
{
batch_type in, out, ref;
detail::load_batch(in, input, i);
out = tanh(in);
detail::load_batch(ref, expected, i);
CHECK_BATCH_EQ(ref, out);
}
}
void test_asinh()
{
std::transform(input.cbegin(), input.cend(), expected.begin(),
[](const value_type& v)
{ using std::asinh; return asinh(v); });
for (size_t i = 0; i < nb_input; i += size)
{
batch_type in, out, ref;
detail::load_batch(in, input, i);
out = asinh(in);
detail::load_batch(ref, expected, i);
CHECK_BATCH_EQ(ref, out);
}
}
void test_acosh()
{
std::transform(acosh_input.cbegin(), acosh_input.cend(), expected.begin(),
[](const value_type& v)
{ using std::acosh; return acosh(v); });
for (size_t i = 0; i < nb_input; i += size)
{
batch_type in, out, ref;
detail::load_batch(in, acosh_input, i);
out = acosh(in);
detail::load_batch(ref, expected, i);
CHECK_BATCH_EQ(ref, out);
}
}
void test_atanh()
{
std::transform(atanh_input.cbegin(), atanh_input.cend(), expected.begin(),
[](const value_type& v)
{ using std::atanh; return atanh(v); });
for (size_t i = 0; i < nb_input; i += size)
{
batch_type in, out, ref;
detail::load_batch(in, atanh_input, i);
out = atanh(in);
detail::load_batch(ref, expected, i);
CHECK_BATCH_EQ(ref, out);
}
}
};
TEST_CASE_TEMPLATE("[complex hyperbolic]", B, BATCH_COMPLEX_TYPES)
{
complex_hyperbolic_test<B> Test;
SUBCASE("sinh")
{
Test.test_sinh();
}
SUBCASE("cosh")
{
Test.test_cosh();
}
SUBCASE("tanh")
{
Test.test_tanh();
}
SUBCASE("asinh")
{
Test.test_asinh();
}
SUBCASE("acosh")
{
Test.test_acosh();
}
SUBCASE("atanh")
{
Test.test_atanh();
}
}
#endif