Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/xsimd/types/xsimd_batch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ struct batch<std::complex<T>, A> {
using real_batch = batch<T, A>;
using arch_type = A;
static constexpr std::size_t size = real_batch::size;
using batch_bool_type = batch_bool<T, A>;

batch() = default;
batch(value_type const& val) : m_real(val.real()), m_imag(val.imag()) {}
Expand Down
1 change: 1 addition & 0 deletions include/xsimd/types/xsimd_register.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef XSIMD_REGISTER_HPP
#define XSIMD_REGISTER_HPP

#include <complex>
#include <type_traits>

namespace xsimd
Expand Down
14 changes: 14 additions & 0 deletions include/xsimd/types/xsimd_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ namespace xsimd
: std::enable_if<simd_condition<T1, T2>::value, batch<std::complex<T2>, A>>
{
};

#if XSIMD_ENABLE_XTL_COMPLEX
template <class T1, class T2, bool I3EC, class A>
struct simd_return_type_impl<xtl::xcomplex<T1, T1, I3EC>, T2, A>
: std::enable_if<simd_condition<T1, T2>::value, batch<std::complex<T2>, A>>
{
};

template <class T1, class T2, bool I3EC, class A>
struct simd_return_type_impl<xtl::xcomplex<T1, T1, I3EC>, xtl::xcomplex<T2, T2, I3EC>, A>
: std::enable_if<simd_condition<T1, T2>::value, batch<std::complex<T2>, A>>
{
};
#endif
}

template <class T1, class T2, class A = default_arch>
Expand Down
2 changes: 1 addition & 1 deletion test/test_batch_complex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class batch_complex_test : public testing::Test
{
protected:

using batch_type = B;
using batch_type = xsimd::simd_type<typename B::value_type>;
using arch_type = typename B::arch_type;
using real_batch_type = typename B::real_batch;
using value_type = typename B::value_type;
Expand Down
64 changes: 63 additions & 1 deletion test/test_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class traits_test : public testing::Test
using rtype1 = xsimd::simd_return_type<value_type, float>;
constexpr bool res1 = std::is_same<rtype1, xsimd::batch<float>>::value;
EXPECT_TRUE(res1);

using rtype2 = xsimd::simd_return_type<bool, value_type>;
constexpr bool res2 = std::is_same<rtype2, xsimd::batch_bool<value_type>>::value;
EXPECT_TRUE(res2);
Expand All @@ -71,3 +71,65 @@ TYPED_TEST(traits_test, simd_return_type)
this->test_simd_return_type();
}

template <class B>
class complex_traits_test : public testing::Test
{
protected:

using batch_type = B;
using value_type = typename B::value_type;

void test_simd_traits()
{
using traits_type = xsimd::simd_traits<value_type>;
EXPECT_EQ(traits_type::size, batch_type::size);
constexpr bool same_type = std::is_same<B, typename traits_type::type>::value;
EXPECT_TRUE(same_type);
using batch_bool_type = xsimd::batch_bool<typename value_type::value_type>;
constexpr bool same_bool_type = std::is_same<batch_bool_type, typename traits_type::bool_type>::value;
EXPECT_TRUE(same_bool_type);

using vector_traits_type = xsimd::simd_traits<std::vector<value_type>>;
EXPECT_EQ(vector_traits_type::size, 1);
constexpr bool vec_same_type = std::is_same<typename vector_traits_type::type, std::vector<value_type>>::value;
EXPECT_TRUE(vec_same_type);
}

void test_revert_simd_traits()
{
using traits_type = xsimd::revert_simd_traits<batch_type>;
EXPECT_EQ(traits_type::size, batch_type::size);
constexpr bool same_type = std::is_same<value_type, typename traits_type::type>::value;
EXPECT_TRUE(same_type);
}

void test_simd_return_type()
{
using rtype1 = xsimd::simd_return_type<value_type, float>;
constexpr bool res1 = std::is_same<rtype1, xsimd::batch<std::complex<float>>>::value;
EXPECT_TRUE(res1);

using rtype2 = xsimd::simd_return_type<bool, value_type>;
constexpr bool res2 = std::is_same<rtype2, xsimd::batch_bool<value_type>>::value;
EXPECT_TRUE(res2);
}
};

TYPED_TEST_SUITE(complex_traits_test, batch_complex_types, simd_test_names);

TYPED_TEST(complex_traits_test, simd_traits)
{
this->test_simd_traits();
}

TYPED_TEST(complex_traits_test, revert_simd_traits)
{
this->test_revert_simd_traits();
}

TYPED_TEST(complex_traits_test, simd_return_type)
{
this->test_simd_return_type();
}