|
11 | 11 |
|
12 | 12 | namespace eve
|
13 | 13 | {
|
14 |
| -//================================================================================================ |
15 |
| -//! @addtogroup core_reduction |
16 |
| -//! @{ |
17 |
| -//! @var count_true |
18 |
| -//! @brief Computes the number of non 0 elements |
19 |
| -//! |
20 |
| -//! @groupheader{Header file} |
21 |
| -//! |
22 |
| -//! @code |
23 |
| -//! #include <eve/module/core.hpp> |
24 |
| -//! @endcode |
25 |
| -//! |
26 |
| -//! @groupheader{Callable Signatures} |
27 |
| -//! |
28 |
| -//! @code |
29 |
| -//! namespace eve |
30 |
| -//! { |
31 |
| -//! // Regular overloads |
32 |
| -//! constexpr auto count_true(logical_value auto x) noexcept; // 1 |
33 |
| -//! constexpr auto count_true(top_bits auto t) noexcept; // 1 |
34 |
| -//! |
35 |
| -//! // Lanes masking |
36 |
| -//! constexpr auto count_true[conditional_expr auto c](/* any of the above overloads */) noexcept; // 2 |
37 |
| -//! constexpr auto count_true[logical_value auto m](/* any of the above overloads */) noexcept; // 2 |
38 |
| -//! } |
39 |
| -//! @endcode |
40 |
| -//! |
41 |
| -//! **Parameters** |
42 |
| -//! |
43 |
| -//! * `x`: [argument](@ref eve::logical_value). |
44 |
| -//! * `t`: [top bits](@ref top_bits). |
45 |
| -//! * `c`: [Conditional expression](@ref eve::conditional_expr) masking the operation. |
46 |
| -//! * `m`: [Logical value](@ref eve::logical_value) masking the operation. |
47 |
| -//! |
48 |
| -//! **Return value** |
49 |
| -//! |
50 |
| -//! 1. The value in the element type of `x` of the number of non 0 elements. |
51 |
| -//! 2. A masked version which return the number of true retained elements. |
52 |
| -//! |
53 |
| -//! **Parameters** |
54 |
| -//! |
55 |
| -//! * `x` : [argument](@ref eve::value). |
56 |
| -//! |
57 |
| -//! **Return value** |
58 |
| -//! |
59 |
| -//! The value of the number of non 0 elements |
60 |
| -//! is returned. |
61 |
| -//! |
62 |
| -//! @groupheader{Example} |
63 |
| -//! |
64 |
| -//! @godbolt{doc/core/count_true.cpp} |
65 |
| -//! @groupheader{Semantic Modifiers} |
66 |
| -//! |
67 |
| -//! * Masked Call |
68 |
| -//! |
69 |
| -//! The call `eve::$name$[mask](x, ...)` provides a masked |
70 |
| -//! version of `count_true which count the non masked non zero element |
71 |
| -//! |
72 |
| -//================================================================================================ |
73 |
| -EVE_MAKE_CALLABLE(count_true_, count_true); |
74 |
| -//================================================================================================ |
75 |
| -//! @} |
76 |
| -//================================================================================================ |
| 14 | + template<typename Options> |
| 15 | + struct count_true_t : conditional_callable<count_true_t, Options> |
| 16 | + { |
| 17 | + template<relaxed_logical_value L> |
| 18 | + EVE_FORCEINLINE std::ptrdiff_t operator()(L v) const noexcept |
| 19 | + { |
| 20 | + static_assert(detail::validate_mask_for<decltype(this->options()), L>(), |
| 21 | + "[eve::count_true] - Cannot use a relative conditional expression or a simd value to mask a scalar value"); |
| 22 | + |
| 23 | + return EVE_DISPATCH_CALL(v); |
| 24 | + } |
| 25 | + |
| 26 | + template<logical_simd_value L> |
| 27 | + EVE_FORCEINLINE std::ptrdiff_t operator()(top_bits<L> v) const noexcept |
| 28 | + { |
| 29 | + return EVE_DISPATCH_CALL(v); |
| 30 | + } |
| 31 | + |
| 32 | + EVE_CALLABLE_OBJECT(count_true_t, count_true_); |
| 33 | + }; |
| 34 | + |
| 35 | + //================================================================================================ |
| 36 | + //! @addtogroup core_reduction |
| 37 | + //! @{ |
| 38 | + //! @var count_true |
| 39 | + //! @brief Computes the number of elements of the input which evaluates to `true`. |
| 40 | + //! |
| 41 | + //! @groupheader{Header file} |
| 42 | + //! |
| 43 | + //! @code |
| 44 | + //! #include <eve/module/core.hpp> |
| 45 | + //! @endcode |
| 46 | + //! |
| 47 | + //! @groupheader{Callable Signatures} |
| 48 | + //! |
| 49 | + //! @code |
| 50 | + //! namespace eve |
| 51 | + //! { |
| 52 | + //! // Regular overloads |
| 53 | + //! template<relaxed_logical_value L> |
| 54 | + //! std::ptrdiff_t count_true(L x) noexcept; // 1 |
| 55 | + //! |
| 56 | + //! template<relaxed_logical_value L> |
| 57 | + //! std::ptrdiff_t count_true(top_bits<L> t) noexcept; // 1 |
| 58 | + //! |
| 59 | + //! // Lanes masking |
| 60 | + //! std::ptrdiff_t count_true[conditional_expr auto c](/* any of the above overloads */) noexcept; // 2 |
| 61 | + //! std::ptrdiff_t count_true[logical_value auto m](/* any of the above overloads */) noexcept; // 2 |
| 62 | + //! } |
| 63 | + //! @endcode |
| 64 | + //! |
| 65 | + //! **Parameters** |
| 66 | + //! |
| 67 | + //! * `x`: [argument](@ref eve::logical_value). |
| 68 | + //! * `t`: [top bits](@ref top_bits). |
| 69 | + //! * `c`: [Conditional expression](@ref eve::conditional_expr) masking the operation. |
| 70 | + //! * `m`: [Logical value](@ref eve::logical_value) masking the operation. |
| 71 | + //! |
| 72 | + //! **Return value** |
| 73 | + //! |
| 74 | + //! 1. The number of elements in `x` which evaluates to `true`. Scalar values are treated as one element. |
| 75 | + //! 2. The masked version which return the number of non-masked true elements. |
| 76 | + //! |
| 77 | + //! @groupheader{Example} |
| 78 | + //! |
| 79 | + //! @godbolt{doc/core/count_true.cpp} |
| 80 | + //! @groupheader{Semantic Modifiers} |
| 81 | + //! |
| 82 | + //================================================================================================ |
| 83 | + inline constexpr auto count_true = functor<count_true_t>; |
| 84 | + //================================================================================================ |
| 85 | + //! @} |
| 86 | + //================================================================================================ |
77 | 87 | }
|
78 | 88 |
|
79 | 89 | #include <eve/module/core/regular/impl/count_true.hpp>
|
|
0 commit comments