Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library Reference Guide

inner_product()

Library:  Numerics


Function

Local Index

No Entries

Summary

A generalized numeric operation that computes the inner product A X B of two ranges A and B

Synopsis

#include <numeric>

namespace std {
  template <class InputIterator1, class InputIterator2,
            class T>
  T inner_product(InputIterator1 start1, 
                  InputIterator1 finish1,
                  InputIterator2 start2, T init);
  
  template <class InputIterator1, class InputIterator2,
            class T,
            class BinaryOperation1,
            class BinaryOperation2>
  T inner_product(InputIterator1 start1, 
                  InputIterator1 finish1,
                  InputIterator2 start2, T init,
                  BinaryOperation1 binary_op1,
                  BinaryOperation2 binary_op2);
}

Description

There are two versions of inner_product(). The first computes an inner product using the default multiplication and addition operators, while the second allows you to specify binary operations to use in place of the default operations.

The first version of the function initializes acc with init and then modifies it with:

acc = acc + ((*i1) * (*i2))

for every iterator i1 in the range [start1, finish1) and iterator i2 in the range [start2, start2 + (finish1 - start1)). The algorithm returns acc.

The second version of the function initializes acc with init, then computes:

acc = binary_op1(acc, binary_op2(*i1, *i2))

for every iterator i1 in the range [start1, finish1) and iterator i2 in the range [start2, start2 + (finish1 - start1)).

Complexity

The inner_product() algorithm computes exactly (finish1 - start1) applications of either:

acc + (*i1) * (*i2)

or

binary_op1(acc, binary_op2(*i1, *i2)).

Example

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 26.4.2



Previous fileTop of DocumentContentsIndex pageNext file