unique_count#

Overloads#

unique_count(exec, first, last, binary_pred)#

template<typename DerivedPolicy, typename ForwardIterator, typename BinaryPredicate>
thrust::detail::it_difference_t<ForwardIterator> thrust::unique_count(
const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
ForwardIterator first,
ForwardIterator last,
BinaryPredicate binary_pred,
)#

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

This version of unique_count uses the function object binary_pred to test for equality.

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

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

#include <thrust/unique.h>
#include <thrust/execution_policy.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, ::cuda::std::equal_to<int>());
// count is now 4

See also

unique_copy

See also

reduce_by_key_copy

Parameters:
  • exec – The execution policy to use for parallelization.

  • first – The beginning of the input range.

  • last – The end of the input range.

  • binary_pred – The binary predicate used to determine equality.

Template Parameters:
  • DerivedPolicy – The name of the derived execution policy.

  • ForwardIterator – is 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.

  • BinaryPredicate – is a model of Binary Predicate.

Returns:

The number of runs of equal elements in [first, new_last)

unique_count(exec, first, last)#

template<typename DerivedPolicy, typename ForwardIterator>
thrust::detail::it_difference_t<ForwardIterator> 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.

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>
#include <thrust/execution_policy.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

See also

reduce_by_key_copy

Parameters:
  • exec – The execution policy to use for parallelization.

  • first – The beginning of the input range.

  • last – The end of the input range.

Template Parameters:
  • DerivedPolicy – The name of the derived execution policy.

  • ForwardIterator – is 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.

  • BinaryPredicate – is a model of Binary Predicate.

Returns:

The number of runs of equal elements in [first, new_last)

unique_count(first, last, binary_pred)#

template<typename ForwardIterator, typename BinaryPredicate>
thrust::detail::it_difference_t<ForwardIterator> thrust::unique_count(
ForwardIterator first,
ForwardIterator last,
BinaryPredicate binary_pred,
)#

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

This version of unique_count uses the function object binary_pred to test for equality.

The following code snippet demonstrates how to use unique_count to determine the number of runs of equal elements:

#include <thrust/unique.h>
#include <thrust/execution_policy.h>
...
const int N = 7;
int A[N] = {1, 3, 3, 3, 2, 2, 1};
int count = thrust::unique_count(A, A + N, ::cuda::std::equal_to<int>());
// count is now 4

See also

unique_copy

See also

reduce_by_key_copy

Parameters:
  • first – The beginning of the input range.

  • last – The end of the input range.

  • binary_pred – The binary predicate used to determine equality.

Template Parameters:
  • ForwardIterator – is 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.

  • BinaryPredicate – is a model of Binary Predicate.

Returns:

The number of runs of equal elements in [first, new_last)

unique_count(first, last)#

template<typename ForwardIterator>
thrust::detail::it_difference_t<ForwardIterator> thrust::unique_count(
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 following code snippet demonstrates how to use unique_count to determine the number of runs of equal elements:

#include <thrust/unique.h>
#include <thrust/execution_policy.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

See also

reduce_by_key_copy

Parameters:
  • first – The beginning of the input range.

  • last – The end of the input range.

Template Parameters:
  • ForwardIterator – is 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.

  • BinaryPredicate – is a model of Binary Predicate.

Returns:

The number of runs of equal elements in [first, new_last)