thrust

◆ inner_product() [3/4]

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 
)

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 user-supplied 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.

Parameters
execThe execution policy to use for parallelization.
first1The beginning of the first sequence.
last1The end of the first sequence.
first2The beginning of the second sequence.
initInitial value of the result.
binary_op1Generalized addition operation.
binary_op2Generalized multiplication operation.
Returns
The inner product of sequences [first1, last1) and [first2, last2).
Template Parameters
DerivedPolicyThe name of the derived execution policy.
InputIterator1is a model of Input Iterator, and InputIterator1's value_type is convertible to BinaryFunction2's first_argument_type.
InputIterator2is a model of Input Iterator. and InputIterator2's value_type is convertible to BinaryFunction2's second_argument_type.
OutputTypeis a model of Assignable, and OutputType is convertible to BinaryFunction1's first_argument_type.
BinaryFunction1is a model of Binary Function, and BinaryFunction1's return_type is convertible to OutputType.
BinaryFunction2is a model of Binary Function, and BinaryFunction2's return_type is convertible to BinaryFunction1's second_argument_type.
...
float vec1[3] = {1.0f, 2.0f, 5.0f};
float vec2[3] = {4.0f, 1.0f, 5.0f};
float init = 0.0f;
float result = thrust::inner_product(thrust::host, vec1, vec1 + 3, vec2, init, binary_op1, binary_op2);
// result == 31.0f
See also
http://www.sgi.com/tech/stl/inner_product.html