thrust::copy_if#
Overloads#
copy_if(exec, first, last, result, pred)#
-
template<typename DerivedPolicy, typename InputIterator, typename OutputIterator, typename Predicate>
OutputIterator thrust::copy_if( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- InputIterator first,
- InputIterator last,
- OutputIterator result,
- Predicate pred,
This version of
copy_ifcopies elements from the range[first,last)to a range beginning atresult, except that any element which causespredto befalseis not copied.copy_ifis stable, meaning that the relative order of elements that are copied is unchanged.More precisely, for every integer
nsuch that0 <= n < last-first,copy_ifperforms the assignment*result = *(first+n)andresultis advanced one position ifpred(*(first+n)). Otherwise, no assignment occurs andresultis not advanced.The algorithm’s execution is parallelized as determined by
system.The following code snippet demonstrates how to use
copy_ifto perform stream compaction to copy even numbers to an output range using thethrust::hostparallelization policy:#include <thrust/copy.h> #include <thrust/execution_policy.h> ... struct is_even { __host__ __device__ bool operator()(const int x) { return (x % 2) == 0; } }; ... const int N = 6; int V[N] = {-2, 0, -1, 0, 1, 2}; int result[4]; thrust::copy_if(thrust::host, V, V + N, result, is_even()); // V remains {-2, 0, -1, 0, 1, 2} // result is now {-2, 0, 0, 2}
See also
- Parameters:
exec – The execution policy to use for parallelization.
first – The beginning of the sequence from which to copy.
last – The end of the sequence from which to copy.
result – The beginning of the sequence into which to copy.
pred – The predicate to test on every value of the range
[first, last).
- 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.OutputIterator – is a model of Output Iterator.
Predicate – is a model of Predicate.
- Returns:
result + n, wherenis equal to the number of timespredevaluated totruein the range[first, last).- Pre:
The ranges
[first, last)and[result, result + (last - first))shall not overlap.
copy_if(first, last, result, pred)#
-
template<typename InputIterator, typename OutputIterator, typename Predicate>
OutputIterator thrust::copy_if( - InputIterator first,
- InputIterator last,
- OutputIterator result,
- Predicate pred,
This version of
copy_ifcopies elements from the range[first,last)to a range beginning atresult, except that any element which causespredtofalseis not copied.copy_ifis stable, meaning that the relative order of elements that are copied is unchanged.More precisely, for every integer
nsuch that0 <= n < last-first,copy_ifperforms the assignment*result = *(first+n)andresultis advanced one position ifpred(*(first+n)). Otherwise, no assignment occurs andresultis not advanced.The following code snippet demonstrates how to use
copy_ifto perform stream compaction to copy even numbers to an output range.#include <thrust/copy.h> ... struct is_even { __host__ __device__ bool operator()(const int x) { return (x % 2) == 0; } }; ... const int N = 6; int V[N] = {-2, 0, -1, 0, 1, 2}; int result[4]; thrust::copy_if(V, V + N, result, is_even()); // V remains {-2, 0, -1, 0, 1, 2} // result is now {-2, 0, 0, 2}
See also
- Parameters:
first – The beginning of the sequence from which to copy.
last – The end of the sequence from which to copy.
result – The beginning of the sequence into which to copy.
pred – The predicate to test on every value of the range
[first, last).
- Template Parameters:
InputIterator – is a model of Input Iterator, and
InputIterator'svalue_typeis convertible toPredicate'sargument type.OutputIterator – is a model of Output Iterator.
Predicate – is a model of Predicate.
- Returns:
result + n, wherenis equal to the number of timespredevaluated totruein the range[first, last).- Pre:
The ranges
[first, last)and[result, result + (last - first))shall not overlap.
copy_if(exec, first, last, stencil, result, pred)#
-
template<typename DerivedPolicy, typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Predicate>
OutputIterator thrust::copy_if( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- InputIterator1 first,
- InputIterator1 last,
- InputIterator2 stencil,
- OutputIterator result,
- Predicate pred,
This version of
copy_ifcopies elements from the range[first,last)to a range beginning atresult, except that any element whose corresponding stencil element causespredto befalseis not copied.copy_ifis stable, meaning that the relative order of elements that are copied is unchanged.More precisely, for every integer
nsuch that0 <= n < last-first,copy_ifperforms the assignment*result = *(first+n)andresultis advanced one position ifpred(*(stencil+n)). Otherwise, no assignment occurs andresultis not advanced.The algorithm’s execution is parallelized as determined by
exec.The following code snippet demonstrates how to use
copy_ifto perform stream compaction to copy numbers to an output range when corresponding stencil elements are even using thethrust::hostexecution policy:#include <thrust/copy.h> #include <thrust/execution_policy.h> ... struct is_even { __host__ __device__ bool operator()(const int x) { return (x % 2) == 0; } }; ... int N = 6; int data[N] = { 0, 1, 2, 3, 4, 5}; int stencil[N] = {-2, 0, -1, 0, 1, 2}; int result[4]; thrust::copy_if(thrust::host, data, data + N, stencil, result, is_even()); // data remains = { 0, 1, 2, 3, 4, 5}; // stencil remains = {-2, 0, -1, 0, 1, 2}; // result is now { 0, 1, 3, 5}
See also
- Parameters:
exec – The execution policy to use for parallelization.
first – The beginning of the sequence from which to copy.
last – The end of the sequence from which to copy.
stencil – The beginning of the stencil sequence.
result – The beginning of the sequence into which to copy.
pred – The predicate to test on every value of the range
[stencil, stencil + (last-first)).
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
InputIterator1 – is a model of Input Iterator.
InputIterator2 – is a model of Input Iterator, and
InputIterator2'svalue_typeis convertible toPredicate'sargument type.OutputIterator – is a model of Output Iterator.
Predicate – is a model of Predicate.
- Returns:
result + n, wherenis equal to the number of timespredevaluated totruein the range[stencil, stencil + (last-first)).- Pre:
The ranges
[first, last)and[result, result + (last - first))shall not overlap.- Pre:
The ranges
[stencil, stencil + (last - first))and[result, result + (last - first))shall not overlap.
copy_if(first, last, stencil, result, pred)#
-
template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Predicate>
OutputIterator thrust::copy_if( - InputIterator1 first,
- InputIterator1 last,
- InputIterator2 stencil,
- OutputIterator result,
- Predicate pred,
This version of
copy_ifcopies elements from the range[first,last)to a range beginning atresult, except that any element whose corresponding stencil element causespredto befalseis not copied.copy_ifis stable, meaning that the relative order of elements that are copied is unchanged.More precisely, for every integer
nsuch that0 <= n < last-first,copy_ifperforms the assignment*result = *(first+n)andresultis advanced one position ifpred(*(stencil+n)). Otherwise, no assignment occurs andresultis not advanced.The following code snippet demonstrates how to use
copy_ifto perform stream compaction to copy numbers to an output range when corresponding stencil elements are even:#include <thrust/copy.h> ... struct is_even { __host__ __device__ bool operator()(const int x) { return (x % 2) == 0; } }; ... int N = 6; int data[N] = { 0, 1, 2, 3, 4, 5}; int stencil[N] = {-2, 0, -1, 0, 1, 2}; int result[4]; thrust::copy_if(data, data + N, stencil, result, is_even()); // data remains = { 0, 1, 2, 3, 4, 5}; // stencil remains = {-2, 0, -1, 0, 1, 2}; // result is now { 0, 1, 3, 5}
See also
- Parameters:
first – The beginning of the sequence from which to copy.
last – The end of the sequence from which to copy.
stencil – The beginning of the stencil sequence.
result – The beginning of the sequence into which to copy.
pred – The predicate to test on every value of the range
[stencil, stencil + (last-first)).
- Template Parameters:
InputIterator1 – is a model of Input Iterator.
InputIterator2 – is a model of Input Iterator, and
InputIterator2'svalue_typeis convertible toPredicate'sargument type.OutputIterator – is a model of Output Iterator.
Predicate – is a model of Predicate.
- Returns:
result + n, wherenis equal to the number of timespredevaluated totruein the range[stencil, stencil + (last-first)).- Pre:
The ranges
[first, last)and[result, result + (last - first))shall not overlap.- Pre:
The ranges
[stencil, stencil + (last - first))and[result, result + (last - first))shall not overlap.