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>Matrix Expressions
</title>
16 <h1><img src=
"../../../../boost.png" align=
"middle" />Matrix Expressions
</h1>
17 <div class=
"toc" id=
"toc"></div>
18 <h2><a name=
"matrix_expression"></a>Matrix Expression
</h2>
20 <p>The templated class
<code>matrix_expression
<E
></code>
21 is required to be a public base of all classes which model the Matrix 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 matrix expression.
</td>
40 <p>None.
<u>Not a Matrix 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>operator[]
</code>,
<code>row
</code>,
<code>column
</code>,
<code>range
</code>,
<code>slice
</code> and
<code>project
</code> functions have been removed. Use the free functions defined in
<a href=
"matrix_proxy.html">matrix proxy
</a> instead.
</p>
66 <h2><a name=
"matrix_container"></a>Matrix Container
</h2>
68 <p>The templated class
<code>matrix_container
<C
></code>
69 is required to be a public base of all classes which model the Matrix concept.
70 This includes the class
<code>matrix
</code> itself.
</p>
72 <p>Defined in the header expression_types.hpp.
</p>
73 <h4>Template parameters
</h4>
74 <table border=
"1" summary=
"parameters">
82 <td><code>E
</code></td>
83 <td>The type of the matrix expression.
</td>
89 <p>None.
<u>Not a Matrix Expression OR Matrix
</u>!
91 <h4>Type requirements
</h4>
93 <h4>Public base classes
</h4>
94 <p><code>matrix_expression
<C
></code></p>
96 <table border=
"1" summary=
"members">
103 <td><code>const container_type
&operator () ()
105 <td>Returns a
<code>const
</code> reference of the container.
</td>
108 <td><code>container_type
&operator () ()
</code></td>
109 <td>Returns a reference of the container.
</td>
113 <h2><a name=
"matrix_references"></a>Matrix References
</h2>
116 <p>The templated class
<code>matrix_reference
<E
></code>
117 contains a reference to a matrix expression.
</p>
119 <p>Defined in the header matrix_expression.hpp.
</p>
120 <h4>Template parameters
</h4>
121 <table border=
"1" summary=
"parameters">
129 <td><code>E
</code></td>
130 <td>The type of the matrix expression.
</td>
136 <p><a href=
"expression_concept.html#matrix_expression">Matrix Expression
</a>
138 <h4>Type requirements
</h4>
139 <p>None, except for those imposed by the requirements of
<a href=
140 "expression_concept.html#matrix_expression">Matrix Expression
</a> .
</p>
141 <h4>Public base classes
</h4>
142 <p><code>matrix_expression
<matrix_reference
<E
>
145 <table border=
"1" summary=
"members">
152 <td><code>matrix_reference (expression_type
&e)
</code></td>
153 <td>Constructs a constant reference of the expression.
</td>
156 <td><code>void resize (size_type size1, size2)
</code></td>
157 <td>Resizes the expression to hold at most
<code>size1
</code> rows
158 of
<code>size2
</code> elements.
</td>
161 <td><code>size_type size1 () const
</code></td>
162 <td>Returns the number of rows.
</td>
165 <td><code>size_type size2 () const
</code></td>
166 <td>Returns the number of columns.
</td>
169 <td><code>const_reference operator () (size_type i, size_type j)
171 <td>Returns the value of the
<code>j
</code>-th element in the
172 <code>i
</code>-th row.
</td>
175 <td><code>reference operator () (size_type i, size_type
177 <td>Returns a reference of the
<code>j
</code>-th element in the
178 <code>i
</code>-th row.
</td>
181 <td><code>const_iterator1 begin1 () const
</code></td>
182 <td>Returns a
<code>const_iterator1
</code> pointing to the
183 beginning of the expression.
</td>
186 <td><code>const_iterator1 end1 () const
</code></td>
187 <td>Returns a
<code>const_iterator1
</code> pointing to the end of
191 <td><code>iterator1 begin1 ()
</code></td>
192 <td>Returns a
<code>iterator1
</code> pointing to the beginning of
196 <td><code>iterator1 end1 ()
</code></td>
197 <td>Returns a
<code>iterator1
</code> pointing to the end of the
201 <td><code>const_iterator2 begin2 () const
</code></td>
202 <td>Returns a
<code>const_iterator2
</code> pointing to the
203 beginning of the expression.
</td>
206 <td><code>const_iterator2 end2 () const
</code></td>
207 <td>Returns a
<code>const_iterator2
</code> pointing to the end of
211 <td><code>iterator2 begin2 ()
</code></td>
212 <td>Returns a
<code>iterator2
</code> pointing to the beginning of
216 <td><code>iterator2 end2 ()
</code></td>
217 <td>Returns a
<code>iterator2
</code> pointing to the end of the
221 <td><code>const_reverse_iterator1 rbegin1 () const
</code></td>
222 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
223 beginning of the reversed expression.
</td>
226 <td><code>const_reverse_iterator1 rend1 () const
</code></td>
227 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
228 end of the reversed expression.
</td>
231 <td><code>reverse_iterator1 rbegin1 ()
</code></td>
232 <td>Returns a
<code>reverse_iterator1
</code> pointing to the
233 beginning of the reversed expression.
</td>
236 <td><code>reverse_iterator1 rend1 ()
</code></td>
237 <td>Returns a
<code>reverse_iterator1
</code> pointing to the end of
238 the reversed expression.
</td>
241 <td><code>const_reverse_iterator2 rbegin2 () const
</code></td>
242 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
243 beginning of the reversed expression.
</td>
246 <td><code>const_reverse_iterator2 rend2 () const
</code></td>
247 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
248 end of the reversed expression.
</td>
251 <td><code>reverse_iterator2 rbegin2 ()
</code></td>
252 <td>Returns a
<code>reverse_iterator2
</code> pointing to the
253 beginning of the reversed expression.
</td>
256 <td><code>reverse_iterator2 rend2 ()
</code></td>
257 <td>Returns a
<code>reverse_iterator2
</code> pointing to the end of
258 the reversed expression.
</td>
262 <h2><a name=
"matrix_operations"></a>Matrix Operations
</h2>
263 <h3>Unary Operation Description
</h3>
265 <p>The templated classes
<code>matrix_unary1
<E, F
></code> and
266 <code>matrix_unary2
<E, F
></code> describe unary matrix
269 <p>Defined in the header matrix_expression.hpp.
</p>
270 <h4>Template parameters
</h4>
271 <table border=
"1" summary=
"parameters">
279 <td><code>E
</code></td>
280 <td>The type of the matrix expression.
</td>
284 <td><code>F
</code></td>
285 <td>The type of the operation.
</td>
291 <p><a href=
"expression_concept.html#matrix_expression">Matrix Expression
</a>
293 <h4>Type requirements
</h4>
294 <p>None, except for those imposed by the requirements of
<a href=
295 "expression_concept.html#matrix_expression">Matrix Expression
</a> .
</p>
296 <h4>Public base classes
</h4>
297 <p><code>matrix_expression
<matrix_unary1
<E, F
> ></code>
298 and
<code>matrix_expression
<matrix_unary2
<E, F
>
299 ></code> resp.
</p>
301 <table border=
"1" summary=
"members">
308 <td><code>matrix_unary1 (const expression_type
&e)
</code></td>
309 <td>Constructs a description of the expression.
</td>
312 <td><code>matrix_unary2 (const expression_type
&e)
</code></td>
313 <td>Constructs a description of the expression.
</td>
316 <td><code>size_type size1 () const
</code></td>
317 <td>Returns the number of rows.
</td>
320 <td><code>size_type size2 () const
</code></td>
321 <td>Returns the number of columns.
</td>
324 <td><code>const_reference operator () (size_type i, size_type j)
326 <td>Returns the value of the
<code>j
</code>-th element in the
327 <code>i
</code>-th row.
</td>
330 <td><code>const_iterator1 begin1 () const
</code></td>
331 <td>Returns a
<code>const_iterator1
</code> pointing to the
332 beginning of the expression.
</td>
335 <td><code>const_iterator1 end1 () const
</code></td>
336 <td>Returns a
<code>const_iterator1
</code> pointing to the end of
340 <td><code>const_iterator2 begin2 () const
</code></td>
341 <td>Returns a
<code>const_iterator2
</code> pointing to the
342 beginning of the expression.
</td>
345 <td><code>const_iterator2 end2 () const
</code></td>
346 <td>Returns a
<code>const_iterator2
</code> pointing to the end of
350 <td><code>const_reverse_iterator1 rbegin1 () const
</code></td>
351 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
352 beginning of the reversed expression.
</td>
355 <td><code>const_reverse_iterator1 rend1 () const
</code></td>
356 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
357 end of the reversed expression.
</td>
360 <td><code>const_reverse_iterator2 rbegin2 () const
</code></td>
361 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
362 beginning of the reversed expression.
</td>
365 <td><code>const_reverse_iterator2 rend2 () const
</code></td>
366 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
367 end of the reversed expression.
</td>
371 <h3>Unary Operations
</h3>
374 <code>template
<class E, class F
>
375 struct matrix_unary1_traits {
376 typedef matrix_unary1
<typename E::const_closure_type, F
> expression_type;
377 typedef expression_type result_type;
380 // (- m) [i] [j] = - m [i] [j]
381 template
<class E
>
382 typename matrix_unary1_traits
<E, scalar_negate
<typename E::value_type
> >::result_type
383 operator - (const matrix_expression
<E
> &e);
385 // (conj m) [i] [j] = conj (m [i] [j])
386 template
<class E
>
387 typename matrix_unary1_traits
<E, scalar_conj
<typename E::value_type
> >::result_type
388 conj (const matrix_expression
<E
> &e);
390 // (real m) [i] [j] = real (m [i] [j])
391 template
<class E
>
392 typename matrix_unary1_traits
<E, scalar_real
<typename E::value_type
> >::result_type
393 real (const matrix_expression
<E
> &e);
395 // (imag m) [i] [j] = imag (m [i] [j])
396 template
<class E
>
397 typename matrix_unary1_traits
<E, scalar_imag
<typename E::value_type
> >::result_type
398 imag (const matrix_expression
<E
> &e);
400 template
<class E, class F
>
401 struct matrix_unary2_traits {
402 typedef matrix_unary2
<typename E::const_closure_type, F
> expression_type;
403 typedef expression_type result_type;
406 // (trans m) [i] [j] = m [j] [i]
407 template
<class E
>
408 typename matrix_unary2_traits
<E, scalar_identity
<typename E::value_type
> >::result_type
409 trans (const matrix_expression
<E
> &e);
411 // (herm m) [i] [j] = conj (m [j] [i])
412 template
<class E
>
413 typename matrix_unary2_traits
<E, scalar_conj
<typename E::value_type
> >::result_type
414 herm (const matrix_expression
<E
> &e);
</code>
417 <p><code>operator -
</code> computes the additive inverse of a
418 matrix expression.
<code>conj
</code> computes the complex conjugate
419 of a matrix expression.
<code>real
</code> and
<code>imag
</code>
420 compute the real and imaginary parts of a matrix expression.
421 <code>trans
</code> computes the transpose of a matrix expression.
422 <code>herm
</code> computes the hermitian, i.e. the complex
423 conjugate of the transpose of a matrix expression.
</p>
425 <p>Defined in the header matrix_expression.hpp.
</p>
426 <h4>Type requirements
</h4>
428 <li><code>E
</code> is a model of
<a href=
429 "expression_concept.html#matrix_expression">Matrix Expression
</a> .
</li>
431 <h4>Preconditions
</h4>
434 <p>Quadratic depending from the size of the matrix expression.
</p>
437 #include
<boost/numeric/ublas/matrix.hpp
>
438 #include
<boost/numeric/ublas/io.hpp
>
441 using namespace boost::numeric::ublas;
442 matrix
<std::complex
<double
> > m (
3,
3);
443 for (unsigned i =
0; i
< m.size1 (); ++ i)
444 for (unsigned j =
0; j
< m.size2 (); ++ j)
445 m (i, j) = std::complex
<double
> (
3 * i + j,
3 * i + j);
447 std::cout
<< - m
<< std::endl;
448 std::cout
<< conj (m)
<< std::endl;
449 std::cout
<< real (m)
<< std::endl;
450 std::cout
<< imag (m)
<< std::endl;
451 std::cout
<< trans (m)
<< std::endl;
452 std::cout
<< herm (m)
<< std::endl;
455 <h3>Binary Operation Description
</h3>
457 <p>The templated class
<code>matrix_binary
<E1, E2, F
></code>
458 describes a binary matrix operation.
</p>
460 <p>Defined in the header matrix_expression.hpp.
</p>
461 <h4>Template parameters
</h4>
462 <table border=
"1" summary=
"parameters">
470 <td><code>E1
</code></td>
471 <td>The type of the first matrix expression.
</td>
475 <td><code>E2
</code></td>
476 <td>The type of the second matrix expression.
</td>
480 <td><code>F
</code></td>
481 <td>The type of the operation.
</td>
487 <p><a href=
"expression_concept.html#matrix_expression">Matrix Expression
</a>
489 <h4>Type requirements
</h4>
490 <p>None, except for those imposed by the requirements of
<a href=
491 "expression_concept.html#matrix_expression">Matrix Expression
</a> .
</p>
492 <h4>Public base classes
</h4>
493 <p><code>matrix_expression
<matrix_binary
<E1, E2, F
>
496 <table border=
"1" summary=
"members">
503 <td><code>matrix_binary (const expression1_type
&e1, const
504 expression2_type
&e2)
</code></td>
505 <td>Constructs a description of the expression.
</td>
508 <td><code>size_type size1 () const
</code></td>
509 <td>Returns the number of rows.
</td>
512 <td><code>size_type size2 () const
</code></td>
513 <td>Returns the number of columns.
</td>
516 <td><code>const_reference operator () (size_type i, size_type j)
518 <td>Returns the value of the
<code>j
</code>-th element in the
519 <code>i
</code>-th row.
</td>
522 <td><code>const_iterator1 begin1 () const
</code></td>
523 <td>Returns a
<code>const_iterator1
</code> pointing to the
524 beginning of the expression.
</td>
527 <td><code>const_iterator1 end1 () const
</code></td>
528 <td>Returns a
<code>const_iterator1
</code> pointing to the end of
532 <td><code>const_iterator2 begin2 () const
</code></td>
533 <td>Returns a
<code>const_iterator2
</code> pointing to the
534 beginning of the expression.
</td>
537 <td><code>const_iterator2 end2 () const
</code></td>
538 <td>Returns a
<code>const_iterator2
</code> pointing to the end of
542 <td><code>const_reverse_iterator1 rbegin1 () const
</code></td>
543 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
544 beginning of the reversed expression.
</td>
547 <td><code>const_reverse_iterator1 rend1 () const
</code></td>
548 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
549 end of the reversed expression.
</td>
552 <td><code>const_reverse_iterator2 rbegin2 () const
</code></td>
553 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
554 beginning of the reversed expression.
</td>
557 <td><code>const_reverse_iterator2 rend2 () const
</code></td>
558 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
559 end of the reversed expression.
</td>
563 <h3>Binary Operations
</h3>
566 <code>template
<class E1, class E2, class F
>
567 struct matrix_binary_traits {
568 typedef matrix_binary
<typename E1::const_closure_type,
569 typename E2::const_closure_type, F
> expression_type;
570 typedef expression_type result_type;
573 // (m1 + m2) [i] [j] = m1 [i] [j] + m2 [i] [j]
574 template
<class E1, class E2
>
575 typename matrix_binary_traits
<E1, E2, scalar_plus
<typename E1::value_type,
576 typename E2::value_type
> >::result_type
577 operator + (const matrix_expression
<E1
> &e1,
578 const matrix_expression
<E2
> &e2);
580 // (m1 - m2) [i] [j] = m1 [i] [j] - m2 [i] [j]
581 template
<class E1, class E2
>
582 typename matrix_binary_traits
<E1, E2, scalar_minus
<typename E1::value_type,
583 typename E2::value_type
> >::result_type
584 operator - (const matrix_expression
<E1
> &e1,
585 const matrix_expression
<E2
> &e2);
</code>
588 <p><code>operator +
</code> computes the sum of two matrix
589 expressions.
<code>operator -
</code> computes the difference of two
590 matrix expressions.
</p>
592 <p>Defined in the header matrix_expression.hpp.
</p>
593 <h4>Type requirements
</h4>
595 <li><code>E1
</code> is a model of
<a href=
596 "expression_concept.html#matrix_expression">Matrix Expression
</a> .
</li>
597 <li><code>E2
</code> is a model of
<a href=
598 "expression_concept.html#matrix_expression">Matrix Expression
</a> .
</li>
600 <h4>Preconditions
</h4>
602 <li><code>e1 ().size1 () == e2 ().size1 ()
</code></li>
603 <li><code>e1 ().size2 () == e2 ().size2 ()
</code></li>
606 <p>Quadratic depending from the size of the matrix expressions.
</p>
609 #include
<boost/numeric/ublas/matrix.hpp
>
610 #include
<boost/numeric/ublas/io.hpp
>
613 using namespace boost::numeric::ublas;
614 matrix
<double
> m1 (
3,
3), m2 (
3,
3);
615 for (unsigned i =
0; i
< std::min (m1.size1 (), m2.size1 ()); ++ i)
616 for (unsigned j =
0; j
< std::min (m1.size2 (), m2.size2 ()); ++ j)
617 m1 (i, j) = m2 (i, j) =
3 * i + j;
619 std::cout
<< m1 + m2
<< std::endl;
620 std::cout
<< m1 - m2
<< std::endl;
623 <h3>Scalar Matrix Operation Description
</h3>
625 <p>The templated classes
<code>matrix_binary_scalar1
<E1, E2,
626 F
></code> and
<code>matrix_binary_scalar2
<E1, E2,
627 F
></code> describe binary operations between a scalar and a
630 <p>Defined in the header matrix_expression.hpp.
</p>
631 <h4>Template parameters
</h4>
632 <table border=
"1" summary=
"parameters">
640 <td><code>E1/E2
</code></td>
641 <td>The type of the scalar expression.
</td>
645 <td><code>E2/E1
</code></td>
646 <td>The type of the matrix expression.
</td>
650 <td><code>F
</code></td>
651 <td>The type of the operation.
</td>
657 <p><a href=
"expression_concept.html#matrix_expression">Matrix Expression
</a>
659 <h4>Type requirements
</h4>
660 <p>None, except for those imposed by the requirements of
<a href=
661 "expression_concept.html#matrix_expression">Matrix Expression
</a> .
</p>
662 <h4>Public base classes
</h4>
663 <p><code>matrix_expression
<matrix_binary_scalar1
<E1, E2,
664 F
> ></code> and
665 <code>matrix_expression
<matrix_binary_scalar2
<E1, E2, F
>
666 ></code> resp.
</p>
668 <table border=
"1" summary=
"members">
675 <td><code>matrix_binary_scalar1 (const expression1_type
&e1,
676 const expression2_type
&e2)
</code></td>
677 <td>Constructs a description of the expression.
</td>
680 <td><code>matrix_binary_scalar1 (const expression1_type
&e1,
681 const expression2_type
&e2)
</code></td>
682 <td>Constructs a description of the expression.
</td>
685 <td><code>size_type size1 () const
</code></td>
686 <td>Returns the number of rows.
</td>
689 <td><code>size_type size2 () const
</code></td>
690 <td>Returns the number of columns.
</td>
693 <td><code>const_reference operator () (size_type i, size_type j)
695 <td>Returns the value of the
<code>j
</code>-th element in the
696 <code>i
</code>-th row.
</td>
699 <td><code>const_iterator1 begin1 () const
</code></td>
700 <td>Returns a
<code>const_iterator1
</code> pointing to the
701 beginning of the expression.
</td>
704 <td><code>const_iterator1 end1 () const
</code></td>
705 <td>Returns a
<code>const_iterator1
</code> pointing to the end of
709 <td><code>const_iterator2 begin2 () const
</code></td>
710 <td>Returns a
<code>const_iterator2
</code> pointing to the
711 beginning of the expression.
</td>
714 <td><code>const_iterator2 end2 () const
</code></td>
715 <td>Returns a
<code>const_iterator2
</code> pointing to the end of
719 <td><code>const_reverse_iterator1 rbegin1 () const
</code></td>
720 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
721 beginning of the reversed expression.
</td>
724 <td><code>const_reverse_iterator1 rend1 () const
</code></td>
725 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
726 end of the reversed expression.
</td>
729 <td><code>const_reverse_iterator2 rbegin2 () const
</code></td>
730 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
731 beginning of the reversed expression.
</td>
734 <td><code>const_reverse_iterator2 rend2 () const
</code></td>
735 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
736 end of the reversed expression.
</td>
740 <h3>Scalar Matrix Operations
</h3>
743 <code>template
<class T1, class E2, class F
>
744 struct matrix_binary_scalar1_traits {
745 typedef matrix_binary_scalar1
<scalar_const_reference
<T1
>,
746 typename E2::const_closure_type, F
> expression_type;
747 typedef expression_type result_type;
750 // (t * m) [i] [j] = t * m [i] [j]
751 template
<class T1, class E2
>
752 typename matrix_binary_scalar1_traits
<T1, E2, scalar_multiplies
<T1, typename E2::value_type
> >::result_type
753 operator * (const T1
&e1,
754 const matrix_expression
<E2
> &e2);
756 template
<class E1, class T2, class F
>
757 struct matrix_binary_scalar2_traits {
758 typedef matrix_binary_scalar2
<typename E1::const_closure_type,
759 scalar_const_reference
<T2
>, F
> expression_type;
760 typedef expression_type result_type;
763 // (m * t) [i] [j] = m [i] [j] * t
764 template
<class E1, class T2
>
765 typename matrix_binary_scalar2_traits
<E1, T2, scalar_multiplies
<typename E1::value_type, T2
> >::result_type
766 operator * (const matrix_expression
<E1
> &e1,
769 // (m / t) [i] [j] = m [i] [j] / t
770 template
<class E1, class T2
>
771 typename matrix_binary_scalar2_traits
<E1, T2, scalar_divides
<typename E1::value_type, T2
> >::result_type
772 operator / (const matrix_expression
<E1
> &e1,
773 const T2
&e2);
</code>
776 <p><code>operator *
</code> computes the product of a scalar and a
777 matrix expression.
<code>operator /
</code> multiplies the matrix
778 with the reciprocal of the scalar.
</p>
780 <p>Defined in the header matrix_expression.hpp.
</p>
781 <h4>Type requirements
</h4>
783 <li><code>T1/T2
</code> is a model of
<a href=
784 "expression_concept.html#scalar_expression">Scalar Expression
</a> .
</li>
785 <li><code>E2/E1
</code> is a model of
<a href=
786 "expression_concept.html#matrix_expression">Matrix Expression
</a> .
</li>
788 <h4>Preconditions
</h4>
791 <p>Quadratic depending from the size of the matrix expression.
</p>
794 #include
<boost/numeric/ublas/matrix.hpp
>
795 #include
<boost/numeric/ublas/io.hpp
>
798 using namespace boost::numeric::ublas;
799 matrix
<double
> m (
3,
3);
800 for (unsigned i =
0; i
< m.size1 (); ++ i)
801 for (unsigned j =
0; j
< m.size2 (); ++ j)
802 m (i, j) =
3 * i + j;
804 std::cout
<< 2.0 * m
<< std::endl;
805 std::cout
<< m *
2.0 << std::endl;
808 <h2><a name=
"matrix_vector_operations"></a>Matrix Vector Operations
</h2>
809 <h3>Binary Operation Description
</h3>
811 <p>The templated classes
<code>matrix_vector_binary1
<E1, E2,
812 F
></code> and
<code>matrix_vector_binary2
<E1, E2,
813 F
></code> describe binary matrix vector operations.
</p>
815 <p>Defined in the header matrix_expression.hpp.
</p>
816 <h4>Template parameters
</h4>
817 <table border=
"1" summary=
"parameters">
825 <td><code>E1
</code></td>
826 <td>The type of the matrix or vector expression.
</td>
830 <td><code>E2
</code></td>
831 <td>The type of the vector or matrix expression.
</td>
835 <td><code>F
</code></td>
836 <td>The type of the operation.
</td>
842 <p><a href=
"expression_concept.html#vector_expression">Vector Expression
</a>
844 <h4>Type requirements
</h4>
845 <p>None, except for those imposed by the requirements of
<a href=
846 "expression_concept.html#vector_expression">Vector Expression
</a> .
</p>
847 <h4>Public base classes
</h4>
848 <p><code>vector_expression
<matrix_vector_binary1
<E1, E2,
849 F
> ></code> and
850 <code>vector_expression
<matrix_vector_binary2
<E1, E2, F
>
851 ></code> resp.
</p>
853 <table border=
"1" summary=
"members">
860 <td><code>matrix_vector_binary1 (const expression1_type
&e1,
861 const expression2_type
&e2)
</code></td>
862 <td>Constructs a description of the expression.
</td>
865 <td><code>matrix_vector_binary2 (const expression1_type
&e1,
866 const expression2_type
&e2)
</code></td>
867 <td>Constructs a description of the expression.
</td>
870 <td><code>size_type size () const
</code></td>
871 <td>Returns the size of the expression.
</td>
874 <td><code>const_reference operator () (size_type i)
876 <td>Returns the value of the
<code>i
</code>-th element.
</td>
879 <td><code>const_iterator begin () const
</code></td>
880 <td>Returns a
<code>const_iterator
</code> pointing to the beginning
881 of the expression.
</td>
884 <td><code>const_iterator end () const
</code></td>
885 <td>Returns a
<code>const_iterator
</code> pointing to the end of
889 <td><code>const_reverse_iterator rbegin () const
</code></td>
890 <td>Returns a
<code>const_reverse_iterator
</code> pointing to the
891 beginning of the reversed expression.
</td>
894 <td><code>const_reverse_iterator rend () const
</code></td>
895 <td>Returns a
<code>const_reverse_iterator
</code> pointing to the
896 end of the reversed expression.
</td>
900 <h3>Binary Operations
</h3>
903 <code>template
<class T1, class E1, class T2, class E2
>
904 struct matrix_vector_binary1_traits {
905 typedef row_major_tag dispatch_category;
906 typedef typename promote_traits
<T1, T2
>::promote_type promote_type;
907 typedef matrix_vector_binary1
<typename E1::const_closure_type,
908 typename E2::const_closure_type,
909 matrix_vector_prod1
<T1, T2, promote_type
> > expression_type;
910 typedef expression_type result_type;
913 template
<class E1, class E2
>
914 typename matrix_vector_binary1_traits
<typename E1::value_type, E1,
915 typename E2::value_type, E2
>::result_type
916 prod (const matrix_expression
<E1
> &e1,
917 const vector_expression
<E2
> &e2,
921 template
<class E1, class E2
>
922 typename matrix_vector_binary1_traits
<typename E1::value_type, E1,
923 typename E2::value_type, E2
>::result_type
924 prod (const matrix_expression
<E1
> &e1,
925 const vector_expression
<E2
> &e2);
927 template
<class E1, class E2
>
928 typename matrix_vector_binary1_traits
<typename type_traits
<typename E1::value_type
>::precision_type, E1,
929 typename type_traits
<typename E2::value_type
>::precision_type, E2
>::result_type
930 prec_prod (const matrix_expression
<E1
> &e1,
931 const vector_expression
<E2
> &e2,
935 template
<class E1, class E2
>
936 typename matrix_vector_binary1_traits
<typename type_traits
<typename E1::value_type
>::precision_type, E1,
937 typename type_traits
<typename E2::value_type
>::precision_type, E2
>::result_type
938 prec_prod (const matrix_expression
<E1
> &e1,
939 const vector_expression
<E2
> &e2);
941 template
<class V, class E1, class E2
>
943 prod (const matrix_expression
<E1
> &e1,
944 const vector_expression
<E2
> &e2);
946 template
<class V, class E1, class E2
>
948 prec_prod (const matrix_expression
<E1
> &e1,
949 const vector_expression
<E2
> &e2);
951 template
<class T1, class E1, class T2, class E2
>
952 struct matrix_vector_binary2_traits {
953 typedef column_major_tag dispatch_category;
954 typedef typename promote_traits
<T1, T2
>::promote_type promote_type;
955 typedef matrix_vector_binary2
<typename E1::const_closure_type,
956 typename E2::const_closure_type,
957 matrix_vector_prod2
<T1, T2, promote_type
> > expression_type;
958 typedef expression_type result_type;
961 template
<class E1, class E2
>
962 typename matrix_vector_binary2_traits
<typename E1::value_type, E1,
963 typename E2::value_type, E2
>::result_type
964 prod (const vector_expression
<E1
> &e1,
965 const matrix_expression
<E2
> &e2,
969 template
<class E1, class E2
>
970 typename matrix_vector_binary2_traits
<typename E1::value_type, E1,
971 typename E2::value_type, E2
>::result_type
972 prod (const vector_expression
<E1
> &e1,
973 const matrix_expression
<E2
> &e2);
975 template
<class E1, class E2
>
976 typename matrix_vector_binary2_traits
<typename type_traits
<typename E1::value_type
>::precision_type, E1,
977 typename type_traits
<typename E2::value_type
>::precision_type, E2
>::result_type
978 prec_prod (const vector_expression
<E1
> &e1,
979 const matrix_expression
<E2
> &e2,
983 template
<class E1, class E2
>
984 typename matrix_vector_binary2_traits
<typename type_traits
<typename E1::value_type
>::precision_type, E1,
985 typename type_traits
<typename E2::value_type
>::precision_type, E2
>::result_type
986 prec_prod (const vector_expression
<E1
> &e1,
987 const matrix_expression
<E2
> &e2);
989 template
<class V, class E1, class E2
>
991 prod (const vector_expression
<E1
> &e1,
992 const matrix_expression
<E2
> &e2);
994 template
<class V, class E1, class E2
>
996 prec_prod (const vector_expression
<E1
> &e1,
997 const matrix_expression
<E2
> &e2);
</code>
1000 <p><code>prod
</code> computes the product of the matrix and the
1001 vector expression.
<code>prec_prod
</code> computes the double
1002 precision product of the matrix and the vector expression.
</p>
1004 <p>Defined in the header matrix_expression.hpp.
</p>
1005 <h4>Type requirements
</h4>
1007 <li><code>E1
</code> is a model of
<a href=
1008 "expression_concept.html#matrix_expression">Matrix Expression
</a> or
1009 <a href=
"expression_concept.html#vector_expression">Vector Expression
</a>
1011 <li><code>E2
</code> is a model of
<a href=
1012 "expression_concept.html#vector_expression">Vector Expression
</a> or
1013 <a href=
"expression_concept.html#matrix_expression">Matrix Expression
</a>
1016 <h4>Preconditions
</h4>
1018 <li><code>e1 ().size2 () == e2 ().size ()
</code></li>
1019 <li><code>e1 ().size () == e2 ().size1 ()
</code></li>
1022 <p>Quadratic depending from the size of the matrix expression.
</p>
1025 #include
<boost/numeric/ublas/matrix.hpp
>
1026 #include
<boost/numeric/ublas/io.hpp
>
1029 using namespace boost::numeric::ublas;
1030 matrix
<double
> m (
3,
3);
1031 vector
<double
> v (
3);
1032 for (unsigned i =
0; i
< std::min (m.size1 (), v.size ()); ++ i) {
1033 for (unsigned j =
0; j
< m.size2 (); ++ j)
1034 m (i, j) =
3 * i + j;
1038 std::cout
<< prod (m, v)
<< std::endl;
1039 std::cout
<< prod (v, m)
<< std::endl;
1042 <h3>Triangular Solver
</h3>
1045 <code>template
<class E1, class E2
>
1046 struct matrix_vector_solve_traits {
1047 typedef typename promote_traits
<typename E1::value_type, typename E2::value_type
>::promote_type promote_type;
1048 typedef vector
<promote_type
> result_type;
1051 template
<class E1, class E2
>
1052 void inplace_solve (const matrix_expression
<E1
> &e1,
1056 template
<class E1, class E2
>
1057 void inplace_solve (const matrix_expression
<E1
> &e1,
1061 template
<class E1, class E2
>
1062 void inplace_solve (const matrix_expression
<E1
> &e1,
1066 template
<class E1, class E2
>
1067 void inplace_solve (const matrix_expression
<E1
> &e1,
1072 template
<class E1, class E2, class C
>
1073 typename matrix_vector_solve_traits
<E1, E2
>::result_type
1074 solve (const matrix_expression
<E1
> &e1,
1075 const vector_expression
<E2
> &e2,
1078 template
<class E1, class E2
>
1079 void inplace_solve (E1
&e1,
1080 const matrix_expression
<E2
> &e2,
1083 template
<class E1, class E2
>
1084 void inplace_solve (E1
&e1,
1085 const matrix_expression
<E2
> &e2,
1088 template
<class E1, class E2
>
1089 void inplace_solve (E1
&e1,
1090 const matrix_expression
<E2
> &e2,
1093 template
<class E1, class E2
>
1094 void inplace_solve (E1
&e1,
1095 const matrix_expression
<E2
> &e2,
1099 template
<class E1, class E2, class C
>
1100 typename matrix_vector_solve_traits
<E1, E2
>::result_type
1101 solve (const vector_expression
<E1
> &e1,
1102 const matrix_expression
<E2
> &e2,
1105 <h4>Description
</h4>
1106 <p><code>solve
</code> solves a linear equation for lower or upper
1107 (unit) triangular matrices.
</p>
1109 <p>Defined in the header triangular.hpp.
</p>
1110 <h4>Type requirements
</h4>
1112 <li><code>E1
</code> is a model of
<a href=
1113 "expression_concept.html#matrix_expression">Matrix Expression
</a> or
1114 <a href=
"expression_concept.html#vector_expression">Vector Expression
</a>
1116 <li><code>E2
</code> is a model of
<a href=
1117 "expression_concept.html#vector_expression">Vector Expression
</a> or
1118 <a href=
"expression_concept.html#matrix_expression">Matrix Expression
</a>
1121 <h4>Preconditions
</h4>
1123 <li><code>e1 ().size1 () == e1 ().size2 ()
</code></li>
1124 <li><code>e1 ().size2 () == e2 ().size ()
</code></li>
1125 <li><code>e1 ().size () == e2 ().size1 ()
</code></li>
1126 <li><code>e2 ().size1 () == e2 ().size2 ()
</code></li>
1129 <p>Quadratic depending from the size of the matrix expression.
</p>
1132 #include
<boost/numeric/ublas/triangular.hpp
>
1133 #include
<boost/numeric/ublas/io.hpp
>
1136 using namespace boost::numeric::ublas;
1137 matrix
<double
> m (
3,
3);
1138 vector
<double
> v (
3);
1139 for (unsigned i =
0; i
< std::min (m.size1 (), v.size ()); ++ i) {
1140 for (unsigned j =
0; j
<= i; ++ j)
1141 m (i, j) =
3 * i + j +
1;
1145 std::cout
<< solve (m, v, lower_tag ())
<< std::endl;
1146 std::cout
<< solve (v, m, lower_tag ())
<< std::endl;
1149 <h2><a name=
"matrix_matrix_operations"></a>Matrix Matrix Operations
</h2>
1150 <h3>Binary Operation Description
</h3>
1151 <h4>Description
</h4>
1152 <p>The templated class
<code>matrix_matrix_binary
<E1, E2,
1153 F
></code> describes a binary matrix operation.
</p>
1155 <p>Defined in the header matrix_expression.hpp.
</p>
1156 <h4>Template parameters
</h4>
1157 <table border=
"1" summary=
"parameters">
1161 <th>Description
</th>
1165 <td><code>E1
</code></td>
1166 <td>The type of the first matrix expression.
</td>
1170 <td><code>E2
</code></td>
1171 <td>The type of the second matrix expression.
</td>
1175 <td><code>F
</code></td>
1176 <td>The type of the operation.
</td>
1182 <p><a href=
"expression_concept.html#matrix_expression">Matrix Expression
</a>
1184 <h4>Type requirements
</h4>
1185 <p>None, except for those imposed by the requirements of
<a href=
1186 "expression_concept.html#matrix_expression">Matrix Expression
</a> .
</p>
1187 <h4>Public base classes
</h4>
1188 <p><code>matrix_expression
<matrix_matrix_binary
<E1, E2, F
>
1191 <table border=
"1" summary=
"members">
1195 <th>Description
</th>
1198 <td><code>matrix_matrix_binary (const expression1_type
&e1,
1199 const expression2_type
&e2)
</code></td>
1200 <td>Constructs a description of the expression.
</td>
1203 <td><code>size_type size1 () const
</code></td>
1204 <td>Returns the number of rows.
</td>
1207 <td><code>size_type size2 () const
</code></td>
1208 <td>Returns the number of columns.
</td>
1211 <td><code>const_reference operator () (size_type i, size_type j)
1213 <td>Returns the value of the
<code>j
</code>-th element in the
1214 <code>i
</code>-th row.
</td>
1217 <td><code>const_iterator1 begin1 () const
</code></td>
1218 <td>Returns a
<code>const_iterator1
</code> pointing to the
1219 beginning of the expression.
</td>
1222 <td><code>const_iterator1 end1 () const
</code></td>
1223 <td>Returns a
<code>const_iterator1
</code> pointing to the end of
1224 the expression.
</td>
1227 <td><code>const_iterator2 begin2 () const
</code></td>
1228 <td>Returns a
<code>const_iterator2
</code> pointing to the
1229 beginning of the expression.
</td>
1232 <td><code>const_iterator2 end2 () const
</code></td>
1233 <td>Returns a
<code>const_iterator2
</code> pointing to the end of
1234 the expression.
</td>
1237 <td><code>const_reverse_iterator1 rbegin1 () const
</code></td>
1238 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
1239 beginning of the reversed expression.
</td>
1242 <td><code>const_reverse_iterator1 rend1 () const
</code></td>
1243 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
1244 end of the reversed expression.
</td>
1247 <td><code>const_reverse_iterator2 rbegin2 () const
</code></td>
1248 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
1249 beginning of the reversed expression.
</td>
1252 <td><code>const_reverse_iterator2 rend2 () const
</code></td>
1253 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
1254 end of the reversed expression.
</td>
1258 <h3>Binary Operations
</h3>
1261 <code>template
<class T1, class E1, class T2, class E2
>
1262 struct matrix_matrix_binary_traits {
1263 typedef unknown_orientation_tag dispatch_category;
1264 typedef typename promote_traits
<T1, T2
>::promote_type promote_type;
1265 typedef matrix_matrix_binary
<typename E1::const_closure_type,
1266 typename E2::const_closure_type,
1267 matrix_matrix_prod
<T1, T2, promote_type
> > expression_type;
1268 typedef expression_type result_type;
1271 template
<class E1, class E2
>
1272 typename matrix_matrix_binary_traits
<typename E1::value_type, E1,
1273 typename E2::value_type, E2
>::result_type
1274 prod (const matrix_expression
<E1
> &e1,
1275 const matrix_expression
<E2
> &e2,
1276 unknown_orientation_tag);
1279 template
<class E1, class E2
>
1280 typename matrix_matrix_binary_traits
<typename E1::value_type, E1,
1281 typename E2::value_type, E2
>::result_type
1282 prod (const matrix_expression
<E1
> &e1,
1283 const matrix_expression
<E2
> &e2);
1285 template
<class E1, class E2
>
1286 typename matrix_matrix_binary_traits
<typename type_traits
<typename E1::value_type
>::precision_type, E1,
1287 typename type_traits
<typename E2::value_type
>::precision_type, E2
>::result_type
1288 prec_prod (const matrix_expression
<E1
> &e1,
1289 const matrix_expression
<E2
> &e2,
1290 unknown_orientation_tag);
1293 template
<class E1, class E2
>
1294 typename matrix_matrix_binary_traits
<typename type_traits
<typename E1::value_type
>::precision_type, E1,
1295 typename type_traits
<typename E2::value_type
>::precision_type, E2
>::result_type
1296 prec_prod (const matrix_expression
<E1
> &e1,
1297 const matrix_expression
<E2
> &e2);
1299 template
<class M, class E1, class E2
>
1301 prod (const matrix_expression
<E1
> &e1,
1302 const matrix_expression
<E2
> &e2);
1304 template
<class M, class E1, class E2
>
1306 prec_prod (const matrix_expression
<E1
> &e1,
1307 const matrix_expression
<E2
> &e2);
</code>
1309 <h4>Description
</h4>
1310 <p><code>prod
</code> computes the product of the matrix
1311 expressions.
<code>prec_prod
</code> computes the double precision
1312 product of the matrix expressions.
</p>
1314 <p>Defined in the header matrix_expression.hpp.
</p>
1315 <h4>Type requirements
</h4>
1317 <li><code>E1
</code> is a model of
<a href=
1318 "expression_concept.html#matrix_expression">Matrix Expression
</a> .
</li>
1319 <li><code>E2
</code> is a model of
<a href=
1320 "expression_concept.html#matrix_expression">Matrix Expression
</a> .
</li>
1322 <h4>Preconditions
</h4>
1324 <li><code>e1 ().size2 () == e2 ().size1 ()
</code></li>
1327 <p>Cubic depending from the size of the matrix expression.
</p>
1330 #include
<boost/numeric/ublas/matrix.hpp
>
1331 #include
<boost/numeric/ublas/io.hpp
>
1334 using namespace boost::numeric::ublas;
1335 matrix
<double
> m1 (
3,
3), m2 (
3,
3);
1336 for (unsigned i =
0; i
< std::min (m1.size1 (), m2.size1 ()); ++ i)
1337 for (unsigned j =
0; j
< std::min (m1.size2 (), m2.size2 ()); ++ j)
1338 m1 (i, j) = m2 (i, j) =
3 * i + j;
1340 std::cout
<< prod (m1, m2)
<< std::endl;
1343 <h3>Triangular Solvers
</h3>
1346 <code>template
<class E1, class E2
>
1347 struct matrix_matrix_solve_traits {
1348 typedef typename promote_traits
<typename E1::value_type, typename E2::value_type
>::promote_type promote_type;
1349 typedef matrix
<promote_type
> result_type;
1352 template
<class E1, class E2
>
1353 void inplace_solve (const matrix_expression
<E1
> &e1,
1357 template
<class E1, class E2
>
1358 void inplace_solve (const matrix_expression
<E1
> &e1,
1362 template
<class E1, class E2
>
1363 void inplace_solve (const matrix_expression
<E1
> &e1,
1367 template
<class E1, class E2
>
1368 void inplace_solve (const matrix_expression
<E1
> &e1,
1373 template
<class E1, class E2, class C
>
1374 typename matrix_matrix_solve_traits
<E1, E2
>::result_type
1375 solve (const matrix_expression
<E1
> &e1,
1376 const matrix_expression
<E2
> &e2,
1379 <h4>Description
</h4>
1380 <p><code>solve
</code> solves a linear equation for lower or upper
1381 (unit) triangular matrices.
</p>
1383 <p>Defined in the header triangular.hpp.
</p>
1384 <h4>Type requirements
</h4>
1386 <li><code>E1
</code> is a model of
<a href=
1387 "expression_concept.html#matrix_expression">Matrix Expression
</a> .
</li>
1388 <li><code>E2
</code> is a model of
<a href=
1389 "expression_concept.html#matrix_expression">Matrix Expression
</a> .
</li>
1391 <h4>Preconditions
</h4>
1393 <li><code>e1 ().size1 () == e1 ().size2 ()
</code></li>
1394 <li><code>e1 ().size2 () == e2 ().size1 ()
</code></li>
1397 <p>Cubic depending from the size of the matrix expressions.
</p>
1400 #include
<boost/numeric/ublas/triangular.hpp
>
1401 #include
<boost/numeric/ublas/io.hpp
>
1404 using namespace boost::numeric::ublas;
1405 matrix
<double
> m1 (
3,
3), m2 (
3,
3);
1406 for (unsigned i =
0; i
< std::min (m1.size1 (), m2.size1 ()); ++ i)
1407 for (unsigned j =
0; j
<= i; ++ j)
1408 m1 (i, j) = m2 (i, j) =
3 * i + j +
1;
1410 std::cout
<< solve (m1, m2, lower_tag ())
<< std::endl;
1414 <p>Copyright (
©)
2000-
2002 Joerg Walter, Mathias Koch
<br />
1415 Use, modification and distribution are subject to the
1416 Boost Software License, Version
1.0.
1417 (See accompanying file LICENSE_1_0.txt
1418 or copy at
<a href=
"http://www.boost.org/LICENSE_1_0.txt">
1419 http://www.boost.org/LICENSE_1_0.txt
1422 <script type=
"text/javascript">