Skip to content

Commit 9836406

Browse files
authored
Merge pull request #583 from JohanMabille/xcomplex
Added missing traits for batch of complex
2 parents 6e1c486 + 75cb735 commit 9836406

File tree

5 files changed

+80
-2
lines changed

5 files changed

+80
-2
lines changed

include/xsimd/types/xsimd_batch.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ struct batch<std::complex<T>, A> {
228228
using real_batch = batch<T, A>;
229229
using arch_type = A;
230230
static constexpr std::size_t size = real_batch::size;
231+
using batch_bool_type = batch_bool<T, A>;
231232

232233
batch() = default;
233234
batch(value_type const& val) : m_real(val.real()), m_imag(val.imag()) {}

include/xsimd/types/xsimd_register.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef XSIMD_REGISTER_HPP
22
#define XSIMD_REGISTER_HPP
33

4+
#include <complex>
45
#include <type_traits>
56

67
namespace xsimd

include/xsimd/types/xsimd_traits.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,20 @@ namespace xsimd
159159
: std::enable_if<simd_condition<T1, T2>::value, batch<std::complex<T2>, A>>
160160
{
161161
};
162+
163+
#if XSIMD_ENABLE_XTL_COMPLEX
164+
template <class T1, class T2, bool I3EC, class A>
165+
struct simd_return_type_impl<xtl::xcomplex<T1, T1, I3EC>, T2, A>
166+
: std::enable_if<simd_condition<T1, T2>::value, batch<std::complex<T2>, A>>
167+
{
168+
};
169+
170+
template <class T1, class T2, bool I3EC, class A>
171+
struct simd_return_type_impl<xtl::xcomplex<T1, T1, I3EC>, xtl::xcomplex<T2, T2, I3EC>, A>
172+
: std::enable_if<simd_condition<T1, T2>::value, batch<std::complex<T2>, A>>
173+
{
174+
};
175+
#endif
162176
}
163177

164178
template <class T1, class T2, class A = default_arch>

test/test_batch_complex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class batch_complex_test : public testing::Test
2121
{
2222
protected:
2323

24-
using batch_type = B;
24+
using batch_type = xsimd::simd_type<typename B::value_type>;
2525
using arch_type = typename B::arch_type;
2626
using real_batch_type = typename B::real_batch;
2727
using value_type = typename B::value_type;

test/test_traits.cpp

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class traits_test : public testing::Test
4747
using rtype1 = xsimd::simd_return_type<value_type, float>;
4848
constexpr bool res1 = std::is_same<rtype1, xsimd::batch<float>>::value;
4949
EXPECT_TRUE(res1);
50-
50+
5151
using rtype2 = xsimd::simd_return_type<bool, value_type>;
5252
constexpr bool res2 = std::is_same<rtype2, xsimd::batch_bool<value_type>>::value;
5353
EXPECT_TRUE(res2);
@@ -71,3 +71,65 @@ TYPED_TEST(traits_test, simd_return_type)
7171
this->test_simd_return_type();
7272
}
7373

74+
template <class B>
75+
class complex_traits_test : public testing::Test
76+
{
77+
protected:
78+
79+
using batch_type = B;
80+
using value_type = typename B::value_type;
81+
82+
void test_simd_traits()
83+
{
84+
using traits_type = xsimd::simd_traits<value_type>;
85+
EXPECT_EQ(traits_type::size, batch_type::size);
86+
constexpr bool same_type = std::is_same<B, typename traits_type::type>::value;
87+
EXPECT_TRUE(same_type);
88+
using batch_bool_type = xsimd::batch_bool<typename value_type::value_type>;
89+
constexpr bool same_bool_type = std::is_same<batch_bool_type, typename traits_type::bool_type>::value;
90+
EXPECT_TRUE(same_bool_type);
91+
92+
using vector_traits_type = xsimd::simd_traits<std::vector<value_type>>;
93+
EXPECT_EQ(vector_traits_type::size, 1);
94+
constexpr bool vec_same_type = std::is_same<typename vector_traits_type::type, std::vector<value_type>>::value;
95+
EXPECT_TRUE(vec_same_type);
96+
}
97+
98+
void test_revert_simd_traits()
99+
{
100+
using traits_type = xsimd::revert_simd_traits<batch_type>;
101+
EXPECT_EQ(traits_type::size, batch_type::size);
102+
constexpr bool same_type = std::is_same<value_type, typename traits_type::type>::value;
103+
EXPECT_TRUE(same_type);
104+
}
105+
106+
void test_simd_return_type()
107+
{
108+
using rtype1 = xsimd::simd_return_type<value_type, float>;
109+
constexpr bool res1 = std::is_same<rtype1, xsimd::batch<std::complex<float>>>::value;
110+
EXPECT_TRUE(res1);
111+
112+
using rtype2 = xsimd::simd_return_type<bool, value_type>;
113+
constexpr bool res2 = std::is_same<rtype2, xsimd::batch_bool<value_type>>::value;
114+
EXPECT_TRUE(res2);
115+
}
116+
};
117+
118+
TYPED_TEST_SUITE(complex_traits_test, batch_complex_types, simd_test_names);
119+
120+
TYPED_TEST(complex_traits_test, simd_traits)
121+
{
122+
this->test_simd_traits();
123+
}
124+
125+
TYPED_TEST(complex_traits_test, revert_simd_traits)
126+
{
127+
this->test_revert_simd_traits();
128+
}
129+
130+
TYPED_TEST(complex_traits_test, simd_return_type)
131+
{
132+
this->test_simd_return_type();
133+
}
134+
135+

0 commit comments

Comments
 (0)