Skip to content

Commit 094b567

Browse files
authored
Merge pull request #586 from JohanMabille/logical
Implemented operator! for batch of complex
2 parents f28c937 + 0030636 commit 094b567

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

include/xsimd/types/xsimd_batch.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ struct batch<std::complex<T>, A> {
247247
batch(real_batch const& real) : m_real(real), m_imag(0) {}
248248
batch(T val) : m_real(val), m_imag(0) {}
249249
batch(std::initializer_list<value_type> data) { *this = load_unaligned(data.begin()); }
250+
explicit batch(batch_bool_type b);
250251

251252
static XSIMD_NO_DISCARD batch load_aligned(const T* real_src, const T* imag_src=nullptr);
252253
static XSIMD_NO_DISCARD batch load_unaligned(const T* real_src, const T* imag_src=nullptr);
@@ -293,6 +294,7 @@ struct batch<std::complex<T>, A> {
293294
}
294295

295296
// unary operators
297+
batch_bool_type operator!() const { return operator==(batch(0)); }
296298
batch operator~() const { return {~m_real, ~m_imag}; }
297299
batch operator-() const { return {-m_real, -m_imag};}
298300
batch operator+() const { return {+m_real, +m_imag}; }
@@ -564,6 +566,13 @@ batch_bool<T, A> batch_bool<T, A>::load_unaligned(bool const* mem) {
564566

565567
// batch complex implementation
566568
//
569+
570+
template <class T, class A>
571+
batch<std::complex<T>, A>::batch(batch_bool_type b)
572+
: m_real(b), m_imag(0)
573+
{
574+
}
575+
567576
template <class T, class A>
568577
batch<std::complex<T>, A> batch<std::complex<T>, A>::load_aligned(const T* real_src, const T* imag_src)
569578
{

test/test_batch_complex.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,18 @@ class batch_complex_test : public testing::Test
533533
}
534534
}
535535

536+
void test_boolean_conversion() const
537+
{
538+
// !batch
539+
{
540+
array_type expected;
541+
std::transform(lhs.cbegin(), lhs.cend(), expected.begin(),
542+
[](const value_type& l) { return l == value_type(0); });
543+
batch_type res = (batch_type)!batch_lhs();
544+
EXPECT_BATCH_EQ(res, expected) << print_function_name("!batch");
545+
}
546+
}
547+
536548
private:
537549

538550
batch_type batch_lhs() const
@@ -596,3 +608,8 @@ TYPED_TEST(batch_complex_test, fused_operations)
596608
{
597609
this->test_fused_operations();
598610
}
611+
612+
TYPED_TEST(batch_complex_test, boolean_conversion)
613+
{
614+
this->test_boolean_conversion();
615+
}

0 commit comments

Comments
 (0)