Skip to content

Commit ccf4ff9

Browse files
authored
Merge pull request #426 from JohanMabille/test
Test refactoring
2 parents 1df22d6 + bfb95ef commit ccf4ff9

File tree

66 files changed

+5993
-10782
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+5993
-10782
lines changed

include/xsimd/types/xsimd_complex_base.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ namespace xsimd
212212
real_batch m_imag;
213213
};
214214

215+
template <class X>
216+
X operator+(const simd_complex_batch<X>& rhs);
217+
215218
template <class X>
216219
X operator-(const simd_complex_batch<X>& rhs);
217220

@@ -877,6 +880,20 @@ namespace xsimd
877880
* @defgroup simd_complex_batch_arithmetic Arithmetic operators
878881
*/
879882

883+
/**
884+
* @ingroup simd_complex_batch_arithmetic
885+
*
886+
* No-op on \c rhs.
887+
* @tparam X the actual type of batch.
888+
* @param rhs batch involved in the operation.
889+
* @return the opposite of \c rhs.
890+
*/
891+
template <class X>
892+
inline X operator+(const simd_complex_batch<X>& rhs)
893+
{
894+
return rhs();
895+
}
896+
880897
/**
881898
* @ingroup simd_complex_batch_arithmetic
882899
*

include/xsimd/types/xsimd_fallback.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,12 +523,12 @@ namespace xsimd
523523

524524
static batch_type bitwise_not(const batch_type& rhs)
525525
{
526-
XSIMD_FALLBACK_UNARY_OP(batch_bool, ~, rhs)
526+
XSIMD_FALLBACK_UNARY_OP(batch_bool, !, rhs)
527527
}
528528

529529
static batch_type bitwise_andnot(const batch_type& lhs, const batch_type& rhs)
530530
{
531-
XSIMD_FALLBACK_MAPPING_LOOP(batch_bool, (~(lhs[i] & rhs[i])))
531+
XSIMD_FALLBACK_MAPPING_LOOP(batch_bool, (!(lhs[i] & rhs[i])))
532532
}
533533

534534
static batch_type equal(const batch_type& lhs, const batch_type& rhs)

test/CMakeLists.txt

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,33 @@ include_directories(${GTEST_INCLUDE_DIRS})
142142

143143
set(XSIMD_TESTS
144144
main.cpp
145-
xsimd_api_test.hpp
145+
test_algorithms.cpp
146+
test_api.cpp
147+
test_basic_math.cpp
148+
test_batch.cpp
149+
test_batch_bool.cpp
150+
test_batch_cast.cpp
151+
test_batch_complex.cpp
152+
test_batch_float.cpp
153+
test_batch_int.cpp
154+
test_bitwise_cast.cpp
155+
test_complex_exponential.cpp
156+
test_complex_hyperbolic.cpp
157+
test_complex_power.cpp
158+
test_complex_trigonometric.cpp
159+
test_conversion.cpp
160+
test_error_gamma.cpp
161+
test_exponential.cpp
162+
test_fp_manipulation.cpp
163+
test_hyperbolic.cpp
164+
test_load_store.cpp
165+
test_memory.cpp
166+
test_poly_evaluation.cpp
167+
test_power.cpp
168+
test_rounding.cpp
169+
test_trigonometric.cpp
170+
test_utils.hpp
171+
#[[ xsimd_api_test.hpp
146172
xsimd_api_test.cpp
147173
xsimd_algorithms.cpp
148174
xsimd_basic_test.hpp
@@ -178,7 +204,7 @@ set(XSIMD_TESTS
178204
xsimd_tester.hpp
179205
xsimd_test_utils.hpp
180206
xsimd_trigonometric_test.hpp
181-
xsimd_trigonometric_test.cpp
207+
xsimd_trigonometric_test.cpp]]
182208
)
183209

184210
add_executable(test_xsimd ${XSIMD_TESTS} ${XSIMD_HEADERS})

test/downloadGTest.cmake.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ project(googletest-download NONE)
1414

1515
include(ExternalProject)
1616
ExternalProject_Add(googletest
17-
GIT_REPOSITORY https://github.com/google/googletest.git
18-
GIT_TAG release-1.8.1
17+
GIT_REPOSITORY https://github.com/JohanMabille/googletest.git
18+
GIT_TAG no_werror
1919
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src"
2020
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build"
2121
CONFIGURE_COMMAND ""
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,8 @@
88
* The full license is in the file LICENSE, distributed with this software. *
99
****************************************************************************/
1010

11-
#include <fstream>
12-
#include <iostream>
1311
#include <numeric>
14-
15-
#include "xsimd/xsimd.hpp"
16-
17-
#include "gtest/gtest.h"
12+
#include "test_utils.hpp"
1813

1914
struct binary_functor
2015
{
@@ -42,7 +37,7 @@ template <class T>
4237
using test_allocator_type = std::allocator<T>;
4338
#endif
4439

45-
TEST(xsimd, binary_transform)
40+
TEST(algorithms, binary_transform)
4641
{
4742
std::vector<double> expected(93);
4843

@@ -89,7 +84,7 @@ TEST(xsimd, binary_transform)
8984
}
9085

9186

92-
TEST(xsimd, unary_transform)
87+
TEST(algorithms, unary_transform)
9388
{
9489
std::vector<double> expected(93);
9590
std::vector<double> a(93, 123), c(93);
@@ -222,7 +217,7 @@ TEST_F(xsimd_reduce, using_custom_binary_function)
222217
}
223218

224219
#if XSIMD_X86_INSTR_SET > XSIMD_VERSION_NUMBER_NOT_AVAILABLE || XSIMD_ARM_INSTR_SET > XSIMD_VERSION_NUMBER_NOT_AVAILABLE
225-
TEST(xsimd, iterator)
220+
TEST(algorithms, iterator)
226221
{
227222
std::vector<float, test_allocator_type<float>> a(10 * 16, 0.2), b(1000, 2.), c(1000, 3.);
228223

test/test_api.cpp

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
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 <random>
12+
13+
#include "test_utils.hpp"
14+
15+
template <class B>
16+
class xsimd_api_test : public testing::Test
17+
{
18+
protected:
19+
20+
using batch_type = B;
21+
using value_type = typename B::value_type;
22+
static constexpr size_t size = B::size;
23+
using array_type = std::array<value_type, size>;
24+
using int8_vector_type = std::vector<int8_t, XSIMD_DEFAULT_ALLOCATOR(int8_t)>;
25+
using uint8_vector_type = std::vector<uint8_t, XSIMD_DEFAULT_ALLOCATOR(uint8_t)>;
26+
using int16_vector_type = std::vector<int16_t, XSIMD_DEFAULT_ALLOCATOR(int16_t)>;
27+
using uint16_vector_type = std::vector<uint16_t, XSIMD_DEFAULT_ALLOCATOR(uint16_t)>;
28+
using int32_vector_type = std::vector<int32_t, XSIMD_DEFAULT_ALLOCATOR(int32_t)>;
29+
using uint32_vector_type = std::vector<uint32_t, XSIMD_DEFAULT_ALLOCATOR(uint32_t)>;
30+
using int64_vector_type = std::vector<int64_t, XSIMD_DEFAULT_ALLOCATOR(int64_t)>;
31+
using uint64_vector_type = std::vector<uint64_t, XSIMD_DEFAULT_ALLOCATOR(uint64_t)>;
32+
using float_vector_type = std::vector<float, XSIMD_DEFAULT_ALLOCATOR(float)>;
33+
using double_vector_type = std::vector<double, XSIMD_DEFAULT_ALLOCATOR(double)>;
34+
35+
int8_vector_type i8_vec;
36+
uint8_vector_type ui8_vec;
37+
int16_vector_type i16_vec;
38+
uint16_vector_type ui16_vec;
39+
int32_vector_type i32_vec;
40+
uint32_vector_type ui32_vec;
41+
int64_vector_type i64_vec;
42+
uint64_vector_type ui64_vec;
43+
float_vector_type f_vec;
44+
double_vector_type d_vec;
45+
46+
array_type expected;
47+
48+
xsimd_api_test()
49+
{
50+
init_test_vector(i8_vec);
51+
init_test_vector(ui8_vec);
52+
init_test_vector(i16_vec);
53+
init_test_vector(ui16_vec);
54+
init_test_vector(i32_vec);
55+
init_test_vector(ui32_vec);
56+
init_test_vector(i64_vec);
57+
init_test_vector(ui64_vec);
58+
init_test_vector(f_vec);
59+
init_test_vector(d_vec);
60+
}
61+
62+
void test_load()
63+
{
64+
test_load_impl(i8_vec, "load int8_t");
65+
test_load_impl(ui8_vec, "load uint8_t");
66+
test_load_impl(i16_vec, "load int16_t");
67+
test_load_impl(ui16_vec, "load uint16_t");
68+
test_load_impl(i32_vec, "load int32_t");
69+
test_load_impl(ui32_vec, "load uint32_t");
70+
test_load_impl(i64_vec, "load int64_t");
71+
test_load_impl(ui64_vec, "load uint64_t");
72+
test_load_impl(f_vec, "load float");
73+
test_load_impl(d_vec, "load double");
74+
}
75+
76+
void test_store()
77+
{
78+
test_store_impl(i8_vec, "load int8_t");
79+
test_store_impl(ui8_vec, "load uint8_t");
80+
test_store_impl(i16_vec, "load int16_t");
81+
test_store_impl(ui16_vec, "load uint16_t");
82+
test_store_impl(i32_vec, "load int32_t");
83+
test_store_impl(ui32_vec, "load uint32_t");
84+
test_store_impl(i64_vec, "load int64_t");
85+
test_store_impl(ui64_vec, "load uint64_t");
86+
test_store_impl(f_vec, "load float");
87+
test_store_impl(d_vec, "load double");
88+
89+
}
90+
91+
void test_set()
92+
{
93+
test_set_impl<int8_t>("set int8_t");
94+
test_set_impl<uint8_t>("set uint8_t");
95+
test_set_impl<int16_t>("set int16_t");
96+
test_set_impl<uint16_t>("set uint16_t");
97+
test_set_impl<int32_t>("set int32_t");
98+
test_set_impl<uint32_t>("set uint32_t");
99+
test_set_impl<int64_t>("set int64_t");
100+
test_set_impl<uint64_t>("set uint64_t");
101+
test_set_impl<float>("set float");
102+
test_set_impl<double>("set double");
103+
}
104+
105+
private:
106+
107+
template <class V>
108+
void test_load_impl(const V& v, const std::string& name)
109+
{
110+
using src_value_type = typename V::value_type;
111+
batch_type b;
112+
std::copy(v.cbegin(), v.cend(), expected.begin());
113+
114+
b = xsimd::load_simd<src_value_type, value_type>(v.data(), xsimd::unaligned_mode());
115+
EXPECT_BATCH_EQ(b, expected) << print_function_name(name + " unaligned");
116+
117+
b = xsimd::load_simd<src_value_type, value_type>(v.data(), xsimd::aligned_mode());
118+
EXPECT_BATCH_EQ(b, expected) << print_function_name(name + " aligned");
119+
}
120+
121+
template <class V>
122+
void test_store_impl(const V& v, const std::string& name)
123+
{
124+
using src_value_type = typename V::value_type;
125+
batch_type b = xsimd::load_simd<src_value_type, value_type>(v.data(), xsimd::aligned_mode());
126+
V res(size);
127+
128+
xsimd::store_simd<src_value_type, value_type>(res.data(), b, xsimd::unaligned_mode());
129+
EXPECT_VECTOR_EQ(res, v) << print_function_name(name + " unaligned");
130+
131+
xsimd::store_simd<src_value_type, value_type>(res.data(), b, xsimd::aligned_mode());
132+
EXPECT_VECTOR_EQ(res, v) << print_function_name(name + " aligned");
133+
}
134+
135+
template <class T>
136+
void test_set_impl(const std::string& name)
137+
{
138+
T v = T(1);
139+
batch_type expected(v);
140+
batch_type res = xsimd::set_simd<T, value_type>(v);
141+
EXPECT_BATCH_EQ(res, expected) << print_function_name(name);
142+
}
143+
144+
template <class V>
145+
void init_test_vector(V& vec)
146+
{
147+
vec.resize(size);
148+
149+
value_type min = value_type(0);
150+
value_type max = value_type(100);
151+
152+
std::default_random_engine generator;
153+
std::uniform_int_distribution<int> distribution(min, max);
154+
155+
auto gen = [&distribution, &generator](){
156+
return static_cast<value_type>(distribution(generator));
157+
};
158+
159+
std::generate(vec.begin(), vec.end(), gen);
160+
}
161+
};
162+
163+
using xsimd_api_types = testing::Types<
164+
165+
#if XSIMD_X86_INSTR_SET >= XSIMD_X86_AVX512_VERSION
166+
xsimd::batch<uint8_t, 64>,
167+
xsimd::batch<int8_t, 64>,
168+
xsimd::batch<uint16_t, 32>,
169+
xsimd::batch<int16_t, 32>,
170+
xsimd::batch<uint32_t, 16>,
171+
xsimd::batch<int32_t, 16>,
172+
xsimd::batch<uint64_t, 8>,
173+
xsimd::batch<int64_t, 8>,
174+
xsimd::batch<float, 16>,
175+
xsimd::batch<double, 8>
176+
#elif XSIMD_X86_INSTR_SET >= XSIMD_X86_AVX_VERSION
177+
xsimd::batch<uint8_t, 32>,
178+
xsimd::batch<int8_t, 32>,
179+
xsimd::batch<uint16_t, 16>,
180+
xsimd::batch<int16_t, 16>,
181+
xsimd::batch<uint32_t, 8>,
182+
xsimd::batch<int32_t, 8>,
183+
xsimd::batch<uint64_t, 4>,
184+
xsimd::batch<int64_t, 4>,
185+
xsimd::batch<float, 8>,
186+
xsimd::batch<double, 4>
187+
#elif XSIMD_X86_INSTR_SET >= XSIMD_X86_SSE2_VERSION
188+
xsimd::batch<uint8_t, 16>,
189+
xsimd::batch<int8_t, 16>,
190+
xsimd::batch<uint16_t, 8>,
191+
xsimd::batch<int16_t, 8>,
192+
xsimd::batch<uint32_t, 4>,
193+
xsimd::batch<int32_t, 4>,
194+
xsimd::batch<uint64_t, 2>,
195+
xsimd::batch<int64_t, 2>,
196+
xsimd::batch<float, 4>,
197+
xsimd::batch<double, 2>
198+
#elif XSIMD_ARM_INSTR_SET >= XSIMD_ARM7_NEON_VERSION
199+
xsimd::batch<uint8_t, 16>,
200+
xsimd::batch<int8_t, 16>,
201+
xsimd::batch<uint16_t, 8>,
202+
xsimd::batch<int16_t, 8>,
203+
xsimd::batch<uint32_t, 4>,
204+
xsimd::batch<int32_t, 4>,
205+
xsimd::batch<uint64_t, 2>,
206+
xsimd::batch<int64_t, 2>,
207+
xsimd::batch<float, 4>
208+
#if XSIMD_ARM_INSTR_SET >= XSIMD_ARM8_64_NEON_VERSION
209+
,
210+
xsimd::batch<double, 2>
211+
#endif
212+
#endif
213+
>;
214+
215+
TYPED_TEST_SUITE(xsimd_api_test, xsimd_api_types, simd_test_names);
216+
217+
TYPED_TEST(xsimd_api_test, load)
218+
{
219+
this->test_load();
220+
}
221+
222+
TYPED_TEST(xsimd_api_test, store)
223+
{
224+
this->test_store();
225+
}
226+
227+
#ifdef XSIMD_BATCH_DOUBLE_SIZE
228+
TYPED_TEST(xsimd_api_test, set)
229+
{
230+
this->test_set();
231+
}
232+
#endif

0 commit comments

Comments
 (0)