E.V.E
v2023.02.15
Loading...
Searching...
No Matches
◆
reduce
eve::reduce = functor<reduce_t>
inline
constexpr
Header file
#include <eve/module/core.hpp>
Callable Signatures
namespace
eve
{
// Regular overloads (non-splat)
template
<value T,
typename
Callable>
element_type_t<T>
reduce
(
T
x
,
Callable
f)
requires
(!O::contains(splat))
noexcept
;
// 1
template
<value T>
element_type_t<T>
reduce
(
T
x
)
requires
(!O::contains(splat))
noexcept
;
// 1
// Splat overloads
template
<simd_value T,
typename
Callable>
T
reduce
(
T
x
,
Callable
f)
requires
(O::contains(splat))
noexcept
;
// 2
template
<simd_value T>
T
reduce
(
T
x
)
requires
(O::contains(splat))
noexcept
;
// 2
// Lanes masking
auto
reduce
[
conditional_expr
auto
c
](
/* any of the above overloads */
)
noexcept
;
// 3
auto
reduce
[
logical_value
auto
m
](
/* any of the above overloads */
)
noexcept
;
// 3
}
eve::conditional_expr
Specifies that a type is a Conditional Expression.
Definition
conditional.hpp:28
eve::logical_value
The concept logical_value<T> is satisfied if and only if T satisfies eve::value and the element type ...
Definition
value.hpp:134
eve::reduce
constexpr auto reduce
Computes the reduction of a SIMD value using a given callable. Performs an horizontal sum by default.
Definition
reduce.hpp:154
eve::translate_t
typename decltype(detail::as_translated_type(as< T >{}))::type translate_t
Returns the final translated type of T.
Definition
translation.hpp:107
eve
EVE Main Namespace.
Definition
abi.hpp:19
Parameters
x
:
argument
.
f
: Callable to use for reduction.
c
:
Conditional expression
masking the operation.
m
:
Logical value
masking the operation.
Return value
The result of reducing all lanes with the given callable (or addition by default). Scalar values are returned as is.
The reduction result splatted across every lane of the input.
Same as any of the above but the masked lanes are ignored during the operation.
Example
#include <eve/module/core.hpp>
#include <eve/wide.hpp>
#include <iostream>
using
wide_ft
=
eve::wide<float, eve::fixed<4>
>;
using
wide_it
=
eve::wide<std::int16_t, eve::fixed<4>
>;
int
main
()
{
wide_ft
pf
= {0.5f,1.5f,2.5f,3.f};
wide_it
qi
= {2,3,4,5};
auto
const
summ
= [](
auto
a
,
auto
b
) {
return
a
+
b
; };
auto
const
prod = [](
auto
a
,
auto
b
) {
return
a
*
b
; };
std::cout <<
"---- simd"
<<
'\n'
<<
"<- pf = "
<<
pf
<<
'\n'
<<
"-> reduce(pf,summ) = "
<<
eve::reduce
(
pf
,
summ
) <<
'\n'
<<
"<- qi = "
<<
qi
<<
'\n'
<<
"-> reduce(qi,prod) = "
<<
eve::reduce
(
qi
, prod) <<
'\n'
;
std::cout <<
"---- simd with splat"
<<
'\n'
<<
"<- pf = "
<<
pf
<<
'\n'
<<
"-> reduce[splat](pf,summ) = "
<<
eve::reduce
[eve::splat](
pf
,
summ
) <<
'\n'
<<
"<- qi = "
<<
qi
<<
'\n'
<<
"-> reduce[splat](qi,prod) = "
<<
eve::reduce
[eve::splat](
qi
, prod) <<
'\n'
;
return
0;
}
eve