thrust
Functions
Extrema

Functions

template<typename DerivedPolicy , typename ForwardIterator >
__host__ __device__ ForwardIterator thrust::min_element (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, ForwardIterator first, ForwardIterator last)
 
template<typename ForwardIterator >
ForwardIterator thrust::min_element (ForwardIterator first, ForwardIterator last)
 
template<typename DerivedPolicy , typename ForwardIterator , typename BinaryPredicate >
__host__ __device__ ForwardIterator thrust::min_element (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, ForwardIterator first, ForwardIterator last, BinaryPredicate comp)
 
template<typename ForwardIterator , typename BinaryPredicate >
ForwardIterator thrust::min_element (ForwardIterator first, ForwardIterator last, BinaryPredicate comp)
 
template<typename DerivedPolicy , typename ForwardIterator >
__host__ __device__ ForwardIterator thrust::max_element (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, ForwardIterator first, ForwardIterator last)
 
template<typename ForwardIterator >
ForwardIterator thrust::max_element (ForwardIterator first, ForwardIterator last)
 
template<typename DerivedPolicy , typename ForwardIterator , typename BinaryPredicate >
__host__ __device__ ForwardIterator thrust::max_element (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, ForwardIterator first, ForwardIterator last, BinaryPredicate comp)
 
template<typename ForwardIterator , typename BinaryPredicate >
ForwardIterator thrust::max_element (ForwardIterator first, ForwardIterator last, BinaryPredicate comp)
 
template<typename DerivedPolicy , typename ForwardIterator >
__host__ __device__
thrust::pair< ForwardIterator,
ForwardIterator > 
thrust::minmax_element (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, ForwardIterator first, ForwardIterator last)
 
template<typename ForwardIterator >
thrust::pair< ForwardIterator,
ForwardIterator > 
thrust::minmax_element (ForwardIterator first, ForwardIterator last)
 
template<typename DerivedPolicy , typename ForwardIterator , typename BinaryPredicate >
__host__ __device__
thrust::pair< ForwardIterator,
ForwardIterator > 
thrust::minmax_element (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, ForwardIterator first, ForwardIterator last, BinaryPredicate comp)
 
template<typename ForwardIterator , typename BinaryPredicate >
thrust::pair< ForwardIterator,
ForwardIterator > 
thrust::minmax_element (ForwardIterator first, ForwardIterator last, BinaryPredicate comp)
 

Detailed Description

Function Documentation

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

max_element finds the largest element in the range [first, last). It returns the first iterator i in [first, last) such that no other iterator in [first, last) points to a value larger than *i. The return value is last if and only if [first, last) is an empty range.

The two versions of max_element differ in how they define whether one element is greater than another. This version compares objects using operator<. Specifically, this version of max_element returns the first iterator i in [first, last) such that, for every iterator j in [first, last), *i < *j is false.

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
An iterator pointing to the largest element of the range [first, last), if it is not an empty range; last, otherwise.
Template Parameters
AThrust backend system.
ForwardIteratoris a model of Forward Iterator, and ForwardIterator's value_type is a model of LessThan Comparable.
#include <thrust/extrema.h>
...
int data[6] = {1, 0, 2, 2, 1, 3};
int *result = thrust::max_element(thrust::host, data, data + 6);
// *result == 3
See Also
http://www.sgi.com/tech/stl/max_element.html
template<typename ForwardIterator >
ForwardIterator thrust::max_element ( ForwardIterator  first,
ForwardIterator  last 
)

max_element finds the largest element in the range [first, last). It returns the first iterator i in [first, last) such that no other iterator in [first, last) points to a value larger than *i. The return value is last if and only if [first, last) is an empty range.

The two versions of max_element differ in how they define whether one element is greater than another. This version compares objects using operator<. Specifically, this version of max_element returns the first iterator i in [first, last) such that, for every iterator j in [first, last), *i < *j is false.

Parameters
firstThe beginning of the sequence.
lastThe end of the sequence.
Returns
An iterator pointing to the largest element of the range [first, last), if it is not an empty range; last, otherwise.
Template Parameters
ForwardIteratoris a model of Forward Iterator, and ForwardIterator's value_type is a model of LessThan Comparable.
#include <thrust/extrema.h>
...
int data[6] = {1, 0, 2, 2, 1, 3};
int *result = thrust::max_element(data, data + 6);
// *result == 3
See Also
http://www.sgi.com/tech/stl/max_element.html
template<typename DerivedPolicy , typename ForwardIterator , typename BinaryPredicate >
__host__ __device__ ForwardIterator thrust::max_element ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
ForwardIterator  first,
ForwardIterator  last,
BinaryPredicate  comp 
)

max_element finds the largest element in the range [first, last). It returns the first iterator i in [first, last) such that no other iterator in [first, last) points to a value larger than *i. The return value is last if and only if [first, last) is an empty range.

The two versions of max_element differ in how they define whether one element is less than another. This version compares objects using a function object comp. Specifically, this version of max_element returns the first iterator i in [first, last) such that, for every iterator j in [first, last), comp(*i, *j) is false.

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.
compA binary predicate used for comparison.
Returns
An iterator pointing to the largest element of the range [first, last), if it is not an empty range; last, 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 comp's first_argument_type and second_argument_type.
BinaryPredicateis a model of Binary Predicate.

The following code snippet demonstrates how to use max_element to find the largest element of a collection of key-value pairs using the thrust::host execution policy for parallelization.

#include <thrust/extrema.h>
...
struct key_value
{
int key;
int value;
};
struct compare_key_value
{
__host__ __device__
bool operator()(key_value lhs, key_value rhs)
{
return lhs.key < rhs.key;
}
};
...
key_value data[4] = { {4,5}, {0,7}, {2,3}, {6,1} };
key_value *largest = thrust::max_element(thrust::host, data, data + 4, compare_key_value());
// largest == data + 3
// *largest == {6,1}
See Also
http://www.sgi.com/tech/stl/max_element.html
template<typename ForwardIterator , typename BinaryPredicate >
ForwardIterator thrust::max_element ( ForwardIterator  first,
ForwardIterator  last,
BinaryPredicate  comp 
)

max_element finds the largest element in the range [first, last). It returns the first iterator i in [first, last) such that no other iterator in [first, last) points to a value larger than *i. The return value is last if and only if [first, last) is an empty range.

The two versions of max_element differ in how they define whether one element is less than another. This version compares objects using a function object comp. Specifically, this version of max_element returns the first iterator i in [first, last) such that, for every iterator j in [first, last), comp(*i, *j) is false.

Parameters
firstThe beginning of the sequence.
lastThe end of the sequence.
compA binary predicate used for comparison.
Returns
An iterator pointing to the largest element of the range [first, last), if it is not an empty range; last, otherwise.
Template Parameters
ForwardIteratoris a model of Forward Iterator, and ForwardIterator's value_type is convertible to both comp's first_argument_type and second_argument_type.
BinaryPredicateis a model of Binary Predicate.

The following code snippet demonstrates how to use max_element to find the largest element of a collection of key-value pairs.

#include <thrust/extrema.h>
struct key_value
{
int key;
int value;
};
struct compare_key_value
{
__host__ __device__
bool operator()(key_value lhs, key_value rhs)
{
return lhs.key < rhs.key;
}
};
...
key_value data[4] = { {4,5}, {0,7}, {2,3}, {6,1} };
key_value *largest = thrust::max_element(data, data + 4, compare_key_value());
// largest == data + 3
// *largest == {6,1}
See Also
http://www.sgi.com/tech/stl/max_element.html
template<typename DerivedPolicy , typename ForwardIterator >
__host__ __device__ ForwardIterator thrust::min_element ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
ForwardIterator  first,
ForwardIterator  last 
)

min_element finds the smallest element in the range [first, last). It returns the first iterator i in [first, last) such that no other iterator in [first, last) points to a value smaller than *i. The return value is last if and only if [first, last) is an empty range.

The two versions of min_element differ in how they define whether one element is less than another. This version compares objects using operator<. Specifically, this version of min_element returns the first iterator i in [first, last) such that, for every iterator j in [first, last), *j < *i is false.

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
An iterator pointing to the smallest element of the range [first, last), if it is not an empty range; last, otherwise.
Template Parameters
ForwardIteratoris a model of Forward Iterator, and ForwardIterator's value_type is a model of LessThan Comparable.
#include <thrust/extrema.h>
...
int data[6] = {1, 0, 2, 2, 1, 3};
int *result = thrust::min_element(thrust::host, data, data + 6);
// result is data + 1
// *result is 0
See Also
http://www.sgi.com/tech/stl/min_element.html
template<typename ForwardIterator >
ForwardIterator thrust::min_element ( ForwardIterator  first,
ForwardIterator  last 
)

min_element finds the smallest element in the range [first, last). It returns the first iterator i in [first, last) such that no other iterator in [first, last) points to a value smaller than *i. The return value is last if and only if [first, last) is an empty range.

The two versions of min_element differ in how they define whether one element is less than another. This version compares objects using operator<. Specifically, this version of min_element returns the first iterator i in [first, last) such that, for every iterator j in [first, last), *j < *i is false.

Parameters
firstThe beginning of the sequence.
lastThe end of the sequence.
Returns
An iterator pointing to the smallest element of the range [first, last), if it is not an empty range; last, otherwise.
Template Parameters
ForwardIteratoris a model of Forward Iterator, and ForwardIterator's value_type is a model of LessThan Comparable.
#include <thrust/extrema.h>
...
int data[6] = {1, 0, 2, 2, 1, 3};
int *result = thrust::min_element(data, data + 6);
// result is data + 1
// *result is 0
See Also
http://www.sgi.com/tech/stl/min_element.html
template<typename DerivedPolicy , typename ForwardIterator , typename BinaryPredicate >
__host__ __device__ ForwardIterator thrust::min_element ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
ForwardIterator  first,
ForwardIterator  last,
BinaryPredicate  comp 
)

min_element finds the smallest element in the range [first, last). It returns the first iterator i in [first, last) such that no other iterator in [first, last) points to a value smaller than *i. The return value is last if and only if [first, last) is an empty range.

The two versions of min_element differ in how they define whether one element is less than another. This version compares objects using a function object comp. Specifically, this version of min_element returns the first iterator i in [first, last) such that, for every iterator j in [first, last), comp(*j, *i) is false.

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.
compA binary predicate used for comparison.
Returns
An iterator pointing to the smallest element of the range [first, last), if it is not an empty range; last, 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 comp's first_argument_type and second_argument_type.
BinaryPredicateis a model of Binary Predicate.

The following code snippet demonstrates how to use min_element to find the smallest element of a collection of key-value pairs using the thrust::host execution policy for parallelization:

#include <thrust/extrema.h>
...
struct key_value
{
int key;
int value;
};
struct compare_key_value
{
__host__ __device__
bool operator()(key_value lhs, key_value rhs)
{
return lhs.key < rhs.key;
}
};
...
key_value data[4] = { {4,5}, {0,7}, {2,3}, {6,1} };
key_value *smallest = thrust::min_element(thrust::host, data, data + 4, compare_key_value());
// smallest == data + 1
// *smallest == {0,7}
See Also
http://www.sgi.com/tech/stl/min_element.html
template<typename ForwardIterator , typename BinaryPredicate >
ForwardIterator thrust::min_element ( ForwardIterator  first,
ForwardIterator  last,
BinaryPredicate  comp 
)

min_element finds the smallest element in the range [first, last). It returns the first iterator i in [first, last) such that no other iterator in [first, last) points to a value smaller than *i. The return value is last if and only if [first, last) is an empty range.

The two versions of min_element differ in how they define whether one element is less than another. This version compares objects using a function object comp. Specifically, this version of min_element returns the first iterator i in [first, last) such that, for every iterator j in [first, last), comp(*j, *i) is false.

Parameters
firstThe beginning of the sequence.
lastThe end of the sequence.
compA binary predicate used for comparison.
Returns
An iterator pointing to the smallest element of the range [first, last), if it is not an empty range; last, otherwise.
Template Parameters
ForwardIteratoris a model of Forward Iterator, and ForwardIterator's value_type is convertible to both comp's first_argument_type and second_argument_type.
BinaryPredicateis a model of Binary Predicate.

The following code snippet demonstrates how to use min_element to find the smallest element of a collection of key-value pairs.

#include <thrust/extrema.h>
struct key_value
{
int key;
int value;
};
struct compare_key_value
{
__host__ __device__
bool operator()(key_value lhs, key_value rhs)
{
return lhs.key < rhs.key;
}
};
...
key_value data[4] = { {4,5}, {0,7}, {2,3}, {6,1} };
key_value *smallest = thrust::min_element(data, data + 4, compare_key_value());
// smallest == data + 1
// *smallest == {0,7}
See Also
http://www.sgi.com/tech/stl/min_element.html
template<typename DerivedPolicy , typename ForwardIterator >
__host__ __device__ thrust::pair<ForwardIterator,ForwardIterator> thrust::minmax_element ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
ForwardIterator  first,
ForwardIterator  last 
)

minmax_element finds the smallest and largest elements in the range [first, last). It returns a pair of iterators (imin, imax) where imin is the same iterator returned by min_element and imax is the same iterator returned by max_element. This function is potentially more efficient than separate calls to min_element and max_element.

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
A pair of iterator pointing to the smallest and largest elements of the range [first, last), if it is not an empty range; last, otherwise.
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.
#include <thrust/extrema.h>
...
int data[6] = {1, 0, 2, 2, 1, 3};
// result.first is data + 1
// result.second is data + 5
// *result.first is 0
// *result.second is 3
See Also
min_element
max_element
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1840.pdf
template<typename ForwardIterator >
thrust::pair<ForwardIterator,ForwardIterator> thrust::minmax_element ( ForwardIterator  first,
ForwardIterator  last 
)

minmax_element finds the smallest and largest elements in the range [first, last). It returns a pair of iterators (imin, imax) where imin is the same iterator returned by min_element and imax is the same iterator returned by max_element. This function is potentially more efficient than separate calls to min_element and max_element.

Parameters
firstThe beginning of the sequence.
lastThe end of the sequence.
Returns
A pair of iterator pointing to the smallest and largest elements of the range [first, last), if it is not an empty range; last, otherwise.
Template Parameters
ForwardIteratoris a model of Forward Iterator, and ForwardIterator's value_type is a model of LessThan Comparable.
#include <thrust/extrema.h>
...
int data[6] = {1, 0, 2, 2, 1, 3};
// result.first is data + 1
// result.second is data + 5
// *result.first is 0
// *result.second is 3
See Also
min_element
max_element
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1840.pdf
template<typename DerivedPolicy , typename ForwardIterator , typename BinaryPredicate >
__host__ __device__ thrust::pair<ForwardIterator,ForwardIterator> thrust::minmax_element ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
ForwardIterator  first,
ForwardIterator  last,
BinaryPredicate  comp 
)

minmax_element finds the smallest and largest elements in the range [first, last). It returns a pair of iterators (imin, imax) where imin is the same iterator returned by min_element and imax is the same iterator returned by max_element. This function is potentially more efficient than separate calls to min_element and max_element.

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.
compA binary predicate used for comparison.
Returns
A pair of iterator pointing to the smallest and largest elements of the range [first, last), if it is not an empty range; last, 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 comp's first_argument_type and second_argument_type.
BinaryPredicateis a model of Binary Predicate.

The following code snippet demonstrates how to use minmax_element to find the smallest and largest elements of a collection of key-value pairs using the thrust::host execution policy for parallelization:

#include <thrust/extrema.h>
#include <thrust/pair.h>
...
struct key_value
{
int key;
int value;
};
struct compare_key_value
{
__host__ __device__
bool operator()(key_value lhs, key_value rhs)
{
return lhs.key < rhs.key;
}
};
...
key_value data[4] = { {4,5}, {0,7}, {2,3}, {6,1} };
thrust::pair<key_value*,key_value*> extrema = thrust::minmax_element(thrust::host, data, data + 4, compare_key_value());
// extrema.first == data + 1
// *extrema.first == {0,7}
// extrema.second == data + 3
// *extrema.second == {6,1}
See Also
min_element
max_element
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1840.pdf
template<typename ForwardIterator , typename BinaryPredicate >
thrust::pair<ForwardIterator,ForwardIterator> thrust::minmax_element ( ForwardIterator  first,
ForwardIterator  last,
BinaryPredicate  comp 
)

minmax_element finds the smallest and largest elements in the range [first, last). It returns a pair of iterators (imin, imax) where imin is the same iterator returned by min_element and imax is the same iterator returned by max_element. This function is potentially more efficient than separate calls to min_element and max_element.

Parameters
firstThe beginning of the sequence.
lastThe end of the sequence.
compA binary predicate used for comparison.
Returns
A pair of iterator pointing to the smallest and largest elements of the range [first, last), if it is not an empty range; last, otherwise.
Template Parameters
ForwardIteratoris a model of Forward Iterator, and ForwardIterator's value_type is convertible to both comp's first_argument_type and second_argument_type.
BinaryPredicateis a model of Binary Predicate.

The following code snippet demonstrates how to use minmax_element to find the smallest and largest elements of a collection of key-value pairs.

#include <thrust/extrema.h>
#include <thrust/pair.h>
struct key_value
{
int key;
int value;
};
struct compare_key_value
{
__host__ __device__
bool operator()(key_value lhs, key_value rhs)
{
return lhs.key < rhs.key;
}
};
...
key_value data[4] = { {4,5}, {0,7}, {2,3}, {6,1} };
thrust::pair<key_value*,key_value*> extrema = thrust::minmax_element(data, data + 4, compare_key_value());
// extrema.first == data + 1
// *extrema.first == {0,7}
// extrema.second == data + 3
// *extrema.second == {6,1}
See Also
min_element
max_element
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1840.pdf