Partitioning
template <typename DerivedPolicy, typename ForwardIterator, typename Predicate> _CCCL_HOST_DEVICE ForwardIterator partition(const thrust::detail::execution_policy_base< DerivedPolicy > & exec, ForwardIterator first, ForwardIterator last, Predicate pred);
template <typename ForwardIterator, typename Predicate> ForwardIterator partition(ForwardIterator first, ForwardIterator last, Predicate pred);
template <typename DerivedPolicy, typename ForwardIterator, typename InputIterator, typename Predicate> _CCCL_HOST_DEVICE ForwardIterator partition(const thrust::detail::execution_policy_base< DerivedPolicy > & exec, ForwardIterator first, ForwardIterator last, InputIterator stencil, Predicate pred);
template <typename ForwardIterator, typename InputIterator, typename Predicate> ForwardIterator partition(ForwardIterator first, ForwardIterator last, InputIterator stencil, Predicate pred);
template <typename DerivedPolicy, typename InputIterator, typename OutputIterator1, typename OutputIterator2, typename Predicate> _CCCL_HOST_DEVICE thrust::pair< OutputIterator1, OutputIterator2 > partition_copy(const thrust::detail::execution_policy_base< DerivedPolicy > & exec, InputIterator first, InputIterator last, OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred);
template <typename InputIterator, typename OutputIterator1, typename OutputIterator2, typename Predicate> thrust::pair< OutputIterator1, OutputIterator2 > partition_copy(InputIterator first, InputIterator last, OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred);
template <typename DerivedPolicy, typename InputIterator1, typename InputIterator2, typename OutputIterator1, typename OutputIterator2, typename Predicate> _CCCL_HOST_DEVICE thrust::pair< OutputIterator1, OutputIterator2 > partition_copy(const thrust::detail::execution_policy_base< DerivedPolicy > & exec, InputIterator1 first, InputIterator1 last, InputIterator2 stencil, OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred);
template <typename InputIterator1, typename InputIterator2, typename OutputIterator1, typename OutputIterator2, typename Predicate> thrust::pair< OutputIterator1, OutputIterator2 > partition_copy(InputIterator1 first, InputIterator1 last, InputIterator2 stencil, OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred);
template <typename DerivedPolicy, typename ForwardIterator, typename Predicate> _CCCL_HOST_DEVICE ForwardIterator stable_partition(const thrust::detail::execution_policy_base< DerivedPolicy > & exec, ForwardIterator first, ForwardIterator last, Predicate pred);
template <typename ForwardIterator, typename Predicate> ForwardIterator stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred);
template <typename DerivedPolicy, typename ForwardIterator, typename InputIterator, typename Predicate> _CCCL_HOST_DEVICE ForwardIterator stable_partition(const thrust::detail::execution_policy_base< DerivedPolicy > & exec, ForwardIterator first, ForwardIterator last, InputIterator stencil, Predicate pred);
template <typename ForwardIterator, typename InputIterator, typename Predicate> ForwardIterator stable_partition(ForwardIterator first, ForwardIterator last, InputIterator stencil, Predicate pred);
template <typename DerivedPolicy, typename InputIterator, typename OutputIterator1, typename OutputIterator2, typename Predicate> _CCCL_HOST_DEVICE thrust::pair< OutputIterator1, OutputIterator2 > stable_partition_copy(const thrust::detail::execution_policy_base< DerivedPolicy > & exec, InputIterator first, InputIterator last, OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred);
template <typename InputIterator, typename OutputIterator1, typename OutputIterator2, typename Predicate> thrust::pair< OutputIterator1, OutputIterator2 > stable_partition_copy(InputIterator first, InputIterator last, OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred);
template <typename DerivedPolicy, typename InputIterator1, typename InputIterator2, typename OutputIterator1, typename OutputIterator2, typename Predicate> _CCCL_HOST_DEVICE thrust::pair< OutputIterator1, OutputIterator2 > stable_partition_copy(const thrust::detail::execution_policy_base< DerivedPolicy > & exec, InputIterator1 first, InputIterator1 last, InputIterator2 stencil, OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred);
template <typename InputIterator1, typename InputIterator2, typename OutputIterator1, typename OutputIterator2, typename Predicate> thrust::pair< OutputIterator1, OutputIterator2 > stable_partition_copy(InputIterator1 first, InputIterator1 last, InputIterator2 stencil, OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred);
Functions
Function partition
template <typename DerivedPolicy, typename ForwardIterator, typename Predicate> _CCCL_HOST_DEVICE ForwardIterator partition(const thrust::detail::execution_policy_base< DerivedPolicy > & exec, ForwardIterator first, ForwardIterator last, Predicate pred);
partition
reorders the elements [first, last)
based on the function object pred
, such that all of the elements that satisfy pred
precede the elements that fail to satisfy it. The postcondition is that, for some iterator middle
in the range [first, last)
, pred(*i)
is true
for every iterator i
in the range [first,middle)
and false
for every iterator i
in the range [middle, last)
. The return value of partition
is middle
.
Note that the relative order of elements in the two reordered sequences is not necessarily the same as it was in the original sequence. A different algorithm, stable_partition
, does guarantee to preserve the relative order.
The algorithm’s execution is parallelized as determined by exec
.
The following code snippet demonstrates how to use partition
to reorder a sequence so that even numbers precede odd numbers using the thrust::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::partition(thrust::host,
A, A + N,
is_even());
// A is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9}
Template Parameters:
DerivedPolicy
The name of the derived execution policy.ForwardIterator
is a model of Forward Iterator, andForwardIterator's
value_type
is convertible toPredicate's
argument_type
, andForwardIterator
is mutable.Predicate
is a model of Predicate.
Function Parameters:
exec
The execution policy to use for parallelization.first
The beginning of the sequence to reorder.last
The end of the sequence to reorder.pred
A function object which decides to which partition each element of the sequence[first, last)
belongs.
Returns: An iterator referring to the first element of the second partition, that is, the sequence of the elements which do not satisfy pred
.
See:
- https://en.cppreference.com/w/cpp/algorithm/partition
stable_partition
partition_copy
Function partition
template <typename ForwardIterator, typename Predicate> ForwardIterator partition(ForwardIterator first, ForwardIterator last, Predicate pred);
partition
reorders the elements [first, last)
based on the function object pred
, such that all of the elements that satisfy pred
precede the elements that fail to satisfy it. The postcondition is that, for some iterator middle
in the range [first, last)
, pred(*i)
is true
for every iterator i
in the range [first,middle)
and false
for every iterator i
in the range [middle, last)
. The return value of partition
is middle
.
Note that the relative order of elements in the two reordered sequences is not necessarily the same as it was in the original sequence. A different algorithm, stable_partition
, does guarantee to preserve the relative order.
The following code snippet demonstrates how to use 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::partition(A, A + N,
is_even());
// A is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9}
Template Parameters:
ForwardIterator
is a model of Forward Iterator, andForwardIterator's
value_type
is convertible toPredicate's
argument_type
, andForwardIterator
is mutable.Predicate
is a model of Predicate.
Function Parameters:
first
The beginning of the sequence to reorder.last
The end of the sequence to reorder.pred
A function object which decides to which partition each element of the sequence[first, last)
belongs.
Returns: An iterator referring to the first element of the second partition, that is, the sequence of the elements which do not satisfy pred
.
See:
- https://en.cppreference.com/w/cpp/algorithm/partition
stable_partition
partition_copy
Function partition
template <typename DerivedPolicy, typename ForwardIterator, typename InputIterator, typename Predicate> _CCCL_HOST_DEVICE ForwardIterator partition(const thrust::detail::execution_policy_base< DerivedPolicy > & exec, ForwardIterator first, ForwardIterator last, InputIterator stencil, Predicate pred);
partition
reorders the elements [first, last)
based on the function object pred
applied to a stencil range [stencil, stencil + (last - first))
, such that all of the elements whose corresponding stencil element satisfies pred
precede all of the elements whose corresponding stencil element fails to satisfy it. The postcondition is that, for some iterator middle
in the range [first, last)
, pred(*stencil_i)
is true
for every iterator stencil_i
in the range [stencil,stencil + (middle - first))
and false
for every iterator stencil_i
in the range [stencil
- (middle - first), stencil + (last - first)). The return value of
stable_partition
ismiddle
. Note that the relative order of elements in the two reordered sequences is not necessarily the same as it was in the original sequence. A different algorithm,stable_partition
, does guarantee to preserve the relative order. The algorithm’s execution is parallelized as determined byexec
.
</code>
execThe execution policy to use for parallelization.
firstThe beginning of the sequence to reorder.
lastThe end of the sequence to reorder.
stencilThe beginning of the stencil sequence.
predA function object which decides to which partition each element of the sequence [first, last)
belongs.
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
.
DerivedPolicyThe name of the derived execution policy.
ForwardIteratoris a model of Forward Iterator, and ForwardIterator
is mutable.
InputIteratoris a model of Input Iterator, and InputIterator's
value_type
is convertible to Predicate's
argument_type
.
Predicateis a model of Predicate.
The ranges [first,last)
and [stencil, stencil + (last - first))
shall not overlap.
The following code snippet demonstrates how to use partition
to reorder a sequence so that even numbers precede odd numbers using the thrust::host
execution policy for parallelization:</code>
#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::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
</code>
https://en.cppreference.com/w/cpp/algorithm/partition
stable_partition
partition_copy
</code>
Function partition
template <typename ForwardIterator, typename InputIterator, typename Predicate> ForwardIterator partition(ForwardIterator first, ForwardIterator last, InputIterator stencil, Predicate pred);
partition
reorders the elements [first, last)
based on the function object pred
applied to a stencil range [stencil, stencil + (last - first))
, such that all of the elements whose corresponding stencil element satisfies pred
precede all of the elements whose corresponding stencil element fails to satisfy it. The postcondition is that, for some iterator middle
in the range [first, last)
, pred(*stencil_i)
is true
for every iterator stencil_i
in the range [stencil,stencil + (middle - first))
and false
for every iterator stencil_i
in the range [stencil
- (middle - first), stencil + (last - first)). The return value of
stable_partition
ismiddle
. Note that the relative order of elements in the two reordered sequences is not necessarily the same as it was in the original sequence. A different algorithm,stable_partition
, does guarantee to preserve the relative order.
</code>
firstThe beginning of the sequence to reorder.
lastThe end of the sequence to reorder.
stencilThe beginning of the stencil sequence.
predA function object which decides to which partition each element of the sequence [first, last)
belongs.
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
.
ForwardIteratoris a model of Forward Iterator, and ForwardIterator
is mutable.
InputIteratoris a model of Input Iterator, and InputIterator's
value_type
is convertible to Predicate's
argument_type
.
Predicateis a model of Predicate.
The ranges [first,last)
and [stencil, stencil + (last - first))
shall not overlap.
The following code snippet demonstrates how to use partition
to reorder a sequence so that even numbers precede odd numbers.</code>
#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::partition(A, A + N, S, is_even());
// A is now {1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
// S is unmodified
</code>
https://en.cppreference.com/w/cpp/algorithm/partition
stable_partition
partition_copy
</code>
Function partition_copy
template <typename DerivedPolicy, typename InputIterator, typename OutputIterator1, typename OutputIterator2, typename Predicate> _CCCL_HOST_DEVICE thrust::pair< OutputIterator1, OutputIterator2 > partition_copy(const thrust::detail::execution_policy_base< DerivedPolicy > & exec, InputIterator first, InputIterator last, OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred);
partition_copy
differs from partition
only in that the reordered sequence is written to difference output sequences, rather than in place.
partition_copy
copies the elements [first, last)
based on the function object pred
. All of the elements that satisfy pred
are copied to the range beginning at out_true
and all the elements that fail to satisfy it are copied to the range beginning at out_false
.
The algorithm’s execution is parallelized as determined by exec
.
The following code snippet demonstrates how to use partition_copy
to separate a sequence into two output sequences of even and odd numbers using the thrust::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};
int result[10];
const int N = sizeof(A)/sizeof(int);
int *evens = result;
int *odds = result + 5;
thrust::partition_copy(thrust::host, A, A + N, evens, odds, is_even());
// A remains {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
// result is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9}
// evens points to {2, 4, 6, 8, 10}
// odds points to {1, 3, 5, 7, 9}
Note: The relative order of elements in the two reordered sequences is not necessarily the same as it was in the original sequence. A different algorithm, stable_partition_copy
, does guarantee to preserve the relative order.
Template Parameters:
DerivedPolicy
The name of the derived execution policy.InputIterator
is a model of Input Iterator, andInputIterator's
value_type
is convertible toPredicate's
argument_type
andInputIterator's
value_type
is convertible toOutputIterator1
andOutputIterator2's
value_types
.OutputIterator1
is a model of Output Iterator.OutputIterator2
is a model of Output Iterator.Predicate
is a model of Predicate.
Function Parameters:
exec
The execution policy to use for parallelization.first
The beginning of the sequence to reorder.last
The end of the sequence to reorder.out_true
The destination of the resulting sequence of elements which satisfypred
.out_false
The destination of the resulting sequence of elements which fail to satisfypred
.pred
A function object which decides to which partition each element of the sequence[first, last)
belongs.
Preconditions: The input range shall not overlap with either output range.
Returns: A pair
p such that p.first
is the end of the output range beginning at out_true
and p.second
is the end of the output range beginning at out_false
.
See:
- http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2569.pdf
stable_partition_copy
partition
Function partition_copy
template <typename InputIterator, typename OutputIterator1, typename OutputIterator2, typename Predicate> thrust::pair< OutputIterator1, OutputIterator2 > partition_copy(InputIterator first, InputIterator last, OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred);
partition_copy
differs from partition
only in that the reordered sequence is written to difference output sequences, rather than in place.
partition_copy
copies the elements [first, last)
based on the function object pred
. All of the elements that satisfy pred
are copied to the range beginning at out_true
and all the elements that fail to satisfy it are copied to the range beginning at out_false
.
The following code snippet demonstrates how to use partition_copy
to separate a sequence into two output sequences of even and 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};
int result[10];
const int N = sizeof(A)/sizeof(int);
int *evens = result;
int *odds = result + 5;
thrust::partition_copy(A, A + N, evens, odds, is_even());
// A remains {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
// result is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9}
// evens points to {2, 4, 6, 8, 10}
// odds points to {1, 3, 5, 7, 9}
Note: The relative order of elements in the two reordered sequences is not necessarily the same as it was in the original sequence. A different algorithm, stable_partition_copy
, does guarantee to preserve the relative order.
Template Parameters:
InputIterator
is a model of Input Iterator, andInputIterator's
value_type
is convertible toPredicate's
argument_type
andInputIterator's
value_type
is convertible toOutputIterator1
andOutputIterator2's
value_types
.OutputIterator1
is a model of Output Iterator.OutputIterator2
is a model of Output Iterator.Predicate
is a model of Predicate.
Function Parameters:
first
The beginning of the sequence to reorder.last
The end of the sequence to reorder.out_true
The destination of the resulting sequence of elements which satisfypred
.out_false
The destination of the resulting sequence of elements which fail to satisfypred
.pred
A function object which decides to which partition each element of the sequence[first, last)
belongs.
Preconditions: The input range shall not overlap with either output range.
Returns: A pair
p such that p.first
is the end of the output range beginning at out_true
and p.second
is the end of the output range beginning at out_false
.
See:
- http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2569.pdf
stable_partition_copy
partition
Function partition_copy
template <typename DerivedPolicy, typename InputIterator1, typename InputIterator2, typename OutputIterator1, typename OutputIterator2, typename Predicate> _CCCL_HOST_DEVICE thrust::pair< OutputIterator1, OutputIterator2 > partition_copy(const thrust::detail::execution_policy_base< DerivedPolicy > & exec, InputIterator1 first, InputIterator1 last, InputIterator2 stencil, OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred);
partition_copy
differs from partition
only in that the reordered sequence is written to difference output sequences, rather than in place.
partition_copy
copies the elements [first, last)
based on the function object pred
which is applied to a range of stencil elements. All of the elements whose corresponding stencil element satisfies pred
are copied to the range beginning at out_true
and all the elements whose stencil element fails to satisfy it are copied to the range beginning at out_false
.
The algorithm’s execution is parallelized as determined by exec
.
The following code snippet demonstrates how to use partition_copy
to separate a sequence into two output sequences of even and odd numbers using the thrust::host
execution policy for parallelization.
#include <thrust/partition.h>
#include <thrust/functional.h>
#include <thrust/execution_policy.h>
...
int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int S[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1};
int result[10];
const int N = sizeof(A)/sizeof(int);
int *evens = result;
int *odds = result + 5;
thrust::stable_partition_copy(thrust::host, A, A + N, S, evens, odds, thrust::identity<int>());
// A remains {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
// S remains {0, 1, 0, 1, 0, 1, 0, 1, 0, 1}
// result is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9}
// evens points to {2, 4, 6, 8, 10}
// odds points to {1, 3, 5, 7, 9}
Note: The relative order of elements in the two reordered sequences is not necessarily the same as it was in the original sequence. A different algorithm, stable_partition_copy
, does guarantee to preserve the relative order.
Template Parameters:
DerivedPolicy
The name of the derived execution policy.InputIterator1
is a model of Input Iterator, andInputIterator's
value_type
is convertible toOutputIterator1
andOutputIterator2's
value_types
.InputIterator2
is a model of Input Iterator, andInputIterator2's
value_type
is convertible toPredicate's
argument_type
.OutputIterator1
is a model of Output Iterator.OutputIterator2
is a model of Output Iterator.Predicate
is a model of Predicate.
Function Parameters:
exec
The execution policy to use for parallelization.first
The beginning of the sequence to reorder.last
The end of the sequence to reorder.stencil
The beginning of the stencil sequence.out_true
The destination of the resulting sequence of elements which satisfypred
.out_false
The destination of the resulting sequence of elements which fail to satisfypred
.pred
A function object which decides to which partition each element of the sequence[first, last)
belongs.
Preconditions: The input ranges shall not overlap with either output range.
Returns: A pair
p such that p.first
is the end of the output range beginning at out_true
and p.second
is the end of the output range beginning at out_false
.
See:
- http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2569.pdf
stable_partition_copy
partition
Function partition_copy
template <typename InputIterator1, typename InputIterator2, typename OutputIterator1, typename OutputIterator2, typename Predicate> thrust::pair< OutputIterator1, OutputIterator2 > partition_copy(InputIterator1 first, InputIterator1 last, InputIterator2 stencil, OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred);
partition_copy
differs from partition
only in that the reordered sequence is written to difference output sequences, rather than in place.
partition_copy
copies the elements [first, last)
based on the function object pred
which is applied to a range of stencil elements. All of the elements whose corresponding stencil element satisfies pred
are copied to the range beginning at out_true
and all the elements whose stencil element fails to satisfy it are copied to the range beginning at out_false
.
The following code snippet demonstrates how to use partition_copy
to separate a sequence into two output sequences of even and odd numbers.
#include <thrust/partition.h>
#include <thrust/functional.h>
...
int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int S[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1};
int result[10];
const int N = sizeof(A)/sizeof(int);
int *evens = result;
int *odds = result + 5;
thrust::stable_partition_copy(A, A + N, S, evens, odds, thrust::identity<int>());
// A remains {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
// S remains {0, 1, 0, 1, 0, 1, 0, 1, 0, 1}
// result is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9}
// evens points to {2, 4, 6, 8, 10}
// odds points to {1, 3, 5, 7, 9}
Note: The relative order of elements in the two reordered sequences is not necessarily the same as it was in the original sequence. A different algorithm, stable_partition_copy
, does guarantee to preserve the relative order.
Template Parameters:
InputIterator1
is a model of Input Iterator, andInputIterator's
value_type
is convertible toOutputIterator1
andOutputIterator2's
value_types
.InputIterator2
is a model of Input Iterator, andInputIterator2's
value_type
is convertible toPredicate's
argument_type
.OutputIterator1
is a model of Output Iterator.OutputIterator2
is a model of Output Iterator.Predicate
is a model of Predicate.
Function Parameters:
first
The beginning of the sequence to reorder.last
The end of the sequence to reorder.stencil
The beginning of the stencil sequence.out_true
The destination of the resulting sequence of elements which satisfypred
.out_false
The destination of the resulting sequence of elements which fail to satisfypred
.pred
A function object which decides to which partition each element of the sequence[first, last)
belongs.
Preconditions: The input ranges shall not overlap with either output range.
Returns: A pair
p such that p.first
is the end of the output range beginning at out_true
and p.second
is the end of the output range beginning at out_false
.
See:
- http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2569.pdf
stable_partition_copy
partition
Function stable_partition
template <typename DerivedPolicy, typename ForwardIterator, typename Predicate> _CCCL_HOST_DEVICE ForwardIterator stable_partition(const thrust::detail::execution_policy_base< DerivedPolicy > & exec, ForwardIterator first, ForwardIterator last, Predicate pred);
stable_partition
is much like partition
: it reorders the elements in the range [first, last)
based on the function object pred
, such that all of the elements that satisfy pred
precede all of the elements that fail to satisfy it. The postcondition is that, for some iterator middle
in the range [first, last)
, pred(*i)
is true
for every iterator i
in the range [first,middle)
and false
for every iterator i
in the range [middle, last)
. The return value of stable_partition
is middle
.
stable_partition
differs from partition
in that stable_partition
is guaranteed to preserve relative order. That is, if x
and y
are elements in [first, last)
, and stencil_x
and stencil_y
are the stencil elements in corresponding positions within [stencil, stencil + (last - first))
, and pred(stencil_x) == pred(stencil_y)
, and if x
precedes y
, then it will still be true after stable_partition
that x
precedes y
.
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 the thrust::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}
Template Parameters:
DerivedPolicy
The name of the derived execution policy.ForwardIterator
is a model of Forward Iterator, andForwardIterator's
value_type
is convertible toPredicate's
argument_type
, andForwardIterator
is mutable.Predicate
is a model of Predicate.
Function 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.
Returns: An iterator referring to the first element of the second partition, that is, the sequence of the elements which do not satisfy pred.
See:
- https://en.cppreference.com/w/cpp/algorithm/stable_partition
partition
stable_partition_copy
Function stable_partition
template <typename ForwardIterator, typename Predicate> ForwardIterator stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred);
stable_partition
is much like partition
: it reorders the elements in the range [first, last)
based on the function object pred
, such that all of the elements that satisfy pred
precede all of the elements that fail to satisfy it. The postcondition is that, for some iterator middle
in the range [first, last)
, pred(*i)
is true
for every iterator i
in the range [first,middle)
and false
for every iterator i
in the range [middle, last)
. The return value of stable_partition
is middle
.
stable_partition
differs from partition
in that stable_partition
is guaranteed to preserve relative order. That is, if x
and y
are elements in [first, last)
, and stencil_x
and stencil_y
are the stencil elements in corresponding positions within [stencil, stencil + (last - first))
, and pred(stencil_x) == pred(stencil_y)
, and if x
precedes y
, then it will still be true after stable_partition
that x
precedes y
.
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}
Template Parameters:
ForwardIterator
is a model of Forward Iterator, andForwardIterator's
value_type
is convertible toPredicate's
argument_type
, andForwardIterator
is mutable.Predicate
is a model of Predicate.
Function 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.
Returns: An iterator referring to the first element of the second partition, that is, the sequence of the elements which do not satisfy pred.
See:
- https://en.cppreference.com/w/cpp/algorithm/stable_partition
partition
stable_partition_copy
Function stable_partition
template <typename DerivedPolicy, typename ForwardIterator, typename InputIterator, typename Predicate> _CCCL_HOST_DEVICE ForwardIterator stable_partition(const thrust::detail::execution_policy_base< DerivedPolicy > & exec, ForwardIterator first, ForwardIterator last, InputIterator stencil, Predicate pred);
stable_partition
is much like partition:
it reorders the elements in the range [first, last)
based on the function object pred
applied to a stencil range [stencil, stencil + (last - first))
, such that all of the elements whose corresponding stencil element satisfies pred
precede all of the elements whose corresponding stencil element fails to satisfy it. The postcondition is that, for some iterator middle
in the range [first, last)
, pred(*stencil_i)
is true
for every iterator stencil_i
in the range [stencil,stencil + (middle - first))
and false
for every iterator stencil_i
in the range [stencil + (middle - first), stencil + (last - first))
. The return value of stable_partition
is middle
.
stable_partition
differs from partition
in that stable_partition
is guaranteed to preserve relative order. That is, if x
and y
are elements in [first, last)
, such that pred(x) == pred(y)
, and if x
precedes y
, then it will still be true after stable_partition
that x
precedes y
.
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 the thrust::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
Template Parameters:
DerivedPolicy
The name of the derived execution policy.ForwardIterator
is a model of Forward Iterator, andForwardIterator
is mutable.InputIterator
is a model of Input Iterator, andInputIterator's
value_type
is convertible toPredicate's
argument_type
.Predicate
is a model of Predicate.
Function 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.
Preconditions: The range [first, last)
shall not overlap with the range [stencil, stencil + (last - first))
.
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
.
See:
- https://en.cppreference.com/w/cpp/algorithm/stable_partition
partition
stable_partition_copy
Function stable_partition
template <typename ForwardIterator, typename InputIterator, typename Predicate> ForwardIterator stable_partition(ForwardIterator first, ForwardIterator last, InputIterator stencil, Predicate pred);
stable_partition
is much like partition:
it reorders the elements in the range [first, last)
based on the function object pred
applied to a stencil range [stencil, stencil + (last - first))
, such that all of the elements whose corresponding stencil element satisfies pred
precede all of the elements whose corresponding stencil element fails to satisfy it. The postcondition is that, for some iterator middle
in the range [first, last)
, pred(*stencil_i)
is true
for every iterator stencil_i
in the range [stencil,stencil + (middle - first))
and false
for every iterator stencil_i
in the range [stencil + (middle - first), stencil + (last - first))
. The return value of stable_partition
is middle
.
stable_partition
differs from partition
in that stable_partition
is guaranteed to preserve relative order. That is, if x
and y
are elements in [first, last)
, such that pred(x) == pred(y)
, and if x
precedes y
, then it will still be true after stable_partition
that x
precedes y
.
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
Template Parameters:
ForwardIterator
is a model of Forward Iterator, andForwardIterator
is mutable.InputIterator
is a model of Input Iterator, andInputIterator's
value_type
is convertible toPredicate's
argument_type
.Predicate
is a model of Predicate.
Function 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.
Preconditions: The range [first, last)
shall not overlap with the range [stencil, stencil + (last - first))
.
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
.
See:
- https://en.cppreference.com/w/cpp/algorithm/stable_partition
partition
stable_partition_copy
Function stable_partition_copy
template <typename DerivedPolicy, typename InputIterator, typename OutputIterator1, typename OutputIterator2, typename Predicate> _CCCL_HOST_DEVICE thrust::pair< OutputIterator1, OutputIterator2 > stable_partition_copy(const thrust::detail::execution_policy_base< DerivedPolicy > & exec, InputIterator first, InputIterator last, OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred);
stable_partition_copy
differs from stable_partition
only in that the reordered sequence is written to different output sequences, rather than in place.
stable_partition_copy
copies the elements [first, last)
based on the function object pred
. All of the elements that satisfy pred
are copied to the range beginning at out_true
and all the elements that fail to satisfy it are copied to the range beginning at out_false
.
stable_partition_copy
differs from partition_copy
in that stable_partition_copy
is guaranteed to preserve relative order. That is, if x
and y
are elements in [first, last)
, such that pred(x) == pred(y)
, and if x
precedes y
, then it will still be true after stable_partition_copy
that x
precedes y
in the output.
The algorithm’s execution is parallelized as determined by exec
.
The following code snippet demonstrates how to use stable_partition_copy
to reorder a sequence so that even numbers precede odd numbers using the thrust::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};
int result[10];
const int N = sizeof(A)/sizeof(int);
int *evens = result;
int *odds = result + 5;
thrust::stable_partition_copy(thrust::host, A, A + N, evens, odds, is_even());
// A remains {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
// result is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9}
// evens points to {2, 4, 6, 8, 10}
// odds points to {1, 3, 5, 7, 9}
Template Parameters:
DerivedPolicy
The name of the derived execution policy.InputIterator
is a model of Input Iterator, andInputIterator's
value_type
is convertible toPredicate's
argument_type
andInputIterator's
value_type
is convertible toOutputIterator1
andOutputIterator2's
value_types
.OutputIterator1
is a model of Output Iterator.OutputIterator2
is a model of Output Iterator.Predicate
is a model of Predicate.
Function 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.out_true
The destination of the resulting sequence of elements which satisfypred
.out_false
The destination of the resulting sequence of elements which fail to satisfypred
.pred
A function object which decides to which partition each element of the sequence[first, last)
belongs.
Preconditions: The input ranges shall not overlap with either output range.
Returns: A pair
p such that p.first
is the end of the output range beginning at out_true
and p.second
is the end of the output range beginning at out_false
.
See:
- http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2569.pdf
partition_copy
stable_partition
Function stable_partition_copy
template <typename InputIterator, typename OutputIterator1, typename OutputIterator2, typename Predicate> thrust::pair< OutputIterator1, OutputIterator2 > stable_partition_copy(InputIterator first, InputIterator last, OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred);
stable_partition_copy
differs from stable_partition
only in that the reordered sequence is written to different output sequences, rather than in place.
stable_partition_copy
copies the elements [first, last)
based on the function object pred
. All of the elements that satisfy pred
are copied to the range beginning at out_true
and all the elements that fail to satisfy it are copied to the range beginning at out_false
.
stable_partition_copy
differs from partition_copy
in that stable_partition_copy
is guaranteed to preserve relative order. That is, if x
and y
are elements in [first, last)
, such that pred(x) == pred(y)
, and if x
precedes y
, then it will still be true after stable_partition_copy
that x
precedes y
in the output.
The following code snippet demonstrates how to use stable_partition_copy
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};
int result[10];
const int N = sizeof(A)/sizeof(int);
int *evens = result;
int *odds = result + 5;
thrust::stable_partition_copy(A, A + N, evens, odds, is_even());
// A remains {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
// result is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9}
// evens points to {2, 4, 6, 8, 10}
// odds points to {1, 3, 5, 7, 9}
Template Parameters:
InputIterator
is a model of Input Iterator, andInputIterator's
value_type
is convertible toPredicate's
argument_type
andInputIterator's
value_type
is convertible toOutputIterator1
andOutputIterator2's
value_types
.OutputIterator1
is a model of Output Iterator.OutputIterator2
is a model of Output Iterator.Predicate
is a model of Predicate.
Function Parameters:
first
The first element of the sequence to reorder.last
One position past the last element of the sequence to reorder.out_true
The destination of the resulting sequence of elements which satisfypred
.out_false
The destination of the resulting sequence of elements which fail to satisfypred
.pred
A function object which decides to which partition each element of the sequence[first, last)
belongs.
Preconditions: The input ranges shall not overlap with either output range.
Returns: A pair
p such that p.first
is the end of the output range beginning at out_true
and p.second
is the end of the output range beginning at out_false
.
See:
- http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2569.pdf
partition_copy
stable_partition
Function stable_partition_copy
template <typename DerivedPolicy, typename InputIterator1, typename InputIterator2, typename OutputIterator1, typename OutputIterator2, typename Predicate> _CCCL_HOST_DEVICE thrust::pair< OutputIterator1, OutputIterator2 > stable_partition_copy(const thrust::detail::execution_policy_base< DerivedPolicy > & exec, InputIterator1 first, InputIterator1 last, InputIterator2 stencil, OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred);
stable_partition_copy
differs from stable_partition
only in that the reordered sequence is written to different output sequences, rather than in place.
stable_partition_copy
copies the elements [first, last)
based on the function object pred
which is applied to a range of stencil elements. All of the elements whose corresponding stencil element satisfies pred
are copied to the range beginning at out_true
and all the elements whose stencil element fails to satisfy it are copied to the range beginning at out_false
.
stable_partition_copy
differs from partition_copy
in that stable_partition_copy
is guaranteed to preserve relative order. That is, if x
and y
are elements in [first, last)
, such that pred(x) == pred(y)
, and if x
precedes y
, then it will still be true after stable_partition_copy
that x
precedes y
in the output.
The algorithm’s execution is parallelized as determined by exec
.
The following code snippet demonstrates how to use stable_partition_copy
to reorder a sequence so that even numbers precede odd numbers using the thrust::host
execution policy for parallelization:
#include <thrust/partition.h>
#include <thrust/functional.h>
#include <thrust/execution_policy.h>
...
int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int S[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1};
int result[10];
const int N = sizeof(A)/sizeof(int);
int *evens = result;
int *odds = result + 5;
thrust::stable_partition_copy(thrust::host, A, A + N, S, evens, odds, thrust::identity<int>());
// A remains {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
// S remains {0, 1, 0, 1, 0, 1, 0, 1, 0, 1}
// result is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9}
// evens points to {2, 4, 6, 8, 10}
// odds points to {1, 3, 5, 7, 9}
Template Parameters:
DerivedPolicy
The name of the derived execution policy.InputIterator1
is a model of Input Iterator, andInputIterator's
value_type
is convertible toOutputIterator1
andOutputIterator2's
value_types
.InputIterator2
is a model of Input Iterator, andInputIterator2's
value_type
is convertible toPredicate's
argument_type
.OutputIterator1
is a model of Output Iterator.OutputIterator2
is a model of Output Iterator.Predicate
is a model of Predicate.
Function 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.out_true
The destination of the resulting sequence of elements which satisfypred
.out_false
The destination of the resulting sequence of elements which fail to satisfypred
.pred
A function object which decides to which partition each element of the sequence[first, last)
belongs.
Preconditions: The input ranges shall not overlap with either output range.
Returns: A pair
p such that p.first
is the end of the output range beginning at out_true
and p.second
is the end of the output range beginning at out_false
.
See:
- http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2569.pdf
partition_copy
stable_partition
Function stable_partition_copy
template <typename InputIterator1, typename InputIterator2, typename OutputIterator1, typename OutputIterator2, typename Predicate> thrust::pair< OutputIterator1, OutputIterator2 > stable_partition_copy(InputIterator1 first, InputIterator1 last, InputIterator2 stencil, OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred);
stable_partition_copy
differs from stable_partition
only in that the reordered sequence is written to different output sequences, rather than in place.
stable_partition_copy
copies the elements [first, last)
based on the function object pred
which is applied to a range of stencil elements. All of the elements whose corresponding stencil element satisfies pred
are copied to the range beginning at out_true
and all the elements whose stencil element fails to satisfy it are copied to the range beginning at out_false
.
stable_partition_copy
differs from partition_copy
in that stable_partition_copy
is guaranteed to preserve relative order. That is, if x
and y
are elements in [first, last)
, such that pred(x) == pred(y)
, and if x
precedes y
, then it will still be true after stable_partition_copy
that x
precedes y
in the output.
The following code snippet demonstrates how to use stable_partition_copy
to reorder a sequence so that even numbers precede odd numbers.
#include <thrust/partition.h>
#include <thrust/functional.h>
...
int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int S[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1};
int result[10];
const int N = sizeof(A)/sizeof(int);
int *evens = result;
int *odds = result + 5;
thrust::stable_partition_copy(A, A + N, S, evens, odds, thrust::identity<int>());
// A remains {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
// S remains {0, 1, 0, 1, 0, 1, 0, 1, 0, 1}
// result is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9}
// evens points to {2, 4, 6, 8, 10}
// odds points to {1, 3, 5, 7, 9}
Template Parameters:
InputIterator1
is a model of Input Iterator, andInputIterator's
value_type
is convertible toOutputIterator1
andOutputIterator2's
value_types
.InputIterator2
is a model of Input Iterator, andInputIterator2's
value_type
is convertible toPredicate's
argument_type
.OutputIterator1
is a model of Output Iterator.OutputIterator2
is a model of Output Iterator.Predicate
is a model of Predicate.
Function 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.out_true
The destination of the resulting sequence of elements which satisfypred
.out_false
The destination of the resulting sequence of elements which fail to satisfypred
.pred
A function object which decides to which partition each element of the sequence[first, last)
belongs.
Preconditions: The input ranges shall not overlap with either output range.
Returns: A pair
p such that p.first
is the end of the output range beginning at out_true
and p.second
is the end of the output range beginning at out_false
.
See:
- http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2569.pdf
partition_copy
stable_partition