thrust
Modules | Functions
Transformations

Modules

 Filling
 
 Modifying
 
 Replacing
 

Functions

template<typename DerivedPolicy , typename InputIterator , typename OutputIterator >
__host__ __device__ OutputIterator thrust::adjacent_difference (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, InputIterator first, InputIterator last, OutputIterator result)
 
template<typename DerivedPolicy , typename InputIterator , typename OutputIterator , typename BinaryFunction >
__host__ __device__ OutputIterator thrust::adjacent_difference (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, InputIterator first, InputIterator last, OutputIterator result, BinaryFunction binary_op)
 
template<typename InputIterator , typename OutputIterator >
OutputIterator thrust::adjacent_difference (InputIterator first, InputIterator last, OutputIterator result)
 
template<typename InputIterator , typename OutputIterator , typename BinaryFunction >
OutputIterator thrust::adjacent_difference (InputIterator first, InputIterator last, OutputIterator result, BinaryFunction binary_op)
 
template<typename DerivedPolicy , typename ForwardIterator , typename Generator >
__host__ __device__ void thrust::generate (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, ForwardIterator first, ForwardIterator last, Generator gen)
 
template<typename ForwardIterator , typename Generator >
void thrust::generate (ForwardIterator first, ForwardIterator last, Generator gen)
 
template<typename DerivedPolicy , typename OutputIterator , typename Size , typename Generator >
__host__ __device__ OutputIterator thrust::generate_n (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, OutputIterator first, Size n, Generator gen)
 
template<typename OutputIterator , typename Size , typename Generator >
OutputIterator thrust::generate_n (OutputIterator first, Size n, Generator gen)
 
template<typename DerivedPolicy , typename ForwardIterator >
__host__ __device__ void thrust::sequence (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, ForwardIterator first, ForwardIterator last)
 
template<typename ForwardIterator >
void thrust::sequence (ForwardIterator first, ForwardIterator last)
 
template<typename DerivedPolicy , typename ForwardIterator , typename T >
__host__ __device__ void thrust::sequence (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, ForwardIterator first, ForwardIterator last, T init)
 
template<typename ForwardIterator , typename T >
void thrust::sequence (ForwardIterator first, ForwardIterator last, T init)
 
template<typename DerivedPolicy , typename ForwardIterator , typename T >
__host__ __device__ void thrust::sequence (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, ForwardIterator first, ForwardIterator last, T init, T step)
 
template<typename ForwardIterator , typename T >
void thrust::sequence (ForwardIterator first, ForwardIterator last, T init, T step)
 
template<typename DerivedPolicy , typename ForwardIterator , typename UnaryOperation >
__host__ __device__ void thrust::tabulate (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, ForwardIterator first, ForwardIterator last, UnaryOperation unary_op)
 
template<typename ForwardIterator , typename UnaryOperation >
void thrust::tabulate (ForwardIterator first, ForwardIterator last, UnaryOperation unary_op)
 
template<typename DerivedPolicy , typename InputIterator , typename OutputIterator , typename UnaryFunction >
__host__ __device__ OutputIterator thrust::transform (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, InputIterator first, InputIterator last, OutputIterator result, UnaryFunction op)
 
template<typename InputIterator , typename OutputIterator , typename UnaryFunction >
OutputIterator thrust::transform (InputIterator first, InputIterator last, OutputIterator result, UnaryFunction op)
 
template<typename DerivedPolicy , typename InputIterator1 , typename InputIterator2 , typename OutputIterator , typename BinaryFunction >
__host__ __device__ OutputIterator thrust::transform (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result, BinaryFunction op)
 
template<typename InputIterator1 , typename InputIterator2 , typename OutputIterator , typename BinaryFunction >
OutputIterator thrust::transform (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result, BinaryFunction op)
 
template<typename DerivedPolicy , typename InputIterator , typename ForwardIterator , typename UnaryFunction , typename Predicate >
__host__ __device__ ForwardIterator thrust::transform_if (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, InputIterator first, InputIterator last, ForwardIterator result, UnaryFunction op, Predicate pred)
 
template<typename InputIterator , typename ForwardIterator , typename UnaryFunction , typename Predicate >
ForwardIterator thrust::transform_if (InputIterator first, InputIterator last, ForwardIterator result, UnaryFunction op, Predicate pred)
 
template<typename DerivedPolicy , typename InputIterator1 , typename InputIterator2 , typename ForwardIterator , typename UnaryFunction , typename Predicate >
__host__ __device__ ForwardIterator thrust::transform_if (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, InputIterator1 first, InputIterator1 last, InputIterator2 stencil, ForwardIterator result, UnaryFunction op, Predicate pred)
 
template<typename InputIterator1 , typename InputIterator2 , typename ForwardIterator , typename UnaryFunction , typename Predicate >
ForwardIterator thrust::transform_if (InputIterator1 first, InputIterator1 last, InputIterator2 stencil, ForwardIterator result, UnaryFunction op, Predicate pred)
 
template<typename DerivedPolicy , typename InputIterator1 , typename InputIterator2 , typename InputIterator3 , typename ForwardIterator , typename BinaryFunction , typename Predicate >
__host__ __device__ ForwardIterator thrust::transform_if (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator3 stencil, ForwardIterator result, BinaryFunction binary_op, Predicate pred)
 
template<typename InputIterator1 , typename InputIterator2 , typename InputIterator3 , typename ForwardIterator , typename BinaryFunction , typename Predicate >
ForwardIterator thrust::transform_if (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator3 stencil, ForwardIterator result, BinaryFunction binary_op, Predicate pred)
 

Detailed Description

Function Documentation

template<typename DerivedPolicy , typename InputIterator , typename OutputIterator >
__host__ __device__ OutputIterator thrust::adjacent_difference ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
InputIterator  first,
InputIterator  last,
OutputIterator  result 
)

adjacent_difference calculates the differences of adjacent elements in the range [first, last). That is, *first is assigned to *result, and, for each iterator i in the range [first + 1, last), the difference of *i and *(i - 1) is assigned to *(result + (i - first)).

This version of adjacent_difference uses operator- to calculate differences.

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

Parameters
execThe execution policy to use for parallelization.
firstThe beginning of the input range.
lastThe end of the input range.
resultThe beginning of the output range.
Returns
The iterator result + (last - first)
Template Parameters
DerivedPolicyThe name of the derived execution policy.
InputIteratoris a model of Input Iterator, and x and y are objects of InputIterator's value_type, then x - is defined, and InputIterator's value_type is convertible to a type in OutputIterator's set of value_types, and the return type of x - y is convertible to a type in OutputIterator's set of value_types.
OutputIteratoris a model of Output Iterator.
Remarks
Note that result is permitted to be the same iterator as first. This is useful for computing differences "in place".

The following code snippet demonstrates how to use adjacent_difference to compute the difference between adjacent elements of a range using the thrust::device execution policy:

...
int h_data[8] = {1, 2, 1, 2, 1, 2, 1, 2};
thrust::device_vector<int> d_data(h_data, h_data + 8);
thrust::adjacent_difference(thrust::device, d_data.begin(), d_data.end(), d_result.begin());
// d_result is now [1, 1, -1, 1, -1, 1, -1, 1]
See Also
http://www.sgi.com/tech/stl/adjacent_difference.html
inclusive_scan
template<typename DerivedPolicy , typename InputIterator , typename OutputIterator , typename BinaryFunction >
__host__ __device__ OutputIterator thrust::adjacent_difference ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
InputIterator  first,
InputIterator  last,
OutputIterator  result,
BinaryFunction  binary_op 
)

adjacent_difference calculates the differences of adjacent elements in the range [first, last). That is, *first is assigned to *result, and, for each iterator i in the range [first + 1, last), binary_op(*i, *(i - 1)) is assigned to *(result + (i - first)).

This version of adjacent_difference uses the binary function binary_op to calculate differences.

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

Parameters
execThe execution policy to use for parallelization.
firstThe beginning of the input range.
lastThe end of the input range.
resultThe beginning of the output range.
binary_opThe binary function used to compute differences.
Returns
The iterator result + (last - first)
Template Parameters
DerivedPolicyThe name of the derived execution policy.
InputIteratoris a model of Input Iterator, and InputIterator's value_type is convertible to BinaryFunction's first_argument_type and second_argument_type, and InputIterator's value_type is convertible to a type in OutputIterator's set of value_types.
OutputIteratoris a model of Output Iterator.
BinaryFunction'sresult_type is convertible to a type in OutputIterator's set of value_types.
Remarks
Note that result is permitted to be the same iterator as first. This is useful for computing differences "in place".

The following code snippet demonstrates how to use adjacent_difference to compute the sum between adjacent elements of a range using the thrust::device execution policy:

...
int h_data[8] = {1, 2, 1, 2, 1, 2, 1, 2};
thrust::device_vector<int> d_data(h_data, h_data + 8);
thrust::adjacent_difference(thrust::device, d_data.begin(), d_data.end(), d_result.begin(), thrust::plus<int>());
// d_data is now [1, 3, 3, 3, 3, 3, 3, 3]
See Also
http://www.sgi.com/tech/stl/adjacent_difference.html
inclusive_scan
template<typename InputIterator , typename OutputIterator >
OutputIterator thrust::adjacent_difference ( InputIterator  first,
InputIterator  last,
OutputIterator  result 
)

adjacent_difference calculates the differences of adjacent elements in the range [first, last). That is, *first is assigned to *result, and, for each iterator i in the range [first + 1, last), the difference of *i and *(i - 1) is assigned to *(result + (i - first)).

This version of adjacent_difference uses operator- to calculate differences.

Parameters
firstThe beginning of the input range.
lastThe end of the input range.
resultThe beginning of the output range.
Returns
The iterator result + (last - first)
Template Parameters
InputIteratoris a model of Input Iterator, and x and y are objects of InputIterator's value_type, then x - is defined, and InputIterator's value_type is convertible to a type in OutputIterator's set of value_types, and the return type of x - y is convertible to a type in OutputIterator's set of value_types.
OutputIteratoris a model of Output Iterator.
Remarks
Note that result is permitted to be the same iterator as first. This is useful for computing differences "in place".

The following code snippet demonstrates how to use adjacent_difference to compute the difference between adjacent elements of a range.

...
int h_data[8] = {1, 2, 1, 2, 1, 2, 1, 2};
thrust::device_vector<int> d_data(h_data, h_data + 8);
thrust::adjacent_difference(d_data.begin(), d_data.end(), d_result.begin());
// d_result is now [1, 1, -1, 1, -1, 1, -1, 1]
See Also
http://www.sgi.com/tech/stl/adjacent_difference.html
inclusive_scan
template<typename InputIterator , typename OutputIterator , typename BinaryFunction >
OutputIterator thrust::adjacent_difference ( InputIterator  first,
InputIterator  last,
OutputIterator  result,
BinaryFunction  binary_op 
)

adjacent_difference calculates the differences of adjacent elements in the range [first, last). That is, *first is assigned to *result, and, for each iterator i in the range [first + 1, last), binary_op(*i, *(i - 1)) is assigned to *(result + (i - first)).

This version of adjacent_difference uses the binary function binary_op to calculate differences.

Parameters
firstThe beginning of the input range.
lastThe end of the input range.
resultThe beginning of the output range.
binary_opThe binary function used to compute differences.
Returns
The iterator result + (last - first)
Template Parameters
InputIteratoris a model of Input Iterator, and InputIterator's value_type is convertible to BinaryFunction's first_argument_type and second_argument_type, and InputIterator's value_type is convertible to a type in OutputIterator's set of value_types.
OutputIteratoris a model of Output Iterator.
BinaryFunction'sresult_type is convertible to a type in OutputIterator's set of value_types.
Remarks
Note that result is permitted to be the same iterator as first. This is useful for computing differences "in place".

The following code snippet demonstrates how to use adjacent_difference to compute the sum between adjacent elements of a range.

...
int h_data[8] = {1, 2, 1, 2, 1, 2, 1, 2};
thrust::device_vector<int> d_data(h_data, h_data + 8);
thrust::adjacent_difference(d_data.begin(), d_data.end(), d_result.begin(), thrust::plus<int>());
// d_data is now [1, 3, 3, 3, 3, 3, 3, 3]
See Also
http://www.sgi.com/tech/stl/adjacent_difference.html
inclusive_scan
template<typename DerivedPolicy , typename ForwardIterator , typename Generator >
__host__ __device__ void thrust::generate ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
ForwardIterator  first,
ForwardIterator  last,
Generator  gen 
)

generate assigns the result of invoking gen, a function object that takes no arguments, to each element in the range [first,last).

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

Parameters
execThe execution policy to use for parallelization.
firstThe first element in the range of interest.
lastThe last element in the range of interest.
genA function argument, taking no parameters, used to generate values to assign to elements in the range [first,last).
Template Parameters
DerivedPolicyThe name of the derived execution policy.
ForwardIteratoris a model of Forward Iterator, and ForwardIterator is mutable.
Generatoris a model of Generator, and Generator's result_type is convertible to ForwardIterator's value_type.

The following code snippet demonstrates how to fill a host_vector with random numbers, using the standard C library function rand using the thrust::host execution policy for parallelization:

#include <cstdlib>
...
thrust::host_vector<int> v(10);
srand(13);
thrust::generate(thrust::host, v.begin(), v.end(), rand);
// the elements of v are now pseudo-random numbers
See Also
generate_n
http://www.sgi.com/tech/stl/generate.html
template<typename ForwardIterator , typename Generator >
void thrust::generate ( ForwardIterator  first,
ForwardIterator  last,
Generator  gen 
)

generate assigns the result of invoking gen, a function object that takes no arguments, to each element in the range [first,last).

Parameters
firstThe first element in the range of interest.
lastThe last element in the range of interest.
genA function argument, taking no parameters, used to generate values to assign to elements in the range [first,last).
Template Parameters
ForwardIteratoris a model of Forward Iterator, and ForwardIterator is mutable.
Generatoris a model of Generator, and Generator's result_type is convertible to ForwardIterator's value_type.

The following code snippet demonstrates how to fill a host_vector with random numbers, using the standard C library function rand.

#include <cstdlib>
...
thrust::host_vector<int> v(10);
srand(13);
thrust::generate(v.begin(), v.end(), rand);
// the elements of v are now pseudo-random numbers
See Also
generate_n
http://www.sgi.com/tech/stl/generate.html
template<typename DerivedPolicy , typename OutputIterator , typename Size , typename Generator >
__host__ __device__ OutputIterator thrust::generate_n ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
OutputIterator  first,
Size  n,
Generator  gen 
)

generate_n assigns the result of invoking gen, a function object that takes no arguments, to each element in the range [first,first + n). The return value is first + n.

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

Parameters
execThe execution policy to use for parallelization.
firstThe first element in the range of interest.
nThe size of the range of interest.
genA function argument, taking no parameters, used to generate values to assign to elements in the range [first,first + n).
Template Parameters
DerivedPolicyThe name of the derived execution policy.
OutputIteratoris a model of Output Iterator.
Sizeis an integral type (either signed or unsigned).
Generatoris a model of Generator, and Generator's result_type is convertible to a type in OutputIterator's set of value_types.

The following code snippet demonstrates how to fill a host_vector with random numbers, using the standard C library function rand using the thrust::host execution policy for parallelization:

#include <cstdlib>
...
thrust::host_vector<int> v(10);
srand(13);
thrust::generate_n(thrust::host, v.begin(), 10, rand);
// the elements of v are now pseudo-random numbers
See Also
generate
http://www.sgi.com/tech/stl/generate.html
template<typename OutputIterator , typename Size , typename Generator >
OutputIterator thrust::generate_n ( OutputIterator  first,
Size  n,
Generator  gen 
)

generate_n assigns the result of invoking gen, a function object that takes no arguments, to each element in the range [first,first + n). The return value is first + n.

Parameters
firstThe first element in the range of interest.
nThe size of the range of interest.
genA function argument, taking no parameters, used to generate values to assign to elements in the range [first,first + n).
Template Parameters
OutputIteratoris a model of Output Iterator.
Sizeis an integral type (either signed or unsigned).
Generatoris a model of Generator, and Generator's result_type is convertible to a type in OutputIterator's set of value_types.

The following code snippet demonstrates how to fill a host_vector with random numbers, using the standard C library function rand.

#include <stdlib.h>
...
thrust::host_vector<int> v(10);
srand(13);
thrust::generate_n(v.begin(), 10, rand);
// the elements of v are now pseudo-random numbers
See Also
generate
http://www.sgi.com/tech/stl/generate.html
template<typename DerivedPolicy , typename ForwardIterator >
__host__ __device__ void thrust::sequence ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
ForwardIterator  first,
ForwardIterator  last 
)

sequence fills the range [first, last) with a sequence of numbers.

For each iterator i in the range [first, last), this version of sequence performs the assignment *i = (i - first).

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

Parameters
execThe execution policy to use for parallelization.
firstThe beginning of the sequence.
lastThe end of the sequence.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
ForwardIteratoris a model of Forward Iterator, and ForwardIterator is mutable, and if x and y are objects of ForwardIterator's value_type, then x + y is defined, and if T is ForwardIterator's value_type, then T(0) is defined.

The following code snippet demonstrates how to use sequence to fill a range with a sequence of numbers using the thrust::host execution policy for parallelization:

...
const int N = 10;
int A[N];
// A is now {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
Note
Unlike the similar C++ STL function std::iota, sequence offers no guarantee on order of execution.
See Also
http://www.sgi.com/tech/stl/iota.html
template<typename ForwardIterator >
void thrust::sequence ( ForwardIterator  first,
ForwardIterator  last 
)

sequence fills the range [first, last) with a sequence of numbers.

For each iterator i in the range [first, last), this version of sequence performs the assignment *i = (i - first).

Parameters
firstThe beginning of the sequence.
lastThe end of the sequence.
Template Parameters
ForwardIteratoris a model of Forward Iterator, and ForwardIterator is mutable, and if x and y are objects of ForwardIterator's value_type, then x + y is defined, and if T is ForwardIterator's value_type, then T(0) is defined.

The following code snippet demonstrates how to use sequence to fill a range with a sequence of numbers.

...
const int N = 10;
int A[N];
thrust::sequence(A, A + 10);
// A is now {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
Note
Unlike the similar C++ STL function std::iota, sequence offers no guarantee on order of execution.
See Also
http://www.sgi.com/tech/stl/iota.html
template<typename DerivedPolicy , typename ForwardIterator , typename T >
__host__ __device__ void thrust::sequence ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
ForwardIterator  first,
ForwardIterator  last,
init 
)

sequence fills the range [first, last) with a sequence of numbers.

For each iterator i in the range [first, last), this version of sequence performs the assignment *i = init + (i - first).

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

Parameters
execThe execution policy to use for parallelization.
firstThe beginning of the sequence.
lastThe end of the sequence.
initThe first value of the sequence of numbers.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
ForwardIteratoris a model of Forward Iterator, and ForwardIterator is mutable, and if x and y are objects of ForwardIterator's value_type, then x + y is defined, and if T is ForwardIterator's value_type, then T(0) is defined.
Tis a model of Assignable, and T is convertible to ForwardIterator's value_type.

The following code snippet demonstrates how to use sequence to fill a range with a sequence of numbers starting from the value 1 using the thrust::host execution policy for parallelization:

...
const int N = 10;
int A[N];
// A is now {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
Note
Unlike the similar C++ STL function std::iota, sequence offers no guarantee on order of execution.
See Also
http://www.sgi.com/tech/stl/iota.html
template<typename ForwardIterator , typename T >
void thrust::sequence ( ForwardIterator  first,
ForwardIterator  last,
init 
)

sequence fills the range [first, last) with a sequence of numbers.

For each iterator i in the range [first, last), this version of sequence performs the assignment *i = init + (i - first).

Parameters
firstThe beginning of the sequence.
lastThe end of the sequence.
initThe first value of the sequence of numbers.
Template Parameters
ForwardIteratoris a model of Forward Iterator, and ForwardIterator is mutable, and if x and y are objects of ForwardIterator's value_type, then x + y is defined, and if T is ForwardIterator's value_type, then T(0) is defined.
Tis a model of Assignable, and T is convertible to ForwardIterator's value_type.

The following code snippet demonstrates how to use sequence to fill a range with a sequence of numbers starting from the value 1.

...
const int N = 10;
int A[N];
thrust::sequence(A, A + 10, 1);
// A is now {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
Note
Unlike the similar C++ STL function std::iota, sequence offers no guarantee on order of execution.
See Also
http://www.sgi.com/tech/stl/iota.html
template<typename DerivedPolicy , typename ForwardIterator , typename T >
__host__ __device__ void thrust::sequence ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
ForwardIterator  first,
ForwardIterator  last,
init,
step 
)

sequence fills the range [first, last) with a sequence of numbers.

For each iterator i in the range [first, last), this version of sequence performs the assignment *i = init + step * (i - first).

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

Parameters
execThe execution policy to use for parallelization.
firstThe beginning of the sequence.
lastThe end of the sequence.
initThe first value of the sequence of numbers
stepThe difference between consecutive elements.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
ForwardIteratoris a model of Forward Iterator, and ForwardIterator is mutable, and if x and y are objects of ForwardIterator's value_type, then x + y is defined, and if T is ForwardIterator's value_type, then T(0) is defined.
Tis a model of Assignable, and T is convertible to ForwardIterator's value_type.

The following code snippet demonstrates how to use sequence to fill a range with a sequence of numbers starting from the value 1 with a step size of 3 using the thrust::host execution policy for parallelization:

...
const int N = 10;
int A[N];
thrust::sequence(thrust::host, A, A + 10, 1, 3);
// A is now {1, 4, 7, 10, 13, 16, 19, 22, 25, 28}
Note
Unlike the similar C++ STL function std::iota, sequence offers no guarantee on order of execution.
See Also
http://www.sgi.com/tech/stl/iota.html
template<typename ForwardIterator , typename T >
void thrust::sequence ( ForwardIterator  first,
ForwardIterator  last,
init,
step 
)

sequence fills the range [first, last) with a sequence of numbers.

For each iterator i in the range [first, last), this version of sequence performs the assignment *i = init + step * (i - first).

Parameters
firstThe beginning of the sequence.
lastThe end of the sequence.
initThe first value of the sequence of numbers
stepThe difference between consecutive elements.
Template Parameters
ForwardIteratoris a model of Forward Iterator, and ForwardIterator is mutable, and if x and y are objects of ForwardIterator's value_type, then x + y is defined, and if T is ForwardIterator's value_type, then T(0) is defined.
Tis a model of Assignable, and T is convertible to ForwardIterator's value_type.

The following code snippet demonstrates how to use sequence to fill a range with a sequence of numbers starting from the value 1 with a step size of 3.

...
const int N = 10;
int A[N];
thrust::sequence(A, A + 10, 1, 3);
// A is now {1, 4, 7, 10, 13, 16, 19, 22, 25, 28}
Note
Unlike the similar C++ STL function std::iota, sequence offers no guarantee on order of execution.
See Also
http://www.sgi.com/tech/stl/iota.html
template<typename DerivedPolicy , typename ForwardIterator , typename UnaryOperation >
__host__ __device__ void thrust::tabulate ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
ForwardIterator  first,
ForwardIterator  last,
UnaryOperation  unary_op 
)

tabulate fills the range [first, last) with the value of a function applied to each element's index.

For each iterator i in the range [first, last), tabulate performs the assignment *i = unary_op(i - first).

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

Parameters
execThe execution policy to use for parallelization.
firstThe beginning of the range.
lastThe end of the range.
unary_opThe unary operation to apply.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
ForwardIteratoris a model of Forward Iterator, and ForwardIterator is mutable, and if x and y are objects of ForwardIterator's value_type, then x + y is defined, and if T is ForwardIterator's value_type, then T(0) is defined.
UnaryOperationis a model of Unary Function and UnaryFunction's result_type is convertible to OutputIterator's value_type.

The following code snippet demonstrates how to use tabulate to generate the first n non-positive integers using the thrust::host execution policy for parallelization:

...
const int N = 10;
int A[N];
// A is now {0, -1, -2, -3, -4, -5, -6, -7, -8, -9}
See Also
thrust::fill
thrust::generate
thrust::sequence
template<typename ForwardIterator , typename UnaryOperation >
void thrust::tabulate ( ForwardIterator  first,
ForwardIterator  last,
UnaryOperation  unary_op 
)

tabulate fills the range [first, last) with the value of a function applied to each element's index.

For each iterator i in the range [first, last), tabulate performs the assignment *i = unary_op(i - first).

Parameters
firstThe beginning of the range.
lastThe end of the range.
unary_opThe unary operation to apply.
Template Parameters
ForwardIteratoris a model of Forward Iterator, and ForwardIterator is mutable, and if x and y are objects of ForwardIterator's value_type, then x + y is defined, and if T is ForwardIterator's value_type, then T(0) is defined.
UnaryOperationis a model of Unary Function and UnaryFunction's result_type is convertible to OutputIterator's value_type.

The following code snippet demonstrates how to use tabulate to generate the first n non-positive integers:

...
const int N = 10;
int A[N];
// A is now {0, -1, -2, -3, -4, -5, -6, -7, -8, -9}
See Also
thrust::fill
thrust::generate
thrust::sequence
template<typename DerivedPolicy , typename InputIterator , typename OutputIterator , typename UnaryFunction >
__host__ __device__ OutputIterator thrust::transform ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
InputIterator  first,
InputIterator  last,
OutputIterator  result,
UnaryFunction  op 
)

This version of transform applies a unary function to each element of an input sequence and stores the result in the corresponding position in an output sequence. Specifically, for each iterator i in the range [first, last) the operation op(*i) is performed and the result is assigned to *o, where o is the corresponding output iterator in the range [result, result + (last - first) ). The input and output sequences may coincide, resulting in an in-place transformation.

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

Parameters
execThe execution policy to use for parallelization.
firstThe beginning of the input sequence.
lastThe end of the input sequence.
resultThe beginning of the output sequence.
opThe tranformation operation.
Returns
The end of the output sequence.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
InputIteratoris a model of Input Iterator and InputIterator's value_type is convertible to UnaryFunction's argument_type.
OutputIteratoris a model of Output Iterator.
UnaryFunctionis a model of Unary Function and UnaryFunction's result_type is convertible to OutputIterator's value_type.
Precondition
first may equal result, but the range [first, last) shall not overlap the range [result, result + (last - first)) otherwise.

The following code snippet demonstrates how to use transform to negate a range in-place using the thrust::host execution policy for parallelization:

...
int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8};
thrust::transform(thrust::host, data, data + 10, data, op); // in-place transformation
// data is now {5, 0, -2, 3, -2, -4, 0, 1, -2, -8};
See Also
http://www.sgi.com/tech/stl/transform.html
template<typename InputIterator , typename OutputIterator , typename UnaryFunction >
OutputIterator thrust::transform ( InputIterator  first,
InputIterator  last,
OutputIterator  result,
UnaryFunction  op 
)

This version of transform applies a unary function to each element of an input sequence and stores the result in the corresponding position in an output sequence. Specifically, for each iterator i in the range [first, last) the operation op(*i) is performed and the result is assigned to *o, where o is the corresponding output iterator in the range [result, result + (last - first) ). The input and output sequences may coincide, resulting in an in-place transformation.

Parameters
firstThe beginning of the input sequence.
lastThe end of the input sequence.
resultThe beginning of the output sequence.
opThe tranformation operation.
Returns
The end of the output sequence.
Template Parameters
InputIteratoris a model of Input Iterator and InputIterator's value_type is convertible to UnaryFunction's argument_type.
OutputIteratoris a model of Output Iterator.
UnaryFunctionis a model of Unary Function and UnaryFunction's result_type is convertible to OutputIterator's value_type.
Precondition
first may equal result, but the range [first, last) shall not overlap the range [result, result + (last - first)) otherwise.

The following code snippet demonstrates how to use transform

int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8};
thrust::transform(data, data + 10, data, op); // in-place transformation
// data is now {5, 0, -2, 3, -2, -4, 0, 1, -2, -8};
See Also
http://www.sgi.com/tech/stl/transform.html
template<typename DerivedPolicy , typename InputIterator1 , typename InputIterator2 , typename OutputIterator , typename BinaryFunction >
__host__ __device__ OutputIterator thrust::transform ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
InputIterator1  first1,
InputIterator1  last1,
InputIterator2  first2,
OutputIterator  result,
BinaryFunction  op 
)

This version of transform applies a binary function to each pair of elements from two input sequences and stores the result in the corresponding position in an output sequence. Specifically, for each iterator i in the range [first1, last1) and j = first + (i - first1) in the range [first2, last2) the operation op(*i,*j) is performed and the result is assigned to *o, where o is the corresponding output iterator in the range [result, result + (last - first) ). The input and output sequences may coincide, resulting in an in-place transformation.

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

Parameters
execThe execution policy to use for parallelization.
first1The beginning of the first input sequence.
last1The end of the first input sequence.
first2The beginning of the second input sequence.
resultThe beginning of the output sequence.
opThe tranformation operation.
Returns
The end of the output sequence.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
InputIterator1is a model of Input Iterator and InputIterator1's value_type is convertible to BinaryFunction's first_argument_type.
InputIterator2is a model of Input Iterator and InputIterator2's value_type is convertible to BinaryFunction's second_argument_type.
OutputIteratoris a model of Output Iterator.
BinaryFunctionis a model of Binary Function and BinaryFunction's result_type is convertible to OutputIterator's value_type.
Precondition
first1 may equal result, but the range [first1, last1) shall not overlap the range [result, result + (last1 - first1)) otherwise.
first2 may equal result, but the range [first2, first2 + (last1 - first1)) shall not overlap the range [result, result + (last1 - first1)) otherwise.

The following code snippet demonstrates how to use transform to compute the sum of two ranges using the thrust::host execution policy for parallelization:

...
int input1[6] = {-5, 0, 2, 3, 2, 4};
int input2[6] = { 3, 6, -2, 1, 2, 3};
int output[6];
thrust::transform(thrust::host, input1, input1 + 6, input2, output, op);
// output is now {-2, 6, 0, 4, 4, 7};
See Also
http://www.sgi.com/tech/stl/transform.html
template<typename InputIterator1 , typename InputIterator2 , typename OutputIterator , typename BinaryFunction >
OutputIterator thrust::transform ( InputIterator1  first1,
InputIterator1  last1,
InputIterator2  first2,
OutputIterator  result,
BinaryFunction  op 
)

This version of transform applies a binary function to each pair of elements from two input sequences and stores the result in the corresponding position in an output sequence. Specifically, for each iterator i in the range [first1, last1) and j = first + (i - first1) in the range [first2, last2) the operation op(*i,*j) is performed and the result is assigned to *o, where o is the corresponding output iterator in the range [result, result + (last - first) ). The input and output sequences may coincide, resulting in an in-place transformation.

Parameters
first1The beginning of the first input sequence.
last1The end of the first input sequence.
first2The beginning of the second input sequence.
resultThe beginning of the output sequence.
opThe tranformation operation.
Returns
The end of the output sequence.
Template Parameters
InputIterator1is a model of Input Iterator and InputIterator1's value_type is convertible to BinaryFunction's first_argument_type.
InputIterator2is a model of Input Iterator and InputIterator2's value_type is convertible to BinaryFunction's second_argument_type.
OutputIteratoris a model of Output Iterator.
BinaryFunctionis a model of Binary Function and BinaryFunction's result_type is convertible to OutputIterator's value_type.
Precondition
first1 may equal result, but the range [first1, last1) shall not overlap the range [result, result + (last1 - first1)) otherwise.
first2 may equal result, but the range [first2, first2 + (last1 - first1)) shall not overlap the range [result, result + (last1 - first1)) otherwise.

The following code snippet demonstrates how to use transform

int input1[6] = {-5, 0, 2, 3, 2, 4};
int input2[6] = { 3, 6, -2, 1, 2, 3};
int output[6];
thrust::transform(input1, input1 + 6, input2, output, op);
// output is now {-2, 6, 0, 4, 4, 7};
See Also
http://www.sgi.com/tech/stl/transform.html
template<typename DerivedPolicy , typename InputIterator , typename ForwardIterator , typename UnaryFunction , typename Predicate >
__host__ __device__ ForwardIterator thrust::transform_if ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
InputIterator  first,
InputIterator  last,
ForwardIterator  result,
UnaryFunction  op,
Predicate  pred 
)

This version of transform_if conditionally applies a unary function to each element of an input sequence and stores the result in the corresponding position in an output sequence if the corresponding position in the input sequence satifies a predicate. Otherwise, the corresponding position in the output sequence is not modified.

Specifically, for each iterator i in the range [first, last) the predicate pred(*i) is evaluated. If this predicate evaluates to true, the result of op(*i) is assigned to *o, where o is the corresponding output iterator in the range [result, result + (last - first) ). Otherwise, op(*i) is not evaluated and no assignment occurs. The input and output sequences may coincide, resulting in an in-place transformation.

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

Parameters
execThe execution policy to use for parallelization.
firstThe beginning of the input sequence.
lastThe end of the input sequence.
resultThe beginning of the output sequence.
opThe tranformation operation.
predThe predicate operation.
Returns
The end of the output sequence.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
InputIteratoris a model of Input Iterator, and InputIterator's value_type is convertible to Predicate's argument_type, and InputIterator's value_type is convertible to UnaryFunction's argument_type.
ForwardIteratoris a model of Forward Iterator.
UnaryFunctionis a model of Unary Function and UnaryFunction's result_type is convertible to OutputIterator's value_type.
Predicateis a model of Predicate.
Precondition
first may equal result, but the range [first, last) shall not overlap the range [result, result + (last - first)) otherwise.

The following code snippet demonstrates how to use transform_if to negate the odd-valued elements of a range using the thrust::host execution policy for parallelization:

...
int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8};
struct is_odd
{
__host__ __device__
bool operator()(int x)
{
return x % 2;
}
};
// negate odd elements
thrust::transform_if(thrust::host, data, data + 10, data, op, is_odd()); // in-place transformation
// data is now {5, 0, 2, 3, 2, 4, 0, 1, 2, 8};
See Also
thrust::transform
template<typename InputIterator , typename ForwardIterator , typename UnaryFunction , typename Predicate >
ForwardIterator thrust::transform_if ( InputIterator  first,
InputIterator  last,
ForwardIterator  result,
UnaryFunction  op,
Predicate  pred 
)

This version of transform_if conditionally applies a unary function to each element of an input sequence and stores the result in the corresponding position in an output sequence if the corresponding position in the input sequence satifies a predicate. Otherwise, the corresponding position in the output sequence is not modified.

Specifically, for each iterator i in the range [first, last) the predicate pred(*i) is evaluated. If this predicate evaluates to true, the result of op(*i) is assigned to *o, where o is the corresponding output iterator in the range [result, result + (last - first) ). Otherwise, op(*i) is not evaluated and no assignment occurs. The input and output sequences may coincide, resulting in an in-place transformation.

Parameters
firstThe beginning of the input sequence.
lastThe end of the input sequence.
resultThe beginning of the output sequence.
opThe tranformation operation.
predThe predicate operation.
Returns
The end of the output sequence.
Template Parameters
InputIteratoris a model of Input Iterator, and InputIterator's value_type is convertible to Predicate's argument_type, and InputIterator's value_type is convertible to UnaryFunction's argument_type.
ForwardIteratoris a model of Forward Iterator.
UnaryFunctionis a model of Unary Function and UnaryFunction's result_type is convertible to OutputIterator's value_type.
Predicateis a model of Predicate.
Precondition
first may equal result, but the range [first, last) shall not overlap the range [result, result + (last - first)) otherwise.

The following code snippet demonstrates how to use transform_if:

int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8};
struct is_odd
{
__host__ __device__
bool operator()(int x)
{
return x % 2;
}
};
// negate odd elements
thrust::transform_if(data, data + 10, data, op, is_odd()); // in-place transformation
// data is now {5, 0, 2, 3, 2, 4, 0, 1, 2, 8};
See Also
thrust::transform
template<typename DerivedPolicy , typename InputIterator1 , typename InputIterator2 , typename ForwardIterator , typename UnaryFunction , typename Predicate >
__host__ __device__ ForwardIterator thrust::transform_if ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
InputIterator1  first,
InputIterator1  last,
InputIterator2  stencil,
ForwardIterator  result,
UnaryFunction  op,
Predicate  pred 
)

This version of transform_if conditionally applies a unary function to each element of an input sequence and stores the result in the corresponding position in an output sequence if the corresponding position in a stencil sequence satisfies a predicate. Otherwise, the corresponding position in the output sequence is not modified.

Specifically, for each iterator i in the range [first, last) the predicate pred(*s) is evaluated, where s is the corresponding input iterator in the range [stencil, stencil + (last - first) ). If this predicate evaluates to true, the result of op(*i) is assigned to *o, where o is the corresponding output iterator in the range [result, result + (last - first) ). Otherwise, op(*i) is not evaluated and no assignment occurs. The input and output sequences may coincide, resulting in an in-place transformation.

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

Parameters
execThe execution policy to use for parallelization.
firstThe beginning of the input sequence.
lastThe end of the input sequence.
stencilThe beginning of the stencil sequence.
resultThe beginning of the output sequence.
opThe tranformation operation.
predThe predicate operation.
Returns
The end of the output sequence.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
InputIterator1is a model of Input Iterator and InputIterator1's value_type is convertible to UnaryFunction's argument_type.
InputIterator2is a model of Input Iterator and InputIterator2's value_type is convertible to Predicate's argument_type.
ForwardIteratoris a model of Forward Iterator.
UnaryFunctionis a model of Unary Function and UnaryFunction's result_type is convertible to OutputIterator's value_type.
Predicateis a model of Predicate.
Precondition
first may equal result, but the range [first, last) shall not overlap the range [result, result + (last - first)) otherwise.
stencil may equal result, but the range [stencil, stencil + (last - first)) shall not overlap the range [result, result + (last - first)) otherwise.

The following code snippet demonstrates how to use transform_if using the thrust::host execution policy for parallelization:

...
int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8};
int stencil[10] = { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0};
thrust::transform_if(thrust::host, data, data + 10, stencil, data, op, identity); // in-place transformation
// data is now {5, 0, -2, -3, -2, 4, 0, -1, -2, 8};
See Also
thrust::transform
template<typename InputIterator1 , typename InputIterator2 , typename ForwardIterator , typename UnaryFunction , typename Predicate >
ForwardIterator thrust::transform_if ( InputIterator1  first,
InputIterator1  last,
InputIterator2  stencil,
ForwardIterator  result,
UnaryFunction  op,
Predicate  pred 
)

This version of transform_if conditionally applies a unary function to each element of an input sequence and stores the result in the corresponding position in an output sequence if the corresponding position in a stencil sequence satisfies a predicate. Otherwise, the corresponding position in the output sequence is not modified.

Specifically, for each iterator i in the range [first, last) the predicate pred(*s) is evaluated, where s is the corresponding input iterator in the range [stencil, stencil + (last - first) ). If this predicate evaluates to true, the result of op(*i) is assigned to *o, where o is the corresponding output iterator in the range [result, result + (last - first) ). Otherwise, op(*i) is not evaluated and no assignment occurs. The input and output sequences may coincide, resulting in an in-place transformation.

Parameters
firstThe beginning of the input sequence.
lastThe end of the input sequence.
stencilThe beginning of the stencil sequence.
resultThe beginning of the output sequence.
opThe tranformation operation.
predThe predicate operation.
Returns
The end of the output sequence.
Template Parameters
InputIterator1is a model of Input Iterator and InputIterator1's value_type is convertible to UnaryFunction's argument_type.
InputIterator2is a model of Input Iterator and InputIterator2's value_type is convertible to Predicate's argument_type.
ForwardIteratoris a model of Forward Iterator.
UnaryFunctionis a model of Unary Function and UnaryFunction's result_type is convertible to OutputIterator's value_type.
Predicateis a model of Predicate.
Precondition
first may equal result, but the range [first, last) shall not overlap the range [result, result + (last - first)) otherwise.
stencil may equal result, but the range [stencil, stencil + (last - first)) shall not overlap the range [result, result + (last - first)) otherwise.

The following code snippet demonstrates how to use transform_if:

int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8};
int stencil[10] = { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0};
thrust::transform_if(data, data + 10, stencil, data, op, identity); // in-place transformation
// data is now {5, 0, -2, -3, -2, 4, 0, -1, -2, 8};
See Also
thrust::transform
template<typename DerivedPolicy , typename InputIterator1 , typename InputIterator2 , typename InputIterator3 , typename ForwardIterator , typename BinaryFunction , typename Predicate >
__host__ __device__ ForwardIterator thrust::transform_if ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
InputIterator1  first1,
InputIterator1  last1,
InputIterator2  first2,
InputIterator3  stencil,
ForwardIterator  result,
BinaryFunction  binary_op,
Predicate  pred 
)

This version of transform_if conditionally applies a binary function to each pair of elements from two input sequences and stores the result in the corresponding position in an output sequence if the corresponding position in a stencil sequence satifies a predicate. Otherwise, the corresponding position in the output sequence is not modified.

Specifically, for each iterator i in the range [first1, last1) and j = first2 + (i - first1) in the range [first2, first2 + (last1 - first1) ), the predicate pred(*s) is evaluated, where s is the corresponding input iterator in the range [stencil, stencil + (last1 - first1) ). If this predicate evaluates to true, the result of binary_op(*i,*j) is assigned to *o, where o is the corresponding output iterator in the range [result, result + (last1 - first1) ). Otherwise, binary_op(*i,*j) is not evaluated and no assignment occurs. The input and output sequences may coincide, resulting in an in-place transformation.

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

Parameters
execThe execution policy to use for parallelization.
first1The beginning of the first input sequence.
last1The end of the first input sequence.
first2The beginning of the second input sequence.
stencilThe beginning of the stencil sequence.
resultThe beginning of the output sequence.
binary_opThe transformation operation.
predThe predicate operation.
Returns
The end of the output sequence.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
InputIterator1is a model of Input Iterator and InputIterator1's value_type is convertible to BinaryFunction's first_argument_type.
InputIterator2is a model of Input Iterator and InputIterator2's value_type is convertible to BinaryFunction's second_argument_type.
ForwardIteratoris a model of Forward Iterator.
BinaryFunctionis a model of Binary Function and BinaryFunction's result_type is convertible to OutputIterator's value_type.
Predicateis a model of Predicate.
Precondition
first1 may equal result, but the range [first1, last1) shall not overlap the range [result, result + (last1 - first1)) otherwise.
first2 may equal result, but the range [first2, first2 + (last1 - first1)) shall not overlap the range [result, result + (last1 - first1)) otherwise.
stencil may equal result, but the range [stencil, stencil + (last1 - first1)) shall not overlap the range [result, result + (last1 - first1)) otherwise.

The following code snippet demonstrates how to use transform_if using the thrust::host execution policy for parallelization:

...
int input1[6] = {-5, 0, 2, 3, 2, 4};
int input2[6] = { 3, 6, -2, 1, 2, 3};
int stencil[8] = { 1, 0, 1, 0, 1, 0};
int output[6];
thrust::transform_if(thrust::host, input1, input1 + 6, input2, stencil, output, op, identity);
// output is now {-2, 0, 0, 3, 4, 4};
See Also
thrust::transform
template<typename InputIterator1 , typename InputIterator2 , typename InputIterator3 , typename ForwardIterator , typename BinaryFunction , typename Predicate >
ForwardIterator thrust::transform_if ( InputIterator1  first1,
InputIterator1  last1,
InputIterator2  first2,
InputIterator3  stencil,
ForwardIterator  result,
BinaryFunction  binary_op,
Predicate  pred 
)

This version of transform_if conditionally applies a binary function to each pair of elements from two input sequences and stores the result in the corresponding position in an output sequence if the corresponding position in a stencil sequence satifies a predicate. Otherwise, the corresponding position in the output sequence is not modified.

Specifically, for each iterator i in the range [first1, last1) and j = first2 + (i - first1) in the range [first2, first2 + (last1 - first1) ), the predicate pred(*s) is evaluated, where s is the corresponding input iterator in the range [stencil, stencil + (last1 - first1) ). If this predicate evaluates to true, the result of binary_op(*i,*j) is assigned to *o, where o is the corresponding output iterator in the range [result, result + (last1 - first1) ). Otherwise, binary_op(*i,*j) is not evaluated and no assignment occurs. The input and output sequences may coincide, resulting in an in-place transformation.

Parameters
first1The beginning of the first input sequence.
last1The end of the first input sequence.
first2The beginning of the second input sequence.
stencilThe beginning of the stencil sequence.
resultThe beginning of the output sequence.
binary_opThe transformation operation.
predThe predicate operation.
Returns
The end of the output sequence.
Template Parameters
InputIterator1is a model of Input Iterator and InputIterator1's value_type is convertible to BinaryFunction's first_argument_type.
InputIterator2is a model of Input Iterator and InputIterator2's value_type is convertible to BinaryFunction's second_argument_type.
ForwardIteratoris a model of Forward Iterator.
BinaryFunctionis a model of Binary Function and BinaryFunction's result_type is convertible to OutputIterator's value_type.
Predicateis a model of Predicate.
Precondition
first1 may equal result, but the range [first1, last1) shall not overlap the range [result, result + (last1 - first1)) otherwise.
first2 may equal result, but the range [first2, first2 + (last1 - first1)) shall not overlap the range [result, result + (last1 - first1)) otherwise.
stencil may equal result, but the range [stencil, stencil + (last1 - first1)) shall not overlap the range [result, result + (last1 - first1)) otherwise.

The following code snippet demonstrates how to use transform_if:

int input1[6] = {-5, 0, 2, 3, 2, 4};
int input2[6] = { 3, 6, -2, 1, 2, 3};
int stencil[8] = { 1, 0, 1, 0, 1, 0};
int output[6];
thrust::transform_if(input1, input1 + 6, input2, stencil, output, op, identity);
// output is now {-2, 0, 0, 3, 4, 4};
See Also
thrust::transform