thrust
Functions
Predicates

Functions

template<typename DerivedPolicy , typename InputIterator , typename Predicate >
__host__ __device__ bool thrust::is_partitioned (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, InputIterator first, InputIterator last, Predicate pred)
 
template<typename InputIterator , typename Predicate >
bool thrust::is_partitioned (InputIterator first, InputIterator last, Predicate pred)
 
template<typename DerivedPolicy , typename ForwardIterator >
__host__ __device__ bool thrust::is_sorted (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, ForwardIterator first, ForwardIterator last)
 
template<typename ForwardIterator >
bool thrust::is_sorted (ForwardIterator first, ForwardIterator last)
 
template<typename DerivedPolicy , typename ForwardIterator , typename Compare >
__host__ __device__ bool thrust::is_sorted (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, ForwardIterator first, ForwardIterator last, Compare comp)
 
template<typename ForwardIterator , typename Compare >
bool thrust::is_sorted (ForwardIterator first, ForwardIterator last, Compare comp)
 
template<typename DerivedPolicy , typename ForwardIterator >
__host__ __device__ ForwardIterator thrust::is_sorted_until (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, ForwardIterator first, ForwardIterator last)
 
template<typename ForwardIterator >
ForwardIterator thrust::is_sorted_until (ForwardIterator first, ForwardIterator last)
 
template<typename DerivedPolicy , typename ForwardIterator , typename Compare >
__host__ __device__ ForwardIterator thrust::is_sorted_until (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, ForwardIterator first, ForwardIterator last, Compare comp)
 
template<typename ForwardIterator , typename Compare >
ForwardIterator thrust::is_sorted_until (ForwardIterator first, ForwardIterator last, Compare comp)
 

Detailed Description

Function Documentation

template<typename DerivedPolicy , typename InputIterator , typename Predicate >
__host__ __device__ bool thrust::is_partitioned ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
InputIterator  first,
InputIterator  last,
Predicate  pred 
)

is_partitioned returns true if the given range is partitioned with respect to a predicate, and false otherwise.

Specifically, is_partitioned returns true if [first, last) is empty of if [first, last) is partitioned by pred, i.e. if all elements that satisfy pred appear before those that do not.

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

Parameters
execThe execution policy to use for parallelization.
firstThe beginning of the range to consider.
lastThe end of the range to consider.
predA function object which decides to which partition each element of the range [first, last) belongs.
Returns
true if the range [first, last) is partitioned with respect to pred, or if [first, last) is empty. false, otherwise.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
InputIteratoris a model of Input Iterator, and InputIterator's value_type is convertible to Predicate's argument_type.
Predicateis a model of Predicate.
struct is_even
{
__host__ __device__
bool operator()(const int &x)
{
return (x % 2) == 0;
}
};
...
int A[] = {2, 4, 6, 8, 10, 1, 3, 5, 7, 9};
int B[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
thrust::is_partitioned(thrust::host, A, A + 10, is_even()); // returns true
thrust::is_partitioned(thrust::host, B, B + 10, is_even()); // returns false
See Also
partition
template<typename InputIterator , typename Predicate >
bool thrust::is_partitioned ( InputIterator  first,
InputIterator  last,
Predicate  pred 
)

is_partitioned returns true if the given range is partitioned with respect to a predicate, and false otherwise.

Specifically, is_partitioned returns true if [first, last) is empty of if [first, last) is partitioned by pred, i.e. if all elements that satisfy pred appear before those that do not.

Parameters
firstThe beginning of the range to consider.
lastThe end of the range to consider.
predA function object which decides to which partition each element of the range [first, last) belongs.
Returns
true if the range [first, last) is partitioned with respect to pred, or if [first, last) is empty. false, otherwise.
Template Parameters
InputIteratoris a model of Input Iterator, and InputIterator's value_type is convertible to Predicate's argument_type.
Predicateis a model of Predicate.
struct is_even
{
__host__ __device__
bool operator()(const int &x)
{
return (x % 2) == 0;
}
};
...
int A[] = {2, 4, 6, 8, 10, 1, 3, 5, 7, 9};
int B[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
thrust::is_partitioned(A, A + 10, is_even()); // returns true
thrust::is_partitioned(B, B + 10, is_even()); // returns false
See Also
partition
template<typename DerivedPolicy , typename ForwardIterator >
__host__ __device__ bool thrust::is_sorted ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
ForwardIterator  first,
ForwardIterator  last 
)

is_sorted returns true if the range [first, last) is sorted in ascending order, and false otherwise.

Specifically, this version of is_sorted returns false if for some iterator i in the range [first, last - 1) the expression *(i + 1) < *i is true.

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

Parameters
execThe execution policy to use for parallelization.
firstThe beginning of the sequence.
lastThe end of the sequence.
Returns
true, if the sequence is sorted; false, otherwise.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
ForwardIteratoris a model of Forward Iterator, ForwardIterator's value_type is a model of LessThan Comparable, and the ordering on objects of ForwardIterator's value_type is a strict weak ordering, as defined in the LessThan Comparable requirements.

The following code demonstrates how to use is_sorted to test whether the contents of a device_vector are stored in ascending order using the thrust::device execution policy for parallelization:

#include <thrust/sort.h>
#include <thrust/sort.h>
...
thrust::device_vector<int> v(6);
v[0] = 1;
v[1] = 4;
v[2] = 2;
v[3] = 8;
v[4] = 5;
v[5] = 7;
bool result = thrust::is_sorted(thrust::device, v.begin(), v.end());
// result == false
thrust::sort(v.begin(), v.end());
result = thrust::is_sorted(thrust::device, v.begin(), v.end());
// result == true
See Also
http://www.sgi.com/tech/stl/is_sorted.html
is_sorted_until
sort
stable_sort
less<T>
template<typename ForwardIterator >
bool thrust::is_sorted ( ForwardIterator  first,
ForwardIterator  last 
)

is_sorted returns true if the range [first, last) is sorted in ascending order, and false otherwise.

Specifically, this version of is_sorted returns false if for some iterator i in the range [first, last - 1) the expression *(i + 1) < *i is true.

Parameters
firstThe beginning of the sequence.
lastThe end of the sequence.
Returns
true, if the sequence is sorted; false, otherwise.
Template Parameters
ForwardIteratoris a model of Forward Iterator, ForwardIterator's value_type is a model of LessThan Comparable, and the ordering on objects of ForwardIterator's value_type is a strict weak ordering, as defined in the LessThan Comparable requirements.

The following code demonstrates how to use is_sorted to test whether the contents of a device_vector are stored in ascending order.

#include <thrust/sort.h>
#include <thrust/sort.h>
...
thrust::device_vector<int> v(6);
v[0] = 1;
v[1] = 4;
v[2] = 2;
v[3] = 8;
v[4] = 5;
v[5] = 7;
bool result = thrust::is_sorted(v.begin(), v.end());
// result == false
thrust::sort(v.begin(), v.end());
result = thrust::is_sorted(v.begin(), v.end());
// result == true
See Also
http://www.sgi.com/tech/stl/is_sorted.html
is_sorted_until
sort
stable_sort
less<T>
template<typename DerivedPolicy , typename ForwardIterator , typename Compare >
__host__ __device__ bool thrust::is_sorted ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
ForwardIterator  first,
ForwardIterator  last,
Compare  comp 
)

is_sorted returns true if the range [first, last) is sorted in ascending order accoring to a user-defined comparison operation, and false otherwise.

Specifically, this version of is_sorted returns false if for some iterator i in the range [first, last - 1) the expression comp(*(i + 1), *i) is true.

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

Parameters
execThe execution policy to use for parallelization.
firstThe beginning of the sequence.
lastThe end of the sequence.
compComparison operator.
Returns
true, if the sequence is sorted according to comp; false, otherwise.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
ForwardIteratoris a model of Forward Iterator, and ForwardIterator's value_type is convertible to both StrictWeakOrdering's first_argument_type and second_argument_type.
Compareis a model of Strict Weak Ordering.

The following code snippet demonstrates how to use is_sorted to test whether the contents of a device_vector are stored in descending order using the thrust::device execution policy for parallelization:

#include <thrust/sort.h>
...
thrust::device_vector<int> v(6);
v[0] = 1;
v[1] = 4;
v[2] = 2;
v[3] = 8;
v[4] = 5;
v[5] = 7;
bool result = thrust::is_sorted(thrust::device, v.begin(), v.end(), comp);
// result == false
thrust::sort(v.begin(), v.end(), comp);
result = thrust::is_sorted(thrust::device, v.begin(), v.end(), comp);
// result == true
See Also
http://www.sgi.com/tech/stl/is_sorted.html
sort
stable_sort
less<T>
template<typename ForwardIterator , typename Compare >
bool thrust::is_sorted ( ForwardIterator  first,
ForwardIterator  last,
Compare  comp 
)

is_sorted returns true if the range [first, last) is sorted in ascending order accoring to a user-defined comparison operation, and false otherwise.

Specifically, this version of is_sorted returns false if for some iterator i in the range [first, last - 1) the expression comp(*(i + 1), *i) is true.

Parameters
firstThe beginning of the sequence.
lastThe end of the sequence.
compComparison operator.
Returns
true, if the sequence is sorted according to comp; false, otherwise.
Template Parameters
ForwardIteratoris a model of Forward Iterator, and ForwardIterator's value_type is convertible to both StrictWeakOrdering's first_argument_type and second_argument_type.
Compareis a model of Strict Weak Ordering.

The following code snippet demonstrates how to use is_sorted to test whether the contents of a device_vector are stored in descending order.

#include <thrust/sort.h>
...
thrust::device_vector<int> v(6);
v[0] = 1;
v[1] = 4;
v[2] = 2;
v[3] = 8;
v[4] = 5;
v[5] = 7;
bool result = thrust::is_sorted(v.begin(), v.end(), comp);
// result == false
thrust::sort(v.begin(), v.end(), comp);
result = thrust::is_sorted(v.begin(), v.end(), comp);
// result == true
See Also
http://www.sgi.com/tech/stl/is_sorted.html
sort
stable_sort
less<T>
template<typename DerivedPolicy , typename ForwardIterator >
__host__ __device__ ForwardIterator thrust::is_sorted_until ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
ForwardIterator  first,
ForwardIterator  last 
)

This version of is_sorted_until returns the last iterator i in [first,last] for which the range [first,last) is sorted using operator<. If distance(first,last) < 2, is_sorted_until simply returns last.

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

Parameters
execThe execution policy to use for parallelization.
firstThe beginning of the range of interest.
lastThe end of the range of interest.
Returns
The last iterator in the input range for which it is sorted.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
ForwardIteratoris a model of Forward Iterator and ForwardIterator's value_type is a model of LessThan Comparable.

The following code snippet demonstrates how to use is_sorted_until to find the first position in an array where the data becomes unsorted using the thrust::host execution policy for parallelization:

#include <thrust/sort.h>
...
int A[8] = {0, 1, 2, 3, 0, 1, 2, 3};
// B - A is 4
// [A, B) is sorted
See Also
is_sorted
sort
sort_by_key
stable_sort
stable_sort_by_key
template<typename ForwardIterator >
ForwardIterator thrust::is_sorted_until ( ForwardIterator  first,
ForwardIterator  last 
)

This version of is_sorted_until returns the last iterator i in [first,last] for which the range [first,last) is sorted using operator<. If distance(first,last) < 2, is_sorted_until simply returns last.

Parameters
firstThe beginning of the range of interest.
lastThe end of the range of interest.
Returns
The last iterator in the input range for which it is sorted.
Template Parameters
ForwardIteratoris a model of Forward Iterator and ForwardIterator's value_type is a model of LessThan Comparable.

The following code snippet demonstrates how to use is_sorted_until to find the first position in an array where the data becomes unsorted:

#include <thrust/sort.h>
...
int A[8] = {0, 1, 2, 3, 0, 1, 2, 3};
int * B = thrust::is_sorted_until(A, A + 8);
// B - A is 4
// [A, B) is sorted
See Also
is_sorted
sort
sort_by_key
stable_sort
stable_sort_by_key
template<typename DerivedPolicy , typename ForwardIterator , typename Compare >
__host__ __device__ ForwardIterator thrust::is_sorted_until ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
ForwardIterator  first,
ForwardIterator  last,
Compare  comp 
)

This version of is_sorted_until returns the last iterator i in [first,last] for which the range [first,last) is sorted using the function object comp. If distance(first,last) < 2, is_sorted_until simply returns last.

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

Parameters
execThe execution policy to use for parallelization:
firstThe beginning of the range of interest.
lastThe end of the range of interest.
compThe function object to use for comparison.
Returns
The last iterator in the input range for which it is sorted.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
ForwardIteratoris a model of Forward Iterator and ForwardIterator's value_type is convertible to Compare's argument_type.
Compareis a model of Strict Weak Ordering.

The following code snippet demonstrates how to use is_sorted_until to find the first position in an array where the data becomes unsorted in descending order using the thrust::host execution policy for parallelization:

#include <thrust/sort.h>
...
int A[8] = {3, 2, 1, 0, 3, 2, 1, 0};
int * B = thrust::is_sorted_until(thrust::host, A, A + 8, comp);
// B - A is 4
// [A, B) is sorted in descending order
See Also
is_sorted
sort
sort_by_key
stable_sort
stable_sort_by_key
template<typename ForwardIterator , typename Compare >
ForwardIterator thrust::is_sorted_until ( ForwardIterator  first,
ForwardIterator  last,
Compare  comp 
)

This version of is_sorted_until returns the last iterator i in [first,last] for which the range [first,last) is sorted using the function object comp. If distance(first,last) < 2, is_sorted_until simply returns last.

Parameters
firstThe beginning of the range of interest.
lastThe end of the range of interest.
compThe function object to use for comparison.
Returns
The last iterator in the input range for which it is sorted.
Template Parameters
ForwardIteratoris a model of Forward Iterator and ForwardIterator's value_type is convertible to Compare's argument_type.
Compareis a model of Strict Weak Ordering.

The following code snippet demonstrates how to use is_sorted_until to find the first position in an array where the data becomes unsorted in descending order:

#include <thrust/sort.h>
...
int A[8] = {3, 2, 1, 0, 3, 2, 1, 0};
int * B = thrust::is_sorted_until(A, A + 8, comp);
// B - A is 4
// [A, B) is sorted in descending order
See Also
is_sorted
sort
sort_by_key
stable_sort
stable_sort_by_key