E.V.E  0.1-beta

◆ reduce

eve::reduce = {}
inlineconstexpr

Callable object computing a generalized fold operation.

Required header: #include <eve/function/reduce.hpp>

Member Functions

Member Effect
operator() the computation of a generalized fold operation
operator[] Construct a conditional version of current function object

template<simd_value T> auto operator()( T v ) const noexcept;
template<simd_value T, Callable F> auto operator()( T v, F binary_op ) const noexcept;

Parameters

v: SIMD value to reduce.

binary_op: Binary callable object that perform a binary, associative and commutative operation. If unspecified, the sum of all element of vis performed.

Return value

Generalized fold of v.get(0), v.get(1), ... v.get(v.size()-1) over binary_op,


auto operator[]( conditional_expression auto cond ) const noexcept;

Higher-order function generating a masked version of eve::reduce

Parameters

cond : conditional expression

Return value

A Callable object so that the expression reduce[cond](x, ...) is equivalent to if_else(cond,reduce(x, ...),x)


Supported decorators

  • eve::splat

    Required header: #include <eve/function/reduce.hpp>

    The expression eve::splat(eve::reduce)(v,binary_op) computes the reduction of v using binary_op but returns a SIMD value containing the result in all lanes.

Example

See it live on Compiler Explorer

#include <eve/function/reduce.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 sum = [](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,sum) = " << eve::reduce(pf, sum) << '\n'
<< "<- qi = " << qi << '\n'
<< "-> reduce(qi,prod) = " << eve::reduce(qi, prod) << '\n';
std::cout << "---- simd with splat" << '\n'
<< "<- pf = " << pf << '\n'
<< "-> splat(reduce)(pf,sum) = " << eve::splat(eve::reduce)(pf, sum) << '\n'
<< "<- qi = " << qi << '\n'
<< "-> splat(reduce)(qi,prod) = " << eve::splat(eve::reduce)(qi, prod) << '\n';
return 0;
}
constexpr splat_type const splat
Higher-order Callable Object allowing reduction to generate wide results instead of scalars.
Definition: splat.hpp:44
constexpr callable_reduce_ reduce
Callable object computing a generalized fold operation.
Definition: reduce.hpp:82
Wrapper for SIMD registers.
Definition: wide.hpp:65