Skip to content

Commit aad2337

Browse files
committed
Test batch_constant from array
1 parent 98c4a59 commit aad2337

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

test/test_batch_constant.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* The full license is in the file LICENSE, distributed with this software. *
1010
****************************************************************************/
1111

12+
#include <numeric>
13+
1214
#include "xsimd/xsimd.hpp"
1315
#ifndef XSIMD_NO_SUPPORTED_ARCHITECTURE
1416

@@ -43,6 +45,22 @@ struct constant_batch_test
4345
CHECK_BATCH_EQ((batch_type)b, expected);
4446
}
4547

48+
void test_init_from_array() const
49+
{
50+
#if __cplusplus >= 202002L
51+
constexpr array_type expected = []()
52+
{
53+
array_type out = {};
54+
std::iota(out.begin(), out.end(), 0);
55+
return out;
56+
}();
57+
58+
constexpr auto b = xsimd::make_batch_constant<expected, arch_type>();
59+
INFO("batch(value_type)");
60+
CHECK_BATCH_EQ((batch_type)b, expected);
61+
#endif
62+
}
63+
4664
void test_init_from_generator() const
4765
{
4866
array_type expected;
@@ -217,6 +235,8 @@ TEST_CASE_TEMPLATE("[constant batch]", B, BATCH_INT_TYPES)
217235
constant_batch_test<B> Test;
218236
SUBCASE("init_from_constant") { Test.test_init_from_constant(); }
219237

238+
SUBCASE("test_init_from_array") { Test.test_init_from_array(); }
239+
220240
SUBCASE("init_from_generator") { Test.test_init_from_generator(); }
221241

222242
SUBCASE("as_batch") { Test.test_cast(); }
@@ -263,6 +283,25 @@ struct constant_bool_batch_test
263283
CHECK_BATCH_EQ((batch_bool_type)b, expected);
264284
}
265285

286+
void test_init_from_array() const
287+
{
288+
#if __cplusplus >= 202002L
289+
constexpr bool_array_type expected = []()
290+
{
291+
bool_array_type out = {};
292+
for (std::size_t k = 0; k < out.size(); ++k)
293+
{
294+
out[k] = k % 2 == 0;
295+
}
296+
return out;
297+
}();
298+
299+
constexpr auto b = xsimd::make_batch_bool_constant<value_type, expected, arch_type>();
300+
INFO("batch_bool_constant(value_type)");
301+
CHECK_BATCH_EQ((batch_bool_type)b, expected);
302+
#endif
303+
}
304+
266305
void test_init_from_generator() const
267306
{
268307
bool_array_type expected;
@@ -357,6 +396,8 @@ TEST_CASE_TEMPLATE("[constant bool batch]", B, BATCH_INT_TYPES)
357396
constant_bool_batch_test<B> Test;
358397
SUBCASE("init_from_constant") { Test.test_init_from_constant(); }
359398

399+
SUBCASE("test_init_from_array") { Test.test_init_from_array(); }
400+
360401
SUBCASE("init_from_generator") { Test.test_init_from_generator(); }
361402

362403
SUBCASE("as_batch") { Test.test_cast(); }

0 commit comments

Comments
 (0)