Diff Detail
Diff Detail
Event Timeline
Comment Actions
Re-reading this, I may have implemented exclusive_scan instead of inclusive_scan here.
Comment Actions
I don't think that this is a correct implementation. Also, I need tests for when the result overwrites the source.
As they say .. I'll be back :-)
Comment Actions
So, the inclusive_scan overloads that do not take an init parameter should be equivalent to partial_sum for the non-parallel version.
Comment Actions
Here's partial_sum:
template <class _InputIterator, class _OutputIterator, class _BinaryOperation> inline _LIBCPP_INLINE_VISIBILITY _OutputIterator partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOperation __binary_op) { if (__first != __last) { typename iterator_traits<_InputIterator>::value_type __t(*__first); *__result = __t; for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result) { __t = __binary_op(__t, *__first); *__result = __t; } } return __result; }
And here's the inclusive_scan that should be equivalent to that partial_sum:
template <class _InputIterator, class _OutputIterator, class _BinaryOp> inline _LIBCPP_INLINE_VISIBILITY _OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOp __b) { if (__first != __last) { typename iterator_traits<_InputIterator>::value_type __init = *__first++; return inclusive_scan(__first, __last, __result, __b, __init); } return __result; }
The inclusive_scan that it forwards to is:
template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp> inline _LIBCPP_INLINE_VISIBILITY _OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOp __b, _Tp __init) { *__result++ = __init; for (; __first != __last; ++__first) { __init = __b(__init, *__first); *__result++ = __init; } return __result; }
Inlining it, we get:
template <class _InputIterator, class _OutputIterator, class _BinaryOp> inline _LIBCPP_INLINE_VISIBILITY _OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOp __b) { if (__first != __last) { typename iterator_traits<_InputIterator>::value_type __init = *__first++; *__result++ = __init; for (; __first != __last; ++__first) { __init = __b(__init, *__first); *__result++ = __init; } } return __result; }
That looks equivalent to the partial_sum implementation above, so I think it is correct.