Skip to content

Commit e60ead6

Browse files
authored
Implemented isnan for batch of complexes (#590)
1 parent 7d8d2ca commit e60ead6

File tree

6 files changed

+30
-3
lines changed

6 files changed

+30
-3
lines changed

include/xsimd/arch/generic/xsimd_generic_complex.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ namespace xsimd {
6161
copysign(real_batch(real_value_type(0)), imag(self))),
6262
batch_type(self));
6363
}
64+
65+
template <class A, class T>
66+
batch_bool<T, A> isnan(batch<std::complex<T>, A> const& self, requires_arch<generic>) {
67+
return batch_bool<T, A>(isnan(self.real()) || isnan(self.imag()));
68+
}
6469
}
6570
}
6671

include/xsimd/arch/generic/xsimd_generic_details.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ namespace xsimd {
5959
template<class T, class A>
6060
batch_bool<T, A> isinf(batch<T, A> const& self);
6161
template<class T, class A>
62-
batch_bool<T, A> isnan(batch<T, A> const& self);
62+
typename batch<T, A>::batch_bool_type isnan(batch<T, A> const& self);
6363
template<class T, class A>
6464
batch<T, A> ldexp(const batch<T, A>& x, const batch<as_integer_t<T>, A>& e);
6565
template<class T, class A>

include/xsimd/types/xsimd_api.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ batch_bool<T, A> isfinite(batch<T, A> const& x) {
852852
* @return a batch of booleans.
853853
*/
854854
template<class T, class A>
855-
batch_bool<T, A> isnan(batch<T, A> const& x) {
855+
typename batch<T, A>::batch_bool_type isnan(batch<T, A> const& x) {
856856
return kernel::isnan<A>(x, A{});
857857
}
858858

include/xsimd/types/xsimd_traits.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ namespace xsimd
148148
{
149149
};
150150

151+
template <class T2, class A>
152+
struct simd_return_type_impl<bool, std::complex<T2>, A>
153+
: std::enable_if<simd_condition<bool, T2>::value, batch_bool<T2, A>>
154+
{
155+
};
156+
151157
template <class T1, class T2, class A>
152158
struct simd_return_type_impl<std::complex<T1>, T2, A>
153159
: std::enable_if<simd_condition<T1, T2>::value, batch<std::complex<T2>, A>>

test/test_batch_complex.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,17 @@ class batch_complex_test : public testing::Test
574574
}
575575
}
576576

577+
void test_isnan() const
578+
{
579+
{
580+
bool_array_type expected;
581+
std::transform(lhs.cbegin(), lhs.cend(), expected.begin(),
582+
[](const value_type& l) { return std::isnan(l.real()) || std::isnan(l.imag()); });
583+
typename batch_type::batch_bool_type res = isnan(batch_lhs());
584+
EXPECT_BATCH_EQ(res, expected) << print_function_name("isnan");
585+
}
586+
}
587+
577588
private:
578589

579590
batch_type batch_lhs() const
@@ -647,3 +658,8 @@ TYPED_TEST(batch_complex_test, boolean_conversion)
647658
{
648659
this->test_boolean_conversion();
649660
}
661+
662+
TYPED_TEST(batch_complex_test, isnan)
663+
{
664+
this->test_isnan();
665+
}

test/test_traits.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class complex_traits_test : public testing::Test
110110
EXPECT_TRUE(res1);
111111

112112
using rtype2 = xsimd::simd_return_type<bool, value_type>;
113-
constexpr bool res2 = std::is_same<rtype2, xsimd::batch_bool<value_type>>::value;
113+
constexpr bool res2 = std::is_same<rtype2, xsimd::batch_bool<typename value_type::value_type>>::value;
114114
EXPECT_TRUE(res2);
115115
}
116116
};

0 commit comments

Comments
 (0)