std::experimental:: reduce, std::experimental:: hmin, std::experimental:: hmax
|
定义于头文件
<experimental/simd>
|
||
|
template
<
class
T,
class
Abi,
class
BinaryOperation
=
std::
plus
<>
>
T reduce ( const simd < T, Abi > & v, BinaryOperation binary_op = { } ) ; |
(1) | (并行 TS v2) |
|
template
<
class
M,
class
V,
class
BinaryOperation
>
typename
V
::
value_type
|
(2) | (并行 TS v2) |
|
template
<
class
M,
class
V
>
typename
V
::
value_type
|
(3) | (并行 TS v2) |
|
template
<
class
M,
class
V
>
typename
V
::
value_type
|
(4) | (并行 TS v2) |
|
template
<
class
M,
class
V
>
typename
V
::
value_type
|
(5) | (并行 TS v2) |
|
template
<
class
M,
class
V
>
typename
V
::
value_type
|
(6) | (并行 TS v2) |
|
template
<
class
M,
class
V
>
typename
V
::
value_type
|
(7) | (并行 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
|
(9) | (并行 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
|
(11) | (并行 TS v2) |
如果 binary_op 不满足结合律或交换律,该行为将具有不确定性。
目录 |
参数
| v | - |
要应用归约操作的
simd
向量
|
| x | - |
要应用归约操作的
where
表达式返回值
|
| identity_element | - | 作为 binary_op 单位元的值;对于类型为 V :: value_type 的所有有限值 a ,必须满足 binary_op ( identity_element, a ) == a |
| binary_op | - |
二元
FunctionObject
,将以未指定顺序应用于类型为
V
::
value_type
或
simd
<
V
::
value_type
, A
>
的参数(具有未指定的 ABI 标签
A
)。
binary_op
(
v, v
)
必须可转换为
V
|
返回值
该类型操作的结果:
T
示例
#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
,但支持乱序执行
(函数模板) |