thrust

Functions  
template<typename InputIterator , typename OutputIterator , typename Predicate >  
OutputIterator  thrust::copy_if (InputIterator first, InputIterator last, OutputIterator result, Predicate pred) 
template<typename InputIterator1 , typename InputIterator2 , typename OutputIterator , typename Predicate >  
OutputIterator  thrust::copy_if (InputIterator1 first, InputIterator1 last, InputIterator2 stencil, OutputIterator result, Predicate pred) 
template<typename ForwardIterator , typename T >  
ForwardIterator  thrust::remove (ForwardIterator first, ForwardIterator last, const T &value) 
template<typename InputIterator , typename OutputIterator , typename T >  
OutputIterator  thrust::remove_copy (InputIterator first, InputIterator last, OutputIterator result, const T &value) 
template<typename ForwardIterator , typename Predicate >  
ForwardIterator  thrust::remove_if (ForwardIterator first, ForwardIterator last, Predicate pred) 
template<typename InputIterator , typename OutputIterator , typename Predicate >  
OutputIterator  thrust::remove_copy_if (InputIterator first, InputIterator last, OutputIterator result, Predicate pred) 
template<typename ForwardIterator , typename InputIterator , typename Predicate >  
ForwardIterator  thrust::remove_if (ForwardIterator first, ForwardIterator last, InputIterator stencil, Predicate pred) 
template<typename InputIterator1 , typename InputIterator2 , typename OutputIterator , typename Predicate >  
OutputIterator  thrust::remove_copy_if (InputIterator1 first, InputIterator1 last, InputIterator2 stencil, OutputIterator result, Predicate pred) 
template<typename ForwardIterator >  
ForwardIterator  thrust::unique (ForwardIterator first, ForwardIterator last) 
template<typename ForwardIterator , typename BinaryPredicate >  
ForwardIterator  thrust::unique (ForwardIterator first, ForwardIterator last, BinaryPredicate binary_pred) 
template<typename InputIterator , typename OutputIterator >  
OutputIterator  thrust::unique_copy (InputIterator first, InputIterator last, OutputIterator output) 
template<typename InputIterator , typename OutputIterator , typename BinaryPredicate >  
OutputIterator  thrust::unique_copy (InputIterator first, InputIterator last, OutputIterator output, BinaryPredicate binary_pred) 
template<typename ForwardIterator1 , typename ForwardIterator2 >  
thrust::pair< ForwardIterator1, ForwardIterator2 >  thrust::unique_by_key (ForwardIterator1 keys_first, ForwardIterator1 keys_last, ForwardIterator2 values_first) 
template<typename ForwardIterator1 , typename ForwardIterator2 , typename BinaryPredicate >  
thrust::pair< ForwardIterator1, ForwardIterator2 >  thrust::unique_by_key (ForwardIterator1 keys_first, ForwardIterator1 keys_last, ForwardIterator2 values_first, BinaryPredicate binary_pred) 
template<typename InputIterator1 , typename InputIterator2 , typename OutputIterator1 , typename OutputIterator2 >  
thrust::pair< OutputIterator1, OutputIterator2 >  thrust::unique_by_key_copy (InputIterator1 keys_first, InputIterator1 keys_last, InputIterator2 values_first, OutputIterator1 keys_output, OutputIterator2 values_output) 
template<typename InputIterator1 , typename InputIterator2 , typename OutputIterator1 , typename OutputIterator2 , typename BinaryPredicate >  
thrust::pair< OutputIterator1, OutputIterator2 >  thrust::unique_by_key_copy (InputIterator1 keys_first, InputIterator1 keys_last, InputIterator2 values_first, OutputIterator1 keys_output, OutputIterator2 values_output, BinaryPredicate binary_pred) 
OutputIterator thrust::copy_if  (  InputIterator  first, 
InputIterator  last,  
OutputIterator  result,  
Predicate  pred  
) 
This version of copy_if
copies elements from the range [first,last)
to a range beginning at \ presult, except that any element which causes pred
to be pred
to be false
is not copied.
More precisely, for every integer n
such that 0 <= n < lastfirst
, copy_if
performs the assignment *result = *(first+n)
and result
is advanced one position if pred(*(first+n))
. Otherwise, no assignment occurs and result
is not advanced.
first  The beginning of the sequence from which to copy. 
last  The end of the sequence from which to copy. 
result  The beginning of the sequence into which to copy. 
pred  The predicate to test on every value of the range [first, last) . 
result + n
, where n
is equal to the number of times pred
evaluated to true
in the range [first, last)
.InputIterator  is a model of Input Iterator, and InputIterator's value_type is convertible to Predicate's argument_type . 
OutputIterator  is a model of Output Iterator. 
Predicate  is a model of Predicate. 
The following code snippet demonstrates how to use copy_if
to perform stream compaction to copy even numbers to an output range.
#include <thrust/copy.h> ... struct is_even { __host__ __device__ bool operator()(const int x) { return (x % 2) == 0; } }; ... const int N = 6; int V[N] = {2, 0, 1, 0, 1, 2}; int result[4]; thrust::copy_if(V, V + N, result, is_even()); // V remains {2, 0, 1, 0, 1, 2} // result is now {2, 0, 0, 2}
remove_copy_if
OutputIterator thrust::copy_if  (  InputIterator1  first, 
InputIterator1  last,  
InputIterator2  stencil,  
OutputIterator  result,  
Predicate  pred  
) 
This version of copy_if
copies elements from the range [first,last)
to a range beginning at result
, except that any element whose corresponding stencil element causes pred
to be false
is not copied.
More precisely, for every integer n
such that 0 <= n < lastfirst
, copy_if
performs the assignment *result = *(first+n)
and result
is advanced one position if pred(*(stencil+n))
. Otherwise, no assignment occurs and result
is not advanced.
first  The beginning of the sequence from which to copy. 
last  The end of the sequence from which to copy. 
stencil  The beginning of the stencil sequence. 
result  The beginning of the sequence into which to copy. 
pred  The predicate to test on every value of the range [stencil, stencil + (lastfirst)) . 
result + n
, where n
is equal to the number of times pred
evaluated to true
in the range [stencil, stencil + (lastfirst))
.InputIterator1  is a model of Input Iterator. 
InputIterator2  is a model of Input Iterator, and InputIterator2's value_type is convertible to Predicate's argument_type . 
OutputIterator  is a model of Output Iterator. 
Predicate  is a model of Predicate. 
The following code snippet demonstrates how to use copy_if
to perform stream compaction to copy numbers to an output range when corresponding stencil elements are even:
#include <thrust/copy.h> ... struct is_even { __host__ __device__ bool operator()(const int x) { return (x % 2) == 0; } }; ... int N = 6; int data[N] = { 0, 1, 2, 3, 4, 5}; int stencil[N] = {2, 0, 1, 0, 1, 2}; int result[4]; thrust::copy_if(data, data + N, stencil, result, is_even()); // data remains = { 0, 1, 2, 3, 4, 5}; // stencil remains = {2, 0, 1, 0, 1, 2}; // result is now { 0, 1, 3, 5}
remove_copy_if
ForwardIterator thrust::remove  (  ForwardIterator  first, 
ForwardIterator  last,  
const T &  value  
) 
remove
removes from the range [first, last)
all elements that are equal to value
. That is, remove
returns an iterator new_last
such that the range [first, new_last)
contains no elements equal to value
. The iterators in the range [new_first,last)
are all still dereferenceable, but the elements that they point to are unspecified. remove
is stable, meaning that the relative order of elements that are not equal to value
is unchanged.
first  The beginning of the range of interest. 
last  The end of the range of interest. 
value  The value to remove from the range [first, last) . Elements which are equal to value are removed from the sequence. 
ForwardIterator
pointing to the end of the resulting range of elements which are not equal to value
.ForwardIterator  is a model of Forward Iterator, and ForwardIterator is mutable. 
T  is a model of Equality Comparable, and objects of type T can be compared for equality with objects of ForwardIterator's value_type . 
The following code snippet demonstrates how to use remove
to remove a number of interest from a range.
#include <thrust/remove.h> ... const int N = 6; int A[N] = {3, 1, 4, 1, 5, 9}; int *new_end = thrust::remove(A, A + N, 1); // The first four values of A are now {3, 4, 5, 9} // Values beyond new_end are unspecified
remove
does not destroy any iterators, and does not change the distance between first
and last
. (There's no way that it could do anything of the sort.) So, for example, if V
is a device_vector, remove(V.begin(), V.end(), 0)
does not change V.size()
: V
will contain just as many elements as it did before. remove
returns an iterator that points to the end of the resulting range after elements have been removed from it; it follows that the elements after that iterator are of no interest, and may be discarded. If you are removing elements from a Sequence, you may simply erase them. That is, a reasonable way of removing elements from a Sequence is S.erase(remove(S.begin(), S.end(), x), S.end())
.OutputIterator thrust::remove_copy  (  InputIterator  first, 
InputIterator  last,  
OutputIterator  result,  
const T &  value  
) 
remove_copy
copies elements that are not equal to value
from the range [first, last)
to a range beginning at result
. The return value is the end of the resulting range. This operation is stable, meaning that the relative order of the elements that are copied is the same as in the range [first, last)
.
first  The beginning of the range of interest. 
last  The end of the range of interest. 
result  The resulting range is copied to the sequence beginning at this location. 
value  The value to omit from the copied range. 
value
.InputIterator  is a model of Input Iterator, and InputIterator's value_type is convertible to a type in OutputIterator's set of value_types . 
OutputIterator  is a model of Output Iterator. 
T  is a model of Equality Comparable, and objects of type T can be compared for equality with objects of InputIterator's value_type . 
The following code snippet demonstrates how to use remove_copy
to copy a sequence of numbers to an output range while omitting a value of interest.
#include <thrust/remove.h> ... const int N = 6; int V[N] = {2, 0, 1, 0, 1, 2}; int result[N2]; thrust::remove_copy(V, V + N, result, 0); // V remains {2, 0, 1, 0, 1, 2} // result is now {2, 1, 1, 2}
OutputIterator thrust::remove_copy_if  (  InputIterator  first, 
InputIterator  last,  
OutputIterator  result,  
Predicate  pred  
) 
remove_copy_if
copies elements from the range [first,last)
to a range beginning at result
, except that elements for which pred
is true
are not copied. The return value is the end of the resulting range. This operation is stable, meaning that the relative order of the elements that are copied is the same as the range [first,last)
.
first  The beginning of the range of interest. 
last  The end of the range of interest. 
result  The resulting range is copied to the sequence beginning at this location. 
pred  A predicate to evaluate for each element of the range [first,last) . Elements for which pred evaluates to false are not copied to the resulting sequence. 
InputIterator  is a model of Input Iterator, InputIterator's value_type is convertible to a type in OutputIterator's set of value_types , and InputIterator's value_type is convertible to Predicate's argument_type . 
OutputIterator  is a model of Output Iterator. 
Predicate  is a model of Predicate. 
The following code snippet demonstrates how to use remove_copy_if
to copy a sequence of numbers to an output range while omitting even numbers.
#include <thrust/remove.h> ... struct is_even { __host__ __device__ bool operator()(const int x) { return (x % 2) == 0; } }; ... const int N = 6; int V[N] = {2, 0, 1, 0, 1, 2}; int result[2]; thrust::remove_copy_if(V, V + N, result, is_even()); // V remains {2, 0, 1, 0, 1, 2} // result is now {1, 1}
OutputIterator thrust::remove_copy_if  (  InputIterator1  first, 
InputIterator1  last,  
InputIterator2  stencil,  
OutputIterator  result,  
Predicate  pred  
) 
remove_copy_if
copies elements from the range [first,last)
to a range beginning at result
, except that elements for which pred
of the corresponding stencil value is true
are not copied. The return value is the end of the resulting range. This operation is stable, meaning that the relative order of the elements that are copied is the same as the range [first,last)
.
first  The beginning of the range of interest. 
last  The end of the range of interest. 
stencil  The beginning of the stencil sequence. 
result  The resulting range is copied to the sequence beginning at this location. 
pred  A predicate to evaluate for each element of the range [first,last) . Elements for which pred evaluates to false are not copied to the resulting sequence. 
InputIterator1  is a model of Input Iterator, InputIterator1's value_type is convertible to a type in OutputIterator's set of value_types . 
InputIterator2  is a model of Input Iterator, and InputIterator2's value_type is convertible to Predicate's argument_type . 
OutputIterator  is a model of Output Iterator. 
Predicate  is a model of Predicate. 
The following code snippet demonstrates how to use remove_copy_if
to copy a sequence of numbers to an output range while omitting specific elements.
#include <thrust/remove.h> ... const int N = 6; int V[N] = {2, 0, 1, 0, 1, 2}; int S[N] = { 1, 1, 0, 1, 0, 1}; int result[2]; thrust::remove_copy_if(V, V + N, S, result, thrust::identity<int>()); // V remains {2, 0, 1, 0, 1, 2} // result is now {1, 1}
ForwardIterator thrust::remove_if  (  ForwardIterator  first, 
ForwardIterator  last,  
Predicate  pred  
) 
remove_if
removes from the range [first, last)
every element x
such that pred(x)
is true
. That is, remove_if
returns an iterator new_last
such that the range [first,new_last)
contains no elements for which pred
is true
. The iterators in the range [new_last,last)
are all still dereferenceable, but the elements that they point to are unspecified. remove_if
is stable, meaning that the relative order of elements that are not removed is unchanged.
first  The beginning of the range of interest. 
last  The end of the range of interest. 
pred  A predicate to evaluate for each element of the range [first,last) . Elements for which pred evaluates to false are removed from the sequence. 
pred
evaluated to true
.ForwardIterator  is a model of Forward Iterator, ForwardIterator is mutable, and ForwardIterator's value_type is convertible to Predicate's argument_type . 
Predicate  is a model of Predicate. 
The following code snippet demonstrates how to use remove_if
to remove all even numbers from an array of integers.
#include <thrust/remove.h> ... struct is_even { __host__ __device__ bool operator()(const int x) { return (x % 2) == 0; } }; ... const int N = 6; int A[N] = {1, 4, 2, 8, 5, 7}; int *new_end = thrust::remove_if(A, A + N, is_even()); // The first three values of A are now {1, 5, 7} // Values beyond new_end are unspecified
remove_if
does not destroy any iterators, and does not change the distance between first
and last
. (There's no way that it could do anything of the sort.) So, for example, if V
is a device_vector, remove_if(V.begin(), V.end(), pred)
does not change V.size()
: V
will contain just as many elements as it did before. remove_if
returns an iterator that points to the end of the resulting range after elements have been removed from it; it follows that the elements after that iterator are of no interest, and may be discarded. If you are removing elements from a Sequence, you may simply erase them. That is, a reasonable way of removing elements from a Sequence is S.erase(remove_if(S.begin(), S.end(), pred), S.end())
.ForwardIterator thrust::remove_if  (  ForwardIterator  first, 
ForwardIterator  last,  
InputIterator  stencil,  
Predicate  pred  
) 
remove_if
removes from the range [first, last)
every element x
such that pred(x)
is true
. That is, remove_if
returns an iterator new_last
such that the range [first, new_last)
contains no elements for which pred
of the corresponding stencil value is true
. The iterators in the range [new_last,last)
are all still dereferenceable, but the elements that they point to are unspecified. remove_if
is stable, meaning that the relative order of elements that are not removed is unchanged.
first  The beginning of the range of interest. 
last  The end of the range of interest. 
stencil  The beginning of the stencil sequence. 
pred  A predicate to evaluate for each element of the range [stencil, stencil + (last  first)) . Elements for which pred evaluates to false are removed from the sequence [first, last) 
pred
evaluated to true
.ForwardIterator  is a model of Forward Iterator and ForwardIterator is mutable. 
InputIterator  is a model of Input Iterator, and InputIterator's value_type is convertible to Predicate's argument_type . 
Predicate  is a model of Predicate. 
The following code snippet demonstrates how to use remove_if
to remove specific elements from an array of integers.
#include <thrust/remove.h> ... const int N = 6; int A[N] = {1, 4, 2, 8, 5, 7}; int S[N] = {0, 1, 1, 1, 0, 0}; int *new_end = thrust::remove(A, A + N, S, thrust::identity<int>()); // The first three values of A are now {1, 5, 7} // Values beyond new_end are unspecified
[first, last)
is not permitted to overlap with the range [stencil, stencil + (last  first))
.ForwardIterator thrust::unique  (  ForwardIterator  first, 
ForwardIterator  last  
) 
For each group of consecutive elements in the range [first, last)
with the same value, unique
removes all but the first element of the group. The return value is an iterator new_last
such 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. unique
is stable, meaning that the relative order of elements that are not removed is unchanged.
This version of unique
uses operator==
to test for equality.
first  The beginning of the input range. 
last  The end of the input range. 
[first, new_last)
.ForwardIterator  is a model of Forward Iterator, and ForwardIterator is mutable, and ForwardIterator's value_type is a model of Equality Comparable. 
The following code snippet demonstrates how to use unique
to 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.
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, unique
removes all but the first element of the group. The return value is an iterator new_last
such 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. unique
is stable, meaning that the relative order of elements that are not removed is unchanged.
This version of unique
uses the function object binary_pred
to test for equality.
first  The beginning of the input range. 
last  The end of the input range. 
binary_pred  The binary predicate used to determine equality. 
[first, new_last)
ForwardIterator  is a model of Forward Iterator, and ForwardIterator is mutable, 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. 
The following code snippet demonstrates how to use unique
to 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, thrust::equal_to<int>()); // The first four values of A are now {1, 3, 2, 1} // Values beyond new_end are unspecified.
thrust::pair<ForwardIterator1,ForwardIterator2> thrust::unique_by_key  (  ForwardIterator1  keys_first, 
ForwardIterator1  keys_last,  
ForwardIterator2  values_first  
) 
unique_by_key
is a generalization of unique
to keyvalue pairs. For each group of consecutive keys in the range [keys_first, keys_last)
that are equal, unique_by_key
removes all but the first element of the group. Similarly, the corresponding values in the range [values_first, values_first + (keys_last  keys_first))
are also removed.
The return value is a pair
of iterators (new_keys_last,new_values_last)
such that no two consecutive elements in the range [keys_first, new_keys_last)
are equal.
This version of unique_by_key
uses operator==
to test for equality and project1st
to reduce values with equal keys.
keys_first  The beginning of the key range. 
keys_last  The end of the key range. 
values_first  The beginning of the value range. 
[key_first, keys_new_last)
and [values_first, values_new_last)
.ForwardIterator1  is a model of Forward Iterator, and ForwardIterator1 is mutable, and ForwardIterator's value_type is a model of Equality Comparable. 
ForwardIterator2  is a model of Forward Iterator, and ForwardIterator2 is mutable. 
The following code snippet demonstrates how to use unique_by_key
to compact a sequence of key/value pairs to remove consecutive duplicates.
#include <thrust/unique.h> ... const int N = 7; int A[N] = {1, 3, 3, 3, 2, 2, 1}; // keys int B[N] = {9, 8, 7, 6, 5, 4, 3}; // values thrust::pair<int*,int*> new_end; new_end = thrust::unique_by_key(A, A + N, B); // The first four keys in A are now {1, 3, 2, 1} and new_end.first  A is 4. // The first four values in B are now {9, 8, 5, 3} and new_end.second  B is 4.
thrust::pair<ForwardIterator1,ForwardIterator2> thrust::unique_by_key  (  ForwardIterator1  keys_first, 
ForwardIterator1  keys_last,  
ForwardIterator2  values_first,  
BinaryPredicate  binary_pred  
) 
unique_by_key
is a generalization of unique
to keyvalue pairs. For each group of consecutive keys in the range [keys_first, keys_last)
that are equal, unique_by_key
removes all but the first element of the group. Similarly, the corresponding values in the range [values_first, values_first + (keys_last  keys_first))
are also removed.
This version of unique_by_key
uses the function object binary_pred
to test for equality and project1st
to reduce values with equal keys.
keys_first  The beginning of the key range. 
keys_last  The end of the key range. 
values_first  The beginning of the value range. 
binary_pred  The binary predicate used to determine equality. 
[first, new_last)
.ForwardIterator1  is a model of Forward Iterator, and ForwardIterator1 is mutable, and ForwardIterator's value_type is a model of Equality Comparable. 
ForwardIterator2  is a model of Forward Iterator, and ForwardIterator2 is mutable. 
BinaryPredicate  is a model of Binary Predicate. 
The following code snippet demonstrates how to use unique_by_key
to compact a sequence of key/value pairs to remove consecutive duplicates.
#include <thrust/unique.h> ... const int N = 7; int A[N] = {1, 3, 3, 3, 2, 2, 1}; // keys int B[N] = {9, 8, 7, 6, 5, 4, 3}; // values thrust::pair<int*,int*> new_end; thrust::equal_to<int> binary_pred; new_end = thrust::unique_by_key(keys, keys + N, values, binary_pred); // The first four keys in A are now {1, 3, 2, 1} and new_end.first  A is 4. // The first four values in B are now {9, 8, 5, 3} and new_end.second  B is 4.
thrust::pair<OutputIterator1,OutputIterator2> thrust::unique_by_key_copy  (  InputIterator1  keys_first, 
InputIterator1  keys_last,  
InputIterator2  values_first,  
OutputIterator1  keys_output,  
OutputIterator2  values_output  
) 
unique_by_key_copy
is a generalization of unique_copy
to keyvalue pairs. For each group of consecutive keys in the range [keys_first, keys_last)
that are equal, unique_by_key_copy
copies the first element of the group to a range beginning with keys_output
and the corresponding values from the range [values_first, values_first + (keys_last  keys_first))
are copied to a range beginning with values_output
.
This version of unique_by_key_copy
uses operator==
to test for equality and project1st
to reduce values with equal keys.
keys_first  The beginning of the input key range. 
keys_last  The end of the input key range. 
values_first  The beginning of the input value range. 
keys_output  The beginning of the output key range. 
values_output  The beginning of the output value range. 
[keys_output, keys_output_last)
and [values_output, values_output_last)
.InputIterator1  is a model of Input Iterator, 
InputIterator2  is a model of Input Iterator, 
OutputIterator1  is a model of Output Iterator and and InputIterator1's value_type is convertible to OutputIterator1's value_type . 
OutputIterator2  is a model of Output Iterator and and InputIterator2's value_type is convertible to OutputIterator2's value_type . 
The following code snippet demonstrates how to use unique_by_key_copy
to compact a sequence of key/value pairs and with equal keys.
#include <thrust/unique.h> ... const int N = 7; int A[N] = {1, 3, 3, 3, 2, 2, 1}; // input keys int B[N] = {9, 8, 7, 6, 5, 4, 3}; // input values int C[N]; // output keys int D[N]; // output values thrust::pair<int*,int*> new_end; new_end = thrust::unique_by_key_copy(A, A + N, B, C, D); // The first four keys in C are now {1, 3, 2, 1} and new_end.first  C is 4. // The first four values in D are now {9, 8, 5, 3} and new_end.second  D is 4.
thrust::pair<OutputIterator1,OutputIterator2> thrust::unique_by_key_copy  (  InputIterator1  keys_first, 
InputIterator1  keys_last,  
InputIterator2  values_first,  
OutputIterator1  keys_output,  
OutputIterator2  values_output,  
BinaryPredicate  binary_pred  
) 
unique_by_key_copy
is a generalization of unique_copy
to keyvalue pairs. For each group of consecutive keys in the range [keys_first, keys_last)
that are equal, unique_by_key_copy
copies the first element of the group to a range beginning with keys_output
and the corresponding values from the range [values_first, values_first + (keys_last  keys_first))
are copied to a range beginning with values_output
.
This version of unique_by_key_copy
uses the function object binary_pred
to test for equality and project1st
to reduce values with equal keys.
keys_first  The beginning of the input key range. 
keys_last  The end of the input key range. 
values_first  The beginning of the input value range. 
keys_output  The beginning of the output key range. 
values_output  The beginning of the output value range. 
binary_pred  The binary predicate used to determine equality. 
[keys_output, keys_output_last)
and [values_output, values_output_last)
.InputIterator1  is a model of Input Iterator, 
InputIterator2  is a model of Input Iterator, 
OutputIterator1  is a model of Output Iterator and and InputIterator1's value_type is convertible to OutputIterator1's value_type . 
OutputIterator2  is a model of Output Iterator and and InputIterator2's value_type is convertible to OutputIterator2's value_type . 
BinaryPredicate  is a model of Binary Predicate. 
The following code snippet demonstrates how to use unique_by_key_copy
to compact a sequence of key/value pairs and with equal keys.
#include <thrust/unique.h> ... const int N = 7; int A[N] = {1, 3, 3, 3, 2, 2, 1}; // input keys int B[N] = {9, 8, 7, 6, 5, 4, 3}; // input values int C[N]; // output keys int D[N]; // output values thrust::pair<int*,int*> new_end; thrust::equal_to<int> binary_pred; new_end = thrust::unique_by_key_copy(A, A + N, B, C, D, binary_pred); // The first four keys in C are now {1, 3, 2, 1} and new_end.first  C is 4. // The first four values in D are now {9, 8, 5, 3} and new_end.second  D is 4.
OutputIterator thrust::unique_copy  (  InputIterator  first, 
InputIterator  last,  
OutputIterator  output  
) 
unique_copy
copies elements from the range [first, last)
to a range beginning with output
, except that in a consecutive group of duplicate elements only the first one is copied. The return value is the end of the range to which the elements are copied.
The reason there are two different versions of unique_copy is that there are two different definitions of what it means for a consecutive group of elements to be duplicates. In the first version, the test is simple equality: the elements in a range [f, l)
are duplicates if, for every iterator i
in the range, either i == f
or else *i == *(i1)
. In the second, the test is an arbitrary BinaryPredicate
binary_pred:
the elements in [f, l)
are duplicates if, for every iterator i
in the range, either i == f
or else binary_pred(*i, *(i1))
is true
.
This version of unique_copy
uses operator==
to test for equality.
first  The beginning of the input range. 
last  The end of the input range. 
output  The beginning of the output range. 
[output, output_end)
.InputIterator  is a model of Input Iterator, and InputIterator's value_type is a model of Equality Comparable. 
OutputIterator  is a model of Output Iterator and and InputIterator's value_type is convertible to OutputIterator's value_type . 
The following code snippet demonstrates how to use unique_copy
to 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 B[N]; int * output_end = thrust::unique_copy(A, A + N, B); // The first four values of B are now {1, 3, 2, 1} and (output_end  B) is 4 // Values beyond output_end are unspecified
OutputIterator thrust::unique_copy  (  InputIterator  first, 
InputIterator  last,  
OutputIterator  output,  
BinaryPredicate  binary_pred  
) 
unique_copy
copies elements from the range [first, last)
to a range beginning with output
, except that in a consecutive group of duplicate elements only the first one is copied. The return value is the end of the range to which the elements are copied.
This version of unique_copy
uses the function object binary_pred
to test for equality.
first  The beginning of the input range. 
last  The end of the input range. 
output  The beginning of the output range. 
binary_pred  The binary predicate used to determine equality. 
[output, output_end)
.InputIterator  is a model of Input Iterator, and InputIterator's value_type is a model of Equality Comparable. 
OutputIterator  is a model of Output Iterator and and InputIterator's value_type is convertible to OutputIterator's value_type . 
BinaryPredicate  is a model of Binary Predicate. 
The following code snippet demonstrates how to use unique_copy
to 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 B[N]; int *output_end = thrust::unique_copy(A, A + N, B, thrust::equal_to<int>()); // The first four values of B are now {1, 3, 2, 1} and (output_end  B) is 4 // Values beyond output_end are unspecified.