tfel
Loading...
Searching...
No Matches
tfel::fsalgo::inner_product< N > Class Template Reference

inner_product calculates a generalized inner product of the ranges [first1,first1+N) and [first2,first2+N) More...

#include </home/runner/work/tfel/tfel/include/TFEL/FSAlgorithm/inner_product.hxx>

Static Public Member Functions

template<typename InputIterator1, typename InputIterator2, typename T>
static TFEL_HOST_DEVICE constexpr T exe (InputIterator1 p, InputIterator2 q, const T init)
template<typename InputIterator1, typename InputIterator2, typename T, typename BinaryFunction1, typename BinaryFunction2>
static TFEL_HOST_DEVICE constexpr T exe (InputIterator1 p, InputIterator2 q, T init, BinaryFunction1 binary_op1, BinaryFunction2 binary_op2)
template<typename T, typename InputIterator1, typename InputIterator2>
static TFEL_HOST_DEVICE constexpr T exe (InputIterator1 p, InputIterator2 q)

Detailed Description

template<unsigned int N>
class tfel::fsalgo::inner_product< N >

inner_product calculates a generalized inner product of the ranges [first1,first1+N) and [first2,first2+N)

Parameters
Nnumber of element of each ranges

This documentation is mostly inspired from: http://www.sgi.com/tech/stl/inner_product.html

See also
inner_product.cxx for some elementary tests.
Author
Thomas Helfer
Date
30/06/2006

Member Function Documentation

◆ exe() [1/3]

template<unsigned int N>
template<typename T, typename InputIterator1, typename InputIterator2>
TFEL_HOST_DEVICE constexpr T tfel::fsalgo::inner_product< N >::exe ( InputIterator1 p,
InputIterator2 q )
inlinestaticconstexpr

The third version of inner_product returns the inner product of the two ranges. That is, it computes:

\[\displaystyle\sum_{i=0}^{N-1}(*(p+i))*(*(q+i))\]

Parameters
InputIterator1iterator to the first range
InputIterator2iterator to the second range
Returns
T, result of the inner product
Precondition
  • InputIterator1 is a model of Input Iterator.
  • InputIterator2 is a model of Input Iterator.
  • T is a model of Assignable.
  • If x is an object of type T, 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.
  • The type of x + y * z is convertible to T.

◆ exe() [2/3]

template<unsigned int N>
template<typename InputIterator1, typename InputIterator2, typename T>
TFEL_HOST_DEVICE constexpr T tfel::fsalgo::inner_product< N >::exe ( InputIterator1 p,
InputIterator2 q,
const T init )
inlinestaticconstexpr

The first version of inner_product returns init plus the inner product of the two ranges [1]. That is, it first initializes the result to init and then computes:

\[\displaystyle\mathrm{init}+\sum_{i=0}^{N-1}(*(p+i))*(*(q+i))\]

Parameters
qiterator to the first range
qiterator to the second range
Tinitial value
Returns
T, result of the inner product
Precondition
  • InputIterator1 is a model of Input Iterator.
  • InputIterator2 is a model of Input Iterator.
  • T is a model of Assignable.
  • If x is an object of type T, 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.
  • The type of x + y * z is convertible to T.

◆ exe() [3/3]

template<unsigned int N>
template<typename InputIterator1, typename InputIterator2, typename T, typename BinaryFunction1, typename BinaryFunction2>
TFEL_HOST_DEVICE constexpr T tfel::fsalgo::inner_product< N >::exe ( InputIterator1 p,
InputIterator2 q,
T init,
BinaryFunction1 binary_op1,
BinaryFunction2 binary_op2 )
inlinestaticconstexpr

The second version of inner_product is identical to the first, except that it uses two user-supplied function objects instead of operator+ and operator*. That is, it first initializes the result to init and then, for each iterator i in [first1, last1), in order from the beginning to the end of the range, updates the result by result = binary_op1(result, binary_op2(*i, *(first2 + (i - first1))).

Parameters
InputIterator1iterator to the first range
InputIterator2iterator to the second range
Tinitial value
BinaryFunction1
BinaryFunction2
Returns
T, result
Precondition
  • InputIterator1 is a model of Input Iterator.
  • InputIterator2 is a model of Input Iterator.
  • T is a model of Assignable.
  • BinaryFunction1 is a model of Binary Function.
  • BinaryFunction2 is a model of Binary Function.
  • InputIterator1's value type is convertible to BinaryFunction2's first argument type.
  • InputIterator2's value type is convertible to BinaryFunction2's second argument type.
  • T is convertible to BinaryFunction1's first argument type.
  • BinaryFunction2's return type is convertible to BinaryFunction1's second argument type.
  • BinaryFunction1's return type is convertible to T.

The documentation for this class was generated from the following file: