On Tue, Dec 1, 2026 at 1:14 PM Jonathan Wakely <[email protected]> wrote:
> On Tue, 1 Dec 2026 at 11:53, Tomasz Kaminski <[email protected]> wrote: > > > > > > > > On Fri, Nov 27, 2026 at 10:54 PM Jonathan Wakely <[email protected]> > wrote: > >> > >> Reapply local fixes to support move-only types in numeric algos, as > >> originally done in r16-426-gdf1d436d17c828 (but lost by rebasing the > >> PSTL headers on the new oneDPL upstream). > >> > >> Also fix the non-parallel std::inclusive_scan to match the proposed > >> requirements in P0571R2 (Type Requirements for <numeric> Algirithms), > >> which say that the intermediate type used for the accumulator should be > >> the iterator's value type, which must be constructible from the input > >> range. > >> > >> Also expand the move_only.cc test to cover the other <numeric> algos > >> and to test the non-parallel overloads, and both the seq and par > >> policies with the parallel overloads. That is needed because they all > >> use different code paths. > >> > >> There are some remaining bugs in the TBB and OpenMP backends, which are > >> not easy to fix. The parts of the test that fail for a given backend are > >> guarded by #ifdef checks for the appropriate macro identifying the > >> backend in use. > >> > >> The changes in this commit and the remaining bugs should be reported > >> upstream at https://github.com/uxlfoundation/oneDPL/issues/1955 > >> > >> libstdc++-v3/ChangeLog: > >> > >> * include/pstl/glue_numeric_impl.h (exclusive_scan) > >> (inclusive_scan, transform_exclusive_scan) > >> (transform_inclusive_scan): Forward __init parameter as rvalue. > >> * include/pstl/numeric_impl.h (__pattern_transform_reduce): > >> Make lambda return decltype(auto) and forward __init parameter > >> as rvalue. > >> (__brick_transform_scan): Forward __init parameter and __temp > >> accumulator as rvalues. > >> (__pattern_transform_scan): Forward __init parameter as rvalue. > >> * include/pstl/omp/parallel_transform_scan.h > >> (__parallel_transform_scan): Likewise. > >> * include/pstl/parallel_backend_tbb.h (__trans_scan_body): > >> Likewise. > >> (__parallel_transform_scan): Use std::move for return value. > >> * include/std/numeric (inclusive_scan): Forward __init > >> parameter to __binary_op as rvalue. > >> (inclusive_scan): Use iterator's value_type as intermediate type > >> and do not move from the input range. > >> (transform_inclusive_scan): Likewise. > >> * testsuite/26_numerics/pstl/numeric_ops/move_only.cc: Add > >> missing tests for transform_reduce, inclusive_scan, > >> transform_exclusive_scan and transform_inclusive_scan. > >> --- > >> > >> Tested x86_64-linux. > >> > >> libstdc++-v3/include/pstl/glue_numeric_impl.h | 22 +-- > >> libstdc++-v3/include/pstl/numeric_impl.h | 24 +-- > >> .../pstl/omp/parallel_transform_scan.h | 2 +- > >> .../include/pstl/parallel_backend_tbb.h | 6 +- > >> libstdc++-v3/include/std/numeric | 11 +- > >> .../26_numerics/pstl/numeric_ops/move_only.cc | 177 +++++++++++++++++- > >> 6 files changed, 207 insertions(+), 35 deletions(-) > >> > >> diff --git a/libstdc++-v3/include/pstl/glue_numeric_impl.h > b/libstdc++-v3/include/pstl/glue_numeric_impl.h > >> index 911bf31b9989..eda4279e80da 100644 > >> --- a/libstdc++-v3/include/pstl/glue_numeric_impl.h > >> +++ b/libstdc++-v3/include/pstl/glue_numeric_impl.h > >> @@ -108,7 +108,7 @@ > __onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, > _ForwardIte > >> exclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, > _ForwardIterator1 __last, > >> _ForwardIterator2 __result, _Tp __init) > >> { > >> - return > transform_exclusive_scan(std::forward<_ExecutionPolicy>(__exec), __first, > __last, __result, __init, > >> + return > transform_exclusive_scan(std::forward<_ExecutionPolicy>(__exec), __first, > __last, __result, std::move(__init), > >> std::plus<_Tp>(), > __onedpl::identity{}); > >> } > >> > >> @@ -118,7 +118,7 @@ > __onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, > _ForwardIte > >> exclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, > _ForwardIterator1 __last, > >> _ForwardIterator2 __result, _Tp __init, > _BinaryOperation __binary_op) > >> { > >> - return > transform_exclusive_scan(std::forward<_ExecutionPolicy>(__exec), __first, > __last, __result, __init, > >> + return > transform_exclusive_scan(std::forward<_ExecutionPolicy>(__exec), __first, > __last, __result, std::move(__init), > >> __binary_op, __onedpl::identity{}); > >> } > >> #else > >> @@ -127,7 +127,7 @@ _ForwardIterator2 > >> exclusive_scan(__onedpl::execution::sequenced_policy __exec, > _ForwardIterator1 __first, _ForwardIterator1 __last, > >> _ForwardIterator2 __result, _Tp __init, > _BinaryOperation __binary_op) > >> { > >> - return transform_exclusive_scan(__exec, __first, __last, __result, > __init, __binary_op, __onedpl::identity{}); > >> + return transform_exclusive_scan(__exec, __first, __last, __result, > std::move(__init), __binary_op, __onedpl::identity{}); > >> } > >> > >> template <class _ForwardIterator1, class _ForwardIterator2, class _Tp, > class _BinaryOperation> > >> @@ -135,7 +135,7 @@ _ForwardIterator2 > >> exclusive_scan(__onedpl::execution::unsequenced_policy __exec, > _ForwardIterator1 __first, _ForwardIterator1 __last, > >> _ForwardIterator2 __result, _Tp __init, > _BinaryOperation __binary_op) > >> { > >> - return transform_exclusive_scan(__exec, __first, __last, __result, > __init, __binary_op, __onedpl::identity{}); > >> + return transform_exclusive_scan(__exec, __first, __last, __result, > std::move(__init), __binary_op, __onedpl::identity{}); > >> } > >> > >> template <class _ForwardIterator1, class _ForwardIterator2, class _Tp, > class _BinaryOperation> > >> @@ -143,7 +143,7 @@ _ForwardIterator2 > >> exclusive_scan(__onedpl::execution::parallel_policy __exec, > _ForwardIterator1 __first, _ForwardIterator1 __last, > >> _ForwardIterator2 __result, _Tp __init, > _BinaryOperation __binary_op) > >> { > >> - return transform_exclusive_scan(__exec, __first, __last, __result, > __init, __binary_op, __onedpl::identity{}); > >> + return transform_exclusive_scan(__exec, __first, __last, __result, > std::move(__init), __binary_op, __onedpl::identity{}); > >> } > >> > >> template <class _ForwardIterator1, class _ForwardIterator2, class _Tp, > class _BinaryOperation> > >> @@ -151,7 +151,7 @@ _ForwardIterator2 > >> exclusive_scan(__onedpl::execution::parallel_unsequenced_policy > __exec, _ForwardIterator1 __first, > >> _ForwardIterator1 __last, _ForwardIterator2 __result, > _Tp __init, _BinaryOperation __binary_op) > >> { > >> - return transform_exclusive_scan(__exec, __first, __last, __result, > __init, __binary_op, __onedpl::identity{}); > >> + return transform_exclusive_scan(__exec, __first, __last, __result, > std::move(__init), __binary_op, __onedpl::identity{}); > >> } > >> > >> # if _ONEDPL_BACKEND_SYCL > >> @@ -160,7 +160,7 @@ _ForwardIterator2 > >> exclusive_scan(const > __onedpl::execution::device_policy<PolicyParams...>& __exec, > _ForwardIterator1 __first, > >> _ForwardIterator1 __last, _ForwardIterator2 __result, > _Tp __init, _BinaryOperation __binary_op) > >> { > >> - return transform_exclusive_scan(__exec, __first, __last, __result, > __init, __binary_op, __onedpl::identity{}); > >> + return transform_exclusive_scan(__exec, __first, __last, __result, > std::move(__init), __binary_op, __onedpl::identity{}); > >> } > >> > >> # if _ONEDPL_FPGA_DEVICE > >> @@ -172,7 +172,7 @@ _ForwardIterator2 > >> exclusive_scan(const __onedpl::execution::fpga_policy<factor, > KernelName>& __exec, _ForwardIterator1 __first, > >> _ForwardIterator1 __last, _ForwardIterator2 __result, > _Tp __init, _BinaryOperation __binary_op) > >> { > >> - return transform_exclusive_scan(__exec, __first, __last, __result, > __init, __binary_op, __onedpl::identity{}); > >> + return transform_exclusive_scan(__exec, __first, __last, __result, > std::move(__init), __binary_op, __onedpl::identity{}); > >> } > >> #pragma GCC diagnostic pop > >> # endif // _ONEDPL_FPGA_DEVICE > >> @@ -207,7 +207,7 @@ inclusive_scan(_ExecutionPolicy&& __exec, > _ForwardIterator1 __first, _ForwardIte > >> _ForwardIterator2 __result, _BinaryOperation > __binary_op, _Tp __init) > >> { > >> return > transform_inclusive_scan(std::forward<_ExecutionPolicy>(__exec), __first, > __last, __result, __binary_op, > >> - __onedpl::identity{}, __init); > >> + __onedpl::identity{}, > std::move(__init)); > >> } > >> > >> // [transform.exclusive.scan] > >> @@ -222,7 +222,7 @@ transform_exclusive_scan(_ExecutionPolicy&& __exec, > _ForwardIterator1 __first, _ > >> const auto __dispatch_tag = > __onedpl::__internal::__select_backend(__exec, __first, __result); > >> > >> return > __onedpl::__internal::__pattern_transform_scan(__dispatch_tag, > ::std::forward<_ExecutionPolicy>(__exec), > >> - __first, > __last, __result, __unary_op, __init, __binary_op, > >> + __first, > __last, __result, __unary_op, std::move(__init), __binary_op, > >> > /*inclusive=*/::std::false_type()); > >> } > >> > >> @@ -238,7 +238,7 @@ transform_inclusive_scan(_ExecutionPolicy&& __exec, > _ForwardIterator1 __first, _ > >> const auto __dispatch_tag = > __onedpl::__internal::__select_backend(__exec, __first, __result); > >> > >> return > __onedpl::__internal::__pattern_transform_scan(__dispatch_tag, > ::std::forward<_ExecutionPolicy>(__exec), > >> - __first, > __last, __result, __unary_op, __init, __binary_op, > >> + __first, > __last, __result, __unary_op, std::move(__init), __binary_op, > >> > /*inclusive=*/::std::true_type()); > >> } > >> > >> diff --git a/libstdc++-v3/include/pstl/numeric_impl.h > b/libstdc++-v3/include/pstl/numeric_impl.h > >> index b050c23b0d57..c140cbbe6b84 100644 > >> --- a/libstdc++-v3/include/pstl/numeric_impl.h > >> +++ b/libstdc++-v3/include/pstl/numeric_impl.h > >> @@ -149,7 +149,7 @@ > __pattern_transform_reduce(__parallel_tag<_IsVector>, _ExecutionPolicy&& > __exec, > >> return __internal::__except_handler([&]() { > >> return __par_backend::__parallel_transform_reduce( > >> __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), > __first, __last, > >> - [__unary_op](_RandomAccessIterator __i) mutable { return > __unary_op(*__i); }, std::move(__init), > >> + [__unary_op](_RandomAccessIterator __i) mutable -> > decltype(auto) { return __unary_op(*__i); }, std::move(__init), > > > > This `decltype(auto)` seems unrelated to the commit's changes: if > returned type is move-only, and __unary_op > > returns an rvalue, then it will still compile. It also wasn't changed a > few lines below, so I would remove that change. > > Without this change it tries to copy the returned object, which fails > for move-only types. > We should then change the lambda in _parallel_transform_scan below in that case. The p0571r2 seem to require that transform return move-only types by xvalue, as the GENERALIZED_NONCOMMUTATIVE_SUM requires IntermediateType(a1). But indeed, that prevents it from working with types like Mint, which provides via operator+ that takes by const& and returns a prvalue. > I'll revert that part and reproduce the error again, but I'm AFK so > can't do it right now. > > > Outside of that LGTM. > >> > >> __binary_op, > >> [__unary_op, __binary_op](_RandomAccessIterator __i, > _RandomAccessIterator __j, _Tp __init_) { > >> return __internal::__brick_transform_reduce(__i, __j, > std::move(__init_), __binary_op, __unary_op, > >> @@ -177,9 +177,9 @@ __brick_transform_scan(_ForwardIterator __first, > _ForwardIterator __last, _Outpu > >> _Tp __temp = *__first; > >> *__result = __init; > >> _ONEDPL_PRAGMA_FORCEINLINE > >> - __init = __binary_op(__init, __unary_op(__temp)); > >> + __init = __binary_op(std::move(__init), > __unary_op(std::move(__temp))); > >> } > >> - return ::std::make_pair(__result, __init); > >> + return ::std::make_pair(__result, std::move(__init)); > >> } > >> > >> // Inclusive form > >> @@ -192,10 +192,10 @@ __brick_transform_scan(_RandomAccessIterator > __first, _RandomAccessIterator __la > >> for (; __first != __last; ++__first, (void)++__result) > >> { > >> _ONEDPL_PRAGMA_FORCEINLINE > >> - __init = __binary_op(__init, __unary_op(*__first)); > >> + __init = __binary_op(std::move(__init), __unary_op(*__first)); > >> *__result = __init; > >> } > >> - return ::std::make_pair(__result, __init); > >> + return ::std::make_pair(__result, std::move(__init)); > >> } > >> > >> // type is arithmetic and binary operation is a user defined operation. > >> @@ -216,12 +216,12 @@ __brick_transform_scan(_RandomAccessIterator > __first, _RandomAccessIterator __la > >> #if _ONEDPL_UDS_PRESENT // PSTL_UDS_PRESENT > >> if (_Inclusive() || > !__onedpl::__internal::__iterators_possibly_equal(__first, __result)) > >> { > >> - return __unseq_backend::__simd_scan(__first, __last - __first, > __result, __unary_op, __init, __binary_op, > >> + return __unseq_backend::__simd_scan(__first, __last - __first, > __result, __unary_op, std::move(__init), __binary_op, > >> _Inclusive()); > >> } > >> #endif > >> // We need to call serial brick here to call function for > inclusive and exclusive scan that depends on _Inclusive() value > >> - return __internal::__brick_transform_scan(__first, __last, > __result, __unary_op, __init, __binary_op, _Inclusive(), > >> + return __internal::__brick_transform_scan(__first, __last, > __result, __unary_op, std::move(__init), __binary_op, _Inclusive(), > >> > /*is_vector=*/::std::false_type()); > >> } > >> > >> @@ -232,7 +232,7 @@ __brick_transform_scan(_RandomAccessIterator > __first, _RandomAccessIterator __la > >> _UnaryOperation __unary_op, _Tp __init, > _BinaryOperation __binary_op, _Inclusive, > >> /*is_vector=*/::std::true_type) noexcept > >> { > >> - return __internal::__brick_transform_scan(__first, __last, > __result, __unary_op, __init, __binary_op, _Inclusive(), > >> + return __internal::__brick_transform_scan(__first, __last, > __result, __unary_op, std::move(__init), __binary_op, _Inclusive(), > >> > /*is_vector=*/::std::false_type()); > >> } > >> > >> @@ -245,7 +245,7 @@ __pattern_transform_scan(_Tag, _ExecutionPolicy&&, > _ForwardIterator __first, _Fo > >> { > >> static_assert(__is_serial_tag_v<_Tag> || > __is_parallel_forward_tag_v<_Tag>); > >> > >> - return __internal::__brick_transform_scan(__first, __last, > __result, __unary_op, __init, __binary_op, _Inclusive(), > >> + return __internal::__brick_transform_scan(__first, __last, > __result, __unary_op, std::move(__init), __binary_op, _Inclusive(), > >> typename > _Tag::__is_vector{}) > >> .first; > >> } > >> @@ -264,17 +264,17 @@> __pattern_transform_scan(__parallel_tag<_IsVector>, > >> _ExecutionPolicy&& > __exec, _ > >> return __internal::__except_handler([&]() { > >> __par_backend::__parallel_transform_scan( > >> __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), > __last - __first, > >> - [__first, __unary_op](_DifferenceType __i) mutable { > return __unary_op(__first[__i]); }, __init, > >> + [__first, __unary_op](_DifferenceType __i) mutable { > return __unary_op(__first[__i]); }, std::move(__init), > I mean one here, to have -> decltype(auto) > >> __binary_op, > >> [__first, __unary_op, __binary_op](_DifferenceType __i, > _DifferenceType __j, _Tp __init) { > >> // Execute serial __brick_transform_reduce, due to the > explicit SIMD vectorization (reduction) requires a commutative operation > for the guarantee of correct scan. > >> - return __internal::__brick_transform_reduce(__first + > __i, __first + __j, __init, __binary_op, > >> + return __internal::__brick_transform_reduce(__first + > __i, __first + __j, std::move(__init), __binary_op, > >> __unary_op, > >> > /*__is_vector*/ ::std::false_type()); > >> }, > >> [__first, __unary_op, __binary_op, > __result](_DifferenceType __i, _DifferenceType __j, _Tp __init) { > >> return __internal::__brick_transform_scan(__first + > __i, __first + __j, __result + __i, __unary_op, > >> - __init, > __binary_op, _Inclusive(), _IsVector{}) > >> + > std::move(__init), __binary_op, _Inclusive(), _IsVector{}) > >> .second; > >> }); > >> return __result + (__last - __first); > >> diff --git a/libstdc++-v3/include/pstl/omp/parallel_transform_scan.h > b/libstdc++-v3/include/pstl/omp/parallel_transform_scan.h > >> index bbd544cfe1ba..c7eeed484611 100644 > >> --- a/libstdc++-v3/include/pstl/omp/parallel_transform_scan.h > >> +++ b/libstdc++-v3/include/pstl/omp/parallel_transform_scan.h > >> @@ -29,7 +29,7 @@ > __parallel_transform_scan(__onedpl::__internal::__omp_backend_tag, > _ExecutionPol > >> _Tp __init, _Cp /* __combine */, _Rp /* > __brick_reduce */, _Sp __scan) > >> { > >> // TODO: parallelize this function. > >> - return __scan(_Index(0), __n, __init); > >> + return __scan(_Index(0), __n, std::move(__init)); > >> } > >> > >> } // namespace __omp_backend > >> diff --git a/libstdc++-v3/include/pstl/parallel_backend_tbb.h > b/libstdc++-v3/include/pstl/parallel_backend_tbb.h > >> index 8f3ca199333f..31fb58b0cd47 100644 > >> --- a/libstdc++-v3/include/pstl/parallel_backend_tbb.h > >> +++ b/libstdc++-v3/include/pstl/parallel_backend_tbb.h > >> @@ -209,7 +209,7 @@ class __trans_scan_body > >> __trans_scan_body(_Up __u, _Tp __init, _Cp __combine, _Rp > __reduce, _Sp __scan) > >> : _M_brick_reduce(__reduce), _M_u(__u), _M_combine(__combine), > _M_scan(__scan), _M_has_sum(true) > >> { > >> - new (_M_sum_storage) _Tp(__init); > >> + new (_M_sum_storage) _Tp(std::move(__init)); > >> } > >> > >> __trans_scan_body(__trans_scan_body& __b, tbb::split) > >> @@ -401,10 +401,10 @@ _Tp > >> __parallel_transform_scan(__onedpl::__internal::__tbb_backend_tag, > _ExecutionPolicy&&, _Index __n, _Up __u, > >> _Tp __init, _Cp __combine, _Rp > __brick_reduce, _Sp __scan) > >> { > >> - __trans_scan_body<_Index, _Up, _Tp, _Cp, _Rp, _Sp> __body(__u, > __init, __combine, __brick_reduce, __scan); > >> + __trans_scan_body<_Index, _Up, _Tp, _Cp, _Rp, _Sp> __body(__u, > std::move(__init), __combine, __brick_reduce, __scan); > >> auto __range = tbb::blocked_range<_Index>(0, __n); > >> tbb::this_task_arena::isolate([__range, &__body]() { > tbb::parallel_scan(__range, __body); }); > >> - return __body.sum(); > >> + return std::move(__body.sum()); > >> } > >> > >> > //------------------------------------------------------------------------ > >> diff --git a/libstdc++-v3/include/std/numeric > b/libstdc++-v3/include/std/numeric > >> index 545131a05432..8f7212c6b957 100644 > >> --- a/libstdc++-v3/include/std/numeric > >> +++ b/libstdc++-v3/include/std/numeric > >> @@ -555,7 +555,7 @@ namespace __detail > >> _Tp __init) > >> { > >> for (; __first != __last; ++__first) > >> - *__result++ = __init = __binary_op(__init, *__first); > >> + *__result++ = __init = __binary_op(std::move(__init), *__first); > >> return __result; > >> } > >> > >> @@ -582,9 +582,10 @@ namespace __detail > >> inclusive_scan(_InputIterator __first, _InputIterator __last, > >> _OutputIterator __result, _BinaryOperation > __binary_op) > >> { > >> + using value_type = typename > iterator_traits<_InputIterator>::value_type; > >> if (__first != __last) > >> { > >> - auto __init = _GLIBCXX_ITER_MOVE(__first); > >> + value_type __init = *__first; > >> *__result++ = __init; > >> ++__first; > >> if (__first != __last) > >> @@ -686,7 +687,8 @@ namespace __detail > >> _Tp __init) > >> { > >> for (; __first != __last; ++__first) > >> - *__result++ = __init = __binary_op(__init, > __unary_op(*__first)); > >> + *__result++ > >> + = __init = __binary_op(std::move(__init), > __unary_op(*__first)); > >> return __result; > >> } > >> > >> @@ -718,9 +720,10 @@ namespace __detail > >> _BinaryOperation __binary_op, > >> _UnaryOperation __unary_op) > >> { > >> + using value_type = typename > iterator_traits<_InputIterator>::value_type; > >> if (__first != __last) > >> { > >> - auto __init = __unary_op(*__first); > >> + value_type __init = __unary_op(*__first); > >> *__result++ = __init; > >> ++__first; > >> if (__first != __last) > >> diff --git > a/libstdc++-v3/testsuite/26_numerics/pstl/numeric_ops/move_only.cc > b/libstdc++-v3/testsuite/26_numerics/pstl/numeric_ops/move_only.cc > >> index 3c5132c292cb..24cacb26a4fc 100644 > >> --- a/libstdc++-v3/testsuite/26_numerics/pstl/numeric_ops/move_only.cc > >> +++ b/libstdc++-v3/testsuite/26_numerics/pstl/numeric_ops/move_only.cc > >> @@ -6,6 +6,7 @@ > >> #include <execution> > >> #include <testsuite_hooks.h> > >> > >> +// A move-only integer > >> struct Mint > >> { > >> Mint(int i = 0) : val(i) { } > >> @@ -28,6 +29,12 @@ struct Mint > >> friend Mint operator+(const Mint& lhs, const Mint& rhs) > >> { return Mint(lhs.val + rhs.val); } > >> > >> + friend Mint operator+(const Mint& lhs, int rhs) > >> + { return Mint(lhs.val + rhs); } > >> + > >> + friend Mint operator+(int lhs, const Mint& rhs) > >> + { return Mint(lhs + rhs.val); } > >> + > >> private: > >> int val; > >> }; > >> @@ -35,8 +42,19 @@ private: > >> void > >> test_reduce() > >> { > >> - Mint input[]{1, 2, 3}; > >> - Mint m = std::reduce(std::execution::seq, input, input+3); > >> + const Mint input[]{1, 2, 3}; > >> + Mint m; > >> + > >> + m = std::reduce(input, input+3); > >> + VERIFY( static_cast<int>(m) == 6 ); > >> + > >> + m = std::reduce(input, input+3, Mint(100)); > >> + VERIFY( static_cast<int>(m) == 106 ); > >> + > >> + m = std::reduce(input, input+3, Mint(200), std::plus<>{}); > >> + VERIFY( static_cast<int>(m) == 206 ); > >> + > >> + m = std::reduce(std::execution::seq, input, input+3); > >> VERIFY( static_cast<int>(m) == 6 ); > >> > >> m = std::reduce(std::execution::seq, input, input+3, Mint(100)); > >> @@ -45,11 +63,59 @@ test_reduce() > >> m = std::reduce(std::execution::seq, input, input+3, Mint(200), > >> std::plus<>{}); > >> VERIFY( static_cast<int>(m) == 206 ); > >> + > >> +#ifndef _ONEDPL_PAR_BACKEND_OPENMP > >> + m = std::reduce(std::execution::par, input, input+3); > >> + VERIFY( static_cast<int>(m) == 6 ); > >> + > >> + m = std::reduce(std::execution::par, input, input+3, Mint(100)); > >> + VERIFY( static_cast<int>(m) == 106 ); > >> + > >> + m = std::reduce(std::execution::par, input, input+3, Mint(200), > >> + std::plus<>{}); > >> + VERIFY( static_cast<int>(m) == 206 ); > >> +#endif > >> } > >> > >> void > >> test_transform_reduce() > >> { > >> + const Mint a[]{1, 2, 3}; > >> + const Mint b[]{4, 5, 6}; > >> + Mint m; > >> + > >> + // transform_reduce over two ranges with explicit reduce and > transform ops. > >> + m = std::transform_reduce( a, a+3, b, Mint(0), > >> + std::plus<>{}, std::plus<>{}); > >> + VERIFY( static_cast<int>(m) == 21 ); // 0 + (1+4) + (2+5) + (3+6) > >> + > >> + // transform_reduce over one range with a unary transform. > >> + m = std::transform_reduce(a, a+3, Mint(10), > >> + std::plus<>{}, > >> + [](const Mint& x) { return x + x; }); > >> + VERIFY( static_cast<int>(m) == 22 ); // 10 + 2 + 4 + 6 > >> + > >> + // transform_reduce over two ranges with explicit reduce and > transform ops. > >> + m = std::transform_reduce(std::execution::seq, a, a+3, b, Mint(0), > >> + std::plus<>{}, std::plus<>{}); > >> + VERIFY( static_cast<int>(m) == 21 ); // 0 + (1+4) + (2+5) + (3+6) > >> + > >> + // transform_reduce over one range with a unary transform. > >> + m = std::transform_reduce(std::execution::seq, a, a+3, Mint(10), > >> + std::plus<>{}, > >> + [](const Mint& x) { return x + x; }); > >> + VERIFY( static_cast<int>(m) == 22 ); // 10 + 2 + 4 + 6 > >> + > >> + // transform_reduce over two ranges with explicit reduce and > transform ops. > >> + m = std::transform_reduce(std::execution::par, a, a+3, b, Mint(0), > >> + std::plus<>{}, std::plus<>{}); > >> + VERIFY( static_cast<int>(m) == 21 ); // 0 + (1+4) + (2+5) + (3+6) > >> + > >> + // transform_reduce over one range with a unary transform. > >> + m = std::transform_reduce(std::execution::par, a, a+3, Mint(10), > >> + std::plus<>{}, > >> + [](const Mint& x) { return x + x; }); > >> + VERIFY( static_cast<int>(m) == 22 ); // 10 + 2 + 4 + 6 > >> } > >> > >> void > >> @@ -57,26 +123,129 @@ test_exclusive_scan() > >> { > >> const int input[]{10, 20, 30}; > >> int output[3]; > >> - std::exclusive_scan(std::execution::seq, input, input+3, output, > Mint(5), > >> - std::plus<int>{}); > >> + std::exclusive_scan(input, input+3, output, Mint(5), std::plus<>{}); > >> VERIFY( output[0] == 5 ); > >> VERIFY( output[1] == 15 ); > >> VERIFY( output[2] == 35 ); > >> + > >> + std::exclusive_scan(std::execution::seq, input, input+3, output, > Mint(5), > >> + std::plus<>{}); > >> + VERIFY( output[0] == 5 ); > >> + VERIFY( output[1] == 15 ); > >> + VERIFY( output[2] == 35 ); > >> + > >> +#ifndef _ONEDPL_PAR_BACKEND_TBB > >> + std::exclusive_scan(std::execution::par, input, input+3, output, > Mint(5), > >> + std::plus<>{}); > >> + VERIFY( output[0] == 5 ); > >> + VERIFY( output[1] == 15 ); > >> + VERIFY( output[2] == 35 ); > >> +#endif > >> } > >> > >> void > >> test_inclusive_scan() > >> { > >> + const int input[]{10, 20, 30}; > >> + int output[3]; > >> + > >> + // Note: for inclusive_scan the binary op precedes the init value. > >> + std::inclusive_scan(input, input+3, output, std::plus<>{}, Mint(5)); > >> + VERIFY( output[0] == 15 ); // 5 + 10 > >> + VERIFY( output[1] == 35 ); // 5 + 10 + 20 > >> + VERIFY( output[2] == 65 ); // 5 + 10 + 20 + 30 > >> + > >> + std::inclusive_scan(input, input+3, output, std::plus<int>{}, > Mint(5)); > >> + VERIFY( output[0] == 15 ); // 5 + 10 > >> + VERIFY( output[1] == 35 ); // 5 + 10 + 20 > >> + VERIFY( output[2] == 65 ); // 5 + 10 + 20 + 30 > >> + > >> + std::inclusive_scan(std::execution::seq, input, input+3, output, > >> + std::plus<>{}, Mint(5)); > >> + VERIFY( output[0] == 15 ); // 5 + 10 > >> + VERIFY( output[1] == 35 ); // 5 + 10 + 20 > >> + VERIFY( output[2] == 65 ); // 5 + 10 + 20 + 30 > >> + > >> + std::inclusive_scan(std::execution::seq, input, input+3, output, > >> + std::plus<int>{}, Mint(5)); > >> + VERIFY( output[0] == 15 ); // 5 + 10 > >> + VERIFY( output[1] == 35 ); // 5 + 10 + 20 > >> + VERIFY( output[2] == 65 ); // 5 + 10 + 20 + 30 > >> + > >> +#ifndef _ONEDPL_PAR_BACKEND_TBB > >> + std::inclusive_scan(std::execution::par, input, input+3, output, > >> + std::plus<>{}, Mint(5)); > >> + VERIFY( output[0] == 15 ); // 5 + 10 > >> + VERIFY( output[1] == 35 ); // 5 + 10 + 20 > >> + VERIFY( output[2] == 65 ); // 5 + 10 + 20 + 30 > >> + > >> + std::inclusive_scan(std::execution::par, input, input+3, output, > >> + std::plus<int>{}, Mint(5)); > >> + VERIFY( output[0] == 15 ); // 5 + 10 > >> + VERIFY( output[1] == 35 ); // 5 + 10 + 20 > >> + VERIFY( output[2] == 65 ); // 5 + 10 + 20 + 30 > >> +#endif > >> } > >> > >> void > >> test_transform_exclusive_scan() > >> { > >> + const int input[]{10, 20, 30}; > >> + int output[3]; > >> + > >> + std::transform_exclusive_scan(input, input+3, output, > >> + Mint(5), std::plus<int>{}, > >> + [](int x) { return x * 2; }); > >> + VERIFY( output[0] == 5 ); // 5 > >> + VERIFY( output[1] == 25 ); // 5 + 20 > >> + VERIFY( output[2] == 65 ); // 5 + 20 + 40 > >> + > >> + std::transform_exclusive_scan(std::execution::seq, input, input+3, > output, > >> + Mint(5), std::plus<int>{}, > >> + [](int x) { return x * 2; }); > >> + VERIFY( output[0] == 5 ); // 5 > >> + VERIFY( output[1] == 25 ); // 5 + 20 > >> + VERIFY( output[2] == 65 ); // 5 + 20 + 40 > >> + > >> +#ifndef _ONEDPL_PAR_BACKEND_TBB > >> + std::transform_exclusive_scan(std::execution::par, input, input+3, > output, > >> + Mint(5), std::plus<int>{}, > >> + [](int x) { return x * 2; }); > >> + VERIFY( output[0] == 5 ); // 5 > >> + VERIFY( output[1] == 25 ); // 5 + 20 > >> + VERIFY( output[2] == 65 ); // 5 + 20 + 40 > >> +#endif > >> } > >> > >> void > >> test_transform_inclusive_scan() > >> { > >> + const int input[]{10, 20, 30}; > >> + int output[3]; > >> + > >> + // Note: for transform_inclusive_scan the init value comes last. > >> + std::transform_inclusive_scan(input, input+3, output, > >> + std::plus<int>{}, [](int x) { return x > * 2; }, > >> + Mint(5)); > >> + VERIFY( output[0] == 25 ); // 5 + 20 > >> + VERIFY( output[1] == 65 ); // 5 + 20 + 40 > >> + VERIFY( output[2] == 125 ); // 5 + 20 + 40 + 60 > >> + > >> + std::transform_inclusive_scan(std::execution::seq, input, input+3, > output, > >> + std::plus<int>{}, [](int x) { return x > * 2; }, > >> + Mint(5)); > >> + VERIFY( output[0] == 25 ); // 5 + 20 > >> + VERIFY( output[1] == 65 ); // 5 + 20 + 40 > >> + VERIFY( output[2] == 125 ); // 5 + 20 + 40 + 60 > >> + > >> +#ifndef _ONEDPL_PAR_BACKEND_TBB > >> + std::transform_inclusive_scan(std::execution::par, input, input+3, > output, > >> + std::plus<int>{}, [](int x) { return x> * > >> 2; }, > >> + Mint(5)); > >> + VERIFY( output[0] == 25 ); // 5 + 20 > >> + VERIFY( output[1] == 65 ); // 5 + 20 + 40 > >> + VERIFY( output[2] == 125 ); // 5 + 20 + 40 + 60 > >> +#endif > >> } > >> > >> int main() > >> -- > >> 2.56.1 > >> > >
