stable_partition
#
Overloads#
stable_partition(exec, first, last, pred)
#
-
template<typename DerivedPolicy, typename ForwardIterator, typename Predicate>
ForwardIterator thrust::stable_partition( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- ForwardIterator first,
- ForwardIterator last,
- Predicate pred,
stable_partition
is much likepartition
: it reorders the elements in the range[first, last)
based on the function objectpred
, such that all of the elements that satisfypred
precede all of the elements that fail to satisfy it. The postcondition is that, for some iteratormiddle
in the range[first, last)
,pred(*i)
istrue
for every iteratori
in the range[first,middle)
andfalse
for every iteratori
in the range[middle, last)
. The return value ofstable_partition
ismiddle
.stable_partition
differs frompartition
in thatstable_partition
is guaranteed to preserve relative order. That is, ifx
andy
are elements in[first, last)
, andstencil_x
andstencil_y
are the stencil elements in corresponding positions within[stencil, stencil + (last - first))
, andpred(stencil_x) == pred(stencil_y)
, and ifx
precedesy
, then it will still be true afterstable_partition
thatx
precedesy
.The algorithm’s execution is parallelized as determined by
exec
.The following code snippet demonstrates how to use
stable_partition
to reorder a sequence so that even numbers precede odd numbers using thethrust::host
execution policy for parallelization:#include <thrust/partition.h> #include <thrust/execution_policy.h> ... struct is_even { __host__ __device__ bool operator()(const int &x) { return (x % 2) == 0; } }; ... int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; const int N = sizeof(A)/sizeof(int); thrust::stable_partition(thrust::host, A, A + N, is_even()); // A is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9}
See also
See also
- Parameters:
exec – The execution policy to use for parallelization.
first – The first element of the sequence to reorder.
last – One position past the last element of the sequence to reorder.
pred – A function object which decides to which partition each element of the sequence
[first, last)
belongs.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
ForwardIterator – is a model of Forward Iterator, and
ForwardIterator's
value_type
is convertible toPredicate's
argument type, andForwardIterator
is mutable.Predicate – is a model of Predicate.
- Returns:
An iterator referring to the first element of the second partition, that is, the sequence of the elements which do not satisfy pred.
stable_partition(first, last, pred)
#
-
template<typename ForwardIterator, typename Predicate>
ForwardIterator thrust::stable_partition( - ForwardIterator first,
- ForwardIterator last,
- Predicate pred,
stable_partition
is much likepartition
: it reorders the elements in the range[first, last)
based on the function objectpred
, such that all of the elements that satisfypred
precede all of the elements that fail to satisfy it. The postcondition is that, for some iteratormiddle
in the range[first, last)
,pred(*i)
istrue
for every iteratori
in the range[first,middle)
andfalse
for every iteratori
in the range[middle, last)
. The return value ofstable_partition
ismiddle
.stable_partition
differs frompartition
in thatstable_partition
is guaranteed to preserve relative order. That is, ifx
andy
are elements in[first, last)
, andstencil_x
andstencil_y
are the stencil elements in corresponding positions within[stencil, stencil + (last - first))
, andpred(stencil_x) == pred(stencil_y)
, and ifx
precedesy
, then it will still be true afterstable_partition
thatx
precedesy
.The following code snippet demonstrates how to use
stable_partition
to reorder a sequence so that even numbers precede odd numbers.#include <thrust/partition.h> ... struct is_even { __host__ __device__ bool operator()(const int &x) { return (x % 2) == 0; } }; ... int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; const int N = sizeof(A)/sizeof(int); thrust::stable_partition(A, A + N, is_even()); // A is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9}
See also
See also
- Parameters:
first – The first element of the sequence to reorder.
last – One position past the last element of the sequence to reorder.
pred – A function object which decides to which partition each element of the sequence
[first, last)
belongs.
- Template Parameters:
ForwardIterator – is a model of Forward Iterator, and
ForwardIterator's
value_type
is convertible toPredicate's
argument type, andForwardIterator
is mutable.Predicate – is a model of Predicate.
- Returns:
An iterator referring to the first element of the second partition, that is, the sequence of the elements which do not satisfy pred.
stable_partition(exec, first, last, stencil, pred)
#
-
template<typename DerivedPolicy, typename ForwardIterator, typename InputIterator, typename Predicate>
ForwardIterator thrust::stable_partition( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- ForwardIterator first,
- ForwardIterator last,
- InputIterator stencil,
- Predicate pred,
stable_partition
is much likepartition:
it reorders the elements in the range[first, last)
based on the function objectpred
applied to a stencil range[stencil, stencil + (last - first))
, such that all of the elements whose corresponding stencil element satisfiespred
precede all of the elements whose corresponding stencil element fails to satisfy it. The postcondition is that, for some iteratormiddle
in the range[first, last)
,pred(*stencil_i)
istrue
for every iteratorstencil_i
in the range[stencil,stencil + (middle - first))
andfalse
for every iteratorstencil_i
in the range[stencil + (middle - first), stencil + (last - first))
. The return value ofstable_partition
ismiddle
.stable_partition
differs frompartition
in thatstable_partition
is guaranteed to preserve relative order. That is, ifx
andy
are elements in[first, last)
, such thatpred(x) == pred(y)
, and ifx
precedesy
, then it will still be true afterstable_partition
thatx
precedesy
.The algorithm’s execution is parallelized as determined by
exec
.The following code snippet demonstrates how to use
stable_partition
to reorder a sequence so that even numbers precede odd numbers using thethrust::host
execution policy for parallelization:#include <thrust/partition.h> #include <thrust/execution_policy.h> ... struct is_even { __host__ __device__ bool operator()(const int &x) { return (x % 2) == 0; } }; ... int A[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1}; int S[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; const int N = sizeof(A)/sizeof(int); thrust::stable_partition(thrust::host, A, A + N, S, is_even()); // A is now {1, 1, 1, 1, 1, 0, 0, 0, 0, 0} // S is unmodified
See also
See also
- Parameters:
exec – The execution policy to use for parallelization.
first – The first element of the sequence to reorder.
last – One position past the last element of the sequence to reorder.
stencil – The beginning of the stencil sequence.
pred – A function object which decides to which partition each element of the sequence
[first, last)
belongs.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
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 toPredicate's
argument type.Predicate – is a model of Predicate.
- Returns:
An iterator referring to the first element of the second partition, that is, the sequence of the elements whose stencil elements do not satisfy
pred
.- Pre:
The range
[first, last)
shall not overlap with the range[stencil, stencil + (last - first))
.
stable_partition(first, last, stencil, pred)
#
-
template<typename ForwardIterator, typename InputIterator, typename Predicate>
ForwardIterator thrust::stable_partition( - ForwardIterator first,
- ForwardIterator last,
- InputIterator stencil,
- Predicate pred,
stable_partition
is much likepartition:
it reorders the elements in the range[first, last)
based on the function objectpred
applied to a stencil range[stencil, stencil + (last - first))
, such that all of the elements whose corresponding stencil element satisfiespred
precede all of the elements whose corresponding stencil element fails to satisfy it. The postcondition is that, for some iteratormiddle
in the range[first, last)
,pred(*stencil_i)
istrue
for every iteratorstencil_i
in the range[stencil,stencil + (middle - first))
andfalse
for every iteratorstencil_i
in the range[stencil + (middle - first), stencil + (last - first))
. The return value ofstable_partition
ismiddle
.stable_partition
differs frompartition
in thatstable_partition
is guaranteed to preserve relative order. That is, ifx
andy
are elements in[first, last)
, such thatpred(x) == pred(y)
, and ifx
precedesy
, then it will still be true afterstable_partition
thatx
precedesy
.The following code snippet demonstrates how to use
stable_partition
to reorder a sequence so that even numbers precede odd numbers.#include <thrust/partition.h> ... struct is_even { __host__ __device__ bool operator()(const int &x) { return (x % 2) == 0; } }; ... int A[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1}; int S[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; const int N = sizeof(A)/sizeof(int); thrust::stable_partition(A, A + N, S, is_even()); // A is now {1, 1, 1, 1, 1, 0, 0, 0, 0, 0} // S is unmodified
See also
See also
- Parameters:
first – The first element of the sequence to reorder.
last – One position past the last element of the sequence to reorder.
stencil – The beginning of the stencil sequence.
pred – A function object which decides to which partition each element of the sequence
[first, last)
belongs.
- Template Parameters:
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 toPredicate's
argument type.Predicate – is a model of Predicate.
- Returns:
An iterator referring to the first element of the second partition, that is, the sequence of the elements whose stencil elements do not satisfy
pred
.- Pre:
The range
[first, last)
shall not overlap with the range[stencil, stencil + (last - first))
.