Namespaces
Variants

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

From cppreference.net
HTMLタグ、属性、コードブロック内のテキストは翻訳せず、元のフォーマットを保持しました。C++固有の用語も翻訳していません。 HTMLタグ、属性、C++コード内のテキストは翻訳せず、元のフォーマットを保持しています。C++固有の用語も翻訳していません。 HTMLタグ、属性、コードブロック内のテキストは翻訳せず、元のフォーマットを保持しました。C++固有の用語も翻訳していません。 **翻訳結果:** - C++コード部分 (` ` 内) は翻訳せず、そのまま保持 - 数値 "(8)" は変更なし - バージョン情報 "(parallelism TS v2)" は変更なし - HTMLタグと属性は完全に保持 **注記:** 指定された要件に従い、C++コード、HTMLタグ、技術用語はすべて原文のまま保持されています。翻訳対象となる自然言語テキストが存在しないため、出力は入力と同一となります。 **翻訳結果:** **翻訳の説明:** - HTMLタグ、属性、C++コード(` `内)は一切翻訳せず保持 - 数値の"(9)"はそのまま保持 - "(parallelism TS v2)"のみを「(並列処理 TS v2)」に翻訳 - C++専門用語(template, class, typename, const, noexceptなど)は翻訳せず保持 - 元のフォーマットと構造を完全に維持 **注記**: このコードはC++のテンプレート宣言であり、HTMLタグやC++固有の用語(`template`, `class`, `const`, `simd`, `noexcept`など)は翻訳対象外です。コード部分は完全に保持されています。 (注:このHTML要素には翻訳対象のテキストコンテンツが含まれていないため、元の構造を保持したまま出力します)
ヘッダーで定義 <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) (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 ;
(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) (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 ;
(6) (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 ;
(7) (parallelism TS v2)
template < class T, class Abi >
T hmin ( const simd < T, Abi > & v ) noexcept ;
(8) (parallelism 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 M, class V >

typename V :: value_type

hmin ( const const_where_expression < M, V > & x ) noexcept ;
(9) (並列処理 TS v2)
template < class T, class Abi >
T hmax ( const simd < T, Abi > & v ) noexcept ;
(10) (parallelism TS v2)
template < class M, class V >

typename V :: value_type

hmax ( const const_where_expression < M, V > & x ) noexcept ;
(11) (parallelism TS v2)
1) v 内の全ての値を binary_op で削減します。
2) 関連するマスク要素が x 内で true である値に対して binary_op による縮約操作を実行します。
3) 関連付けられたマスク要素が true である x 内の全ての値の合計を返します。
4) 関連するマスク要素が x 内の true であるすべての値の積を返します。
5) 関連するマスク要素が true である x 内の全ての値のビット単位ANDを用いた集約を返します。
6) 関連するマスク要素が true である x 内の全ての値のビット単位ORを使用した集約を返します。
7) 関連付けられたマスク要素が true である x 内の全ての値のビット単位XORによる集約を返します。
8) v 内の全ての値を std:: min で縮約します。
9) 関連するマスク要素が x 内で true であるすべての値を std:: min で削減します。
10) v 内の全ての値を std:: max で縮約します。
11) 関連するマスク要素が x 内の true であるすべての値を std:: max で削減します。

binary_op が結合的でも可換的でもない場合、動作は非決定的となります。

目次

パラメータ

v - リダクションを適用する simd ベクトル
x - リダクションを適用する where 式の戻り値
identity_element - binary_op に対する単位元として機能する値。 binary_op ( identity_element, a ) == a V :: value_type 型のすべての有限な a に対して成り立たなければならない
binary_op - 二項 FunctionObject V :: value_type 型または simd < V :: value_type , A > 型(未指定の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 と同様だが、順序が不定
(関数テンプレート)