E.V.E
v2023.02.15
 
Loading...
Searching...
No Matches

◆ reduce

eve::reduce = functor<reduce_t>
inlineconstexpr

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
}
Specifies that a type is a Conditional Expression.
Definition conditional.hpp:28
The concept logical_value<T> is satisfied if and only if T satisfies eve::value and the element type ...
Definition value.hpp:134
constexpr auto reduce
Computes the reduction of a SIMD value using a given callable. Performs an horizontal sum by default.
Definition reduce.hpp:154
typename decltype(detail::as_translated_type(as< T >{}))::type translate_t
Returns the final translated type of T.
Definition translation.hpp:107
EVE Main Namespace.
Definition abi.hpp:19

Parameters

Return value

  1. The result of reducing all lanes with the given callable (or addition by default). Scalar values are returned as is.
  2. The reduction result splatted across every lane of the input.
  3. 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>
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;
}