Skip to content

Commit

Permalink
Provide and test scalar version f xsimd::all xsimd::none and xsimd::any
Browse files Browse the repository at this point in the history
Fix #886
  • Loading branch information
serge-sans-paille committed Mar 8, 2023
1 parent 8c831af commit 1a8c4df
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
15 changes: 15 additions & 0 deletions include/xsimd/arch/xsimd_scalar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,21 @@ namespace xsimd
return x + y;
}

inline bool all(bool mask)
{
return mask;
}

inline bool any(bool mask)
{
return mask;
}

inline bool none(bool mask)
{
return !mask;
}

template <class T>
inline typename std::enable_if<std::is_integral<T>::value, T>::type
bitwise_and(T x, T y) noexcept
Expand Down
35 changes: 35 additions & 0 deletions test/test_xsimd_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1231,3 +1231,38 @@ TEST_CASE_TEMPLATE("[xsimd api | all floating point types functions]", B, ALL_FL
xsimd_api_all_floating_point_types_functions<B> Test;
Test.test_neq_nan();
}

/*
* Functions that apply only to mask type
*/
template <typename T>
struct xsimd_api_all_mask_functions
{
using value_type = typename scalar_type<T>::type;

void test_all()
{
value_type val(1);
CHECK_EQ(xsimd::all(T(val) == T(val)), xsimd::all(val == val));
}

void test_any()
{
value_type val(1);
CHECK_EQ(xsimd::any(T(val) == T(val)), xsimd::any(val == val));
}

void test_none()
{
value_type val(1);
CHECK_EQ(xsimd::none(T(val) != T(val)), xsimd::none(val != val));
}
};

TEST_CASE_TEMPLATE("[xsimd api | all mask functions]", B, ALL_TYPES)
{
xsimd_api_all_mask_functions<B> Test;
Test.test_all();
Test.test_any();
Test.test_none();
}

0 comments on commit 1a8c4df

Please sign in to comment.