Skip to content

Commit

Permalink
Implement thrust::all_of/any_of via thrust::count_if
Browse files Browse the repository at this point in the history
Related to: NVIDIA#720
  • Loading branch information
bernhardmgruber committed Jun 24, 2024
1 parent ba3fd2e commit 1d3085a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions thrust/thrust/system/detail/generic/logical.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/internal_functional.h>
#include <thrust/find.h>
#include <thrust/count.h>
#include <thrust/logical.h>
#include <thrust/system/detail/generic/tag.h>

THRUST_NAMESPACE_BEGIN
namespace system
Expand All @@ -42,14 +40,16 @@ template <typename ExecutionPolicy, typename InputIterator, typename Predicate>
_CCCL_HOST_DEVICE bool
all_of(thrust::execution_policy<ExecutionPolicy>& exec, InputIterator first, InputIterator last, Predicate pred)
{
return thrust::find_if(exec, first, last, thrust::detail::not1(pred)) == last;
// TODO(bgruber): we could implement this even better using an early exit
return thrust::count_if(exec, first, last, thrust::detail::not1(pred)) == 0;
}

template <typename ExecutionPolicy, typename InputIterator, typename Predicate>
_CCCL_HOST_DEVICE bool
any_of(thrust::execution_policy<ExecutionPolicy>& exec, InputIterator first, InputIterator last, Predicate pred)
{
return thrust::find_if(exec, first, last, pred) != last;
// TODO(bgruber): we could implement this even better using an early exit
return thrust::count_if(exec, first, last, pred) > 0;
}

template <typename ExecutionPolicy, typename InputIterator, typename Predicate>
Expand Down

0 comments on commit 1d3085a

Please sign in to comment.