std::experimental::reduce, std::experimental::hmin, std::experimental::hmax
来自cppreference.com
| 在标头 <experimental/simd> 定义
|
||
| |
(1) | (并行 TS v2) |
| |
(2) | (并行 TS v2) |
| |
(3) | (并行 TS v2) |
| |
(4) | (并行 TS v2) |
| |
(5) | (并行 TS v2) |
| |
(6) | (并行 TS v2) |
| |
(7) | (并行 TS v2) |
| |
(8) | (并行 TS v2) |
| |
(9) | (并行 TS v2) |
| |
(10) | (并行 TS v2) |
| |
(11) | (并行 TS v2) |
1) 在
binary_op 上归约 v 中的所有者。2) 在
binary_op 上归约 x 中关联掩码元素为 true 的所有值。3) 返回
x 中关联掩码为 true 的所有值的和。4) 返回
x 中关联掩码为 true 的所有值的乘积。5) 返回对
x 中关联掩码为 true 的所有值使用按位与的聚合。6) 返回对
x 中关联掩码为 true 的所有值使用按位或的聚合。7) 返回对
x 中关联掩码为 true 的所有值使用按位异或的聚合。8) 在
std::min 上归约 v 中的所有者。9) 在
std::min 上归约 x 中关联掩码元素为 true 的所有值。10) 在
std::max 上归约 v 中的所有者。11) 在
std::max 上归约 x 中关联掩码元素为 true 的所有值。如果 binary_op 并无结合性或交换性,则其行为不确定。
参数
| v | - | 要运用归约的 simd 向量
|
| x | - | 要运用归约的 where 表达式的返回值
|
| identity_element | - | 对于 binary_op 表现为相同元素的值;binary_op(identity_element, a) == a 必须持有类型 V::value_type 的所有有穷值
|
| binary_op | - | 以未指明的 ABI 标签 A,以未指明的顺序,运用于 V::value_type 或 simd<V::value_type, 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,但不依序执行 (函数模板) |