Skip to content

Commit

Permalink
Fix initial_value load in algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyKopienko committed Oct 21, 2021
1 parent 581639d commit 39a3553
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions include/oneapi/dpl/internal/inclusive_scan_by_segment_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,13 @@ inclusive_scan_by_segment_impl(Policy&& policy, InputIterator1 first1, InputIter
typedef typename ::std::iterator_traits<InputIterator2>::value_type ValueType;
typedef typename ::std::decay<Policy>::type policy_type;

ValueType initial_value = internal::get_data_0<ValueType>(policy, first2);

const auto n = ::std::distance(first1, last1);
// Check for empty and single element ranges
if (n <= 0)
return result;

ValueType initial_value = internal::get_data_0<ValueType>(policy, first2);

if (n == 1)
{
internal::set_data_0(policy, result, initial_value);
Expand Down
4 changes: 2 additions & 2 deletions include/oneapi/dpl/internal/reduce_by_segment_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ reduce_by_segment_impl(Policy&& policy, InputIterator1 first1, InputIterator1 la

namespace __bknd = __par_backend_hetero;

ValueType initial_value = internal::get_data_0<ValueType>(policy, first2);

const auto n = ::std::distance(first1, last1);
if (n <= 0)
return ::std::make_pair(result1, result2);
if (n == 1)
{
ValueType initial_value = internal::get_data_0<ValueType>(policy, first2);

internal::set_data_0(policy, result1, internal::get_data_0<DerefValueType>(policy, first1));
internal::set_data_0(policy, result2, initial_value);
return ::std::make_pair(result1 + 1, result2 + 1);
Expand Down

0 comments on commit 39a3553

Please sign in to comment.