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

Functions

template<typename InputIterator , typename OutputType >
OutputType bolt::cl::inner_product (bolt::cl::control &ctl, InputIterator first1, InputIterator last1, InputIterator first2, OutputType init, const std::string &cl_code="")
 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::cl::inner_product (InputIterator first1, InputIterator last1, InputIterator first2, OutputType init, const std::string &cl_code="")
 
template<typename InputIterator , typename OutputType , typename BinaryFunction1 , typename BinaryFunction2 >
OutputType bolt::cl::inner_product (bolt::cl::control &ctl, InputIterator first1, InputIterator last1, InputIterator first2, OutputType init, BinaryFunction1 f1, BinaryFunction2 f2, const std::string &cl_code="")
 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::cl::inner_product (InputIterator first1, InputIterator last1, InputIterator first2, OutputType init, BinaryFunction1 f1, BinaryFunction2 f2, const std::string &cl_code="")
 

Detailed Description

Function Documentation

template<typename InputIterator , typename OutputType >
OutputType bolt::cl::inner_product ( bolt::cl::control ctl,
InputIterator  first1,
InputIterator  last1,
InputIterator  first2,
OutputType  init,
const std::string &  cl_code = "" 
)

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 command-queue, debug, tuning. See bolt::cl::control.
first1The beginning of input sequence.
last1The end of input sequence.
first2The beginning of the second input sequence.
initThe initial value for the accumulator.
cl_codeOptional OpenCL(TM) code to be passed to the OpenCL compiler. The cl_code is inserted first in the generated code, before the cl_code trait.
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::cl::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::cl::inner_product ( bolt::cl::control ctl,
InputIterator  first1,
InputIterator  last1,
InputIterator  first2,
OutputType  init,
BinaryFunction1  f1,
BinaryFunction2  f2,
const std::string &  cl_code = "" 
)

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
ctlOptional Control structure to control command-queue, debug, tuning. See FIXME.
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.
cl_codeOptional OpenCL(TM) code to be passed to the OpenCL compiler. The cl_code is inserted first in the generated code, before the cl_code trait.
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/cl/functional.h> //for bolt::cl::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};
int ip = bolt::cl::inner_product(a, a+10, b, 0, bolt::cl::plus<int>(),bolt::cl::multiplies<int>());
// sum = 76
See Also
http://www.sgi.com/tech/stl/inner_product.html