Files
cppdraft_translate/cppdraft/simd/reductions.md
2025-10-25 03:02:53 +03:00

6.6 KiB
Raw Blame History

[simd.reductions]

29 Numerics library [numerics]

29.10 Data-parallel types [simd]

29.10.8 basic_vec non-member operations [simd.nonmembers]

29.10.8.5 basic_vec reductions [simd.reductions]

🔗

template<class T, class Abi, class BinaryOperation = plus<>> constexpr T reduce(const basic_vec<T, Abi>& x, BinaryOperation binary_op = {});

1

#

Constraints: BinaryOperation modelsreduction-binary-operation.

2

#

Preconditions: binary_op does not modify x.

3

#

Returns: GENERALIZED_SUM(binary_op, vec<T, 1>(x[0]), …, vec<T, 1>(x[x.size() - 1]))[0] ([numerics.defns]).

4

#

Throws: Any exception thrown from binary_op.

🔗

template<class T, class Abi, class BinaryOperation = plus<>> constexpr T reduce( const basic_vec<T, Abi>& x, const typename basic_vec<T, Abi>::mask_type& mask, BinaryOperation binary_op = {}, type_identity_t<T> identity_element = see below);

5

#

Constraints:

  • (5.1)

    BinaryOperation models reduction-binary-operation.

  • (5.2)

    An argument for identity_element is provided for the invocation, unless BinaryOperation is one of plus<>, multiplies<>, bit_and<>, bit_or<>, or bit_xor<>.

6

#

Preconditions:

  • (6.1)

    binary_op does not modify x.

  • (6.2)

    For all finite values y representable by T, the results of y == binary_op(vec<T, 1>(identity_element), vec<T, 1>(y))[0] and y == binary_op(vec<T, 1>(y), vec<T, 1>(identity_element))[0] are true.

7

#

Returns: If none_of(mask) is true, returns identity_element.

Otherwise, returns GENERALIZED_SUM(binary_op, vec<T,1>(x[k0]), …, vec<T, 1>(x[kn]))[0] where k0,…,kn are the selected indices of mask.

8

#

Throws: Any exception thrown from binary_op.

9

#

Remarks: The default argument for identity_element is equal to

T() if BinaryOperation is plus<>,

T(1) if BinaryOperation is multiplies<>,

T(~T()) if BinaryOperation is bit_and<>,

T() if BinaryOperation is bit_or<>, or

T() if BinaryOperation is bit_xor<>.

🔗

template<class T, class Abi> constexpr T reduce_min(const basic_vec<T, Abi>& x) noexcept;

10

#

Constraints: T models totally_ordered.

11

#

Returns: The value of an element x[j] for which x[i] < x[j] isfalse for all i in the range of [0, basic_vec<T, Abi>::size()).

🔗

template<class T, class Abi> constexpr T reduce_min( const basic_vec<T, Abi>&, const typename basic_vec<T, Abi>::mask_type&) noexcept;

12

#

Constraints: T models totally_ordered.

13

#

Returns: If none_of(mask) is true, returnsnumeric_limits::max().

Otherwise, returns the value of a selected element x[j] for whichx[i] < x[j] is false for all selected indices i ofmask.

🔗

template<class T, class Abi> constexpr T reduce_max(const basic_vec<T, Abi>& x) noexcept;

14

#

Constraints: T models totally_ordered.

15

#

Returns: The value of an element x[j] for which x[j] < x[i] isfalse for all i in the range of [0, basic_vec<T, Abi>::size()).

🔗

template<class T, class Abi> constexpr T reduce_max( const basic_vec<T, Abi>&, const typename basic_vec<T, Abi>::mask_type&) noexcept;

16

#

Constraints: T models totally_ordered.

17

#

Returns: If none_of(mask) is true, returnsnumeric_limits<V::value_type>::lowest().

Otherwise, returns the value of a selected element x[j] for whichx[j] < x[i] is false for all selected indices i ofmask.