Bolt  1.3
C++ template library with support for OpenCL
Functions
Stream_compaction

Functions

template<typename DerivedPolicy , typename InputIterator , typename OutputIterator , typename Predicate >
OutputIterator bolt::amp::copy_if (const bolt::amp::control &ctl, InputIterator first, InputIterator last, OutputIterator result, Predicate pred)
 
template<typename InputIterator , typename OutputIterator , typename Predicate >
OutputIterator bolt::amp::copy_if (InputIterator first, InputIterator last, OutputIterator result, Predicate pred)
 
template<typename DerivedPolicy , typename InputIterator1 , typename InputIterator2 , typename OutputIterator , typename Predicate >
OutputIterator bolt::amp::copy_if (const bolt::amp::control &ctl, InputIterator1 first, InputIterator1 last, InputIterator2 stencil, OutputIterator result, Predicate pred)
 
template<typename InputIterator1 , typename InputIterator2 , typename OutputIterator , typename Predicate >
OutputIterator bolt::amp::copy_if (InputIterator1 first, InputIterator1 last, InputIterator2 stencil, OutputIterator result, Predicate pred)
 

Detailed Description

Function Documentation

template<typename DerivedPolicy , typename InputIterator , typename OutputIterator , typename Predicate >
OutputIterator bolt::amp::copy_if ( const bolt::amp::control ctl,
InputIterator  first,
InputIterator  last,
OutputIterator  result,
Predicate  pred 
)

This version of copy_if copies elements from the range [first,last) to a range beginning at \ presult, except that any element which causes pred to be pred to be false is not copied.

More precisely, for every integer n such that 0 <= n < last-first, copy_if performs the assignment *result = *(first+n) and result is advanced one position if pred(*(first+n)). Otherwise, no assignment occurs and result is not advanced.

The algorithm's execution is parallelized as determined by system.

Parameters
ctlOptional Control structure to control accelerator, debug, tuning, etc.See bolt::amp::control.
firstThe beginning of the sequence from which to copy.
lastThe end of the sequence from which to copy.
resultThe beginning of the sequence into which to copy.
predThe predicate to test on every value of the range [first, last).
Returns
result + n, where n is equal to the number of times pred evaluated to true in the range [first, last).
Template Parameters
InputIteratoris a model of Input Iterator, and InputIterator's value_type is convertible to Predicate's argument_type.
OutputIteratoris a model of Output Iterator.
Predicateis a model of Predicate.
Precondition
The ranges [first, last) and [result, result + (last - first)) shall not overlap.

The following code snippet demonstrates how to use copy_if to perform stream compaction

#include <bolt/amp/copy.h>
...
struct is_even
{
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];
bolt::amp::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
remove_copy_if
template<typename DerivedPolicy , typename InputIterator1 , typename InputIterator2 , typename OutputIterator , typename Predicate >
OutputIterator bolt::amp::copy_if ( const bolt::amp::control ctl,
InputIterator1  first,
InputIterator1  last,
InputIterator2  stencil,
OutputIterator  result,
Predicate  pred 
)

This version of copy_if copies elements from the range [first,last) to a range beginning at result, except that any element whose corresponding stencil element causes pred to be false is not copied.

More precisely, for every integer n such that 0 <= n < last-first, copy_if performs the assignment *result = *(first+n) and result is advanced one position if pred(*(stencil+n)). Otherwise, no assignment occurs and result is not advanced.

The algorithm's execution is parallelized as determined by exec.

Parameters
ctlOptional Control structure to control accelerator, debug, tuning, etc.See bolt::amp::control.
firstThe beginning of the sequence from which to copy.
lastThe end of the sequence from which to copy.
stencilThe beginning of the stencil sequence.
resultThe beginning of the sequence into which to copy.
predThe predicate to test on every value of the range [stencil, stencil + (last-first)).
Returns
result + n, where n is equal to the number of times pred evaluated to true in the range [stencil, stencil + (last-first)).
Template Parameters
DerivedPolicyThe name of the derived execution policy.
InputIterator1is a model of Input Iterator.
InputIterator2is a model of Input Iterator, and InputIterator2's value_type is convertible to Predicate's argument_type.
OutputIteratoris a model of Output Iterator.
Predicateis a model of Predicate.
Precondition
The ranges [first, last) and [result, result + (last - first)) shall not overlap.
The ranges [stencil, stencil + (last - first)) and [result, result + (last - first)) shall not overlap.
#include <bolt/amp/copy.h>
#include <bolt/amp/execution_policy.h>
...
struct is_even
{
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];
bolt::amp::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
remove_copy_if