Namespaces
Variants

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

From cppreference.net
헤더에 정의됨 <experimental/simd>
template < class T, class Abi, class BinaryOperation = std:: plus <> >
T reduce ( const simd < T, Abi > & v, BinaryOperation binary_op = { } ) ;
(1) (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 = { } ) ;
(2) (병렬성 TS v2)
template < class M, class V >

typename V :: value_type

reduce ( const const_where_expression < M, V > & x, std:: plus <> binary_op ) noexcept ;
(3) (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 ;
(4) (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 ;
(5) (병렬성 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 ;
(6) (병렬성 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 ;
(7) (parallelism TS v2)
template < class T, class Abi >
T hmin ( const simd < T, Abi > & v ) noexcept ;
(8) (병렬성 TS v2)
template < class M, class V >

typename V :: value_type

hmin ( const const_where_expression < M, V > & x ) noexcept ;
(9) (parallelism TS v2)
template < class T, class Abi >
T hmax ( const simd < T, Abi > & v ) noexcept ;
(10) (병렬성 TS v2)
template < class M, class V >

typename V :: value_type

hmax ( const const_where_expression < M, V > & x ) noexcept ;
(11) (병렬성 TS v2)
1) v 내의 모든 값을 binary_op 를 통해 축소합니다.
2) 마스크 요소가 true 인 경우 x 의 값을 binary_op 를 통해 축소합니다.
3) 연관된 마스크 요소가 true x 의 모든 값들의 합을 반환합니다.
4) 연관된 마스크 요소가 true x 내의 모든 값들의 곱을 반환합니다.
5) 연관된 마스크 요소가 true x 의 모든 값들에 대한 비트 단위 AND 연산 집계를 반환합니다.
6) 연관된 마스크 요소가 true x 내의 모든 값들에 대한 비트 OR 연산 집계를 반환합니다.
7) 연관된 마스크 요소가 true x 의 모든 값들에 대한 비트별 배타적 논리합 연산을 사용한 집계 결과를 반환합니다.
8) v 내의 모든 값을 std:: min 를 사용하여 축소합니다.
9) 마스크 요소가 true x 의 모든 값을 std:: min 를 통해 축소합니다.
10) v 내의 모든 값을 std:: max 를 사용하여 축소합니다.
11) 마스크 요소가 true x 의 모든 값을 std:: max 를 통해 축소합니다.

binary_op 이 결합 법칙이나 교환 법칙을 따르지 않는 경우, 해당 동작은 비결정적입니다.

목차

매개변수

v - 감소를 적용할 simd 벡터
x - 감소를 적용할 where 표현식의 반환 값
identity_element - binary_op 에 대한 항등원 역할을 하는 값; binary_op ( identity_element, a ) == a V :: value_type 타입의 모든 유한 a 에 대해 성립해야 함
binary_op - V :: value_type 또는 simd < V :: value_type , A > 타입 인수에 지정되지 않은 순서로 적용될 이항 FunctionObject (지정되지 않은 ABI 태그 A 포함). binary_op ( v, v ) V 로 변환 가능해야 함

반환값

해당 유형의 연산 결과:

1,8,10) T
2-7,9,11) V :: value_type

예제

#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);
}

출력:

sum of data = 523776

참고 항목

(C++17)
std::accumulate 와 유사하지만 순서가 보장되지 않음
(함수 템플릿)