thrust

Functions  
template<typename DerivedPolicy , typename InputIterator1 , typename InputIterator2 , typename OutputType >  
__host__ __device__ OutputType  thrust::inner_product (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputType init) 
template<typename InputIterator1 , typename InputIterator2 , typename OutputType >  
OutputType  thrust::inner_product (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputType init) 
template<typename DerivedPolicy , typename InputIterator1 , typename InputIterator2 , typename OutputType , typename BinaryFunction1 , typename BinaryFunction2 >  
__host__ __device__ OutputType  thrust::inner_product (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputType init, BinaryFunction1 binary_op1, BinaryFunction2 binary_op2) 
template<typename InputIterator1 , typename InputIterator2 , typename OutputType , typename BinaryFunction1 , typename BinaryFunction2 >  
OutputType  thrust::inner_product (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputType init, BinaryFunction1 binary_op1, BinaryFunction2 binary_op2) 
template<typename DerivedPolicy , typename InputIterator , typename UnaryFunction , typename OutputType , typename BinaryFunction >  
__host__ __device__ OutputType  thrust::transform_reduce (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, InputIterator first, InputIterator last, UnaryFunction unary_op, OutputType init, BinaryFunction binary_op) 
template<typename InputIterator , typename UnaryFunction , typename OutputType , typename BinaryFunction >  
OutputType  thrust::transform_reduce (InputIterator first, InputIterator last, UnaryFunction unary_op, OutputType init, BinaryFunction binary_op) 
__host__ __device__ OutputType thrust::inner_product  (  const thrust::detail::execution_policy_base< DerivedPolicy > &  exec, 
InputIterator1  first1,  
InputIterator1  last1,  
InputIterator2  first2,  
OutputType  init  
) 
inner_product
calculates an inner product of the ranges [first1, last1)
and [first2, first2 + (last1  first1))
.
Specifically, this version of inner_product
computes the sum init + (*first1 * *first2) + (*(first1+1) * *(first2+1)) + ...
The algorithm's execution is parallelized as determined by exec
.
exec  The execution policy to use for parallelization. 
first1  The beginning of the first sequence. 
last1  The end of the first sequence. 
first2  The beginning of the second sequence. 
init  Initial value of the result. 
[first1, last1)
and [first2, last2)
plus init
.DerivedPolicy  The name of the derived execution policy. 
InputIterator1  is a model of Input Iterator, 
InputIterator2  is a model of Input Iterator, 
OutputType  is a model of Assignable, and if x is an object of type OutputType , and y is an object of InputIterator1's value_type , and z is an object of InputIterator2's value_type , then x + y * z is defined and is convertible to OutputType . 
The following code demonstrates how to use inner_product
to compute the dot product of two vectors using the thrust::host
execution policy for parallelization.
OutputType thrust::inner_product  (  InputIterator1  first1, 
InputIterator1  last1,  
InputIterator2  first2,  
OutputType  init  
) 
inner_product
calculates an inner product of the ranges [first1, last1)
and [first2, first2 + (last1  first1))
.
Specifically, this version of inner_product
computes the sum init + (*first1 * *first2) + (*(first1+1) * *(first2+1)) + ...
Unlike the C++ Standard Template Library function std::inner_product
, this version offers no guarantee on order of execution.
first1  The beginning of the first sequence. 
last1  The end of the first sequence. 
first2  The beginning of the second sequence. 
init  Initial value of the result. 
[first1, last1)
and [first2, last2)
plus init
.InputIterator1  is a model of Input Iterator, 
InputIterator2  is a model of Input Iterator, 
OutputType  is a model of Assignable, and if x is an object of type OutputType , and y is an object of InputIterator1's value_type , and z is an object of InputIterator2's value_type , then x + y * z is defined and is convertible to OutputType . 
The following code demonstrates how to use inner_product
to compute the dot product of two vectors.
__host__ __device__ OutputType thrust::inner_product  (  const thrust::detail::execution_policy_base< DerivedPolicy > &  exec, 
InputIterator1  first1,  
InputIterator1  last1,  
InputIterator2  first2,  
OutputType  init,  
BinaryFunction1  binary_op1,  
BinaryFunction2  binary_op2  
) 
inner_product
calculates an inner product of the ranges [first1, last1)
and [first2, first2 + (last1  first1))
.
This version of inner_product
is identical to the first, except that is uses two usersupplied function objects instead of operator+
and operator*
.
Specifically, this version of inner_product
computes the sum binary_op1( init, binary_op2(*first1, *first2) ), ...
The algorithm's execution is parallelized as determined by exec
.
exec  The execution policy to use for parallelization. 
first1  The beginning of the first sequence. 
last1  The end of the first sequence. 
first2  The beginning of the second sequence. 
init  Initial value of the result. 
binary_op1  Generalized addition operation. 
binary_op2  Generalized multiplication operation. 
[first1, last1)
and [first2, last2)
.DerivedPolicy  The name of the derived execution policy. 
InputIterator1  is a model of Input Iterator, and InputIterator1's value_type is convertible to BinaryFunction2's first_argument_type . 
InputIterator2  is a model of Input Iterator. and InputIterator2's value_type is convertible to BinaryFunction2's second_argument_type . 
OutputType  is a model of Assignable, and OutputType is convertible to BinaryFunction1's first_argument_type . 
BinaryFunction1  is a model of Binary Function, and BinaryFunction1's return_type is convertible to OutputType . 
BinaryFunction2  is a model of Binary Function, and BinaryFunction2's return_type is convertible to BinaryFunction1's second_argument_type . 
OutputType thrust::inner_product  (  InputIterator1  first1, 
InputIterator1  last1,  
InputIterator2  first2,  
OutputType  init,  
BinaryFunction1  binary_op1,  
BinaryFunction2  binary_op2  
) 
inner_product
calculates an inner product of the ranges [first1, last1)
and [first2, first2 + (last1  first1))
.
This version of inner_product
is identical to the first, except that is uses two usersupplied function objects instead of operator+
and operator*
.
Specifically, this version of inner_product
computes the sum binary_op1( init, binary_op2(*first1, *first2) ), ...
Unlike the C++ Standard Template Library function std::inner_product
, this version offers no guarantee on order of execution.
first1  The beginning of the first sequence. 
last1  The end of the first sequence. 
first2  The beginning of the second sequence. 
init  Initial value of the result. 
binary_op1  Generalized addition operation. 
binary_op2  Generalized multiplication operation. 
[first1, last1)
and [first2, last2)
.InputIterator1  is a model of Input Iterator, and InputIterator1's value_type is convertible to BinaryFunction2's first_argument_type . 
InputIterator2  is a model of Input Iterator. and InputIterator2's value_type is convertible to BinaryFunction2's second_argument_type . 
OutputType  is a model of Assignable, and OutputType is convertible to BinaryFunction1's first_argument_type . 
BinaryFunction1  is a model of Binary Function, and BinaryFunction1's return_type is convertible to OutputType . 
BinaryFunction2  is a model of Binary Function, and BinaryFunction2's return_type is convertible to BinaryFunction1's second_argument_type . 
__host__ __device__ OutputType thrust::transform_reduce  (  const thrust::detail::execution_policy_base< DerivedPolicy > &  exec, 
InputIterator  first,  
InputIterator  last,  
UnaryFunction  unary_op,  
OutputType  init,  
BinaryFunction  binary_op  
) 
transform_reduce
fuses the transform
and reduce
operations. transform_reduce
is equivalent to performing a transformation defined by unary_op
into a temporary sequence and then performing reduce
on the transformed sequence. In most cases, fusing these two operations together is more efficient, since fewer memory reads and writes are required.
transform_reduce
performs a reduction on the transformation of the sequence [first, last)
according to unary_op
. Specifically, unary_op
is applied to each element of the sequence and then the result is reduced to a single value with binary_op
using the initial value init
. Note that the transformation unary_op
is not applied to the initial value init
. The order of reduction is not specified, so binary_op
must be both commutative and associative.
The algorithm's execution is parallelized as determined by exec
.
exec  The execution policy to use for parallelization. 
first  The beginning of the sequence. 
last  The end of the sequence. 
unary_op  The function to apply to each element of the input sequence. 
init  The result is initialized to this value. 
binary_op  The reduction operation. 
DerivedPolicy  The name of the derived execution policy. 
InputIterator  is a model of Input Iterator, and InputIterator's value_type is convertible to UnaryFunction's argument_type . 
UnaryFunction  is a model of Unary Function, and UnaryFunction's result_type is convertible to OutputType . 
OutputType  is a model of Assignable, and is convertible to BinaryFunction's first_argument_type and second_argument_type . 
BinaryFunction  is a model of Binary Function, and BinaryFunction's result_type is convertible to OutputType . 
The following code snippet demonstrates how to use transform_reduce
to compute the maximum value of the absolute value of the elements of a range using the thrust::host
execution policy for parallelization:
OutputType thrust::transform_reduce  (  InputIterator  first, 
InputIterator  last,  
UnaryFunction  unary_op,  
OutputType  init,  
BinaryFunction  binary_op  
) 
transform_reduce
fuses the transform
and reduce
operations. transform_reduce
is equivalent to performing a transformation defined by unary_op
into a temporary sequence and then performing reduce
on the transformed sequence. In most cases, fusing these two operations together is more efficient, since fewer memory reads and writes are required.
transform_reduce
performs a reduction on the transformation of the sequence [first, last)
according to unary_op
. Specifically, unary_op
is applied to each element of the sequence and then the result is reduced to a single value with binary_op
using the initial value init
. Note that the transformation unary_op
is not applied to the initial value init
. The order of reduction is not specified, so binary_op
must be both commutative and associative.
first  The beginning of the sequence. 
last  The end of the sequence. 
unary_op  The function to apply to each element of the input sequence. 
init  The result is initialized to this value. 
binary_op  The reduction operation. 
InputIterator  is a model of Input Iterator, and InputIterator's value_type is convertible to UnaryFunction's argument_type . 
UnaryFunction  is a model of Unary Function, and UnaryFunction's result_type is convertible to OutputType . 
OutputType  is a model of Assignable, and is convertible to BinaryFunction's first_argument_type and second_argument_type . 
BinaryFunction  is a model of Binary Function, and BinaryFunction's result_type is convertible to OutputType . 
The following code snippet demonstrates how to use transform_reduce
to compute the maximum value of the absolute value of the elements of a range.