Skip to content

Commit 495a387

Browse files
Simplify test using a stack allocated array
This also happens to fix #1232, although this makes little sense to me.
1 parent 96a98f8 commit 495a387

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

test/test_api.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,29 +138,31 @@ struct xsimd_api_test
138138
batch_type b = batch_type::load(v.data(), xsimd::aligned_mode());
139139
V res(size);
140140

141-
bool* b_data = new bool[size];
141+
std::array<bool, size> b_data;
142+
143+
std::array<bool, size> b_ref;
144+
std::fill(b_ref.begin(), b_ref.end(), true);
142145

143146
xsimd::store_as(res.data(), b, xsimd::unaligned_mode());
144147
INFO(name, " unaligned");
145148
CHECK_VECTOR_EQ(res, v);
146149

147-
std::fill(b_data, b_data + size, false);
150+
std::fill(b_data.begin(), b_data.end(), false);
148151
batch_bool_type bb = (b == b);
149-
xsimd::store_as(b_data, bb, xsimd::unaligned_mode());
152+
xsimd::store_as(&b_data[0], bb, xsimd::unaligned_mode());
153+
150154
INFO(name, " batch_bool unaligned");
151-
CHECK_UNARY(std::accumulate(b_data, b_data + size, true, std::logical_and<bool>()));
155+
CHECK_ARRAY_EQ(b_ref, b_data);
152156

153157
xsimd::store_as(res.data(), b, xsimd::aligned_mode());
154158
INFO(name, " aligned");
155159
CHECK_VECTOR_EQ(res, v);
156160

157-
std::fill(b_data, b_data + size, false);
161+
std::fill(b_data.begin(), b_data.end(), false);
158162
bb = (b == b);
159-
xsimd::store_as(b_data, bb, xsimd::aligned_mode());
163+
xsimd::store_as(&b_data[0], bb, xsimd::aligned_mode());
160164
INFO(name, " batch_bool aligned");
161-
CHECK_UNARY(std::accumulate(b_data, b_data + size, true, std::logical_and<bool>()));
162-
163-
delete[] b_data;
165+
CHECK_ARRAY_EQ(b_ref, b_data);
164166
}
165167

166168
template <class T>

test/test_utils.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,13 @@ namespace detail
538538
INFO(#v2 ":", v2); \
539539
CHECK_UNARY(::detail::expect_vector_near(v1, v2)); \
540540
} while (0)
541+
#define CHECK_ARRAY_EQ(v1, v2) \
542+
do \
543+
{ \
544+
INFO(#v1 ":", v1); \
545+
INFO(#v2 ":", v2); \
546+
CHECK_UNARY(::detail::expect_array_near(v1, v2)); \
547+
} while (0)
541548

542549
namespace xsimd
543550
{

0 commit comments

Comments
 (0)