Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::experimental::reduce,std::experimental::hmin,std::experimental::hmax

      From cppreference.com
      <cpp‎ |experimental‎ |simd
       
       
       
       
       
      Defined in header<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
      reduce(const const_where_expression<M, V>& x,

             typename V::value_type identity_element, BinaryOperation binary_op={});
      (2)(parallelism TS v2)
      template<class M,class V>

      typename V::value_type

      reduce(const const_where_expression<M, V>& x,std::plus<> binary_op)noexcept;
      (3)(parallelism TS v2)
      template<class M,class V>

      typename V::value_type

      reduce(const const_where_expression<M, V>& x,std::multiplies<> binary_op)noexcept;
      (4)(parallelism TS v2)
      template<class M,class V>

      typename V::value_type

      reduce(const const_where_expression<M, V>& x,std::bit_and<> binary_op)noexcept;
      (5)(parallelism TS v2)
      template<class M,class V>

      typename V::value_type

      reduce(const const_where_expression<M, V>& x,std::bit_or<> binary_op)noexcept;
      (6)(parallelism TS v2)
      template<class M,class V>

      typename V::value_type

      reduce(const const_where_expression<M, V>& x,std::bit_xor<> binary_op)noexcept;
      (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

      hmin(const const_where_expression<M, V>& x)noexcept;
      (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

      hmax(const const_where_expression<M, V>& x)noexcept;
      (11)(parallelism TS v2)
      1) Reduces all values inv overbinary_op.
      2) Reduces the values inx where the associated mask element istrue overbinary_op.
      3) Returns the sum of all values inx where the associated mask element istrue.
      4) Returns the product of all values inx where the associated mask element istrue.
      5) Returns the aggregation using bitwise-and of all values inx where the associated mask element istrue.
      6) Returns the aggregation using bitwise-or of all values inx where the associated mask element istrue.
      7) Returns the aggregation using bitwise-xor of all values inx where the associated mask element istrue.
      8) Reduces all values inv overstd::min.
      9) Reduces all values inx where the associated mask element istrue overstd::min.
      10) Reduces all values inv overstd::max.
      11) Reduces all values inx where the associated mask element istrue overstd::max.

      The behavior is non-deterministic ifbinary_op is not associative or not commutative.

      Contents

      [edit]Parameters

      v - thesimd vector to apply the reduction to
      x - the return value of awhere expression to apply the reduction to
      identity_element - a value that acts as identity element forbinary_op;binary_op(identity_element, a)== a must hold for all finitea of typeV::value_type
      binary_op - binaryFunctionObject that will be applied in unspecified order to arguments of typeV::value_type orsimd<V::value_type, A>, with unspecified ABI tagA.binary_op(v, v) must be convertible toV

      [edit]Return value

      The result of operation of the type:

      1,8,10)T
      2-7,9,11)V::value_type

      [edit]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

      [edit]See also

      (C++17)
      similar tostd::accumulate, except out of order
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/experimental/simd/reduce&oldid=159775"

      [8]ページ先頭

      ©2009-2025 Movatter.jp