Skip to content

Commit c6e4981

Browse files
[test] Improve testing logging and accuracy
Logging only the number of diff does not help solving or reproducing bug, so log every comparison instead. Get rid of usuned types / functions from test_utils.h No functional change intended.
1 parent 4baba66 commit c6e4981

16 files changed

+309
-582
lines changed

test/test_arch.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,12 @@ TEST_CASE("[multi arch support]")
204204
{
205205
// make sure load_aligned / load_unaligned work for the default arch and
206206
// return the appropriate type.
207-
using type_list = xsimd::mpl::type_list<short, int, long, float, std::complex<float>
207+
try_loads<short, int, long, float, std::complex<float>
208208
#if XSIMD_WITH_NEON64 || !XSIMD_WITH_NEON
209-
,
210-
double, std::complex<double>
209+
,
210+
double, std::complex<double>
211211
#endif
212-
>;
213-
try_loads<type_list>();
212+
>();
214213
}
215214
}
216215

test/test_batch.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -920,35 +920,35 @@ struct batch_test
920920
return batch_type::load_unaligned(rhs.data());
921921
}
922922

923-
template <class T = value_type>
924-
xsimd::enable_integral_t<T, void> init_operands()
923+
void init_operands()
925924
{
926-
for (size_t i = 0; i < size; ++i)
925+
XSIMD_IF_CONSTEXPR(std::is_integral<value_type>::value)
927926
{
928-
bool negative_lhs = std::is_signed<T>::value && (i % 2 == 1);
929-
lhs[i] = value_type(i) * (negative_lhs ? -3 : 3);
930-
if (lhs[i] == value_type(0))
927+
for (size_t i = 0; i < size; ++i)
931928
{
932-
lhs[i] += value_type(1);
929+
bool negative_lhs = std::is_signed<value_type>::value && (i % 2 == 1);
930+
lhs[i] = value_type(i) * (negative_lhs ? -3 : 3);
931+
if (lhs[i] == value_type(0))
932+
{
933+
lhs[i] += value_type(1);
934+
}
935+
rhs[i] = value_type(i) + value_type(2);
933936
}
934-
rhs[i] = value_type(i) + value_type(2);
937+
scalar = value_type(3);
935938
}
936-
scalar = value_type(3);
937-
}
938-
939-
template <class T = value_type>
940-
xsimd::enable_floating_point_t<T, void> init_operands()
941-
{
942-
for (size_t i = 0; i < size; ++i)
939+
else
943940
{
944-
lhs[i] = value_type(i) / 4 + value_type(1.2) * std::sqrt(value_type(i + 0.25));
945-
if (lhs[i] == value_type(0))
941+
for (size_t i = 0; i < size; ++i)
946942
{
947-
lhs[i] += value_type(0.1);
943+
lhs[i] = value_type(i) / 4 + value_type(1.2) * std::sqrt(value_type(i + 0.25));
944+
if (lhs[i] == value_type(0))
945+
{
946+
lhs[i] += value_type(0.1);
947+
}
948+
rhs[i] = value_type(10.2) / (i + 2) + value_type(0.25);
948949
}
949-
rhs[i] = value_type(10.2) / (i + 2) + value_type(0.25);
950+
scalar = value_type(1.2);
950951
}
951-
scalar = value_type(1.2);
952952
}
953953
};
954954

test/test_complex_exponential.cpp

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ struct complex_exponential_test
2929
vector_type huge_exp_input;
3030
vector_type log_input;
3131
vector_type expected;
32-
vector_type res;
3332

3433
complex_exponential_test()
3534
{
@@ -46,23 +45,21 @@ struct complex_exponential_test
4645
real_value_type(0.002 + i * 110 / nb_input));
4746
}
4847
expected.resize(nb_input);
49-
res.resize(nb_input);
5048
}
5149

5250
void test_exp()
5351
{
5452
std::transform(exp_input.cbegin(), exp_input.cend(), expected.begin(),
5553
[](const value_type& v)
5654
{ using std::exp; return exp(v); });
57-
batch_type in, out;
5855
for (size_t i = 0; i < nb_input; i += size)
5956
{
57+
batch_type in, out, ref;
6058
detail::load_batch(in, exp_input, i);
6159
out = exp(in);
62-
detail::store_batch(out, res, i);
60+
detail::load_batch(ref, expected, i);
61+
CHECK_BATCH_EQ(ref, out);
6362
}
64-
size_t diff = detail::get_nb_diff(res, expected);
65-
CHECK_EQ(diff, 0);
6663
}
6764

6865
void test_expm1()
@@ -71,111 +68,104 @@ struct complex_exponential_test
7168
[](const value_type& v)
7269
{ using xsimd::expm1; return expm1(v); });
7370

74-
batch_type in, out;
7571
for (size_t i = 0; i < nb_input; i += size)
7672
{
73+
batch_type in, out, ref;
7774
detail::load_batch(in, exp_input, i);
7875
out = expm1(in);
79-
detail::store_batch(out, res, i);
76+
detail::load_batch(ref, expected, i);
77+
CHECK_BATCH_EQ(ref, out);
8078
}
81-
size_t diff = detail::get_nb_diff(res, expected);
82-
CHECK_EQ(diff, 0);
8379
}
8480

8581
void test_huge_exp()
8682
{
8783
std::transform(huge_exp_input.cbegin(), huge_exp_input.cend(), expected.begin(),
8884
[](const value_type& v)
8985
{ using std::exp; return exp(v); });
90-
batch_type in, out;
9186
for (size_t i = 0; i < nb_input; i += size)
9287
{
88+
batch_type in, out, ref;
9389
detail::load_batch(in, huge_exp_input, i);
9490
out = exp(in);
95-
detail::store_batch(out, res, i);
91+
detail::load_batch(ref, expected, i);
92+
CHECK_BATCH_EQ(ref, out);
9693
}
97-
size_t diff = detail::get_nb_diff(res, expected);
98-
CHECK_EQ(diff, 0);
9994
}
10095

10196
void test_log()
10297
{
10398
std::transform(log_input.cbegin(), log_input.cend(), expected.begin(),
10499
[](const value_type& v)
105100
{ using std::log; return log(v); });
106-
batch_type in, out;
107101
for (size_t i = 0; i < nb_input; i += size)
108102
{
103+
batch_type in, out, ref;
109104
detail::load_batch(in, log_input, i);
110105
out = log(in);
111-
detail::store_batch(out, res, i);
106+
detail::load_batch(ref, expected, i);
107+
CHECK_BATCH_EQ(ref, out);
112108
}
113-
size_t diff = detail::get_nb_diff(res, expected);
114-
CHECK_EQ(diff, 0);
115109
}
116110

117111
void test_log2()
118112
{
119113
std::transform(log_input.cbegin(), log_input.cend(), expected.begin(),
120114
[](const value_type& v)
121115
{ using xsimd::log2; return log2(v); });
122-
batch_type in, out;
123116
for (size_t i = 0; i < nb_input; i += size)
124117
{
118+
batch_type in, out, ref;
125119
detail::load_batch(in, log_input, i);
126120
out = log2(in);
127-
detail::store_batch(out, res, i);
121+
detail::load_batch(ref, expected, i);
122+
CHECK_BATCH_EQ(ref, out);
128123
}
129-
size_t diff = detail::get_nb_diff(res, expected);
130-
CHECK_EQ(diff, 0);
131124
}
132125

133126
void test_log10()
134127
{
135128
std::transform(log_input.cbegin(), log_input.cend(), expected.begin(),
136129
[](const value_type& v)
137130
{ using std::log10; return log10(v); });
138-
batch_type in, out;
139131
for (size_t i = 0; i < nb_input; i += size)
140132
{
133+
batch_type in, out, ref;
141134
detail::load_batch(in, log_input, i);
142135
out = log10(in);
143-
detail::store_batch(out, res, i);
136+
detail::load_batch(ref, expected, i);
137+
CHECK_BATCH_EQ(ref, out);
144138
}
145-
size_t diff = detail::get_nb_diff(res, expected);
146-
CHECK_EQ(diff, 0);
147139
}
148140

149141
void test_log1p()
150142
{
151143
std::transform(log_input.cbegin(), log_input.cend(), expected.begin(),
152144
[](const value_type& v)
153145
{ using xsimd::log1p; return log1p(v); });
154-
batch_type in, out;
155146
for (size_t i = 0; i < nb_input; i += size)
156147
{
148+
batch_type in, out, ref;
157149
detail::load_batch(in, log_input, i);
158150
out = log1p(in);
159-
detail::store_batch(out, res, i);
151+
detail::load_batch(ref, expected, i);
152+
CHECK_BATCH_EQ(ref, out);
160153
}
161-
size_t diff = detail::get_nb_diff(res, expected);
162-
CHECK_EQ(diff, 0);
163154
}
164155

165156
void test_sign()
166157
{
167158
std::transform(log_input.cbegin(), log_input.cend(), expected.begin(),
168159
[](const value_type& v)
169160
{ using xsimd::sign; return sign(v); });
170-
batch_type in, out;
171161
for (size_t i = 0; i < nb_input; i += size)
172162
{
163+
batch_type in, out, ref;
173164
detail::load_batch(in, log_input, i);
174165
out = sign(in);
175-
detail::store_batch(out, res, i);
166+
detail::load_batch(ref, expected, i);
167+
CHECK_BATCH_EQ(ref, out);
176168
}
177-
size_t diff = detail::get_nb_diff(res, expected);
178-
CHECK_EQ(diff, 0);
179169
}
180170
};
181171

test/test_complex_hyperbolic.cpp

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ struct complex_hyperbolic_test
2929
vector_type acosh_input;
3030
vector_type atanh_input;
3131
vector_type expected;
32-
vector_type res;
3332

3433
complex_hyperbolic_test()
3534
{
@@ -47,103 +46,96 @@ struct complex_hyperbolic_test
4746
real_value_type(-0.94) + i * real_value_type(1.8) / nb_input);
4847
}
4948
expected.resize(nb_input);
50-
res.resize(nb_input);
5149
}
5250

5351
void test_sinh()
5452
{
5553
std::transform(input.cbegin(), input.cend(), expected.begin(),
5654
[](const value_type& v)
5755
{ using std::sinh; return sinh(v); });
58-
batch_type in, out;
5956
for (size_t i = 0; i < nb_input; i += size)
6057
{
58+
batch_type in, out, ref;
6159
detail::load_batch(in, input, i);
6260
out = sinh(in);
63-
detail::store_batch(out, res, i);
61+
detail::load_batch(ref, expected, i);
62+
CHECK_BATCH_EQ(ref, out);
6463
}
65-
size_t diff = detail::get_nb_diff(res, expected);
66-
CHECK_EQ(diff, 0);
6764
}
6865

6966
void test_cosh()
7067
{
7168
std::transform(input.cbegin(), input.cend(), expected.begin(),
7269
[](const value_type& v)
7370
{ using std::cosh; return cosh(v); });
74-
batch_type in, out;
7571
for (size_t i = 0; i < nb_input; i += size)
7672
{
73+
batch_type in, out, ref;
7774
detail::load_batch(in, input, i);
7875
out = cosh(in);
79-
detail::store_batch(out, res, i);
76+
detail::load_batch(ref, expected, i);
77+
CHECK_BATCH_EQ(ref, out);
8078
}
81-
size_t diff = detail::get_nb_diff(res, expected);
82-
CHECK_EQ(diff, 0);
8379
}
8480

8581
void test_tanh()
8682
{
8783
std::transform(input.cbegin(), input.cend(), expected.begin(),
8884
[](const value_type& v)
8985
{ using std::tanh; return tanh(v); });
90-
batch_type in, out;
9186
for (size_t i = 0; i < nb_input; i += size)
9287
{
88+
batch_type in, out, ref;
9389
detail::load_batch(in, input, i);
9490
out = tanh(in);
95-
detail::store_batch(out, res, i);
91+
detail::load_batch(ref, expected, i);
92+
CHECK_BATCH_EQ(ref, out);
9693
}
97-
size_t diff = detail::get_nb_diff(res, expected);
98-
CHECK_EQ(diff, 0);
9994
}
10095

10196
void test_asinh()
10297
{
10398
std::transform(input.cbegin(), input.cend(), expected.begin(),
10499
[](const value_type& v)
105100
{ using std::asinh; return asinh(v); });
106-
batch_type in, out;
107101
for (size_t i = 0; i < nb_input; i += size)
108102
{
103+
batch_type in, out, ref;
109104
detail::load_batch(in, input, i);
110105
out = asinh(in);
111-
detail::store_batch(out, res, i);
106+
detail::load_batch(ref, expected, i);
107+
CHECK_BATCH_EQ(ref, out);
112108
}
113-
size_t diff = detail::get_nb_diff(res, expected);
114-
CHECK_EQ(diff, 0);
115109
}
116110

117111
void test_acosh()
118112
{
119113
std::transform(acosh_input.cbegin(), acosh_input.cend(), expected.begin(),
120114
[](const value_type& v)
121115
{ using std::acosh; return acosh(v); });
122-
batch_type in, out;
123116
for (size_t i = 0; i < nb_input; i += size)
124117
{
118+
batch_type in, out, ref;
125119
detail::load_batch(in, acosh_input, i);
126120
out = acosh(in);
127-
detail::store_batch(out, res, i);
121+
detail::load_batch(ref, expected, i);
122+
CHECK_BATCH_EQ(ref, out);
128123
}
129-
size_t diff = detail::get_nb_diff(res, expected);
130-
CHECK_EQ(diff, 0);
131124
}
132125

133126
void test_atanh()
134127
{
135128
std::transform(atanh_input.cbegin(), atanh_input.cend(), expected.begin(),
136129
[](const value_type& v)
137130
{ using std::atanh; return atanh(v); });
138-
batch_type in, out;
139131
for (size_t i = 0; i < nb_input; i += size)
140132
{
133+
batch_type in, out, ref;
141134
detail::load_batch(in, atanh_input, i);
142135
out = atanh(in);
143-
detail::store_batch(out, res, i);
136+
detail::load_batch(ref, expected, i);
137+
CHECK_BATCH_EQ(ref, out);
144138
}
145-
size_t diff = detail::get_nb_diff(res, expected);
146-
CHECK_EQ(diff, 0);
147139
}
148140
};
149141

0 commit comments

Comments
 (0)