Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Standard C++ Library Module Reference Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

inner_product()

Module:  Standard C++ Library   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

Copyright (c) 1994-2006 Rogue Wave Software, a Quovadx Division.
Licensed under the Apache License, Version 2.0.
Contact Rogue Wave about documentation or support issues. You can also seek help from other developers through the Apache stdcxx community (see below).

For more information on the Rogue Wave Standard C++ Library under open source, see Section 1.2 of the user's guide.