thrust::minmax_element#
Overloads#
minmax_element(exec, first, last)#
-
template<typename DerivedPolicy, typename ForwardIterator>
thrust::pair<ForwardIterator, ForwardIterator> thrust::minmax_element( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- ForwardIterator first,
- ForwardIterator last,
minmax_elementfinds the smallest and largest elements in the range[first, last). It returns a pair of iterators(imin, imax)whereiminis the same iterator returned bymin_elementandimaxis the same iterator returned bymax_element. This function is potentially more efficient than separate calls tomin_elementandmax_element.The algorithm’s execution is parallelized as determined by
exec.#include <thrust/extrema.h> #include <thrust/execution_policy.h> ... int data[6] = {1, 0, 2, 2, 1, 3}; thrust::pair<int *, int *> result = thrust::minmax_element(thrust::host, data, data + 6); // result.first is data + 1 // result.second is data + 5 // *result.first is 0 // *result.second is 3
See also
See also
- Parameters:
exec – The execution policy to use for parallelization.
first – The beginning of the sequence.
last – The end of the sequence.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
ForwardIterator – is a model of Forward Iterator, and
ForwardIterator'svalue_typeis a model of LessThan Comparable.
- 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.
minmax_element(first, last)#
-
template<typename ForwardIterator>
thrust::pair<ForwardIterator, ForwardIterator> thrust::minmax_element( - ForwardIterator first,
- ForwardIterator last,
minmax_elementfinds the smallest and largest elements in the range[first, last). It returns a pair of iterators(imin, imax)whereiminis the same iterator returned bymin_elementandimaxis the same iterator returned bymax_element. This function is potentially more efficient than separate calls tomin_elementandmax_element.#include <thrust/extrema.h> ... int data[6] = {1, 0, 2, 2, 1, 3}; thrust::pair<int *, int *> result = thrust::minmax_element(data, data + 6); // result.first is data + 1 // result.second is data + 5 // *result.first is 0 // *result.second is 3
See also
See also
- Parameters:
first – The beginning of the sequence.
last – The end of the sequence.
- Template Parameters:
ForwardIterator – is a model of Forward Iterator, and
ForwardIterator'svalue_typeis a model of LessThan Comparable.- 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.
minmax_element(exec, first, last, comp)#
-
template<typename DerivedPolicy, typename ForwardIterator, typename BinaryPredicate>
thrust::pair<ForwardIterator, ForwardIterator> thrust::minmax_element( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- ForwardIterator first,
- ForwardIterator last,
- BinaryPredicate comp,
minmax_elementfinds the smallest and largest elements in the range[first, last). It returns a pair of iterators(imin, imax)whereiminis the same iterator returned bymin_elementandimaxis the same iterator returned bymax_element. This function is potentially more efficient than separate calls tomin_elementandmax_element.The algorithm’s execution is parallelized as determined by
exec.The following code snippet demonstrates how to use
minmax_elementto find the smallest and largest elements of a collection of key-value pairs using thethrust::hostexecution policy for parallelization:#include <thrust/extrema.h> #include <thrust/pair.h> #include <thrust/execution_policy.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
See also
- Parameters:
exec – The execution policy to use for parallelization.
first – The beginning of the sequence.
last – The end of the sequence.
comp – A binary predicate used for comparison.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
ForwardIterator – is a model of Forward Iterator, and
ForwardIterator'svalue_typeis convertible to bothcomp'sfirst and second argument type.BinaryPredicate – is a model of Binary Predicate.
- 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.
minmax_element(first, last, comp)#
-
template<typename ForwardIterator, typename BinaryPredicate>
thrust::pair<ForwardIterator, ForwardIterator> thrust::minmax_element( - ForwardIterator first,
- ForwardIterator last,
- BinaryPredicate comp,
minmax_elementfinds the smallest and largest elements in the range[first, last). It returns a pair of iterators(imin, imax)whereiminis the same iterator returned bymin_elementandimaxis the same iterator returned bymax_element. This function is potentially more efficient than separate calls tomin_elementandmax_element.The following code snippet demonstrates how to use
minmax_elementto 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
See also
- Parameters:
first – The beginning of the sequence.
last – The end of the sequence.
comp – A binary predicate used for comparison.
- Template Parameters:
ForwardIterator – is a model of Forward Iterator, and
ForwardIterator'svalue_typeis convertible to bothcomp'sfirst and second argument type.BinaryPredicate – is a model of Binary Predicate.
- 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.