std::experimental::reduce, std::experimental::hmin, std::experimental::hmax

Header: <experimental/simd>

  1. Reduces all values in v over binary_op.

# Declarations

template< class T, class Abi, class BinaryOperation = std::plus<> >
T reduce( const simd<T, Abi>& v, BinaryOperation binary_op = {} );

(parallelism TS v2)

template< class M, class V, class BinaryOperation >
typename V::value_type
reduce( const const_where_expression<M, V>& x,
typename V::value_type identity_element, BinaryOperation binary_op = {} );

(parallelism TS v2)

template< class M, class V >
typename V::value_type
reduce( const const_where_expression<M, V>& x, std::plus<> binary_op ) noexcept;

(parallelism TS v2)

template< class M, class V >
typename V::value_type
reduce( const const_where_expression<M, V>& x, std::multiplies<> binary_op ) noexcept;

(parallelism TS v2)

template< class M, class V >
typename V::value_type
reduce( const const_where_expression<M, V>& x, std::bit_and<> binary_op ) noexcept;

(parallelism TS v2)

template< class M, class V >
typename V::value_type
reduce( const const_where_expression<M, V>& x, std::bit_or<> binary_op ) noexcept;

(parallelism TS v2)

template< class M, class V >
typename V::value_type
reduce( const const_where_expression<M, V>& x, std::bit_xor<> binary_op ) noexcept;

(parallelism TS v2)

template< class T, class Abi >
T hmin( const simd<T, Abi>& v ) noexcept;

(parallelism TS v2)

template< class M, class V >
typename V::value_type
hmin( const const_where_expression<M, V>& x ) noexcept;

(parallelism TS v2)

template< class T, class Abi >
T hmax( const simd<T, Abi>& v ) noexcept;

(parallelism TS v2)

template< class M, class V >
typename V::value_type
hmax( const const_where_expression<M, V>& x ) noexcept;

(parallelism TS v2)

# Parameters

# Return value

The result of operation of the type:

# Example

#include <array>
#include <cassert>
#include <cstddef>
#include <experimental/simd>
#include <functional>
#include <iostream>
#include <numeric>
namespace stdx = std::experimental;
 
int main()
{
    using V = stdx::native_simd<double>;
 
    alignas(stdx::memory_alignment_v<V>) std::array<V::value_type, 1024> data;
    std::iota(data.begin(), data.end(), 0);
 
    V::value_type acc{};
    for (std::size_t i = 0; i < data.size(); i += V::size())
        acc += stdx::reduce(V(&data[i], stdx::vector_aligned), std::plus{});
    std::cout << "sum of data = " << acc << '\n';
 
    using W = stdx::fixed_size_simd<int, 4>;
    alignas(stdx::memory_alignment_v<W>) std::array<int, 4> arr{2, 5, 4, 1};
    auto w = W(&arr[0], stdx::vector_aligned);
    assert(stdx::hmin(w) == 1 and stdx::hmax(w) == 5);
}

# See also