Skip to content

Commit

Permalink
std_algos: fix wrong corner case for is_partitioned (kokkos#6257)
Browse files Browse the repository at this point in the history
* std_algos: fix wrong corner case for is_partitioned

* avoid turning format off
  • Loading branch information
fnrizzi committed Jul 5, 2023
1 parent 6a8488d commit 07a0f0c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions algorithms/src/std_algorithms/impl/Kokkos_IsPartitioned.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,16 @@ bool is_partitioned_impl(const std::string& label, const ExecutionSpace& ex,

if (red_result.max_loc_true != red_id_max &&
red_result.min_loc_false != red_id_min) {
// this occurs when the reduction yields nontrivial values
return red_result.max_loc_true < red_result.min_loc_false;
} else if (red_result.max_loc_true == red_id_max &&
red_result.min_loc_false == 0) {
// this occurs when all values do NOT satisfy
// the predicate, and this corner case should also be true
return true;
} else if (first + red_result.max_loc_true == --last) {
// this occurs when all values DO satisfy the predicate,
// this corner case should also be true
return true;
} else {
return false;
Expand Down
2 changes: 1 addition & 1 deletion algorithms/unit_tests/TestStdAlgorithmsPartitioningOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ struct std_algorithms_partitioning_test : public std_algorithms_test {
case Mixed: return false;
case NegativeFirst: return true;
case AllNegative: return true;
case AllPositive: return false;
case AllPositive: return true;
case NegativeLast: return false;
case SingleNegative: return true;
default: return false;
Expand Down

0 comments on commit 07a0f0c

Please sign in to comment.