thrust::unique#
Overloads#
unique(exec, first, last)#
-
template<typename DerivedPolicy, typename ForwardIterator>
ForwardIterator thrust::unique( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- ForwardIterator first,
- ForwardIterator last,
For each group of consecutive elements in the range
[first, last)with the same value,uniqueremoves all but the first element of the group. The return value is an iteratornew_lastsuch that no two consecutive elements in the range[first, new_last)are equal. The iterators in the range[new_last, last)are all still dereferenceable, but the elements that they point to are unspecified.uniqueis stable, meaning that the relative order of elements that are not removed is unchanged.This version of
uniqueusesoperator==to test for equality.The algorithm’s execution is parallelized as determined by
exec.The following code snippet demonstrates how to use
uniqueto compact a sequence of numbers to remove consecutive duplicates using thethrust::hostexecution 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 *new_end = thrust::unique(thrust::host, A, A + N); // The first four values of A are now {1, 3, 2, 1} // Values beyond new_end are unspecified.
See also
- 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
ForwardIteratoris mutable, andForwardIterator'svalue_typeis a model of Equality Comparable.
- Returns:
The end of the unique range
[first, new_last).
unique(first, last)#
-
template<typename ForwardIterator>
ForwardIterator thrust::unique( - ForwardIterator first,
- ForwardIterator last,
For each group of consecutive elements in the range
[first, last)with the same value,uniqueremoves all but the first element of the group. The return value is an iteratornew_lastsuch that no two consecutive elements in the range[first, new_last)are equal. The iterators in the range[new_last, last)are all still dereferenceable, but the elements that they point to are unspecified.uniqueis stable, meaning that the relative order of elements that are not removed is unchanged.This version of
uniqueusesoperator==to test for equality.The following code snippet demonstrates how to use
uniqueto compact a sequence of numbers to remove consecutive duplicates.#include <thrust/unique.h> ... const int N = 7; int A[N] = {1, 3, 3, 3, 2, 2, 1}; int *new_end = thrust::unique(A, A + N); // The first four values of A are now {1, 3, 2, 1} // Values beyond new_end are unspecified.
See also
- 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
ForwardIteratoris mutable, andForwardIterator'svalue_typeis a model of Equality Comparable.- Returns:
The end of the unique range
[first, new_last).
unique(exec, first, last, binary_pred)#
-
template<typename DerivedPolicy, typename ForwardIterator, typename BinaryPredicate>
ForwardIterator thrust::unique( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- ForwardIterator first,
- ForwardIterator last,
- BinaryPredicate binary_pred,
For each group of consecutive elements in the range
[first, last)with the same value,uniqueremoves all but the first element of the group. The return value is an iteratornew_lastsuch that no two consecutive elements in the range[first, new_last)are equal. The iterators in the range[new_last, last)are all still dereferenceable, but the elements that they point to are unspecified.uniqueis stable, meaning that the relative order of elements that are not removed is unchanged.This version of
uniqueuses the function objectbinary_predto test for equality.The algorithm’s execution is parallelized as determined by
exec.The following code snippet demonstrates how to use
uniqueto compact a sequence of numbers to remove consecutive duplicates using thethrust::hostexecution 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 *new_end = thrust::unique(thrust::host, A, A + N, ::cuda::std::equal_to<int>()); // The first four values of A are now {1, 3, 2, 1} // Values beyond new_end are unspecified.
See also
- 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
ForwardIteratoris mutable, andForwardIterator'svalue_typeis convertible toBinaryPredicate'sfirst argument type and toBinaryPredicate'ssecond argument type.BinaryPredicate – is a model of Binary Predicate.
- Returns:
The end of the unique range
[first, new_last)
unique(first, last, binary_pred)#
-
template<typename ForwardIterator, typename BinaryPredicate>
ForwardIterator thrust::unique( - ForwardIterator first,
- ForwardIterator last,
- BinaryPredicate binary_pred,
For each group of consecutive elements in the range
[first, last)with the same value,uniqueremoves all but the first element of the group. The return value is an iteratornew_lastsuch that no two consecutive elements in the range[first, new_last)are equal. The iterators in the range[new_last, last)are all still dereferenceable, but the elements that they point to are unspecified.uniqueis stable, meaning that the relative order of elements that are not removed is unchanged.This version of
uniqueuses the function objectbinary_predto test for equality.The following code snippet demonstrates how to use
uniqueto compact a sequence of numbers to remove consecutive duplicates.#include <thrust/unique.h> ... const int N = 7; int A[N] = {1, 3, 3, 3, 2, 2, 1}; int *new_end = thrust::unique(A, A + N, ::cuda::std::equal_to<int>()); // The first four values of A are now {1, 3, 2, 1} // Values beyond new_end are unspecified.
See also
- 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
ForwardIteratoris mutable, andForwardIterator'svalue_typeis convertible toBinaryPredicate'sfirst argument type and toBinaryPredicate'ssecond argument type.BinaryPredicate – is a model of Binary Predicate.
- Returns:
The end of the unique range
[first, new_last)