Bolt  1.3
C++ template library with support for OpenCL
Functions
AMP-inner_product

Functions

template<typename InputIterator , typename OutputType >
OutputType bolt::amp::inner_product (bolt::amp::control &ctl, InputIterator first1, InputIterator last1, InputIterator first2, OutputType init)
 Inner Product returns the inner product of two iterators. This is similar to calculating binary transform and then reducing the result. The inner_product operation is similar the std::inner_product function. This function can take optional control structure to control command-queue.
 
template<typename InputIterator , typename OutputType >
OutputType bolt::amp::inner_product (InputIterator first1, InputIterator last1, InputIterator first2, OutputType init)
 
template<typename InputIterator , typename OutputType , typename BinaryFunction1 , typename BinaryFunction2 >
OutputType bolt::amp::inner_product (bolt::amp::control &ctl, InputIterator first1, InputIterator last1, InputIterator first2, OutputType init, BinaryFunction1 f1, BinaryFunction2 f2)
 Inner Product returns the inner product of two iterators using user specified binary functors f1 and f2. This is similar to calculating transform and then reducing the result. The functor f1 should be commutative. This function can take optional control structure to control command-queue. The inner_product operation is similar the std::inner_product function.
 
template<typename InputIterator , typename OutputType , typename BinaryFunction1 , typename BinaryFunction2 >
OutputType bolt::amp::inner_product (InputIterator first1, InputIterator last1, InputIterator first2, OutputType init, BinaryFunction1 f1, BinaryFunction2 f2)
 

Detailed Description

Function Documentation

template<typename InputIterator , typename OutputType >
OutputType bolt::amp::inner_product ( bolt::amp::control ctl,
InputIterator  first1,
InputIterator  last1,
InputIterator  first2,
OutputType  init 
)

Inner Product returns the inner product of two iterators. This is similar to calculating binary transform and then reducing the result. The inner_product operation is similar the std::inner_product function. This function can take optional control structure to control command-queue.

Parameters
ctlOptional Control structure to control accelerator, debug, tuning, etc.See bolt::amp::control.
first1The beginning of input sequence.
last1The end of input sequence.
first2The beginning of the second input sequence.
initThe initial value for the accumulator.
Template Parameters
InputIteratorAn iterator that can be dereferenced for an object, and can be incremented to get to the next element in a sequence.
OutputTypeThe type of the result.
Returns
The result of the inner product.

The following code example shows the use of inner_product to perform dot product on two vectors of size 10 , using the default multiplies and plus operator.

int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int b[10] = {1, 1, 2, 3, 5, 8, 13, 21, 34, 55};
int ip = bolt::amp::inner_product(a, a+10, b,0);
// sum = 1209
See Also
http://www.sgi.com/tech/stl/inner_product.html
template<typename InputIterator , typename OutputType , typename BinaryFunction1 , typename BinaryFunction2 >
OutputType bolt::amp::inner_product ( bolt::amp::control ctl,
InputIterator  first1,
InputIterator  last1,
InputIterator  first2,
OutputType  init,
BinaryFunction1  f1,
BinaryFunction2  f2 
)

Inner Product returns the inner product of two iterators using user specified binary functors f1 and f2. This is similar to calculating transform and then reducing the result. The functor f1 should be commutative. This function can take optional control structure to control command-queue. The inner_product operation is similar the std::inner_product function.

Parameters
ctlControl structure to control accelerator, debug, tuning, etc.See bolt::amp::control.
first1The first position in the input sequence.
last1The last position in the input sequence.
first2The beginning of second input sequence.
initThe initial value for the accumulator.
f1Binary functor for reduction.
f2Binary functor for transformation.
Template Parameters
InputIteratorAn iterator that can be dereferenced for an object, and can be incremented to get to the next element in a sequence.
OutputTypeThe type of the result.
Returns
The result of the inner product.

The following code example shows the use of inner_product on two vectors of size 10, using the user defined functors.

#include <bolt/amp/functional.h> //for bolt::amp::plus
int a[10] = {-5, 0, 2, 3, 2, 4, -2, 1, 2, 3};
int b[10] = {-5, 0, 2, 3, 2, 4, -2, 1, 2, 3};
// sum = 76
See Also
http://www.sgi.com/tech/stl/inner_product.html