std::experi...mental::hmax(3)
π
std::experi...mental::hmax(3) π
okay so this is from the C++ Standard Libary manual (yes, that's the manual name, and no, I'm not fixing the typo π). The page title is std::experi...mental::hmax(3), and it's basically a group chat for three besties: std::experimental::reduce, std::experimental::hmin, and std::experimental::hmax.
β¨ NAME β¨
std::experimental::reduce,std::experimental::hmin,std::experimental::hmax β that's the trio, periodt. They share a page and they're all up in this manual's business.
πΈ Synopsis πΈ
Defined in header <experimental/simd>:
template< class T, class Abi, class BinaryOperation =
std::plus<> > (1)
(parallelism TS v2)
T reduce( const simd<T, Abi>& v, BinaryOperation binary_op
= {} );
template< class M, class V, class BinaryOperation >
typename V::value_type
reduce( const const_where_expression<M, V>& x, (2)
(parallelism TS v2)
typename V::value_type identity_element,
BinaryOperation binary_op = {} );
template< class M, class V >
typename V::value_type (3)
(parallelism TS v2)
reduce( const const_where_expression<M, V>& x, std::plus<>
binary_op ) noexcept;
template< class M, class V >
typename V::value_type (4)
(parallelism TS v2)
reduce( const const_where_expression<M, V>& x,
std::multiplies<> binary_op ) noexcept;
template< class M, class V >
typename V::value_type (5)
(parallelism TS v2)
reduce( const const_where_expression<M, V>& x,
std::bit_and<> binary_op ) noexcept;
template< class M, class V >
typename V::value_type (6)
(parallelism TS v2)
reduce( const const_where_expression<M, V>& x,
std::bit_or<> binary_op ) noexcept;
template< class M, class V >
typename V::value_type (7)
(parallelism TS v2)
reduce( const const_where_expression<M, V>& x,
std::bit_xor<> binary_op ) noexcept;
template< class T, class Abi > (8)
(parallelism TS v2)
T hmin( const simd<T, Abi>& v ) noexcept;
template< class M, class V >
typename V::value_type (9)
(parallelism TS v2)
hmin( const const_where_expression<M, V>& x ) noexcept;
template< class T, class Abi > (10)
(parallelism TS v2)
T hmax( const simd<T, Abi>& v ) noexcept;
template< class M, class V >
typename V::value_type (11)
(parallelism TS v2)
hmax( const const_where_expression<M, V>& x ) noexcept;
- Reduces all values in
voverbinary_op. - Reduces the values in
xwhere the associated mask element is true overbinary_op. - Returns the sum of all values in
xwhere the associated mask element is true. - Returns the product of all values in
xwhere the associated mask element is true. - Returns the aggregation using bitwise-and of all values in
xwhere the associated mask element is true. - Returns the aggregation using bitwise-or of all values in
xwhere the associated mask element is true. - Returns the aggregation using bitwise-xor of all values in
xwhere the associated mask element is true. - Reduces all values in
voverstd::min. - Reduces all values in
xwhere the associated mask element is true overstd::min. - Reduces all values in
voverstd::max. - Reduces all values in
xwhere the associated mask element is true overstd::max.
β οΈ The behavior is non-deterministic if binary_op is not associative or not commutative. Not me being dramatic, that's literally the page π
π Parameters π
vβ thesimdvector to apply the reduction toxβ the return value of awhereexpression to apply the reduction toidentity_elementβ a value that acts as identity element forbinary_op;binary_op(identity_element, a) == amust hold for all finiteaof typeV::value_typebinary_opβ binaryFunctionObjectthat will be applied in unspecified order to arguments of typeV::value_typeorsimd<V::value_type, A>, with unspecified ABI tagA.binary_op(v, v)must be convertible toV
π Return value π
The result of operation of the type:
1,8,10)βT2-7,9,11)βV::value_type
π§ͺ Example π§ͺ
Run this code:
#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);
}
Output:
sum of data = 523776
π See also π
reduceβ similar tostd::accumulate, except out of order (C++17) (function template)
π okay that's the whole page, bestie. source/version/date sign-off: http://cppreference.com, 2024.06.10, page std::experi...mental::hmax(3), from the C++ Standard Libary manual. mwah π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms