thrust::max_element#
Overloads#
max_element(exec, first, last)#
-
template<typename DerivedPolicy, typename ForwardIterator>
ForwardIterator thrust::max_element( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- ForwardIterator first,
- ForwardIterator last,
max_elementfinds the largest element in the range[first, last). It returns the first iteratoriin[first, last)such that no other iterator in[first, last)points to a value larger than*i. The return value islastif and only if[first, last)is an empty range.The two versions of
max_elementdiffer in how they define whether one element is greater than another. This version compares objects usingoperator<. Specifically, this version ofmax_elementreturns the first iteratoriin[first, last)such that, for every iteratorjin[first, last),*i < *jisfalse.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}; int *result = thrust::max_element(thrust::host, data, data + 6); // *result == 3
- Parameters:
exec – The execution policy to use for parallelization.
first – The beginning of the sequence.
last – The end of the sequence.
- Template Parameters:
A – Thrust backend system.
ForwardIterator – is a model of Forward Iterator, and
ForwardIterator'svalue_typeis a model of LessThan Comparable.
- Returns:
An iterator pointing to the largest element of the range
[first, last), if it is not an empty range;last, otherwise.
max_element(first, last)#
-
template<typename ForwardIterator>
ForwardIterator thrust::max_element( - ForwardIterator first,
- ForwardIterator last,
max_elementfinds the largest element in the range[first, last). It returns the first iteratoriin[first, last)such that no other iterator in[first, last)points to a value larger than*i. The return value islastif and only if[first, last)is an empty range.The two versions of
max_elementdiffer in how they define whether one element is greater than another. This version compares objects usingoperator<. Specifically, this version ofmax_elementreturns the first iteratoriin[first, last)such that, for every iteratorjin[first, last),*i < *jisfalse.#include <thrust/extrema.h> ... int data[6] = {1, 0, 2, 2, 1, 3}; int *result = thrust::max_element(data, data + 6); // *result == 3
- 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:
An iterator pointing to the largest element of the range
[first, last), if it is not an empty range;last, otherwise.
max_element(exec, first, last, comp)#
-
template<typename DerivedPolicy, typename ForwardIterator, typename BinaryPredicate>
ForwardIterator thrust::max_element( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- ForwardIterator first,
- ForwardIterator last,
- BinaryPredicate comp,
max_elementfinds the largest element in the range[first, last). It returns the first iteratoriin[first, last)such that no other iterator in[first, last)points to a value larger than*i. The return value islastif and only if[first, last)is an empty range.The two versions of
max_elementdiffer in how they define whether one element is less than another. This version compares objects using a function objectcomp. Specifically, this version ofmax_elementreturns the first iteratoriin[first, last)such that, for every iteratorjin[first, last),comp(*i, *j)isfalse.The algorithm’s execution is parallelized as determined by
exec.The following code snippet demonstrates how to use
max_elementto find the largest element of a collection of key-value pairs using thethrust::hostexecution policy for parallelization.#include <thrust/extrema.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} }; key_value *largest = thrust::max_element(thrust::host, data, data + 4, compare_key_value()); // largest == data + 3 // *largest == {6,1}
- 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:
An iterator pointing to the largest element of the range
[first, last), if it is not an empty range;last, otherwise.
max_element(first, last, comp)#
-
template<typename ForwardIterator, typename BinaryPredicate>
ForwardIterator thrust::max_element( - ForwardIterator first,
- ForwardIterator last,
- BinaryPredicate comp,
max_elementfinds the largest element in the range[first, last). It returns the first iteratoriin[first, last)such that no other iterator in[first, last)points to a value larger than*i. The return value islastif and only if[first, last)is an empty range.The two versions of
max_elementdiffer in how they define whether one element is less than another. This version compares objects using a function objectcomp. Specifically, this version ofmax_elementreturns the first iteratoriin[first, last)such that, for every iteratorjin[first, last),comp(*i, *j)isfalse.The following code snippet demonstrates how to use
max_elementto 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}
- 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:
An iterator pointing to the largest element of the range
[first, last), if it is not an empty range;last, otherwise.