thrust::inner_product#
Overloads#
inner_product(exec, first1, last1, first2, init)#
-
template<typename DerivedPolicy, typename InputIterator1, typename InputIterator2, typename OutputType>
OutputType thrust::inner_product( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- InputIterator1 first1,
- InputIterator1 last1,
- InputIterator2 first2,
- OutputType init
inner_productcalculates an inner product of the ranges[first1, last1)and[first2, first2 + (last1 - first1)).Specifically, this version of
inner_productcomputes the suminit + (*first1 * *first2) + (*(first1+1) * *(first2+1)) + ...The algorithm’s execution is parallelized as determined by
exec.The following code demonstrates how to use
inner_productto compute the dot product of two vectors using thethrust::hostexecution policy for parallelization.#include <thrust/inner_product.h> #include <thrust/execution_policy.h> ... float vec1[3] = {1.0f, 2.0f, 5.0f}; float vec2[3] = {4.0f, 1.0f, 5.0f}; float result = thrust::inner_product(thrust::host, vec1, vec1 + 3, vec2, 0.0f); // result == 31.0f
- Parameters:
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.
- Template Parameters:
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
xis an object of typeOutputType, andyis an object ofInputIterator1'svalue_type, andzis an object ofInputIterator2'svalue_type, thenx + y * zis defined and is convertible toOutputType.
- Returns:
The inner product of sequences
[first1, last1)and[first2, last2)plusinit.
inner_product(first1, last1, first2, init)#
-
template<typename InputIterator1, typename InputIterator2, typename OutputType>
OutputType thrust::inner_product( - InputIterator1 first1,
- InputIterator1 last1,
- InputIterator2 first2,
- OutputType init
inner_productcalculates an inner product of the ranges[first1, last1)and[first2, first2 + (last1 - first1)).Specifically, this version of
inner_productcomputes the suminit + (*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.The following code demonstrates how to use
inner_productto compute the dot product of two vectors.#include <thrust/inner_product.h> ... float vec1[3] = {1.0f, 2.0f, 5.0f}; float vec2[3] = {4.0f, 1.0f, 5.0f}; float result = thrust::inner_product(vec1, vec1 + 3, vec2, 0.0f); // result == 31.0f
- Parameters:
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.
- Template Parameters:
InputIterator1 – is a model of Input Iterator,
InputIterator2 – is a model of Input Iterator,
OutputType – is a model of Assignable, and if
xis an object of typeOutputType, andyis an object ofInputIterator1'svalue_type, andzis an object ofInputIterator2'svalue_type, thenx + y * zis defined and is convertible toOutputType.
- Returns:
The inner product of sequences
[first1, last1)and[first2, last2)plusinit.
inner_product(exec, first1, last1, first2, init, binary_op1, binary_op2)#
-
template<typename DerivedPolicy, typename InputIterator1, typename InputIterator2, typename OutputType, typename BinaryFunction1, typename BinaryFunction2>
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_productcalculates an inner product of the ranges[first1, last1)and[first2, first2 + (last1 - first1)).This version of
inner_productis identical to the first, except that is uses two user-supplied function objects instead ofoperator+andoperator*.Specifically, this version of
inner_productcomputes the sumbinary_op1( init, binary_op2(*first1, *first2) ), ...The algorithm’s execution is parallelized as determined by
exec.#include <thrust/inner_product.h> #include <thrust/execution_policy.h> ... float vec1[3] = {1.0f, 2.0f, 5.0f}; float vec2[3] = {4.0f, 1.0f, 5.0f}; float init = 0.0f; ::cuda::std::plus<float> binary_op1; ::cuda::std::multiplies<float> binary_op2; float result = thrust::inner_product(thrust::host, vec1, vec1 + 3, vec2, init, binary_op1, binary_op2); // result == 31.0f
- Parameters:
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.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
InputIterator1 – is a model of Input Iterator, and
InputIterator1'svalue_typeis convertible toBinaryFunction2'sfirst argument type.InputIterator2 – is a model of Input Iterator. and
InputIterator2'svalue_typeis convertible toBinaryFunction2'ssecond argument type.OutputType – is a model of Assignable, and
OutputTypeis convertible toBinaryFunction1'sfirst argument type.BinaryFunction1 – The function’s return type must be convertible to
OutputType.BinaryFunction2 – The function’s return type must be convertible to
BinaryFunction1'ssecond argument type.
- Returns:
The inner product of sequences
[first1, last1)and[first2, last2).
inner_product(first1, last1, first2, init, binary_op1, 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
inner_productcalculates an inner product of the ranges[first1, last1)and[first2, first2 + (last1 - first1)).This version of
inner_productis identical to the first, except that is uses two user-supplied function objects instead ofoperator+andoperator*.Specifically, this version of
inner_productcomputes the sumbinary_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.#include <thrust/inner_product.h> ... float vec1[3] = {1.0f, 2.0f, 5.0f}; float vec2[3] = {4.0f, 1.0f, 5.0f}; float init = 0.0f; ::cuda::std::plus<float> binary_op1; ::cuda::std::multiplies<float> binary_op2; float result = thrust::inner_product(vec1, vec1 + 3, vec2, init, binary_op1, binary_op2); // result == 31.0f
- Parameters:
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.
- Template Parameters:
InputIterator1 – is a model of Input Iterator, and
InputIterator1'svalue_typeis convertible toBinaryFunction2'sfirst argument type.InputIterator2 – is a model of Input Iterator. and
InputIterator2'svalue_typeis convertible toBinaryFunction2'ssecond argument type.OutputType – is a model of Assignable, and
OutputTypeis convertible toBinaryFunction1'sfirst argument type.BinaryFunction1 – The function’s return type must be convertible to
OutputType.BinaryFunction2 – The function’s return type must be convertible to
BinaryFunction1'ssecond argument type.
- Returns:
The inner product of sequences
[first1, last1)and[first2, last2).