Thrust

◆ unique_count() [2/4]

template<typename DerivedPolicy , typename ForwardIterator >
__host__ __device__ thrust::iterator_traits<ForwardIterator>::difference_type thrust::unique_count ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
ForwardIterator  first,
ForwardIterator  last 
)

unique_count counts runs of equal elements in the range [first, last) with the same value,

This version of unique_count uses operator== to test for equality.

The algorithm's execution is parallelized as determined by exec.

Parameters
execThe execution policy to use for parallelization.
firstThe beginning of the input range.
lastThe end of the input range.
binary_predThe binary predicate used to determine equality.
Returns
The number of runs of equal elements in [first, new_last)
Template Parameters
DerivedPolicyThe name of the derived execution policy.
ForwardIteratoris a model of Forward Iterator, and ForwardIterator's value_type is convertible to BinaryPredicate's first_argument_type and to BinaryPredicate's second_argument_type.
BinaryPredicateis a model of Binary Predicate.

The following code snippet demonstrates how to use unique_count to determine the number of runs of equal elements using the thrust::host execution policy for parallelization:

#include <thrust/unique.h>
...
const int N = 7;
int A[N] = {1, 3, 3, 3, 2, 2, 1};
int count = thrust::unique_count(thrust::host, A, A + N);
// count is now 4
See also
unique_copy
unique_by_key_copy
reduce_by_key_copy