std::experimental::reduce, std::experimental::hmin, std::experimental::hmax
From cppreference.com
< cpp | experimental | simd
| ヘッダー <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 |
(2) | (parallelism TS v2) |
| template< class M, class V > typename V::value_type |
(3) | (parallelism TS v2) |
| template< class M, class V > typename V::value_type |
(4) | (parallelism TS v2) |
| template< class M, class V > typename V::value_type |
(5) | (parallelism TS v2) |
| template< class M, class V > typename V::value_type |
(6) | (parallelism TS v2) |
| template< class M, class V > typename V::value_type |
(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 |
(9) | (parallelism 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 |
(11) | (parallelism 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 のすべての値のビット単位 XOR による集計を返します。
binary_op が結合的でも可換でもない場合、動作は非決定論的です。
目次 |
[編集] パラメータ
| v | - | 還元を適用する simd ベクトル |
| x | - | 還元を適用する where 式の戻り値 |
| identity_element | - | binary_op の単位元として機能する値。有限な a (V::value_type 型) に対して、binary_op(identity_element, a) = a が成り立つ必要があります。 |
| binary_op | - | V::value_type または simd<V::value_type, A> (ABI タグ A は未指定) 型の引数に、未指定の順序で適用される二項 FunctionObject。binary_op(v, v) は V に変換可能である必要があります。 |
[編集] 戻り値
操作の結果。型は以下の通りです。
1,8,10)
T2-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 に似ているが、順序不同 (関数テンプレート) |