1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml">
5 <meta name=
"generator" content=
6 "HTML Tidy for Linux/x86 (vers 1st March 2004), see www.w3.org" />
7 <meta http-equiv=
"Content-Type" content=
8 "text/html; charset=us-ascii" />
9 <link rel=
"stylesheet" href=
"../../../../boost.css" type=
"text/css"/>
10 <link rel=
"stylesheet" href=
"ublas.css" type=
"text/css" />
11 <script type=
"text/javascript" src=
"js/jquery-1.3.2.min.js" async=
"async" ></script>
12 <script type=
"text/javascript" src=
"js/jquery.toc-gw.js" async=
"async" ></script>
13 <title>Vector Expressions
</title>
16 <h1><img src=
"../../../../boost.png" align=
"middle" />Vector Expressions
</h1>
17 <div class=
"toc" id=
"toc"></div>
18 <h2><a name=
"vector_expression"></a>Vector Expression
</h2>
20 <p>The templated class
<code>vector_expression
<E
></code>
21 is required to be a public base of all classes which model the Vector Expression concept.
</p>
23 <p>Defined in the header expression_types.hpp.
</p>
24 <h4>Template parameters
</h4>
25 <table border=
"1" summary=
"parameters">
33 <td><code>E
</code></td>
34 <td>The type of the vector expression.
</td>
40 <p>None.
<u>Not a Vector Expression
</u>!
42 <h4>Type requirements
</h4>
44 <h4>Public base classes
</h4>
47 <table border=
"1" summary=
"members">
54 <td><code>const expression_type
&operator () ()
56 <td>Returns a
<code>const
</code> reference of the expression.
</td>
59 <td><code>expression_type
&operator () ()
</code></td>
60 <td>Returns a reference of the expression.
</td>
65 <p>The
<code>range
</code>,
<code>slice
</code> and
<code>project
</code> functions have been removed. Use the free functions defined in
<a href=
"vector_proxy.html">vector proxy
</a> instead.
</p>
67 <h2><a name=
"vector_container"></a>Vector Container
</h2>
69 <p>The templated class
<code>vector_container
<C
></code>
70 is required to be a public base of all classes which model the Vector concept.
71 This includes the class
<code>vector
</code> itself.
</p>
73 <p>Defined in the header expression_types.hpp.
</p>
74 <h4>Template parameters
</h4>
75 <table border=
"1" summary=
"parameters">
83 <td><code>C
</code></td>
84 <td>The type of the vector container.
</td>
90 <p>None.
<u>Not a Vector Expression OR Vector
</u>!
92 <h4>Type requirements
</h4>
94 <h4>Public base classes
</h4>
95 <p><code>vector_expression
<C
></code></p>
97 <table border=
"1" summary=
"members">
104 <td><code>const container_type
&operator () ()
106 <td>Returns a
<code>const
</code> reference of the container.
</td>
109 <td><code>container_type
&operator () ()
</code></td>
110 <td>Returns a reference of the container.
</td>
115 <h2><a name=
"vector_references"></a>Vector References
</h2>
118 <p>The templated class
<code>vector_reference
<E
></code>
119 contains a reference to a vector expression.
</p>
121 <p>Defined in the header vector_expression.hpp.
</p>
122 <h4>Template parameters
</h4>
123 <table border=
"1" summary=
"parameters">
131 <td><code>E
</code></td>
132 <td>The type of the vector expression.
</td>
138 <p><a href=
"expression_concept.html#vector_expression">Vector Expression
</a>
140 <h4>Type requirements
</h4>
141 <p>None, except for those imposed by the requirements of
<a href=
142 "expression_concept.html#vector_expression">Vector Expression
</a> .
</p>
143 <h4>Public base classes
</h4>
144 <p><code>vector_expression
<vector_reference
<E
>
147 <table border=
"1" summary=
"members">
154 <td><code>vector_reference (expression_type
&e)
</code></td>
155 <td>Constructs a reference of the expression.
</td>
158 <td><code>void resize (size_type size)
</code></td>
159 <td>Resizes the expression to hold at most
<code>size
</code>
163 <td><code>size_type size () const
</code></td>
164 <td>Returns the size of the expression.
</td>
167 <td><code>const_reference operator () (size_type i)
169 <td>Returns the value of the
<code>i
</code>-th element.
</td>
172 <td><code>reference operator () (size_type i)
</code></td>
173 <td>Returns a reference of the
<code>i
</code>-th element.
</td>
176 <td><code>const_iterator begin () const
</code></td>
177 <td>Returns a
<code>const_iterator
</code> pointing to the beginning
178 of the expression.
</td>
181 <td><code>const_iterator end () const
</code></td>
182 <td>Returns a
<code>const_iterator
</code> pointing to the end of
186 <td><code>iterator begin ()
</code></td>
187 <td>Returns a
<code>iterator
</code> pointing to the beginning of
191 <td><code>iterator end ()
</code></td>
192 <td>Returns a
<code>iterator
</code> pointing to the end of the
196 <td><code>const_reverse_iterator rbegin () const
</code></td>
197 <td>Returns a
<code>const_reverse_iterator
</code> pointing to the
198 beginning of the reversed expression.
</td>
201 <td><code>const_reverse_iterator rend () const
</code></td>
202 <td>Returns a
<code>const_reverse_iterator
</code> pointing to the
203 end of the reversed expression.
</td>
206 <td><code>reverse_iterator rbegin ()
</code></td>
207 <td>Returns a
<code>reverse_iterator
</code> pointing to the
208 beginning of the reversed expression.
</td>
211 <td><code>reverse_iterator rend ()
</code></td>
212 <td>Returns a
<code>reverse_iterator
</code> pointing to the end of
213 the reversed expression.
</td>
217 <h2><a name=
"vector_operations"></a>Vector Operations
</h2>
218 <h3>Unary Operation Description
</h3>
220 <p>The templated class
<code>vector_unary
<E, F
></code>
221 describes a unary vector operation.
</p>
223 <p>Defined in the header vector_expression.hpp.
</p>
224 <h4>Template parameters
</h4>
225 <table border=
"1" summary=
"parameters">
233 <td><code>E
</code></td>
234 <td>The type of the vector expression.
</td>
238 <td><code>F
</code></td>
239 <td>The type of the operation.
</td>
245 <p><a href=
"expression_concept.html#vector_expression">Vector Expression
</a>
247 <h4>Type requirements
</h4>
248 <p>None, except for those imposed by the requirements of
<a href=
249 "expression_concept.html#vector_expression">Vector Expression
</a> .
</p>
250 <h4>Public base classes
</h4>
251 <p><code>vector_expression
<vector_unary
<E, F
>
254 <table border=
"1" summary=
"members">
261 <td><code>vector_unary (const expression_type
&e)
</code></td>
262 <td>Constructs a description of the expression.
</td>
265 <td><code>size_type size () const
</code></td>
266 <td>Returns the size of the expression.
</td>
269 <td><code>const_reference operator () (size_type i)
271 <td>Returns the value of the
<code>i
</code>-th element.
</td>
274 <td><code>const_iterator begin () const
</code></td>
275 <td>Returns a
<code>const_iterator
</code> pointing to the beginning
276 of the expression.
</td>
279 <td><code>const_iterator end () const
</code></td>
280 <td>Returns a
<code>const_iterator
</code> pointing to the end of
284 <td><code>const_reverse_iterator rbegin () const
</code></td>
285 <td>Returns a
<code>const_reverse_iterator
</code> pointing to the
286 beginning of the reversed expression.
</td>
289 <td><code>const_reverse_iterator rend () const
</code></td>
290 <td>Returns a
<code>const_reverse_iterator
</code> pointing to the
291 end of the reversed expression.
</td>
295 <h3>Unary Operations
</h3>
298 <code>template
<class E, class F
>
299 struct vector_unary_traits {
300 typedef vector_unary
<typename E::const_closure_type, F
> expression_type;
301 typedef expression_type result_type;
304 // (- v) [i] = - v [i]
305 template
<class E
>
306 typename vector_unary_traits
<E, scalar_negate
<typename E::value_type
> >::result_type
307 operator - (const vector_expression
<E
> &e);
309 // (conj v) [i] = conj (v [i])
310 template
<class E
>
311 typename vector_unary_traits
<E, scalar_conj
<typename E::value_type
> >::result_type
312 conj (const vector_expression
<E
> &e);
314 // (real v) [i] = real (v [i])
315 template
<class E
>
316 typename vector_unary_traits
<E, scalar_real
<typename E::value_type
> >::result_type
317 real (const vector_expression
<E
> &e);
319 // (imag v) [i] = imag (v [i])
320 template
<class E
>
321 typename vector_unary_traits
<E, scalar_imag
<typename E::value_type
> >::result_type
322 imag (const vector_expression
<E
> &e);
324 // (trans v) [i] = v [i]
325 template
<class E
>
326 typename vector_unary_traits
<E, scalar_identity
<typename E::value_type
> >::result_type
327 trans (const vector_expression
<E
> &e);
329 // (herm v) [i] = conj (v [i])
330 template
<class E
>
331 typename vector_unary_traits
<E, scalar_conj
<typename E::value_type
> >::result_type
332 herm (const vector_expression
<E
> &e);
</code>
335 <p><code>operator -
</code> computes the additive inverse of a
336 vector expression.
<code>conj
</code> computes the complex conjugate
337 of a vector expression.
<code>real
</code> and
<code>imag
</code>
338 compute the real and imaginary parts of a vector expression.
339 <code>trans
</code> computes the transpose of a vector expression.
340 <code>herm
</code> computes the hermitian, i.e. the complex
341 conjugate of the transpose of a vector expression.
</p>
343 <p>Defined in the header vector_expression.hpp.
</p>
344 <h4>Type requirements
</h4>
346 <li><code>E
</code> is a model of
<a href=
347 "expression_concept.html#vector_expression">Vector Expression
</a> .
</li>
349 <h4>Preconditions
</h4>
352 <p>Linear depending from the size of the vector expression.
</p>
355 #include
<boost/numeric/ublas/vector.hpp
>
356 #include
<boost/numeric/ublas/io.hpp
>
359 using namespace boost::numeric::ublas;
360 vector
<std::complex
<double
> > v (
3);
361 for (unsigned i =
0; i
< v.size (); ++ i)
362 v (i) = std::complex
<double
> (i, i);
364 std::cout
<< - v
<< std::endl;
365 std::cout
<< conj (v)
<< std::endl;
366 std::cout
<< real (v)
<< std::endl;
367 std::cout
<< imag (v)
<< std::endl;
368 std::cout
<< trans (v)
<< std::endl;
369 std::cout
<< herm (v)
<< std::endl;
372 <h3>Binary Operation Description
</h3>
374 <p>The templated class
<code>vector_binary
<E1, E2, F
></code>
375 describes a binary vector operation.
</p>
377 <p>Defined in the header vector_expression.hpp.
</p>
378 <h4>Template parameters
</h4>
379 <table border=
"1" summary=
"parameters">
387 <td><code>E1
</code></td>
388 <td>The type of the first vector expression.
</td>
392 <td><code>E2
</code></td>
393 <td>The type of the second vector expression.
</td>
397 <td><code>F
</code></td>
398 <td>The type of the operation.
</td>
404 <p><a href=
"expression_concept.html#vector_expression">Vector Expression
</a>
406 <h4>Type requirements
</h4>
407 <p>None, except for those imposed by the requirements of
<a href=
408 "expression_concept.html#vector_expression">Vector Expression
</a> .
</p>
409 <h4>Public base classes
</h4>
410 <p><code>vector_expression
<vector_binary
<E1, E2, F
>
413 <table border=
"1" summary=
"members">
420 <td><code>vector_binary (const expression1_type
&e1, const
421 expression2_type
&e2)
</code></td>
422 <td>Constructs a description of the expression.
</td>
425 <td><code>size_type size () const
</code></td>
426 <td>Returns the size of the expression.
</td>
429 <td><code>const_reference operator () (size_type i)
431 <td>Returns the value of the
<code>i
</code>-th element.
</td>
434 <td><code>const_iterator begin () const
</code></td>
435 <td>Returns a
<code>const_iterator
</code> pointing to the beginning
436 of the expression.
</td>
439 <td><code>const_iterator end () const
</code></td>
440 <td>Returns a
<code>const_iterator
</code> pointing to the end of
444 <td><code>const_reverse_iterator rbegin () const
</code></td>
445 <td>Returns a
<code>const_reverse_iterator
</code> pointing to the
446 beginning of the reversed expression.
</td>
449 <td><code>const_reverse_iterator rend () const
</code></td>
450 <td>Returns a
<code>const_reverse_iterator
</code> pointing to the
451 end of the reversed expression.
</td>
455 <h3>Binary Operations
</h3>
458 <code>template
<class E1, class E2, class F
>
459 struct vector_binary_traits {
460 typedef vector_binary
<typename E1::const_closure_type,
461 typename E2::const_closure_type, F
> expression_type;
462 typedef expression_type result_type;
465 // (v1 + v2) [i] = v1 [i] + v2 [i]
466 template
<class E1, class E2
>
467 typename vector_binary_traits
<E1, E2, scalar_plus
<typename E1::value_type,
468 typename E2::value_type
> >::result_type
469 operator + (const vector_expression
<E1
> &e1,
470 const vector_expression
<E2
> &e2);
472 // (v1 - v2) [i] = v1 [i] - v2 [i]
473 template
<class E1, class E2
>
474 typename vector_binary_traits
<E1, E2, scalar_minus
<typename E1::value_type,
475 typename E2::value_type
> >::result_type
476 operator - (const vector_expression
<E1
> &e1,
477 const vector_expression
<E2
> &e2);
</code>
480 <p><code>operator +
</code> computes the sum of two vector
481 expressions.
<code>operator -
</code> computes the difference of two
482 vector expressions.
</p>
484 <p>Defined in the header vector_expression.hpp.
</p>
485 <h4>Type requirements
</h4>
487 <li><code>E1
</code> is a model of
<a href=
488 "expression_concept.html#vector_expression">Vector Expression
</a> .
</li>
489 <li><code>E2
</code> is a model of
<a href=
490 "expression_concept.html#vector_expression">Vector Expression
</a> .
</li>
492 <h4>Preconditions
</h4>
494 <li><code>e1 ().size () == e2 ().size ()
</code></li>
497 <p>Linear depending from the size of the vector expressions.
</p>
500 #include
<boost/numeric/ublas/vector.hpp
>
501 #include
<boost/numeric/ublas/io.hpp
>
504 using namespace boost::numeric::ublas;
505 vector
<double
> v1 (
3), v2 (
3);
506 for (unsigned i =
0; i
< std::min (v1.size (), v2.size ()); ++ i)
509 std::cout
<< v1 + v2
<< std::endl;
510 std::cout
<< v1 - v2
<< std::endl;
513 <h3>Binary Outer Operation Description
</h3>
515 <p>The templated class
<code>vector_matrix_binary
<E1, E2,
516 F
></code> describes a binary outer vector operation.
</p>
518 <p>Defined in the header matrix_expression.hpp.
</p>
519 <h4>Template parameters
</h4>
520 <table border=
"1" summary=
"parameters">
528 <td><code>E1
</code></td>
529 <td>The type of the first vector expression.
</td>
533 <td><code>E2
</code></td>
534 <td>The type of the second vector expression.
</td>
538 <td><code>F
</code></td>
539 <td>The type of the operation.
</td>
545 <p><a href=
"expression_concept.html#matrix_expression">Matrix Expression
</a>
547 <h4>Type requirements
</h4>
548 <p>None, except for those imposed by the requirements of
<a href=
549 "expression_concept.html#matrix_expression">Matrix Expression
</a> .
</p>
550 <h4>Public base classes
</h4>
551 <p><code>matrix_expression
<vector_matrix_binary
<E1, E2, F
>
554 <table border=
"1" summary=
"members">
561 <td><code>vector_matrix_binary (const expression1_type
&e1,
562 const expression2_type
&e2)
</code></td>
563 <td>Constructs a description of the expression.
</td>
566 <td><code>size_type size1 () const
</code></td>
567 <td>Returns the number of rows.
</td>
570 <td><code>size_type size2 () const
</code></td>
571 <td>Returns the number of columns.
</td>
574 <td><code>const_reference operator () (size_type i, size_type j)
576 <td>Returns the value of the
<code>j
</code>-th element in the
577 <code>i
</code>-th row.
</td>
580 <td><code>const_iterator1 begin1 () const
</code></td>
581 <td>Returns a
<code>const_iterator1
</code> pointing to the
582 beginning of the expression.
</td>
585 <td><code>const_iterator1 end1 () const
</code></td>
586 <td>Returns a
<code>const_iterator1
</code> pointing to the end of
590 <td><code>const_iterator2 begin2 () const
</code></td>
591 <td>Returns a
<code>const_iterator2
</code> pointing to the
592 beginning of the expression.
</td>
595 <td><code>const_iterator2 end2 () const
</code></td>
596 <td>Returns a
<code>const_iterator2
</code> pointing to the end of
600 <td><code>const_reverse_iterator1 rbegin1 () const
</code></td>
601 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
602 beginning of the reversed expression.
</td>
605 <td><code>const_reverse_iterator1 rend1 () const
</code></td>
606 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
607 end of the reversed expression.
</td>
610 <td><code>const_reverse_iterator2 rbegin2 () const
</code></td>
611 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
612 beginning of the reversed expression.
</td>
615 <td><code>const_reverse_iterator2 rend2 () const
</code></td>
616 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
617 end of the reversed expression.
</td>
621 <h3>Binary Outer Operations
</h3>
624 <code>template
<class E1, class E2, class F
>
625 struct vector_matrix_binary_traits {
626 typedef vector_matrix_binary
<typename E1::const_closure_type,
627 typename E2::const_closure_type, F
> expression_type;
628 typedef expression_type result_type;
631 // (outer_prod (v1, v2)) [i] [j] = v1 [i] * v2 [j]
632 template
<class E1, class E2
>
633 typename vector_matrix_binary_traits
<E1, E2, scalar_multiplies
<typename E1::value_type, typename E2::value_type
> >::result_type
634 outer_prod (const vector_expression
<E1
> &e1,
635 const vector_expression
<E2
> &e2);
</code>
638 <p><code>outer_prod
</code> computes the outer product of two vector
641 <p>Defined in the header matrix_expression.hpp.
</p>
642 <h4>Type requirements
</h4>
644 <li><code>E1
</code> is a model of
<a href=
645 "expression_concept.html#vector_expression">Vector Expression
</a> .
</li>
646 <li><code>E2
</code> is a model of
<a href=
647 "expression_concept.html#vector_expression">Vector Expression
</a> .
</li>
649 <h4>Preconditions
</h4>
652 <p>Quadratic depending from the size of the vector expressions.
</p>
655 #include
<boost/numeric/ublas/matrix.hpp
>
656 #include
<boost/numeric/ublas/io.hpp
>
659 using namespace boost::numeric::ublas;
660 vector
<double
> v1 (
3), v2 (
3);
661 for (unsigned i =
0; i
< std::min (v1.size (), v2.size ()); ++ i)
664 std::cout
<< outer_prod (v1, v2)
<< std::endl;
667 <h3>Scalar Vector Operation Description
</h3>
669 <p>The templated classes
<code>vector_binary_scalar1
<E1, E2,
670 F
></code> and
<code>vector_binary_scalar2
<E1, E2,
671 F
></code> describe binary operations between a scalar and a
674 <p>Defined in the header vector_expression.hpp.
</p>
675 <h4>Template parameters
</h4>
676 <table border=
"1" summary=
"parameters">
684 <td><code>E1/E2
</code></td>
685 <td>The type of the scalar expression.
</td>
689 <td><code>E2/E1
</code></td>
690 <td>The type of the vector expression.
</td>
694 <td><code>F
</code></td>
695 <td>The type of the operation.
</td>
701 <p><a href=
"expression_concept.html#vector_expression">Vector Expression
</a>
703 <h4>Type requirements
</h4>
704 <p>None, except for those imposed by the requirements of
<a href=
705 "expression_concept.html#vector_expression">Vector Expression
</a> .
</p>
706 <h4>Public base classes
</h4>
707 <p><code>vector_expression
<vector_binary_scalar1
<E1, E2,
708 F
> ></code> and
709 <code>vector_expression
<vector_binary_scalar2
<E1, E2, F
>
710 ></code> resp.
</p>
712 <table border=
"1" summary=
"members">
719 <td><code>vector_binary_scalar1 (const expression1_type
&e1,
720 const expression2_type
&e2)
</code></td>
721 <td>Constructs a description of the expression.
</td>
724 <td><code>vector_binary_scalar2 (const expression1_type
&e1,
725 const expression2_type
&e2)
</code></td>
726 <td>Constructs a description of the expression.
</td>
729 <td><code>size_type size () const
</code></td>
730 <td>Returns the size of the expression.
</td>
733 <td><code>const_reference operator () (size_type i)
735 <td>Returns the value of the
<code>i
</code>-th element.
</td>
738 <td><code>const_iterator begin () const
</code></td>
739 <td>Returns a
<code>const_iterator
</code> pointing to the beginning
740 of the expression.
</td>
743 <td><code>const_iterator end () const
</code></td>
744 <td>Returns a
<code>const_iterator
</code> pointing to the end of
748 <td><code>const_reverse_iterator rbegin () const
</code></td>
749 <td>Returns a
<code>const_reverse_iterator
</code> pointing to the
750 beginning of the reversed expression.
</td>
753 <td><code>const_reverse_iterator rend () const
</code></td>
754 <td>Returns a
<code>const_reverse_iterator
</code> pointing to the
755 end of the reversed expression.
</td>
759 <h3>Scalar Vector Operations
</h3>
762 <code>template
<class T1, class E2, class F
>
763 struct vector_binary_scalar1_traits {
764 typedef vector_binary_scalar1
<scalar_const_reference
<T1
>,
765 typename E2::const_closure_type, F
> expression_type;
766 typedef expression_type result_type;
769 // (t * v) [i] = t * v [i]
770 template
<class T1, class E2
>
771 typename vector_binary_scalar1_traits
<T1, E2, scalar_multiplies
<T1, typename E2::value_type
> >::result_type
772 operator * (const T1
&e1,
773 const vector_expression
<E2
> &e2);
775 template
<class E1, class T2, class F
>
776 struct vector_binary_scalar2_traits {
777 typedef vector_binary_scalar2
<typename E1::const_closure_type,
778 scalar_const_reference
<T2
>, F
> expression_type;
779 typedef expression_type result_type;
782 // (v * t) [i] = v [i] * t
783 template
<class E1, class T2
>
784 typename vector_binary_scalar2_traits
<E1, T2, scalar_multiplies
<typename E1::value_type, T2
> >::result_type
785 operator * (const vector_expression
<E1
> &e1,
788 // (v / t) [i] = v [i] / t
789 template
<class E1, class T2
>
790 typename vector_binary_scalar2_traits
<E1, T2, scalar_divides
<typename E1::value_type, T2
> >::result_type
791 operator / (const vector_expression
<E1
> &e1,
792 const T2
&e2);
</code>
795 <p><code>operator *
</code> computes the product of a scalar and a
796 vector expression.
<code>operator /
</code> multiplies the vector
797 with the reciprocal of the scalar.
</p>
799 <p>Defined in the header vector_expression.hpp.
</p>
800 <h4>Type requirements
</h4>
802 <li><code>T1/T2
</code> is a model of
<a href=
803 "expression_concept.html#scalar_expression">Scalar Expression
</a> .
</li>
804 <li><code>E2/E1
</code> is a model of
<a href=
805 "expression_concept.html#vector_expression">Vector Expression
</a> .
</li>
807 <h4>Preconditions
</h4>
810 <p>Linear depending from the size of the vector expression.
</p>
813 #include
<boost/numeric/ublas/vector.hpp
>
814 #include
<boost/numeric/ublas/io.hpp
>
817 using namespace boost::numeric::ublas;
818 vector
<double
> v (
3);
819 for (unsigned i =
0; i
< v.size (); ++ i)
822 std::cout
<< 2.0 * v
<< std::endl;
823 std::cout
<< v *
2.0 << std::endl;
826 <h2><a name=
"vector_reductions"></a>Vector Reductions
</h2>
827 <h3>Unary Reductions
</h3>
830 <code>template
<class E, class F
>
831 struct vector_scalar_unary_traits {
832 typedef typename F::result_type result_type;
835 // sum v = sum (v [i])
836 template
<class E
>
837 typename vector_scalar_unary_traits
<E, vector_sum
<typename E::value_type
> >::result_type
838 sum (const vector_expression
<E
> &e);
840 // norm_1 v = sum (abs (v [i]))
841 template
<class E
>
842 typename vector_scalar_unary_traits
<E, vector_norm_1
<typename E::value_type
> >::result_type
843 norm_1 (const vector_expression
<E
> &e);
845 // norm_2 v = sqrt (sum (v [i] * v [i]))
846 template
<class E
>
847 typename vector_scalar_unary_traits
<E, vector_norm_2
<typename E::value_type
> >::result_type
848 norm_2 (const vector_expression
<E
> &e);
850 // norm_inf v = max (abs (v [i]))
851 template
<class E
>
852 typename vector_scalar_unary_traits
<E, vector_norm_inf
<typename E::value_type
> >::result_type
853 norm_inf (const vector_expression
<E
> &e);
855 // index_norm_inf v = min (i: abs (v [i]) == max (abs (v [i])))
856 template
<class E
>
857 typename vector_scalar_unary_traits
<E, vector_index_norm_inf
<typename E::value_type
> >::result_type
858 index_norm_inf (const vector_expression
<E
> &e);
</code>
861 <p><code>sum
</code> computes the sum of the vector expression's
862 elements.
<code>norm_1
</code>,
<code>norm_2
</code> and
863 <code>norm_inf
</code> compute the corresponding
864 <em>||.||
</em><sub><em>1</em></sub>,
865 <em>||.||
</em><sub><em>2</em></sub> and
866 <em>||.||
</em><sub><em>inf
</em></sub> vector norms.
867 <code>index_norm_1
</code> computes the index of the vector
868 expression's first element having maximal absolute value.
</p>
870 <p>Defined in the header vector_expression.hpp.
</p>
871 <h4>Type requirements
</h4>
873 <li><code>E
</code> is a model of
<a href=
874 "#vector_expression">Vector Expression
</a> .
</li>
876 <h4>Preconditions
</h4>
879 <p>Linear depending from the size of the vector expression.
</p>
882 #include
<boost/numeric/ublas/vector.hpp
>
885 using namespace boost::numeric::ublas;
886 vector
<double
> v (
3);
887 for (unsigned i =
0; i
< v.size (); ++ i)
890 std::cout
<< sum (v)
<< std::endl;
891 std::cout
<< norm_1 (v)
<< std::endl;
892 std::cout
<< norm_2 (v)
<< std::endl;
893 std::cout
<< norm_inf (v)
<< std::endl;
894 std::cout
<< index_norm_inf (v)
<< std::endl;
897 <h3>Binary Reductions
</h3>
900 <code>template
<class E1, class E2, class F
>
901 struct vector_scalar_binary_traits {
902 typedef typename F::result_type result_type;
905 // inner_prod (v1, v2) = sum (v1 [i] * v2 [i])
906 template
<class E1, class E2
>
907 typename vector_scalar_binary_traits
<E1, E2, vector_inner_prod
<typename E1::value_type,
908 typename E2::value_type,
909 typename promote_traits
<typename E1::value_type,
910 typename E2::value_type
>::promote_type
> >::result_type
911 inner_prod (const vector_expression
<E1
> &e1,
912 const vector_expression
<E2
> &e2);
914 template
<class E1, class E2
>
915 typename vector_scalar_binary_traits
<E1, E2, vector_inner_prod
<typename E1::value_type,
916 typename E2::value_type,
917 typename type_traits
<typename promote_traits
<typename E1::value_type,
918 typename E2::value_type
>::promote_type
>::precision_type
> >::result_type
919 prec_inner_prod (const vector_expression
<E1
> &e1,
920 const vector_expression
<E2
> &e2);
</code>
923 <p><code>inner_prod
</code> computes the inner product of the vector
924 expressions.
<code>prec_inner_prod
</code> computes the double
925 precision inner product of the vector expressions
<code>.
</code></p>
927 <p>Defined in the header vector_expression.hpp.
</p>
928 <h4>Type requirements
</h4>
930 <li><code>E1
</code> is a model of
<a href=
931 "#vector_expression">Vector Expression
</a> .
</li>
932 <li><code>E2
</code> is a model of
<a href=
933 "#vector_expression">Vector Expression
</a> .
</li>
935 <h4>Preconditions
</h4>
937 <li><code>e1 ().size () == e2 ().size ()
</code></li>
940 <p>Linear depending from the size of the vector expressions.
</p>
943 #include
<boost/numeric/ublas/vector.hpp
>
946 using namespace boost::numeric::ublas;
947 vector
<double
> v1 (
3), v2 (
3);
948 for (unsigned i =
0; i
< std::min (v1.size (), v2.size ()); ++ i)
951 std::cout
<< inner_prod (v1, v2)
<< std::endl;
955 <p>Copyright (
©)
2000-
2002 Joerg Walter, Mathias Koch
<br />
956 Use, modification and distribution are subject to the
957 Boost Software License, Version
1.0.
958 (See accompanying file LICENSE_1_0.txt
959 or copy at
<a href=
"http://www.boost.org/LICENSE_1_0.txt">
960 http://www.boost.org/LICENSE_1_0.txt
963 <script type=
"text/javascript">