thrust::partition_copy#
Overloads#
partition_copy(exec, first, last, out_true, out_false, pred)#
-
template<typename DerivedPolicy, typename InputIterator, typename OutputIterator1, typename OutputIterator2, typename Predicate>
::cuda::std::pair<OutputIterator1, OutputIterator2> thrust::partition_copy( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- InputIterator first,
- InputIterator last,
- OutputIterator1 out_true,
- OutputIterator2 out_false,
- Predicate pred
partition_copydiffers frompartitiononly in that the reordered sequence is written to different output sequences, rather than in place.partition_copycopies the elements[first, last)based on the function objectpred. All of the elements that satisfypredare copied to the range beginning atout_trueand all the elements that fail to satisfy it are copied to the range beginning atout_false.The algorithm’s execution is parallelized as determined by
exec.The following code snippet demonstrates how to use
partition_copyto separate a sequence into two output sequences of even and odd numbers using thethrust::hostexecution 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}
Added in version 2.2.0.
See also
See also
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.- 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 satisfy
pred.out_false – The destination of the resulting sequence of elements which fail to satisfy
pred.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.
InputIterator – is a model of Input Iterator, and
InputIterator'svalue_typeis convertible toPredicate'sargument type andInputIterator'svalue_typeis convertible toOutputIterator1andOutputIterator2'svalue_types.OutputIterator1 – is a model of Output Iterator.
OutputIterator2 – is a model of Output Iterator.
Predicate – is a model of Predicate.
- Returns:
A
pairp such thatp.firstis the end of the output range beginning atout_trueandp.secondis the end of the output range beginning atout_false.- Pre:
The input range shall not overlap with either output range.
partition_copy(first, last, out_true, out_false, pred)#
-
template<typename InputIterator, typename OutputIterator1, typename OutputIterator2, typename Predicate>
::cuda::std::pair<OutputIterator1, OutputIterator2> thrust::partition_copy( - InputIterator first,
- InputIterator last,
- OutputIterator1 out_true,
- OutputIterator2 out_false,
- Predicate pred
partition_copydiffers frompartitiononly in that the reordered sequence is written to different output sequences, rather than in place.partition_copycopies the elements[first, last)based on the function objectpred. All of the elements that satisfypredare copied to the range beginning atout_trueand all the elements that fail to satisfy it are copied to the range beginning atout_false.The following code snippet demonstrates how to use
partition_copyto 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}
Added in version 2.2.0.
See also
See also
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.- 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 satisfy
pred.out_false – The destination of the resulting sequence of elements which fail to satisfy
pred.pred – A function object which decides to which partition each element of the sequence
[first, last)belongs.
- Template Parameters:
InputIterator – is a model of Input Iterator, and
InputIterator'svalue_typeis convertible toPredicate'sargument type andInputIterator'svalue_typeis convertible toOutputIterator1andOutputIterator2'svalue_types.OutputIterator1 – is a model of Output Iterator.
OutputIterator2 – is a model of Output Iterator.
Predicate – is a model of Predicate.
- Returns:
A
pairp such thatp.firstis the end of the output range beginning atout_trueandp.secondis the end of the output range beginning atout_false.- Pre:
The input range shall not overlap with either output range.
partition_copy(exec, first, last, stencil, out_true, out_false, pred)#
-
template<typename DerivedPolicy, typename InputIterator1, typename InputIterator2, typename OutputIterator1, typename OutputIterator2, typename Predicate>
::cuda::std::pair<OutputIterator1, OutputIterator2> thrust::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_copydiffers frompartitiononly in that the reordered sequence is written to different output sequences, rather than in place.partition_copycopies the elements[first, last)based on the function objectpredwhich is applied to a range of stencil elements. All of the elements whose corresponding stencil element satisfiespredare copied to the range beginning atout_trueand all the elements whose stencil element fails to satisfy it are copied to the range beginning atout_false.The algorithm’s execution is parallelized as determined by
exec.The following code snippet demonstrates how to use
partition_copyto separate a sequence into two output sequences of even and odd numbers using thethrust::hostexecution 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, ::cuda::std::identity{}); // 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}
Added in version 2.2.0.
See also
See also
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.- 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 satisfy
pred.out_false – The destination of the resulting sequence of elements which fail to satisfy
pred.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.
InputIterator1 – is a model of Input Iterator, and
InputIterator'svalue_typeis convertible toOutputIterator1andOutputIterator2'svalue_types.InputIterator2 – is a model of Input Iterator, and
InputIterator2'svalue_typeis convertible toPredicate'sargument type.OutputIterator1 – is a model of Output Iterator.
OutputIterator2 – is a model of Output Iterator.
Predicate – is a model of Predicate.
- Returns:
A
pairp such thatp.firstis the end of the output range beginning atout_trueandp.secondis the end of the output range beginning atout_false.- Pre:
The input ranges shall not overlap with either output range.
partition_copy(first, last, stencil, out_true, out_false, pred)#
-
template<typename InputIterator1, typename InputIterator2, typename OutputIterator1, typename OutputIterator2, typename Predicate>
::cuda::std::pair<OutputIterator1, OutputIterator2> thrust::partition_copy( - InputIterator1 first,
- InputIterator1 last,
- InputIterator2 stencil,
- OutputIterator1 out_true,
- OutputIterator2 out_false,
- Predicate pred
partition_copydiffers frompartitiononly in that the reordered sequence is written to different output sequences, rather than in place.partition_copycopies the elements[first, last)based on the function objectpredwhich is applied to a range of stencil elements. All of the elements whose corresponding stencil element satisfiespredare copied to the range beginning atout_trueand all the elements whose stencil element fails to satisfy it are copied to the range beginning atout_false.The following code snippet demonstrates how to use
partition_copyto 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, ::cuda::std::identity{}); // 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}
Added in version 2.2.0.
See also
See also
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.- 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 satisfy
pred.out_false – The destination of the resulting sequence of elements which fail to satisfy
pred.pred – A function object which decides to which partition each element of the sequence
[first, last)belongs.
- Template Parameters:
InputIterator1 – is a model of Input Iterator, and
InputIterator'svalue_typeis convertible toOutputIterator1andOutputIterator2'svalue_types.InputIterator2 – is a model of Input Iterator, and
InputIterator2'svalue_typeis convertible toPredicate'sargument type.OutputIterator1 – is a model of Output Iterator.
OutputIterator2 – is a model of Output Iterator.
Predicate – is a model of Predicate.
- Returns:
A
pairp such thatp.firstis the end of the output range beginning atout_trueandp.secondis the end of the output range beginning atout_false.- Pre:
The input ranges shall not overlap with either output range.