2
0
mirror of https://github.com/boostorg/ublas.git synced 2026-02-14 01:02:16 +00:00
Files
ublas/doc/vector_expression.htm
Jörg Walter 058e8a8820 Merge.
svn path=/trunk/boost/libs/numeric/ublas/; revision=15321
2002-09-14 09:48:41 +00:00

1761 lines
58 KiB
HTML
Raw Blame History

<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<title>Vector Expressions</title>
</head>
<body bgcolor="#FFFFFF">
<h1><img src="c++boost.gif" alt="c++boost.gif" align="center">Vector Expressions</h1>
<h2><a name="vector_expression"></a>Vector Expression</h2>
<h4>Description</h4>
<p>The templated class <code>vector_expression&lt;E&gt; </code>forms
the base for all static derived vector expression classes
including class <code>vector</code> itself.</p>
<h4>Definition</h4>
<p>Defined in the header vector_expression.hpp.</p>
<h4>Template parameters</h4>
<table border="1">
<tr>
<th>Parameter </th>
<th>Description </th>
<th>Default </th>
</tr>
<tr>
<td><code>E</code> </td>
<td>The type of the vector expression. </td>
<td>&nbsp;</td>
</tr>
</table>
<h4>Model of</h4>
<p>None. </p>
<h4>Type requirements</h4>
<p>None.</p>
<h4>Public base classes</h4>
<p>None.</p>
<h4>Members</h4>
<table border="1">
<tr>
<th>Member </th>
<th>Description </th>
</tr>
<tr>
<td><code>const expression_type &amp;operator () () const</code></td>
<td>Returns a <code>const </code>reference of the
expression. </td>
</tr>
<tr>
<td><code>expression_type &amp;operator () ()</code></td>
<td>Returns a reference of the expression. </td>
</tr>
</table>
<h4>Interface</h4>
<pre><code> // Base class for the Barton Nackman trick
template&lt;class E&gt;
struct vector_expression {
typedef E expression_type;
typedef vector_tag type_category;
// This class could define an common interface for all
// statically derived expression type classes.
// Due to a compiler deficiency - one can not reference class typedefs of E
// on MSVC 6.0 (error C2027) - we only implement the casts.
const expression_type &amp;operator () () const;
expression_type &amp;operator () ();
};</code></pre>
<h2><a name="vector_references"></a>Vector References</h2>
<h3>Constant Reference</h3>
<h4>Description</h4>
<p>The templated class <code>vector_const_reference&lt;E&gt; </code>contains
a constant reference to a vector expression.</p>
<h4>Definition</h4>
<p>Defined in the header vector_expression.hpp.</p>
<h4>Template parameters</h4>
<table border="1">
<tr>
<th>Parameter </th>
<th>Description </th>
<th>Default </th>
</tr>
<tr>
<td><code>E</code> </td>
<td>The type of the vector expression. </td>
<td>&nbsp;</td>
</tr>
</table>
<h4>Model of</h4>
<p><a href="expression.htm#vector_expression">Vector Expression</a>.</p>
<h4>Type requirements</h4>
<p>None, except for those imposed by the requirements of <a
href="expression.htm#vector_expression">Vector Expression</a>.</p>
<h4>Public base classes</h4>
<p><code>vector_expression&lt;vector_const_reference&lt;E&gt;
&gt;</code></p>
<h4>Members</h4>
<table border="1">
<tr>
<th>Member </th>
<th>Description </th>
</tr>
<tr>
<td><code>vector_const_reference (const expression_type
&amp;e)</code> </td>
<td>Constructs a constant reference of the expression.</td>
</tr>
<tr>
<td><code>size_type size () const</code></td>
<td>Returns the size of the expression. </td>
</tr>
<tr>
<td><code>const_reference operator () (size_type i) const</code></td>
<td>Returns the value of the <code>i</code>-th element. </td>
</tr>
<tr>
<td><code>const_iterator begin () const</code></td>
<td>Returns a <code>const_iterator</code> pointing to the
beginning of the expression. </td>
</tr>
<tr>
<td><code>const_iterator end () const</code></td>
<td>Returns a <code>const_iterator</code> pointing to the
end of the expression. </td>
</tr>
<tr>
<td><code>const_reverse_iterator rbegin () const</code></td>
<td>Returns a <code>const_reverse_iterator</code>
pointing to the beginning of the reversed expression. </td>
</tr>
<tr>
<td><code>const_reverse_iterator rend () const</code></td>
<td>Returns a <code>const_reverse_iterator</code>
pointing to the end of the reversed expression. </td>
</tr>
</table>
<h4>Interface</h4>
<pre><code> template&lt;class E&gt;
class vector_const_reference:
public vector_expression&lt;vector_const_reference&lt;E&gt; &gt; {
public:
typedef E expression_type;
typedef typename E::size_type size_type;
typedef typename E::difference_type difference_type;
typedef typename E::value_type value_type;
typedef typename E::const_reference const_reference;
typedef const_reference reference;
typedef typename E::const_pointer const_pointer;
typedef const_pointer pointer;
typedef typename E::const_iterator const_iterator_type;
typedef unknown_storage_tag storage_category;
// Construction and destruction
vector_const_reference ();
vector_const_reference (const expression_type &amp;e);
// Accessors
size_type size () const;
const expression_type &amp;expression () const;
// Element access
const_reference operator () (size_type i) const;
const_reference operator [] (size_type i) const;
typedef const_iterator_type const_iterator;
typedef const_iterator iterator;
// Element lookup
const_iterator find_first (size_type i) const;
const_iterator find_last (size_type i) const;
// Iterator is the iterator of the referenced expression.
const_iterator begin () const;
const_iterator end () const;
// Reverse iterator
typedef reverse_iterator_base&lt;const_iterator&gt; const_reverse_iterator;
const_reverse_iterator rbegin () const;
const_reverse_iterator rend () const;
};</code></pre>
<h3>Reference</h3>
<h4>Description</h4>
<p>The templated class <code>vector_reference&lt;E&gt; </code>contains
a reference to a vector expression.</p>
<h4>Definition</h4>
<p>Defined in the header vector_expression.hpp.</p>
<h4>Template parameters</h4>
<table border="1">
<tr>
<th>Parameter </th>
<th>Description </th>
<th>Default </th>
</tr>
<tr>
<td><code>E</code> </td>
<td>The type of the vector expression. </td>
<td>&nbsp;</td>
</tr>
</table>
<h4>Model of</h4>
<p><a href="expression.htm#vector_expression">Vector Expression</a>.</p>
<h4>Type requirements</h4>
<p>None, except for those imposed by the requirements of <a
href="expression.htm#vector_expression">Vector Expression</a>.</p>
<h4>Public base classes</h4>
<p><code>vector_expression&lt;vector_reference&lt;E&gt; &gt;</code></p>
<h4>Members</h4>
<table border="1">
<tr>
<th>Member </th>
<th>Description </th>
</tr>
<tr>
<td><code>vector_reference (expression_type &amp;e)</code></td>
<td>Constructs a reference of the expression.</td>
</tr>
<tr>
<td><code>void resize (size_type size)</code></td>
<td>Resizes the expression to hold at most <code>size</code>
elements. </td>
</tr>
<tr>
<td><code>size_type size () const</code></td>
<td>Returns the size of the expression. </td>
</tr>
<tr>
<td><code>const_reference operator () (size_type i) const</code></td>
<td>Returns the value of the <code>i</code>-th element. </td>
</tr>
<tr>
<td><code>reference operator () (size_type i)</code></td>
<td>Returns a reference of the <code>i</code>-th element.
</td>
</tr>
<tr>
<td><code>const_iterator begin () const</code></td>
<td>Returns a <code>const_iterator</code> pointing to the
beginning of the expression. </td>
</tr>
<tr>
<td><code>const_iterator end () const</code></td>
<td>Returns a <code>const_iterator</code> pointing to the
end of the expression. </td>
</tr>
<tr>
<td><code>iterator begin () </code></td>
<td>Returns a <code>iterator</code> pointing to the
beginning of the expression. </td>
</tr>
<tr>
<td><code>iterator end () </code></td>
<td>Returns a <code>iterator</code> pointing to the end
of the expression. </td>
</tr>
<tr>
<td><code>const_reverse_iterator rbegin () const</code></td>
<td>Returns a <code>const_reverse_iterator</code>
pointing to the beginning of the reversed expression. </td>
</tr>
<tr>
<td><code>const_reverse_iterator rend () const</code></td>
<td>Returns a <code>const_reverse_iterator</code>
pointing to the end of the reversed expression. </td>
</tr>
<tr>
<td><code>reverse_iterator rbegin () </code></td>
<td>Returns a <code>reverse_iterator</code> pointing to
the beginning of the reversed expression. </td>
</tr>
<tr>
<td><code>reverse_iterator rend () </code></td>
<td>Returns a <code>reverse_iterator</code> pointing to
the end of the reversed expression. </td>
</tr>
</table>
<h4>Interface</h4>
<pre><code> template&lt;class E&gt;
class vector_reference:
public vector_expression&lt;vector_reference&lt;E&gt; &gt; {
public:
typedef E expression_type;
typedef typename E::size_type size_type;
typedef typename E::difference_type difference_type;
typedef typename E::value_type value_type;
typedef typename E::const_reference const_reference;
typedef typename E::reference reference;
typedef typename E::const_pointer const_pointer;
typedef typename E::pointer pointer;
typedef typename E::const_iterator const_iterator_type;
typedef typename E::iterator iterator_type;
typedef unknown_storage_tag storage_category;
// Construction and destruction
vector_reference ();
vector_reference (expression_type &amp;e);
// Accessors
size_type size () const;
const expression_type &amp;expression () const;
expression_type &amp;expression ();
// Resizing
void resize (size_type size);
// Element access
const_reference operator () (size_type i) const;
reference operator () (size_type i);
const_reference operator [] (size_type i) const;
reference operator [] (size_type i);
typedef const_iterator_type const_iterator;
typedef iterator_type iterator;
// Element lookup
const_iterator find_first (size_type i) const;
iterator find_first (size_type i);
const_iterator find_last (size_type i) const;
iterator find_last (size_type i);
// Iterator is the iterator of the referenced expression.
const_iterator begin () const;
const_iterator end () const;
iterator begin ();
iterator end ();
// Reverse iterator
typedef reverse_iterator_base&lt;const_iterator&gt; const_reverse_iterator;
const_reverse_iterator rbegin () const;
const_reverse_iterator rend () const;
typedef reverse_iterator_base&lt;iterator&gt; reverse_iterator;
reverse_iterator rbegin ();
reverse_iterator rend ();
};</code></pre>
<h2><a name="vector_operations"></a>Vector Operations</h2>
<h3>Unary Operation Description</h3>
<h4>Description</h4>
<p>The templated class <code>vector_unary&lt;E, F&gt; </code>describes
a unary vector operation.</p>
<h4>Definition</h4>
<p>Defined in the header vector_expression.hpp.</p>
<h4>Template parameters</h4>
<table border="1">
<tr>
<th>Parameter </th>
<th>Description </th>
<th>Default </th>
</tr>
<tr>
<td><code>E</code> </td>
<td>The type of the vector expression. </td>
<td>&nbsp;</td>
</tr>
<tr>
<td><code>F</code></td>
<td>The type of the operation.</td>
<td>&nbsp;</td>
</tr>
</table>
<h4>Model of</h4>
<p><a href="expression.htm#vector_expression">Vector Expression</a>.</p>
<h4>Type requirements</h4>
<p>None, except for those imposed by the requirements of <a
href="expression.htm#vector_expression">Vector Expression</a>.</p>
<h4>Public base classes</h4>
<p><code>vector_expression&lt;vector_unary&lt;E, F&gt; &gt;</code></p>
<h4>Members</h4>
<table border="1">
<tr>
<th>Member </th>
<th>Description </th>
</tr>
<tr>
<td><code>vector_unary (const expression_type &amp;e)</code></td>
<td>Constructs a description of the expression.</td>
</tr>
<tr>
<td><code>size_type size () const</code></td>
<td>Returns the size of the expression. </td>
</tr>
<tr>
<td><code>const_reference operator () (size_type i) const</code></td>
<td>Returns the value of the <code>i</code>-th element. </td>
</tr>
<tr>
<td><code>const_iterator begin () const</code></td>
<td>Returns a <code>const_iterator</code> pointing to the
beginning of the expression. </td>
</tr>
<tr>
<td><code>const_iterator end () const</code></td>
<td>Returns a <code>const_iterator</code> pointing to the
end of the expression. </td>
</tr>
<tr>
<td><code>const_reverse_iterator rbegin () const</code></td>
<td>Returns a <code>const_reverse_iterator</code>
pointing to the beginning of the reversed expression. </td>
</tr>
<tr>
<td><code>const_reverse_iterator rend () const</code></td>
<td>Returns a <code>const_reverse_iterator</code>
pointing to the end of the reversed expression. </td>
</tr>
</table>
<h4>Interface</h4>
<pre><code> template&lt;class E, class F&gt;
class vector_unary:
public vector_expression&lt;vector_unary&lt;E, F&gt; &gt; {
public:
typedef E expression_type;
typedef F functor_type;
typedef typename E::size_type size_type;
typedef typename E::difference_type difference_type;
typedef typename F::result_type value_type;
typedef value_type const_reference;
typedef const_reference reference;
typedef const value_type *const_pointer;
typedef const_pointer pointer;
typedef const vector_unary&lt;E, F&gt; const_closure_type;
typedef typename E::const_iterator const_iterator_type;
typedef unknown_storage_tag storage_category;
// Construction and destruction
vector_unary ();
vector_unary (const expression_type &amp;e);
// Accessors
size_type size () const;
const expression_type &amp;expression () const;
// Element access
const_reference operator () (size_type i) const;
const_reference operator [] (size_type i) const;
class const_iterator;
typedef const_iterator iterator;
// Element lookup
const_iterator find_first (size_type i) const;
const_iterator find_last (size_type i) const;
// Iterator enhances the iterator of the referenced expression
// with the unary functor.
class const_iterator:
public container_const_reference&lt;vector_unary&gt;,
public random_access_iterator_base&lt;const_iterator, value_type&gt; {
public:
typedef typename E::const_iterator::iterator_category iterator_category;
typedef typename vector_unary::difference_type difference_type;
typedef typename vector_unary::value_type value_type;
typedef typename vector_unary::const_reference reference;
typedef typename vector_unary::const_pointer pointer;
// Construction and destruction
const_iterator ();
const_iterator (const vector_unary &amp;vu, const const_iterator_type &amp;it);
// Arithmetic
const_iterator &amp;operator ++ ();
const_iterator &amp;operator -- ();
const_iterator &amp;operator += (difference_type n);
const_iterator &amp;operator -= (difference_type n);
difference_type operator - (const const_iterator &amp;it) const;
// Dereference
reference operator * () const;
// Index
size_type index () const;
// Assignment
const_iterator &amp;operator = (const const_iterator &amp;it);
// Comparison
bool operator == (const const_iterator &amp;it) const;
bool operator &lt;(const const_iterator &amp;it) const;
};
const_iterator begin () const;
const_iterator end () const;
// Reverse iterator
typedef reverse_iterator_base&lt;const_iterator&gt; const_reverse_iterator;
const_reverse_iterator rbegin () const;
const_reverse_iterator rend () const;
};</code></pre>
<h3>Unary Operations</h3>
<h4>Prototypes</h4>
<pre><code> template&lt;class E, class F&gt;
struct vector_unary_traits {
typedef vector_unary&lt;typename E::const_closure_type, F&gt; expression_type;
typedef expression_type result_type;
};
// (- v) [i] = - v [i]
template&lt;class E&gt;
typename vector_unary_traits&lt;E, scalar_negate&lt;typename E::value_type&gt; &gt;::result_type
operator - (const vector_expression&lt;E&gt; &amp;e);
// (conj v) [i] = conj (v [i])
template&lt;class E&gt;
typename vector_unary_traits&lt;E, scalar_conj&lt;typename E::value_type&gt; &gt;::result_type
conj (const vector_expression&lt;E&gt; &amp;e);
// (real v) [i] = real (v [i])
template&lt;class E&gt;
typename vector_unary_traits&lt;E, scalar_real&lt;typename E::value_type&gt; &gt;::result_type
real (const vector_expression&lt;E&gt; &amp;e);
// (imag v) [i] = imag (v [i])
template&lt;class E&gt;
typename vector_unary_traits&lt;E, scalar_imag&lt;typename E::value_type&gt; &gt;::result_type
imag (const vector_expression&lt;E&gt; &amp;e);
// (trans v) [i] = v [i]
template&lt;class E&gt;
typename vector_unary_traits&lt;E, scalar_identity&lt;typename E::value_type&gt; &gt;::result_type
trans (const vector_expression&lt;E&gt; &amp;e);
// (herm v) [i] = conj (v [i])
template&lt;class E&gt;
typename vector_unary_traits&lt;E, scalar_conj&lt;typename E::value_type&gt; &gt;::result_type
herm (const vector_expression&lt;E&gt; &amp;e);</code></pre>
<h4>Description</h4>
<p><code>operator -</code> computes the additive inverse of a
vector expression. <code>conj</code> computes the complex
conjugate of a vector expression. <code>real</code> and <code>imag</code>
compute the real and imaginary parts of a vector expression. <code>trans</code>
computes the transpose of a vector expression. <code>herm</code>
computes the hermitian, i.e. the complex conjugate of the
transpose of a vector expression.</p>
<h4>Definition</h4>
<p>Defined in the header vector_expression.hpp.</p>
<h4>Type requirements</h4>
<dir>
<li><code>E</code> is a model of <a
href="expression.htm#vector_expression">Vector Expression</a>.</li>
</dir>
<h4>Preconditions</h4>
<p>None.</p>
<h4>Complexity</h4>
<p>Linear depending from the size of the vector expression.</p>
<h4>Examples</h4>
<pre>int main () {
using namespace boost::numeric::ublas;
vector&lt;std::complex&lt;double&gt; &gt; v (3);
for (int i = 0; i &lt; v.size (); ++ i)
v (i) = std::complex (i, i);
std::cout &lt;&lt; - v &lt;&lt; std::endl;
std::cout &lt;&lt; conj (v) &lt;&lt; std::endl;
std::cout &lt;&lt; real (v) &lt;&lt; std::endl;
std::cout &lt;&lt; imag (v) &lt;&lt; std::endl;
std::cout &lt;&lt; trans (v) &lt;&lt; std::endl;
std::cout &lt;&lt; herm (v) &lt;&lt; std::endl;
}</pre>
<h3>Binary Operation Description</h3>
<h4>Description</h4>
<p>The templated class <code>vector_binary&lt;E1, E2, F&gt; </code>describes
a binary vector operation.</p>
<h4>Definition</h4>
<p>Defined in the header vector_expression.hpp.</p>
<h4>Template parameters</h4>
<table border="1">
<tr>
<th>Parameter </th>
<th>Description </th>
<th>Default </th>
</tr>
<tr>
<td><code>E1</code> </td>
<td>The type of the first vector expression. </td>
<td>&nbsp;</td>
</tr>
<tr>
<td><code>E2</code></td>
<td>The type of the second vector expression. </td>
<td>&nbsp;</td>
</tr>
<tr>
<td><code>F</code></td>
<td>The type of the operation.</td>
<td>&nbsp;</td>
</tr>
</table>
<h4>Model of</h4>
<p><a href="expression.htm#vector_expression">Vector Expression</a>.</p>
<h4>Type requirements</h4>
<p>None, except for those imposed by the requirements of <a
href="expression.htm#vector_expression">Vector Expression</a>.</p>
<h4>Public base classes</h4>
<p><code>vector_expression&lt;vector_binary&lt;E1, E2, F&gt; &gt;</code></p>
<h4>Members</h4>
<table border="1">
<tr>
<th>Member </th>
<th>Description </th>
</tr>
<tr>
<td><code>vector_binary (const expression1_type &amp;e1,
const expression2_type &amp;e2)</code></td>
<td>Constructs a description of the expression.</td>
</tr>
<tr>
<td><code>size_type size () const</code></td>
<td>Returns the size of the expression. </td>
</tr>
<tr>
<td><code>const_reference operator () (size_type i) const</code></td>
<td>Returns the value of the <code>i</code>-th element. </td>
</tr>
<tr>
<td><code>const_iterator begin () const</code></td>
<td>Returns a <code>const_iterator</code> pointing to the
beginning of the expression. </td>
</tr>
<tr>
<td><code>const_iterator end () const</code></td>
<td>Returns a <code>const_iterator</code> pointing to the
end of the expression. </td>
</tr>
<tr>
<td><code>const_reverse_iterator rbegin () const</code></td>
<td>Returns a <code>const_reverse_iterator</code>
pointing to the beginning of the reversed expression. </td>
</tr>
<tr>
<td><code>const_reverse_iterator rend () const</code></td>
<td>Returns a <code>const_reverse_iterator</code>
pointing to the end of the reversed expression. </td>
</tr>
</table>
<h4>Interface</h4>
<pre><code> template&lt;class E1, class E2, class F&gt;
class vector_binary:
public vector_expression&lt;vector_binary&lt;E1, E2, F&gt; &gt; {
public:
typedef E1 expression1_type;
typedef E2 expression2_type;
typedef F functor_type;
typedef typename promote_traits&lt;typename E1::size_type, typename E2::size_type&gt;::promote_type size_type;
typedef typename promote_traits&lt;typename E1::difference_type, typename E2::difference_type&gt;::promote_type difference_type;
typedef typename F::result_type value_type;
typedef value_type const_reference;
typedef const_reference reference;
typedef const value_type *const_pointer;
typedef const_pointer pointer;
typedef const vector_binary&lt;E1, E2, F&gt; const_closure_type;
typedef typename E1::const_iterator const_iterator1_type;
typedef typename E2::const_iterator const_iterator2_type;
typedef unknown_storage_tag storage_category;
// Construction and destruction
vector_binary ();
vector_binary (const expression1_type &amp;e1, const expression2_type &amp;e2);
// Accessors
size_type size () const;
const expression1_type &amp;expression1 () const;
const expression2_type &amp;expression2 () const;
// Element access
const_reference operator () (size_type i) const;
const_reference operator [] (size_type i) const;
class const_iterator;
typedef const_iterator iterator;
// Element lookup
const_iterator find_first (size_type i) const;
const_iterator find_last (size_type i) const;
// Iterator merges the iterators of the referenced expressions and
// enhances them with the binary functor.
class const_iterator:
public container_const_reference&lt;vector_binary&gt;,
public random_access_iterator_base&lt;const_iterator, value_type&gt; {
public:
typedef typename restrict_traits&lt;typename E1::const_iterator::iterator_category,
typename E2::const_iterator::iterator_category&gt;::iterator_category iterator_category;
typedef typename vector_binary::difference_type difference_type;
typedef typename vector_binary::value_type value_type;
typedef typename vector_binary::const_reference reference;
typedef typename vector_binary::const_pointer pointer;
// Construction and destruction
const_iterator ();
const_iterator (const vector_binary &amp;vb, size_type i,
const const_iterator1_type &amp;it1, const const_iterator1_type &amp;it1_end,
const const_iterator2_type &amp;it2, const const_iterator2_type &amp;it2_end);
// Dense specializations
void increment (dense_random_access_iterator_tag);
void decrement (dense_random_access_iterator_tag);
value_type dereference (dense_random_access_iterator_tag) const;
// Packed specializations
void increment (packed_random_access_iterator_tag);
void decrement (packed_random_access_iterator_tag);
value_type dereference (packed_random_access_iterator_tag) const;
// Sparse specializations
void increment (sparse_bidirectional_iterator_tag);
void decrement (sparse_bidirectional_iterator_tag);
value_type dereference (sparse_bidirectional_iterator_tag) const;
// Arithmetic
const_iterator &amp;operator ++ ();
const_iterator &amp;operator -- ();
const_iterator &amp;operator += (difference_type n);
const_iterator &amp;operator -= (difference_type n);
difference_type operator - (const const_iterator &amp;it) const;
// Dereference
reference operator * () const;
// Index
size_type index () const;
// Assignment
const_iterator &amp;operator = (const const_iterator &amp;it);
// Comparison
bool operator == (const const_iterator &amp;it) const;
bool operator &lt;(const const_iterator &amp;it) const;
};
const_iterator begin () const;
const_iterator end () const;
// Reverse iterator
typedef reverse_iterator_base&lt;const_iterator&gt; const_reverse_iterator;
const_reverse_iterator rbegin () const;
const_reverse_iterator rend () const;
};
</code></pre>
<h3>Binary Operations</h3>
<h4>Prototypes</h4>
<pre><code> template&lt;class E1, class E2, class F&gt;
struct vector_binary_traits {
typedef vector_binary&lt;typename E1::const_closure_type,
typename E2::const_closure_type, F&gt; expression_type;
typedef expression_type result_type;
};
// (v1 + v2) [i] = v1 [i] + v2 [i]
template&lt;class E1, class E2&gt;
typename vector_binary_traits&lt;E1, E2, scalar_plus&lt;typename E1::value_type,
typename E2::value_type&gt; &gt;::result_type
operator + (const vector_expression&lt;E1&gt; &amp;e1,
const vector_expression&lt;E2&gt; &amp;e2);
// (v1 - v2) [i] = v1 [i] - v2 [i]
template&lt;class E1, class E2&gt;
typename vector_binary_traits&lt;E1, E2, scalar_minus&lt;typename E1::value_type,
typename E2::value_type&gt; &gt;::result_type
operator - (const vector_expression&lt;E1&gt; &amp;e1,
const vector_expression&lt;E2&gt; &amp;e2);</code></pre>
<h4>Description</h4>
<p><code>operator +</code> computes the sum of two vector
expressions. <code>operator - </code>computes the difference of
two vector expressions.</p>
<h4>Definition</h4>
<p>Defined in the header vector_expression.hpp.</p>
<h4>Type requirements</h4>
<dir>
<li><code>E1</code> is a model of <a
href="expression.htm#vector_expression">Vector Expression</a>.</li>
<li><code>E2</code> is a model of <a
href="expression.htm#vector_expression">Vector Expression</a>.</li>
</dir>
<h4>Preconditions</h4>
<dir>
<li><code>e1 ().size () == e2 ().size ()</code></li>
</dir>
<h4>Complexity</h4>
<p>Linear depending from the size of the vector expressions.</p>
<h4>Examples</h4>
<pre>int main () {
using namespace boost::numeric::ublas;
vector&lt;double&gt; v1 (3), v2 (3);
for (int i = 0; i &lt; std::min (v1.size (), v2.size ()); ++ i)
v1 (i) = v2 (i) = i;
std::cout &lt;&lt; v1 + v2 &lt;&lt; std::endl;
std::cout &lt;&lt; v1 - v2 &lt;&lt; std::endl;
}</pre>
<h3>Binary Outer Operation Description</h3>
<h4>Description</h4>
<p>The templated class <code>vector_matrix_binary&lt;E1, E2,
F&gt; </code>describes a binary outer vector operation.</p>
<h4>Definition</h4>
<p>Defined in the header matrix_expression.hpp.</p>
<h4>Template parameters</h4>
<table border="1">
<tr>
<th>Parameter </th>
<th>Description </th>
<th>Default </th>
</tr>
<tr>
<td><code>E1</code> </td>
<td>The type of the first vector expression. </td>
<td>&nbsp;</td>
</tr>
<tr>
<td><code>E2</code></td>
<td>The type of the second vector expression. </td>
<td>&nbsp;</td>
</tr>
<tr>
<td><code>F</code></td>
<td>The type of the operation.</td>
<td>&nbsp;</td>
</tr>
</table>
<h4>Model of</h4>
<p><a href="expression.htm#matrix_expression">Matrix Expression</a>.</p>
<h4>Type requirements</h4>
<p>None, except for those imposed by the requirements of <a
href="expression.htm#matrix_expression">Matrix Expression</a>.</p>
<h4>Public base classes</h4>
<p><code>matrix_expression&lt;vector_matrix_binary&lt;E1, E2,
F&gt; &gt;</code></p>
<h4>Members</h4>
<table border="1">
<tr>
<th>Member </th>
<th>Description </th>
</tr>
<tr>
<td><code>vector_matrix_binary (const expression1_type
&amp;e1, const expression2_type &amp;e2)</code> </td>
<td>Constructs a description of the expression.</td>
</tr>
<tr>
<td><code>size_type size1 () const</code></td>
<td>Returns the number of rows. </td>
</tr>
<tr>
<td><code>size_type size2 () const</code></td>
<td>Returns the number of columns. </td>
</tr>
<tr>
<td><code>const_reference operator () (size_type i, size_type
j) const</code></td>
<td>Returns the value of the <code>j</code>-th element in
the<code> i</code>-th row. </td>
</tr>
<tr>
<td><code>const_iterator1 begin1 () const</code></td>
<td>Returns a <code>const_iterator1</code> pointing to
the beginning of the expression. </td>
</tr>
<tr>
<td><code>const_iterator1 end1 () const</code></td>
<td>Returns a <code>const_iterator1</code> pointing to
the end of the expression. </td>
</tr>
<tr>
<td><code>const_iterator2 begin2 () const</code></td>
<td>Returns a <code>const_iterator2</code> pointing to
the beginning of the expression. </td>
</tr>
<tr>
<td><code>const_iterator2 end2 () const</code></td>
<td>Returns a <code>const_iterator2</code> pointing to
the end of the expression. </td>
</tr>
<tr>
<td><code>const_reverse_iterator1 rbegin1 () const</code></td>
<td>Returns a <code>const_reverse_iterator1</code>
pointing to the beginning of the reversed expression. </td>
</tr>
<tr>
<td><code>const_reverse_iterator1 rend1 () const</code></td>
<td>Returns a <code>const_reverse_iterator1</code>
pointing to the end of the reversed expression. </td>
</tr>
<tr>
<td><code>const_reverse_iterator2 rbegin2 () const</code></td>
<td>Returns a <code>const_reverse_iterator2</code>
pointing to the beginning of the reversed expression. </td>
</tr>
<tr>
<td><code>const_reverse_iterator2 rend2 () const</code></td>
<td>Returns a <code>const_reverse_iterator2</code>
pointing to the end of the reversed expression. </td>
</tr>
</table>
<h4>Interface</h4>
<pre><code> template&lt;class E1, class E2, class F&gt;
class vector_matrix_binary:
public matrix_expression&lt;vector_matrix_binary&lt;E1, E2, F&gt; &gt; {
public:
typedef E1 expression1_type;
typedef E2 expression2_type;
typedef F functor_type;
typedef typename promote_traits&lt;typename E1::size_type, typename E2::size_type&gt;::promote_type size_type;
typedef typename promote_traits&lt;typename E1::difference_type, typename E2::difference_type&gt;::promote_type difference_type;
typedef typename F::result_type value_type;
typedef value_type const_reference;
typedef const_reference reference;
typedef const value_type *const_pointer;
typedef const_pointer pointer;
typedef const vector_matrix_binary&lt;E1, E2, F&gt; const_closure_type;
typedef unknown_orientation_tag orientation_category;
typedef typename E1::const_iterator const_iterator1_type;
typedef typename E2::const_iterator const_iterator2_type;
typedef unknown_storage_tag storage_category;
// Construction and destruction
vector_matrix_binary ();
vector_matrix_binary (const expression1_type &amp;e1, const expression2_type &amp;e2);
// Accessors
size_type size1 () const;
size_type size2 () const;
const expression1_type &amp;expression1 () const;
const expression2_type &amp;expression2 () const;
// Element access
const_reference operator () (size_type i, size_type j) const;
class const_iterator1;
typedef const_iterator1 iterator1;
class const_iterator2;
typedef const_iterator2 iterator2;
// Element lookup
const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
// Iterators enhance the iterators of the referenced expressions
// with the binary functor.
class const_iterator1:
public container_const_reference&lt;vector_matrix_binary&gt;,
public random_access_iterator_base&lt;const_iterator1, value_type&gt; {
public:
typedef typename restrict_traits&lt;typename E1::const_iterator::iterator_category,
typename E2::const_iterator::iterator_category&gt;::iterator_category iterator_category;
typedef typename vector_matrix_binary::difference_type difference_type;
typedef typename vector_matrix_binary::value_type value_type;
typedef typename vector_matrix_binary::const_reference reference;
typedef typename vector_matrix_binary::const_pointer pointer;
typedef const_iterator2 dual_iterator_type;
typedef const_reverse_iterator2 dual_reverse_iterator_type;
// Construction and destruction
const_iterator1 ();
const_iterator1 (const vector_matrix_binary &amp;vmb, const const_iterator1_type &amp;it1, const const_iterator2_type &amp;it2);
// Arithmetic
const_iterator1 &amp;operator ++ ();
const_iterator1 &amp;operator -- ();
const_iterator1 &amp;operator += (difference_type n);
const_iterator1 &amp;operator -= (difference_type n);
difference_type operator - (const const_iterator1 &amp;it) const;
// Dereference
reference operator * () const;
const_iterator2 begin () const;
const_iterator2 end () const;
const_reverse_iterator2 rbegin () const;
const_reverse_iterator2 rend () const;
// Indices
size_type index1 () const;
size_type index2 () const;
// Assignment
const_iterator1 &amp;operator = (const const_iterator1 &amp;it);
// Comparison
bool operator == (const const_iterator1 &amp;it) const;
bool operator &lt;(const const_iterator1 &amp;it) const;
};
const_iterator1 begin1 () const;
const_iterator1 end1 () const;
class const_iterator2:
public container_const_reference&lt;vector_matrix_binary&gt;,
public random_access_iterator_base&lt;const_iterator2, value_type&gt; {
public:
typedef typename restrict_traits&lt;typename E1::const_iterator::iterator_category,
typename E2::const_iterator::iterator_category&gt;::iterator_category iterator_category;
typedef typename vector_matrix_binary::difference_type difference_type;
typedef typename vector_matrix_binary::value_type value_type;
typedef typename vector_matrix_binary::const_reference reference;
typedef typename vector_matrix_binary::const_pointer pointer;
typedef const_iterator1 dual_iterator_type;
typedef const_reverse_iterator1 dual_reverse_iterator_type;
// Construction and destruction
const_iterator2 ();
const_iterator2 (const vector_matrix_binary &amp;vmb, const const_iterator1_type &amp;it1, const const_iterator2_type &amp;it2);
// Arithmetic
const_iterator2 &amp;operator ++ ();
const_iterator2 &amp;operator -- ();
const_iterator2 &amp;operator += (difference_type n);
const_iterator2 &amp;operator -= (difference_type n);
difference_type operator - (const const_iterator2 &amp;it) const;
// Dereference
reference operator * () const;
const_iterator1 begin () const;
const_iterator1 end () const;
const_reverse_iterator1 rbegin () const;
const_reverse_iterator1 rend () const;
// Indices
size_type index1 () const;
size_type index2 () const;
// Assignment
const_iterator2 &amp;operator = (const const_iterator2 &amp;it);
// Comparison
bool operator == (const const_iterator2 &amp;it) const;
bool operator &lt;(const const_iterator2 &amp;it) const;
};
const_iterator2 begin2 () const;
const_iterator2 end2 () const;
// Reverse iterators
const_reverse_iterator1 rbegin1 () const;
const_reverse_iterator1 rend1 () const;
const_reverse_iterator2 rbegin2 () const;
const_reverse_iterator2 rend2 () const;
};</code></pre>
<h3>Binary Outer Operations</h3>
<h4>Prototypes</h4>
<pre><code> template&lt;class E1, class E2, class F&gt;
struct vector_matrix_binary_traits {
typedef vector_matrix_binary&lt;typename E1::const_closure_type,
typename E2::const_closure_type, F&gt; expression_type;
typedef expression_type result_type;
};
// (outer_prod (v1, v2)) [i] [j] = v1 [i] * v2 [j]
template&lt;class E1, class E2&gt;
typename vector_matrix_binary_traits&lt;E1, E2, scalar_multiplies&lt;typename E1::value_type, typename E2::value_type&gt; &gt;::result_type
outer_prod (const vector_expression&lt;E1&gt; &amp;e1,
const vector_expression&lt;E2&gt; &amp;e2);</code></pre>
<h4>Description</h4>
<p><code>outer_prod </code>computes the outer product of two
vector expressions.</p>
<h4>Definition</h4>
<p>Defined in the header matrix_expression.hpp.</p>
<h4>Type requirements</h4>
<dir>
<li><code>E1</code> is a model of <a
href="expression.htm#vector_expression">Vector Expression</a>.</li>
<li><code>E2</code> is a model of <a
href="expression.htm#vector_expression">Vector Expression</a>.</li>
</dir>
<h4>Preconditions</h4>
<p>None.</p>
<h4>Complexity</h4>
<p>Quadratic depending from the size of the vector expressions.</p>
<h4>Examples</h4>
<pre>int main () {
using namespace boost::numeric::ublas;
vector&lt;double&gt; v1 (3), v2 (3);
for (int i = 0; i &lt; std::min (v1.size (), v2.size ()); ++ i)
v1 (i) = v2 (i) = i;
std::cout &lt;&lt; outer_prod (v1, v2) &lt;&lt; std::endl;
}</pre>
<h3>Scalar Vector Operation Description</h3>
<h4>Description</h4>
<p>The templated classes <code>vector_binary_scalar1&lt;E1, E2,
F&gt; </code>and <code>vector_binary_scalar2&lt;E1, E2, F&gt;</code>
describe binary operations between a scalar and a vector.</p>
<h4>Definition</h4>
<p>Defined in the header vector_expression.hpp.</p>
<h4>Template parameters</h4>
<table border="1">
<tr>
<th>Parameter </th>
<th>Description </th>
<th>Default </th>
</tr>
<tr>
<td><code>E1/E2</code> </td>
<td>The type of the scalar expression. </td>
<td>&nbsp;</td>
</tr>
<tr>
<td><code>E2/E1</code></td>
<td>The type of the vector expression. </td>
<td>&nbsp;</td>
</tr>
<tr>
<td><code>F</code></td>
<td>The type of the operation.</td>
<td>&nbsp;</td>
</tr>
</table>
<h4>Model of</h4>
<p><a href="expression.htm#vector_expression">Vector Expression</a>.</p>
<h4>Type requirements</h4>
<p>None, except for those imposed by the requirements of <a
href="expression.htm#vector_expression">Vector Expression</a>.</p>
<h4>Public base classes</h4>
<p><code>vector_expression&lt;vector_binary_scalar1&lt;E1, E2,
F&gt; &gt;</code> and<code>
vector_expression&lt;vector_binary_scalar2&lt;E1, E2, F&gt; &gt; </code>resp.</p>
<h4>Members</h4>
<table border="1">
<tr>
<th>Member </th>
<th>Description </th>
</tr>
<tr>
<td><code>vector_binary_scalar1 (const expression1_type
&amp;e1, const expression2_type &amp;e2)</code></td>
<td>Constructs a description of the expression.</td>
</tr>
<tr>
<td><code>vector_binary_scalar2 (const expression1_type
&amp;e1, const expression2_type &amp;e2)</code></td>
<td>Constructs a description of the expression.</td>
</tr>
<tr>
<td><code>size_type size () const</code></td>
<td>Returns the size of the expression. </td>
</tr>
<tr>
<td><code>const_reference operator () (size_type i) const</code></td>
<td>Returns the value of the <code>i</code>-th element. </td>
</tr>
<tr>
<td><code>const_iterator begin () const</code></td>
<td>Returns a <code>const_iterator</code> pointing to the
beginning of the expression. </td>
</tr>
<tr>
<td><code>const_iterator end () const</code></td>
<td>Returns a <code>const_iterator</code> pointing to the
end of the expression. </td>
</tr>
<tr>
<td><code>const_reverse_iterator rbegin () const</code></td>
<td>Returns a <code>const_reverse_iterator</code>
pointing to the beginning of the reversed expression. </td>
</tr>
<tr>
<td><code>const_reverse_iterator rend () const</code></td>
<td>Returns a <code>const_reverse_iterator</code>
pointing to the end of the reversed expression. </td>
</tr>
</table>
<h4>Interface</h4>
<pre><code> template&lt;class E1, class E2, class F&gt;
class vector_binary_scalar1:
public vector_expression&lt;vector_binary_scalar1&lt;E1, E2, F&gt; &gt; {
public:
typedef E1 expression1_type;
typedef E2 expression2_type;
typedef F functor_type;
typedef typename E2::size_type size_type;
typedef typename E2::difference_type difference_type;
typedef typename F::result_type value_type;
typedef value_type const_reference;
typedef const_reference reference;
typedef const value_type *const_pointer;
typedef const_pointer pointer;
typedef const vector_binary_scalar1&lt;E1, E2, F&gt; const_closure_type;
typedef typename E1::value_type const_iterator1_type;
typedef typename E2::const_iterator const_iterator2_type;
typedef unknown_storage_tag storage_category;
// Construction and destruction
vector_binary_scalar1 ();
vector_binary_scalar1 (const expression1_type &amp;e1, const expression2_type &amp;e2);
// Accessors
size_type size () const;
const expression1_type &amp;expression1 () const;
const expression2_type &amp;expression2 () const;
// Element access
const_reference operator () (size_type i) const;
const_reference operator [] (size_type i) const;
class const_iterator;
typedef const_iterator iterator;
// Element lookup
const_iterator find_first (size_type i) const;
const_iterator find_last (size_type i) const;
// Iterator enhances the iterator of the referenced vector expression
// with the binary functor.
class const_iterator:
public container_const_reference&lt;vector_binary_scalar1&gt;,
public random_access_iterator_base&lt;const_iterator, value_type&gt; {
public:
typedef typename E2::const_iterator::iterator_category iterator_category;
typedef typename vector_binary_scalar1::difference_type difference_type;
typedef typename vector_binary_scalar1::value_type value_type;
typedef typename vector_binary_scalar1::const_reference reference;
typedef typename vector_binary_scalar1::const_pointer pointer;
// Construction and destruction
const_iterator ();
const_iterator (const vector_binary_scalar1 &amp;vbs, const const_iterator1_type &amp;it1, const const_iterator2_type &amp;it2);
// Arithmetic
const_iterator &amp;operator ++ ();
const_iterator &amp;operator -- ();
const_iterator &amp;operator += (difference_type n);
const_iterator &amp;operator -= (difference_type n);
difference_type operator - (const const_iterator &amp;it) const;
// Dereference
reference operator * () const;
// Index
size_type index () const;
// Assignment
const_iterator &amp;operator = (const const_iterator &amp;it);
// Comparison
bool operator == (const const_iterator &amp;it) const;
bool operator &lt;(const const_iterator &amp;it) const;
};
const_iterator begin () const;
const_iterator end () const;
// Reverse iterator
typedef reverse_iterator_base&lt;const_iterator&gt; const_reverse_iterator;
const_reverse_iterator rbegin () const;
const_reverse_iterator rend () const;
};
template&lt;class E1, class E2, class F&gt;
class vector_binary_scalar2:
public vector_expression&lt;vector_binary_scalar2&lt;E1, E2, F&gt; &gt; {
public:
typedef E1 expression1_type;
typedef E2 expression2_type;
typedef F functor_type;
typedef typename E1::size_type size_type;
typedef typename E1::difference_type difference_type;
typedef typename F::result_type value_type;
typedef value_type const_reference;
typedef const_reference reference;
typedef const value_type *const_pointer;
typedef const_pointer pointer;
typedef const vector_binary_scalar2&lt;E1, E2, F&gt; const_closure_type;
typedef typename E1::const_iterator const_iterator1_type;
typedef typename E2::value_type const_iterator2_type;
typedef unknown_storage_tag storage_category;
// Construction and destruction
vector_binary_scalar2 ();
vector_binary_scalar2 (const expression1_type &amp;e1, const expression2_type &amp;e2);
// Accessors
size_type size () const;
const expression1_type &amp;expression1 () const;
const expression2_type &amp;expression2 () const;
// Element access
const_reference operator () (size_type i) const;
const_reference operator [] (size_type i) const ;
class const_iterator;
typedef const_iterator iterator;
// Element lookup
const_iterator find_first (size_type i) const;
const_iterator find_last (size_type i) const;
// Iterator enhances the iterator of the referenced vector expression
// with the binary functor.
class const_iterator:
public container_const_reference&lt;vector_binary_scalar2&gt;,
public random_access_iterator_base&lt;const_iterator, value_type&gt; {
public:
typedef typename E1::const_iterator::iterator_category iterator_category;
typedef typename vector_binary_scalar2::difference_type difference_type;
typedef typename vector_binary_scalar2::value_type value_type;
typedef typename vector_binary_scalar2::const_reference reference;
typedef typename vector_binary_scalar2::const_pointer pointer;
// Construction and destruction
const_iterator ();
const_iterator (const vector_binary_scalar2 &amp;vbs, const const_iterator1_type &amp;it1, const const_iterator2_type &amp;it2);
// Arithmetic
const_iterator &amp;operator ++ ();
const_iterator &amp;operator -- ();
const_iterator &amp;operator += (difference_type n);
const_iterator &amp;operator -= (difference_type n);
difference_type operator - (const const_iterator &amp;it) const;
// Dereference
reference operator * () const;
// Index
size_type index () const;
// Assignment
const_iterator &amp;operator = (const const_iterator &amp;it);
// Comparison
bool operator == (const const_iterator &amp;it) const;
bool operator &lt;(const const_iterator &amp;it) const;
};
const_iterator begin () const;
const_iterator end () const;
// Reverse iterator
typedef reverse_iterator_base&lt;const_iterator&gt; const_reverse_iterator;
const_reverse_iterator rbegin () const;
const_reverse_iterator rend () const;
};</code></pre>
<h3>Scalar Vector Operations </h3>
<h4>Prototypes</h4>
<pre><code> template&lt;class T1, class E2, class F&gt;
struct vector_binary_scalar1_traits {
typedef vector_binary_scalar1&lt;scalar_const_reference&lt;T1&gt;,
typename E2::const_closure_type, F&gt; expression_type;
typedef expression_type result_type;
};
// (t * v) [i] = t * v [i]
template&lt;class T1, class E2&gt;
typename vector_binary_scalar1_traits&lt;T1, E2, scalar_multiplies&lt;T1, typename E2::value_type&gt; &gt;::result_type
operator * (const T1 &amp;e1,
const vector_expression&lt;E2&gt; &amp;e2);
template&lt;class E1, class T2, class F&gt;
struct vector_binary_scalar2_traits {
typedef vector_binary_scalar2&lt;typename E1::const_closure_type,
scalar_const_reference&lt;T2&gt;, F&gt; expression_type;
typedef expression_type result_type;
};
// (v * t) [i] = v [i] * t
template&lt;class E1, class T2&gt;
typename vector_binary_scalar2_traits&lt;E1, T2, scalar_multiplies&lt;typename E1::value_type, T2&gt; &gt;::result_type
operator * (const vector_expression&lt;E1&gt; &amp;e1,
const T2 &amp;e2);
// (v / t) [i] = v [i] / t
template&lt;class E1, class T2&gt;
typename vector_binary_scalar2_traits&lt;E1, T2, scalar_divides&lt;typename E1::value_type, T2&gt; &gt;::result_type
operator / (const vector_expression&lt;E1&gt; &amp;e1,
const T2 &amp;e2);</code></pre>
<h4>Description</h4>
<p><code>operator *</code> computes the product of a scalar and a
vector expression. <code>operator /</code> multiplies the vector
with the reciprocal of the scalar. </p>
<h4>Definition</h4>
<p>Defined in the header vector_expression.hpp.</p>
<h4>Type requirements</h4>
<dir>
<li><code>T1/T2</code> is a model of <a
href="expression.htm#scalar_expression">Scalar Expression</a>.</li>
<li><code>E2/E1</code> is a model of <a
href="expression.htm#vector_expression">Vector Expression</a>.</li>
</dir>
<h4>Preconditions</h4>
<p>None.</p>
<h4>Complexity</h4>
<p>Linear depending from the size of the vector expression.</p>
<h4>Examples</h4>
<pre>int main () {
using namespace boost::numeric::ublas;
vector&lt;double&gt; v (3);
for (int i = 0; i &lt; v.size (); ++ i)
v (i) = i;
std::cout &lt;&lt; 2.0 * v &lt;&lt; std::endl;
std::cout &lt;&lt; v * 2.0 &lt;&lt; std::endl;
}</pre>
<h2><a name="vector_reductions"></a>Vector Reductions</h2>
<h3>Unary Reductions</h3>
<h4>Prototypes</h4>
<pre><code> template&lt;class E, class F&gt;
struct vector_scalar_unary_traits {
typedef typename F::result_type result_type;
};
// sum v = sum (v [i])
template&lt;class E&gt;
typename vector_scalar_unary_traits&lt;E, vector_sum&lt;typename E::value_type&gt; &gt;::result_type
sum (const vector_expression&lt;E&gt; &amp;e);
// norm_1 v = sum (abs (v [i]))
template&lt;class E&gt;
typename vector_scalar_unary_traits&lt;E, vector_norm_1&lt;typename E::value_type&gt; &gt;::result_type
norm_1 (const vector_expression&lt;E&gt; &amp;e);
// norm_2 v = sqrt (sum (v [i] * v [i]))
template&lt;class E&gt;
typename vector_scalar_unary_traits&lt;E, vector_norm_2&lt;typename E::value_type&gt; &gt;::result_type
norm_2 (const vector_expression&lt;E&gt; &amp;e);
// norm_inf v = max (abs (v [i]))
template&lt;class E&gt;
typename vector_scalar_unary_traits&lt;E, vector_norm_inf&lt;typename E::value_type&gt; &gt;::result_type
norm_inf (const vector_expression&lt;E&gt; &amp;e);
// index_norm_inf v = min (i: abs (v [i]) == max (abs (v [i])))
template&lt;class E&gt;
typename vector_scalar_unary_traits&lt;E, vector_index_norm_inf&lt;typename E::value_type&gt; &gt;::result_type
index_norm_inf (const vector_expression&lt;E&gt; &amp;e);</code></pre>
<h4>Description</h4>
<p><code>sum</code> computes the sum of the vector expression's
elements. <code>norm_1</code>, <code>norm_2</code> and <code>norm_inf</code>
compute the corresponding <em>||.||</em><sub><em>1</em></sub>, <em>||.||</em><sub><em>2</em></sub>
and <em>||.||</em><sub><em>inf</em></sub> vector norms.<code>
index_norm_1</code> computes the index of the vector expression's
first element having maximal absolute value.</p>
<h4>Definition</h4>
<p>Defined in the header vector_expression.hpp.</p>
<h4>Type requirements</h4>
<dir>
<li><code>E</code> is a model of <a href="#vector_expression">Vector
Expression</a>.</li>
</dir>
<h4>Preconditions</h4>
<p>None.</p>
<h4>Complexity</h4>
<p>Linear depending from the size of the vector expression.</p>
<h4>Examples</h4>
<pre>int main () {
using namespace boost::numeric::ublas;
vector&lt;double&gt; v (3);
for (int i = 0; i &lt; v.size (); ++ i)
v (i) = i;
std::cout &lt;&lt; sum (v) &lt;&lt; std::endl;
std::cout &lt;&lt; norm_1 (v) &lt;&lt; std::endl;
std::cout &lt;&lt; norm_2 (v) &lt;&lt; std::endl;
std::cout &lt;&lt; norm_inf (v) &lt;&lt; std::endl;
std::cout &lt;&lt; index_norm_inf (v) &lt;&lt; std::endl;
}</pre>
<h3>Binary Reductions</h3>
<h4>Prototypes</h4>
<pre><code> template&lt;class E1, class E2, class F&gt;
struct vector_scalar_binary_traits {
typedef typename F::result_type result_type;
};
// inner_prod (v1, v2) = sum (v1 [i] * v2 [i]
template&lt;class E1, class E2&gt;
typename vector_scalar_binary_traits&lt;E1, E2, vector_inner_prod&lt;typename E1::value_type,
typename E2::value_type,
typename promote_traits&lt;typename E1::value_type,
typename E2::value_type&gt;::promote_type&gt; &gt;::result_type
inner_prod (const vector_expression&lt;E1&gt; &amp;e1,
const vector_expression&lt;E2&gt; &amp;e2);
template&lt;class E1, class E2&gt;
typename vector_scalar_binary_traits&lt;E1, E2, vector_inner_prod&lt;typename E1::value_type,
typename E2::value_type,
typename type_traits&lt;typename promote_traits&lt;typename E1::value_type,
typename E2::value_type&gt;::promote_type&gt;::precision_type&gt; &gt;::result_type
prec_inner_prod (const vector_expression&lt;E1&gt; &amp;e1,
const vector_expression&lt;E2&gt; &amp;e2);</code></pre>
<h4>Description</h4>
<p><code>inner_prod </code>computes the inner product of the
vector expressions. <code>prec_inner_prod </code>computes the
double precision inner product of the vector expressions<code>.</code></p>
<h4>Definition</h4>
<p>Defined in the header vector_expression.hpp.</p>
<h4>Type requirements</h4>
<dir>
<li><code>E1</code> is a model of <a
href="#vector_expression">Vector Expression</a>.</li>
<li><code>E2</code> is a model of <a
href="#vector_expression">Vector Expression</a>.</li>
</dir>
<h4>Preconditions</h4>
<dir>
<li><code>e1 ().size () == e2 ().size ()</code></li>
</dir>
<h4>Complexity</h4>
<p>Linear depending from the size of the vector expressions.</p>
<h4>Examples</h4>
<pre>int main () {
using namespace boost::numeric::ublas;
vector&lt;double&gt; v1 (3), v2 (3);
for (int i = 0; i &lt; std::min (v1.size (), v2.size ()); ++ i)
v1 (i) = v2 (i) = i;
std::cout &lt;&lt; inner_prod (v1, v2) &lt;&lt; std::endl;
}</pre>
<hr>
<p>Copyright (<28>) 2000-2002 Joerg Walter, Mathias Koch <br>
Permission to copy, use, modify, sell and distribute this document is granted
provided this copyright notice appears in all copies. This document is provided
``as is'' without express or implied warranty, and with no claim as to its suitability
for any purpose.</p>
<p>Last revised: 8/3/2002</p>
</body>
</html>