Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/numeric/ublas/doc/matrix_expression.htm @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

File size: 47.6 KB
Line 
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">
4<head>
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 href="ublas.css" type="text/css" />
10<title>Matrix Expressions</title>
11</head>
12<body>
13<h1><img src="../../../../boost.png" align="middle" />
14Matrix Expressions</h1>
15<h2><a name="matrix_expression" id="matrix_expression"></a>Matrix Expression</h2>
16<h4>Description</h4>
17<p>The templated class <code>matrix_expression&lt;E&gt;</code>
18is required to be a public base of all classes which model the Matrix Expression concept.</p>
19<h4>Definition</h4>
20<p>Defined in the header expression_types.hpp.</p>
21<h4>Template parameters</h4>
22<table border="1" summary="parameters">
23<tbody>
24<tr>
25<th>Parameter</th>
26<th>Description</th>
27<th>Default</th>
28</tr>
29<tr>
30<td><code>E</code></td>
31<td>The type of the matrix expression.</td>
32<td>&nbsp;</td>
33</tr>
34</tbody>
35</table>
36<h4>Model of</h4>
37<p>None. <u>Not a Matrix Expression</u>!
38</p>
39<h4>Type requirements</h4>
40<p>None.</p>
41<h4>Public base classes</h4>
42<p>None.</p>
43<h4>Members</h4>
44<table border="1" summary="members">
45<tbody>
46<tr>
47<th>Member</th>
48<th>Description</th>
49</tr>
50<tr>
51<td><code>const expression_type &amp;operator () ()
52const</code></td>
53<td>Returns a <code>const</code> reference of the expression.</td>
54</tr>
55<tr>
56<td><code>expression_type &amp;operator () ()</code></td>
57<td>Returns a reference of the expression.</td>
58</tr>
59</tbody>
60</table>
61<h4>Notes</h4>
62<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.htm">matrix proxy</a> instead.</p>
63<h2><a name="matrix_container" id="matrix_container"></a>Matrix Container</h2>
64<h4>Description</h4>
65<p>The templated class <code>matrix_container&lt;C&gt;</code>
66is required to be a public base of all classes which model the Matrix concept.
67This includes the class <code>matrix</code> itself.</p>
68<h4>Definition</h4>
69<p>Defined in the header expression_types.hpp.</p>
70<h4>Template parameters</h4>
71<table border="1" summary="parameters">
72<tbody>
73<tr>
74<th>Parameter</th>
75<th>Description</th>
76<th>Default</th>
77</tr>
78<tr>
79<td><code>E</code></td>
80<td>The type of the matrix expression.</td>
81<td>&nbsp;</td>
82</tr>
83</tbody>
84</table>
85<h4>Model of</h4>
86<p>None. <u>Not a Matrix Expression OR Matrix</u>!
87</p>
88<h4>Type requirements</h4>
89<p>None.</p>
90<h4>Public base classes</h4>
91<p><code>matrix_expression&lt;C&gt;</code></p>
92<h4>Members</h4>
93<table border="1" summary="members">
94<tbody>
95<tr>
96<th>Member</th>
97<th>Description</th>
98</tr>
99<tr>
100<td><code>const container_type &amp;operator () ()
101const</code></td>
102<td>Returns a <code>const</code> reference of the container.</td>
103</tr>
104<tr>
105<td><code>container_type &amp;operator () ()</code></td>
106<td>Returns a reference of the container.</td>
107</tr>
108</tbody>
109</table>
110<h2><a name="matrix_references" id="matrix_references"></a>Matrix References</h2>
111<h3>Reference</h3>
112<h4>Description</h4>
113<p>The templated class <code>matrix_reference&lt;E&gt;</code>
114contains a reference to a matrix expression.</p>
115<h4>Definition</h4>
116<p>Defined in the header matrix_expression.hpp.</p>
117<h4>Template parameters</h4>
118<table border="1" summary="parameters">
119<tbody>
120<tr>
121<th>Parameter</th>
122<th>Description</th>
123<th>Default</th>
124</tr>
125<tr>
126<td><code>E</code></td>
127<td>The type of the matrix expression.</td>
128<td>&nbsp;</td>
129</tr>
130</tbody>
131</table>
132<h4>Model of</h4>
133<p><a href="expression_concept.htm#matrix_expression">Matrix Expression</a>
134.</p>
135<h4>Type requirements</h4>
136<p>None, except for those imposed by the requirements of <a href=
137"expression_concept.htm#matrix_expression">Matrix Expression</a> .</p>
138<h4>Public base classes</h4>
139<p><code>matrix_expression&lt;matrix_reference&lt;E&gt;
140&gt;</code></p>
141<h4>Members</h4>
142<table border="1" summary="members">
143<tbody>
144<tr>
145<th>Member</th>
146<th>Description</th>
147</tr>
148<tr>
149<td><code>matrix_reference (expression_type &amp;e)</code></td>
150<td>Constructs a constant reference of the expression.</td>
151</tr>
152<tr>
153<td><code>void resize (size_type size1, size2)</code></td>
154<td>Resizes the expression to hold at most <code>size1</code> rows
155of <code>size2</code> elements.</td>
156</tr>
157<tr>
158<td><code>size_type size1 () const</code></td>
159<td>Returns the number of rows.</td>
160</tr>
161<tr>
162<td><code>size_type size2 () const</code></td>
163<td>Returns the number of columns.</td>
164</tr>
165<tr>
166<td><code>const_reference operator () (size_type i, size_type j)
167const</code></td>
168<td>Returns the value of the <code>j</code>-th element in the
169<code>i</code>-th row.</td>
170</tr>
171<tr>
172<td><code>reference operator () (size_type i, size_type
173j)</code></td>
174<td>Returns a reference of the <code>j</code>-th element in the
175<code>i</code>-th row.</td>
176</tr>
177<tr>
178<td><code>const_iterator1 begin1 () const</code></td>
179<td>Returns a <code>const_iterator1</code> pointing to the
180beginning of the expression.</td>
181</tr>
182<tr>
183<td><code>const_iterator1 end1 () const</code></td>
184<td>Returns a <code>const_iterator1</code> pointing to the end of
185the expression.</td>
186</tr>
187<tr>
188<td><code>iterator1 begin1 ()</code></td>
189<td>Returns a <code>iterator1</code> pointing to the beginning of
190the expression.</td>
191</tr>
192<tr>
193<td><code>iterator1 end1 ()</code></td>
194<td>Returns a <code>iterator1</code> pointing to the end of the
195expression.</td>
196</tr>
197<tr>
198<td><code>const_iterator2 begin2 () const</code></td>
199<td>Returns a <code>const_iterator2</code> pointing to the
200beginning of the expression.</td>
201</tr>
202<tr>
203<td><code>const_iterator2 end2 () const</code></td>
204<td>Returns a <code>const_iterator2</code> pointing to the end of
205the expression.</td>
206</tr>
207<tr>
208<td><code>iterator2 begin2 ()</code></td>
209<td>Returns a <code>iterator2</code> pointing to the beginning of
210the expression.</td>
211</tr>
212<tr>
213<td><code>iterator2 end2 ()</code></td>
214<td>Returns a <code>iterator2</code> pointing to the end of the
215expression.</td>
216</tr>
217<tr>
218<td><code>const_reverse_iterator1 rbegin1 () const</code></td>
219<td>Returns a <code>const_reverse_iterator1</code> pointing to the
220beginning of the reversed expression.</td>
221</tr>
222<tr>
223<td><code>const_reverse_iterator1 rend1 () const</code></td>
224<td>Returns a <code>const_reverse_iterator1</code> pointing to the
225end of the reversed expression.</td>
226</tr>
227<tr>
228<td><code>reverse_iterator1 rbegin1 ()</code></td>
229<td>Returns a <code>reverse_iterator1</code> pointing to the
230beginning of the reversed expression.</td>
231</tr>
232<tr>
233<td><code>reverse_iterator1 rend1 ()</code></td>
234<td>Returns a <code>reverse_iterator1</code> pointing to the end of
235the reversed expression.</td>
236</tr>
237<tr>
238<td><code>const_reverse_iterator2 rbegin2 () const</code></td>
239<td>Returns a <code>const_reverse_iterator2</code> pointing to the
240beginning of the reversed expression.</td>
241</tr>
242<tr>
243<td><code>const_reverse_iterator2 rend2 () const</code></td>
244<td>Returns a <code>const_reverse_iterator2</code> pointing to the
245end of the reversed expression.</td>
246</tr>
247<tr>
248<td><code>reverse_iterator2 rbegin2 ()</code></td>
249<td>Returns a <code>reverse_iterator2</code> pointing to the
250beginning of the reversed expression.</td>
251</tr>
252<tr>
253<td><code>reverse_iterator2 rend2 ()</code></td>
254<td>Returns a <code>reverse_iterator2</code> pointing to the end of
255the reversed expression.</td>
256</tr>
257</tbody>
258</table>
259<h2><a name="matrix_operations" id="matrix_operations"></a>Matrix Operations</h2>
260<h3>Unary Operation Description</h3>
261<h4>Description</h4>
262<p>The templated classes <code>matrix_unary1&lt;E, F&gt;</code> and
263<code>matrix_unary2&lt;E, F&gt;</code> describe unary matrix
264operations.</p>
265<h4>Definition</h4>
266<p>Defined in the header matrix_expression.hpp.</p>
267<h4>Template parameters</h4>
268<table border="1" summary="parameters">
269<tbody>
270<tr>
271<th>Parameter</th>
272<th>Description</th>
273<th>Default</th>
274</tr>
275<tr>
276<td><code>E</code></td>
277<td>The type of the matrix expression.</td>
278<td>&nbsp;</td>
279</tr>
280<tr>
281<td><code>F</code></td>
282<td>The type of the operation.</td>
283<td>&nbsp;</td>
284</tr>
285</tbody>
286</table>
287<h4>Model of</h4>
288<p><a href="expression_concept.htm#matrix_expression">Matrix Expression</a>
289.</p>
290<h4>Type requirements</h4>
291<p>None, except for those imposed by the requirements of <a href=
292"expression_concept.htm#matrix_expression">Matrix Expression</a> .</p>
293<h4>Public base classes</h4>
294<p><code>matrix_expression&lt;matrix_unary1&lt;E, F&gt; &gt;</code>
295and <code>matrix_expression&lt;matrix_unary2&lt;E, F&gt;
296&gt;</code> resp.</p>
297<h4>Members</h4>
298<table border="1" summary="members">
299<tbody>
300<tr>
301<th>Member</th>
302<th>Description</th>
303</tr>
304<tr>
305<td><code>matrix_unary1 (const expression_type &amp;e)</code></td>
306<td>Constructs a description of the expression.</td>
307</tr>
308<tr>
309<td><code>matrix_unary2 (const expression_type &amp;e)</code></td>
310<td>Constructs a description of the expression.</td>
311</tr>
312<tr>
313<td><code>size_type size1 () const</code></td>
314<td>Returns the number of rows.</td>
315</tr>
316<tr>
317<td><code>size_type size2 () const</code></td>
318<td>Returns the number of columns.</td>
319</tr>
320<tr>
321<td><code>const_reference operator () (size_type i, size_type j)
322const</code></td>
323<td>Returns the value of the <code>j</code>-th element in the
324<code>i</code>-th row.</td>
325</tr>
326<tr>
327<td><code>const_iterator1 begin1 () const</code></td>
328<td>Returns a <code>const_iterator1</code> pointing to the
329beginning of the expression.</td>
330</tr>
331<tr>
332<td><code>const_iterator1 end1 () const</code></td>
333<td>Returns a <code>const_iterator1</code> pointing to the end of
334the expression.</td>
335</tr>
336<tr>
337<td><code>const_iterator2 begin2 () const</code></td>
338<td>Returns a <code>const_iterator2</code> pointing to the
339beginning of the expression.</td>
340</tr>
341<tr>
342<td><code>const_iterator2 end2 () const</code></td>
343<td>Returns a <code>const_iterator2</code> pointing to the end of
344the expression.</td>
345</tr>
346<tr>
347<td><code>const_reverse_iterator1 rbegin1 () const</code></td>
348<td>Returns a <code>const_reverse_iterator1</code> pointing to the
349beginning of the reversed expression.</td>
350</tr>
351<tr>
352<td><code>const_reverse_iterator1 rend1 () const</code></td>
353<td>Returns a <code>const_reverse_iterator1</code> pointing to the
354end of the reversed expression.</td>
355</tr>
356<tr>
357<td><code>const_reverse_iterator2 rbegin2 () const</code></td>
358<td>Returns a <code>const_reverse_iterator2</code> pointing to the
359beginning of the reversed expression.</td>
360</tr>
361<tr>
362<td><code>const_reverse_iterator2 rend2 () const</code></td>
363<td>Returns a <code>const_reverse_iterator2</code> pointing to the
364end of the reversed expression.</td>
365</tr>
366</tbody>
367</table>
368<h3>Unary Operations</h3>
369<h4>Prototypes</h4>
370<pre>
371<code>template&lt;class E, class F&gt;
372    struct matrix_unary1_traits {
373        typedef matrix_unary1&lt;typename E::const_closure_type, F&gt; expression_type;
374        typedef expression_type result_type;
375     };
376
377    // (- m) [i] [j] = - m [i] [j]
378    template&lt;class E&gt;
379     typename matrix_unary1_traits&lt;E, scalar_negate&lt;typename E::value_type&gt; &gt;::result_type
380    operator - (const matrix_expression&lt;E&gt; &amp;e);
381
382    // (conj m) [i] [j] = conj (m [i] [j])
383    template&lt;class E&gt;
384     typename matrix_unary1_traits&lt;E, scalar_conj&lt;typename E::value_type&gt; &gt;::result_type
385    conj (const matrix_expression&lt;E&gt; &amp;e);
386
387    // (real m) [i] [j] = real (m [i] [j])
388    template&lt;class E&gt;
389     typename matrix_unary1_traits&lt;E, scalar_real&lt;typename E::value_type&gt; &gt;::result_type
390    real (const matrix_expression&lt;E&gt; &amp;e);
391
392    // (imag m) [i] [j] = imag (m [i] [j])
393    template&lt;class E&gt;
394     typename matrix_unary1_traits&lt;E, scalar_imag&lt;typename E::value_type&gt; &gt;::result_type
395    imag (const matrix_expression&lt;E&gt; &amp;e);
396
397    template&lt;class E, class F&gt;
398    struct matrix_unary2_traits {
399        typedef matrix_unary2&lt;typename E::const_closure_type, F&gt; expression_type;
400        typedef expression_type result_type;
401     };
402
403    // (trans m) [i] [j] = m [j] [i]
404    template&lt;class E&gt;
405     typename matrix_unary2_traits&lt;E, scalar_identity&lt;typename E::value_type&gt; &gt;::result_type
406    trans (const matrix_expression&lt;E&gt; &amp;e);
407
408    // (herm m) [i] [j] = conj (m [j] [i])
409    template&lt;class E&gt;
410     typename matrix_unary2_traits&lt;E, scalar_conj&lt;typename E::value_type&gt; &gt;::result_type
411    herm (const matrix_expression&lt;E&gt; &amp;e);</code>
412</pre>
413<h4>Description</h4>
414<p><code>operator -</code> computes the additive inverse of a
415matrix expression. <code>conj</code> computes the complex conjugate
416of a matrix expression. <code>real</code> and <code>imag</code>
417compute the real and imaginary parts of a matrix expression.
418<code>trans</code> computes the transpose of a matrix expression.
419<code>herm</code> computes the hermitian, i.e. the complex
420conjugate of the transpose of a matrix expression.</p>
421<h4>Definition</h4>
422<p>Defined in the header matrix_expression.hpp.</p>
423<h4>Type requirements</h4>
424<ul>
425<li><code>E</code> is a model of <a href=
426"expression_concept.htm#matrix_expression">Matrix Expression</a> .</li>
427</ul>
428<h4>Preconditions</h4>
429<p>None.</p>
430<h4>Complexity</h4>
431<p>Quadratic depending from the size of the matrix expression.</p>
432<h4>Examples</h4>
433<pre>
434#include &lt;boost/numeric/ublas/matrix.hpp&gt;
435#include &lt;boost/numeric/ublas/io.hpp&gt;
436
437int main () {
438    using namespace boost::numeric::ublas;
439    matrix&lt;std::complex&lt;double&gt; &gt; m (3, 3);
440    for (unsigned i = 0; i &lt; m.size1 (); ++ i)
441        for (unsigned j = 0; j &lt; m.size2 (); ++ j)
442            m (i, j) = std::complex&lt;double&gt; (3 * i + j, 3 * i + j);
443
444    std::cout &lt;&lt; - m &lt;&lt; std::endl;
445    std::cout &lt;&lt; conj (m) &lt;&lt; std::endl;
446    std::cout &lt;&lt; real (m) &lt;&lt; std::endl;
447    std::cout &lt;&lt; imag (m) &lt;&lt; std::endl;
448    std::cout &lt;&lt; trans (m) &lt;&lt; std::endl;
449    std::cout &lt;&lt; herm (m) &lt;&lt; std::endl;
450}
451</pre>
452<h3>Binary Operation Description</h3>
453<h4>Description</h4>
454<p>The templated class <code>matrix_binary&lt;E1, E2, F&gt;</code>
455describes a binary matrix operation.</p>
456<h4>Definition</h4>
457<p>Defined in the header matrix_expression.hpp.</p>
458<h4>Template parameters</h4>
459<table border="1" summary="parameters">
460<tbody>
461<tr>
462<th>Parameter</th>
463<th>Description</th>
464<th>Default</th>
465</tr>
466<tr>
467<td><code>E1</code></td>
468<td>The type of the first matrix expression.</td>
469<td></td>
470</tr>
471<tr>
472<td><code>E2</code></td>
473<td>The type of the second matrix expression.</td>
474<td></td>
475</tr>
476<tr>
477<td><code>F</code></td>
478<td>The type of the operation.</td>
479<td></td>
480</tr>
481</tbody>
482</table>
483<h4>Model of</h4>
484<p><a href="expression_concept.htm#matrix_expression">Matrix Expression</a>
485.</p>
486<h4>Type requirements</h4>
487<p>None, except for those imposed by the requirements of <a href=
488"expression_concept.htm#matrix_expression">Matrix Expression</a> .</p>
489<h4>Public base classes</h4>
490<p><code>matrix_expression&lt;matrix_binary&lt;E1, E2, F&gt;
491&gt;</code>.</p>
492<h4>Members</h4>
493<table border="1" summary="members">
494<tbody>
495<tr>
496<th>Member</th>
497<th>Description</th>
498</tr>
499<tr>
500<td><code>matrix_binary (const expression1_type &amp;e1, const
501expression2_type &amp;e2)</code></td>
502<td>Constructs a description of the expression.</td>
503</tr>
504<tr>
505<td><code>size_type size1 () const</code></td>
506<td>Returns the number of rows.</td>
507</tr>
508<tr>
509<td><code>size_type size2 () const</code></td>
510<td>Returns the number of columns.</td>
511</tr>
512<tr>
513<td><code>const_reference operator () (size_type i, size_type j)
514const</code></td>
515<td>Returns the value of the <code>j</code>-th element in the
516<code>i</code>-th row.</td>
517</tr>
518<tr>
519<td><code>const_iterator1 begin1 () const</code></td>
520<td>Returns a <code>const_iterator1</code> pointing to the
521beginning of the expression.</td>
522</tr>
523<tr>
524<td><code>const_iterator1 end1 () const</code></td>
525<td>Returns a <code>const_iterator1</code> pointing to the end of
526the expression.</td>
527</tr>
528<tr>
529<td><code>const_iterator2 begin2 () const</code></td>
530<td>Returns a <code>const_iterator2</code> pointing to the
531beginning of the expression.</td>
532</tr>
533<tr>
534<td><code>const_iterator2 end2 () const</code></td>
535<td>Returns a <code>const_iterator2</code> pointing to the end of
536the expression.</td>
537</tr>
538<tr>
539<td><code>const_reverse_iterator1 rbegin1 () const</code></td>
540<td>Returns a <code>const_reverse_iterator1</code> pointing to the
541beginning of the reversed expression.</td>
542</tr>
543<tr>
544<td><code>const_reverse_iterator1 rend1 () const</code></td>
545<td>Returns a <code>const_reverse_iterator1</code> pointing to the
546end of the reversed expression.</td>
547</tr>
548<tr>
549<td><code>const_reverse_iterator2 rbegin2 () const</code></td>
550<td>Returns a <code>const_reverse_iterator2</code> pointing to the
551beginning of the reversed expression.</td>
552</tr>
553<tr>
554<td><code>const_reverse_iterator2 rend2 () const</code></td>
555<td>Returns a <code>const_reverse_iterator2</code> pointing to the
556end of the reversed expression.</td>
557</tr>
558</tbody>
559</table>
560<h3>Binary Operations</h3>
561<h4>Prototypes</h4>
562<pre>
563<code>template&lt;class E1, class E2, class F&gt;
564    struct matrix_binary_traits {
565        typedef matrix_binary&lt;typename E1::const_closure_type,
566                               typename E2::const_closure_type, F&gt; expression_type;
567        typedef expression_type result_type;
568     };
569
570    // (m1 + m2) [i] [j] = m1 [i] [j] + m2 [i] [j]
571    template&lt;class E1, class E2&gt;
572    typename matrix_binary_traits&lt;E1, E2, scalar_plus&lt;typename E1::value_type,
573                                                       typename E2::value_type&gt; &gt;::result_type
574    operator + (const matrix_expression&lt;E1&gt; &amp;e1,
575                 const matrix_expression&lt;E2&gt; &amp;e2);
576
577    // (m1 - m2) [i] [j] = m1 [i] [j] - m2 [i] [j]
578    template&lt;class E1, class E2&gt;
579    typename matrix_binary_traits&lt;E1, E2, scalar_minus&lt;typename E1::value_type,
580                                                        typename E2::value_type&gt; &gt;::result_type
581    operator - (const matrix_expression&lt;E1&gt; &amp;e1,
582                 const matrix_expression&lt;E2&gt; &amp;e2);</code>
583</pre>
584<h4>Description</h4>
585<p><code>operator +</code> computes the sum of two matrix
586expressions. <code>operator -</code> computes the difference of two
587matrix expressions.</p>
588<h4>Definition</h4>
589<p>Defined in the header matrix_expression.hpp.</p>
590<h4>Type requirements</h4>
591<ul>
592<li><code>E1</code> is a model of <a href=
593"expression_concept.htm#matrix_expression">Matrix Expression</a> .</li>
594<li><code>E2</code> is a model of <a href=
595"expression_concept.htm#matrix_expression">Matrix Expression</a> .</li>
596</ul>
597<h4>Preconditions</h4>
598<ul>
599<li><code>e1 ().size1 () == e2 ().size1 ()</code></li>
600<li><code>e1 ().size2 () == e2 ().size2 ()</code></li>
601</ul>
602<h4>Complexity</h4>
603<p>Quadratic depending from the size of the matrix expressions.</p>
604<h4>Examples</h4>
605<pre>
606#include &lt;boost/numeric/ublas/matrix.hpp&gt;
607#include &lt;boost/numeric/ublas/io.hpp&gt;
608
609int main () {
610    using namespace boost::numeric::ublas;
611    matrix&lt;double&gt; m1 (3, 3), m2 (3, 3);
612    for (unsigned i = 0; i &lt; std::min (m1.size1 (), m2.size1 ()); ++ i)
613        for (unsigned j = 0; j &lt; std::min (m1.size2 (), m2.size2 ()); ++ j)
614            m1 (i, j) = m2 (i, j) = 3 * i + j;
615
616    std::cout &lt;&lt; m1 + m2 &lt;&lt; std::endl;
617    std::cout &lt;&lt; m1 - m2 &lt;&lt; std::endl;
618}
619</pre>
620<h3>Scalar Matrix Operation Description</h3>
621<h4>Description</h4>
622<p>The templated classes <code>matrix_binary_scalar1&lt;E1, E2,
623F&gt;</code> and <code>matrix_binary_scalar2&lt;E1, E2,
624F&gt;</code> describe binary operations between a scalar and a
625matrix.</p>
626<h4>Definition</h4>
627<p>Defined in the header matrix_expression.hpp.</p>
628<h4>Template parameters</h4>
629<table border="1" summary="parameters">
630<tbody>
631<tr>
632<th>Parameter</th>
633<th>Description</th>
634<th>Default</th>
635</tr>
636<tr>
637<td><code>E1/E2</code></td>
638<td>The type of the scalar expression.</td>
639<td></td>
640</tr>
641<tr>
642<td><code>E2/E1</code></td>
643<td>The type of the matrix expression.</td>
644<td></td>
645</tr>
646<tr>
647<td><code>F</code></td>
648<td>The type of the operation.</td>
649<td></td>
650</tr>
651</tbody>
652</table>
653<h4>Model of</h4>
654<p><a href="expression_concept.htm#matrix_expression">Matrix Expression</a>
655.</p>
656<h4>Type requirements</h4>
657<p>None, except for those imposed by the requirements of <a href=
658"expression_concept.htm#matrix_expression">Matrix Expression</a> .</p>
659<h4>Public base classes</h4>
660<p><code>matrix_expression&lt;matrix_binary_scalar1&lt;E1, E2,
661F&gt; &gt;</code> and
662<code>matrix_expression&lt;matrix_binary_scalar2&lt;E1, E2, F&gt;
663&gt;</code> resp.</p>
664<h4>Members</h4>
665<table border="1" summary="members">
666<tbody>
667<tr>
668<th>Member</th>
669<th>Description</th>
670</tr>
671<tr>
672<td><code>matrix_binary_scalar1 (const expression1_type &amp;e1,
673const expression2_type &amp;e2)</code></td>
674<td>Constructs a description of the expression.</td>
675</tr>
676<tr>
677<td><code>matrix_binary_scalar1 (const expression1_type &amp;e1,
678const expression2_type &amp;e2)</code></td>
679<td>Constructs a description of the expression.</td>
680</tr>
681<tr>
682<td><code>size_type size1 () const</code></td>
683<td>Returns the number of rows.</td>
684</tr>
685<tr>
686<td><code>size_type size2 () const</code></td>
687<td>Returns the number of columns.</td>
688</tr>
689<tr>
690<td><code>const_reference operator () (size_type i, size_type j)
691const</code></td>
692<td>Returns the value of the <code>j</code>-th element in the
693<code>i</code>-th row.</td>
694</tr>
695<tr>
696<td><code>const_iterator1 begin1 () const</code></td>
697<td>Returns a <code>const_iterator1</code> pointing to the
698beginning of the expression.</td>
699</tr>
700<tr>
701<td><code>const_iterator1 end1 () const</code></td>
702<td>Returns a <code>const_iterator1</code> pointing to the end of
703the expression.</td>
704</tr>
705<tr>
706<td><code>const_iterator2 begin2 () const</code></td>
707<td>Returns a <code>const_iterator2</code> pointing to the
708beginning of the expression.</td>
709</tr>
710<tr>
711<td><code>const_iterator2 end2 () const</code></td>
712<td>Returns a <code>const_iterator2</code> pointing to the end of
713the expression.</td>
714</tr>
715<tr>
716<td><code>const_reverse_iterator1 rbegin1 () const</code></td>
717<td>Returns a <code>const_reverse_iterator1</code> pointing to the
718beginning of the reversed expression.</td>
719</tr>
720<tr>
721<td><code>const_reverse_iterator1 rend1 () const</code></td>
722<td>Returns a <code>const_reverse_iterator1</code> pointing to the
723end of the reversed expression.</td>
724</tr>
725<tr>
726<td><code>const_reverse_iterator2 rbegin2 () const</code></td>
727<td>Returns a <code>const_reverse_iterator2</code> pointing to the
728beginning of the reversed expression.</td>
729</tr>
730<tr>
731<td><code>const_reverse_iterator2 rend2 () const</code></td>
732<td>Returns a <code>const_reverse_iterator2</code> pointing to the
733end of the reversed expression.</td>
734</tr>
735</tbody>
736</table>
737<h3>Scalar Matrix Operations</h3>
738<h4>Prototypes</h4>
739<pre>
740<code>template&lt;class T1, class E2, class F&gt;
741    struct matrix_binary_scalar1_traits {
742        typedef matrix_binary_scalar1&lt;scalar_const_reference&lt;T1&gt;,
743                                      typename E2::const_closure_type, F&gt; expression_type;
744        typedef expression_type result_type;
745     };
746
747    // (t * m) [i] [j] = t * m [i] [j]
748    template&lt;class T1, class E2&gt;
749    typename matrix_binary_scalar1_traits&lt;T1, E2, scalar_multiplies&lt;T1, typename E2::value_type&gt; &gt;::result_type
750    operator * (const T1 &amp;e1,
751                 const matrix_expression&lt;E2&gt; &amp;e2);
752
753    template&lt;class E1, class T2, class F&gt;
754    struct matrix_binary_scalar2_traits {
755        typedef matrix_binary_scalar2&lt;typename E1::const_closure_type,
756                                      scalar_const_reference&lt;T2&gt;, F&gt; expression_type;
757        typedef expression_type result_type;
758     };
759
760    // (m * t) [i] [j] = m [i] [j] * t
761    template&lt;class E1, class T2&gt;
762    typename matrix_binary_scalar2_traits&lt;E1, T2, scalar_multiplies&lt;typename E1::value_type, T2&gt; &gt;::result_type
763    operator * (const matrix_expression&lt;E1&gt; &amp;e1,
764                 const T2 &amp;e2);
765
766    // (m / t) [i] [j] = m [i] [j] / t
767    template&lt;class E1, class T2&gt;
768    typename matrix_binary_scalar2_traits&lt;E1, T2, scalar_divides&lt;typename E1::value_type, T2&gt; &gt;::result_type
769    operator / (const matrix_expression&lt;E1&gt; &amp;e1,
770                 const T2 &amp;e2);</code>
771</pre>
772<h4>Description</h4>
773<p><code>operator *</code> computes the product of a scalar and a
774matrix expression. <code>operator /</code> multiplies the matrix
775with the reciprocal of the scalar.</p>
776<h4>Definition</h4>
777<p>Defined in the header matrix_expression.hpp.</p>
778<h4>Type requirements</h4>
779<ul>
780<li><code>T1/T2</code> is a model of <a href=
781"expression_concept.htm#scalar_expression">Scalar Expression</a> .</li>
782<li><code>E2/E1</code> is a model of <a href=
783"expression_concept.htm#matrix_expression">Matrix Expression</a> .</li>
784</ul>
785<h4>Preconditions</h4>
786<p>None.</p>
787<h4>Complexity</h4>
788<p>Quadratic depending from the size of the matrix expression.</p>
789<h4>Examples</h4>
790<pre>
791#include &lt;boost/numeric/ublas/matrix.hpp&gt;
792#include &lt;boost/numeric/ublas/io.hpp&gt;
793
794int main () {
795    using namespace boost::numeric::ublas;
796    matrix&lt;double&gt; m (3, 3);
797    for (unsigned i = 0; i &lt; m.size1 (); ++ i)
798        for (unsigned j = 0; j &lt; m.size2 (); ++ j)
799            m (i, j) = 3 * i + j;
800
801    std::cout &lt;&lt; 2.0 * m &lt;&lt; std::endl;
802    std::cout &lt;&lt; m * 2.0 &lt;&lt; std::endl;
803}
804</pre>
805<h2><a name="matrix_vector_operations" id="matrix_vector_operations"></a>Matrix Vector Operations</h2>
806<h3>Binary Operation Description</h3>
807<h4>Description</h4>
808<p>The templated classes <code>matrix_vector_binary1&lt;E1, E2,
809F&gt;</code> and <code>matrix_vector_binary2&lt;E1, E2,
810F&gt;</code> describe binary matrix vector operations.</p>
811<h4>Definition</h4>
812<p>Defined in the header matrix_expression.hpp.</p>
813<h4>Template parameters</h4>
814<table border="1" summary="parameters">
815<tbody>
816<tr>
817<th>Parameter</th>
818<th>Description</th>
819<th>Default</th>
820</tr>
821<tr>
822<td><code>E1</code></td>
823<td>The type of the matrix or vector expression.</td>
824<td></td>
825</tr>
826<tr>
827<td><code>E2</code></td>
828<td>The type of the vector or matrix expression.</td>
829<td></td>
830</tr>
831<tr>
832<td><code>F</code></td>
833<td>The type of the operation.</td>
834<td></td>
835</tr>
836</tbody>
837</table>
838<h4>Model of</h4>
839<p><a href="expression_concept.htm#vector_expression">Vector Expression</a>
840.</p>
841<h4>Type requirements</h4>
842<p>None, except for those imposed by the requirements of <a href=
843"expression_concept.htm#vector_expression">Vector Expression</a> .</p>
844<h4>Public base classes</h4>
845<p><code>vector_expression&lt;matrix_vector_binary1&lt;E1, E2,
846F&gt; &gt;</code> and
847<code>vector_expression&lt;matrix_vector_binary2&lt;E1, E2, F&gt;
848&gt;</code> resp.</p>
849<h4>Members</h4>
850<table border="1" summary="members">
851<tbody>
852<tr>
853<th>Member</th>
854<th>Description</th>
855</tr>
856<tr>
857<td><code>matrix_vector_binary1 (const expression1_type &amp;e1,
858const expression2_type &amp;e2)</code></td>
859<td>Constructs a description of the expression.</td>
860</tr>
861<tr>
862<td><code>matrix_vector_binary2 (const expression1_type &amp;e1,
863const expression2_type &amp;e2)</code></td>
864<td>Constructs a description of the expression.</td>
865</tr>
866<tr>
867<td><code>size_type size () const</code></td>
868<td>Returns the size of the expression.</td>
869</tr>
870<tr>
871<td><code>const_reference operator () (size_type i)
872const</code></td>
873<td>Returns the value of the <code>i</code>-th element.</td>
874</tr>
875<tr>
876<td><code>const_iterator begin () const</code></td>
877<td>Returns a <code>const_iterator</code> pointing to the beginning
878of the expression.</td>
879</tr>
880<tr>
881<td><code>const_iterator end () const</code></td>
882<td>Returns a <code>const_iterator</code> pointing to the end of
883the expression.</td>
884</tr>
885<tr>
886<td><code>const_reverse_iterator rbegin () const</code></td>
887<td>Returns a <code>const_reverse_iterator</code> pointing to the
888beginning of the reversed expression.</td>
889</tr>
890<tr>
891<td><code>const_reverse_iterator rend () const</code></td>
892<td>Returns a <code>const_reverse_iterator</code> pointing to the
893end of the reversed expression.</td>
894</tr>
895</tbody>
896</table>
897<h3>Binary Operations</h3>
898<h4>Prototypes</h4>
899<pre>
900<code>template&lt;class T1, class E1, class T2, class E2&gt;
901    struct matrix_vector_binary1_traits {
902        typedef row_major_tag dispatch_category;
903        typedef typename promote_traits&lt;T1, T2&gt;::promote_type promote_type;
904        typedef matrix_vector_binary1&lt;typename E1::const_closure_type,
905                                       typename E2::const_closure_type,
906                                       matrix_vector_prod1&lt;T1, T2, promote_type&gt; &gt; expression_type;
907        typedef expression_type result_type;
908     };
909
910    template&lt;class E1, class E2&gt;
911    typename matrix_vector_binary1_traits&lt;typename E1::value_type, E1,
912                                           typename E2::value_type, E2&gt;::result_type
913    prod (const matrix_expression&lt;E1&gt; &amp;e1,
914           const vector_expression&lt;E2&gt; &amp;e2,
915          row_major_tag);
916
917    // Dispatcher
918    template&lt;class E1, class E2&gt;
919    typename matrix_vector_binary1_traits&lt;typename E1::value_type, E1,
920                                           typename E2::value_type, E2&gt;::result_type
921    prod (const matrix_expression&lt;E1&gt; &amp;e1,
922           const vector_expression&lt;E2&gt; &amp;e2);
923
924    template&lt;class E1, class E2&gt;
925    typename matrix_vector_binary1_traits&lt;typename type_traits&lt;typename E1::value_type&gt;::precision_type, E1,
926                                           typename type_traits&lt;typename E2::value_type&gt;::precision_type, E2&gt;::result_type
927    prec_prod (const matrix_expression&lt;E1&gt; &amp;e1,
928                const vector_expression&lt;E2&gt; &amp;e2,
929               row_major_tag);
930
931    // Dispatcher
932    template&lt;class E1, class E2&gt;
933    typename matrix_vector_binary1_traits&lt;typename type_traits&lt;typename E1::value_type&gt;::precision_type, E1,
934                                           typename type_traits&lt;typename E2::value_type&gt;::precision_type, E2&gt;::result_type
935    prec_prod (const matrix_expression&lt;E1&gt; &amp;e1,
936                const vector_expression&lt;E2&gt; &amp;e2);
937
938    template&lt;class V, class E1, class E2&gt;
939    V
940    prod (const matrix_expression&lt;E1&gt; &amp;e1,
941          const vector_expression&lt;E2&gt; &amp;e2);
942
943    template&lt;class V, class E1, class E2&gt;
944    V
945    prec_prod (const matrix_expression&lt;E1&gt; &amp;e1,
946               const vector_expression&lt;E2&gt; &amp;e2);
947
948    template&lt;class T1, class E1, class T2, class E2&gt;
949    struct matrix_vector_binary2_traits {
950        typedef column_major_tag dispatch_category;
951        typedef typename promote_traits&lt;T1, T2&gt;::promote_type promote_type;
952        typedef matrix_vector_binary2&lt;typename E1::const_closure_type,
953                                       typename E2::const_closure_type,
954                                       matrix_vector_prod2&lt;T1, T2, promote_type&gt; &gt; expression_type;
955        typedef expression_type result_type;
956     };
957
958    template&lt;class E1, class E2&gt;
959    typename matrix_vector_binary2_traits&lt;typename E1::value_type, E1,
960                                           typename E2::value_type, E2&gt;::result_type
961    prod (const vector_expression&lt;E1&gt; &amp;e1,
962           const matrix_expression&lt;E2&gt; &amp;e2,
963          column_major_tag);
964
965    // Dispatcher
966    template&lt;class E1, class E2&gt;
967    typename matrix_vector_binary2_traits&lt;typename E1::value_type, E1,
968                                           typename E2::value_type, E2&gt;::result_type
969    prod (const vector_expression&lt;E1&gt; &amp;e1,
970           const matrix_expression&lt;E2&gt; &amp;e2);
971
972    template&lt;class E1, class E2&gt;
973    typename matrix_vector_binary2_traits&lt;typename type_traits&lt;typename E1::value_type&gt;::precision_type, E1,
974                                           typename type_traits&lt;typename E2::value_type&gt;::precision_type, E2&gt;::result_type
975    prec_prod (const vector_expression&lt;E1&gt; &amp;e1,
976                const matrix_expression&lt;E2&gt; &amp;e2,
977               column_major_tag);
978
979    // Dispatcher
980    template&lt;class E1, class E2&gt;
981    typename matrix_vector_binary2_traits&lt;typename type_traits&lt;typename E1::value_type&gt;::precision_type, E1,
982                                           typename type_traits&lt;typename E2::value_type&gt;::precision_type, E2&gt;::result_type
983    prec_prod (const vector_expression&lt;E1&gt; &amp;e1,
984                const matrix_expression&lt;E2&gt; &amp;e2);
985
986    template&lt;class V, class E1, class E2&gt;
987    V
988    prod (const vector_expression&lt;E1&gt; &amp;e1,
989          const matrix_expression&lt;E2&gt; &amp;e2);
990
991    template&lt;class V, class E1, class E2&gt;
992    V
993    prec_prod (const vector_expression&lt;E1&gt; &amp;e1,
994               const matrix_expression&lt;E2&gt; &amp;e2);</code>
995</pre>
996<h4>Description</h4>
997<p><code>prod</code> computes the product of the matrix and the
998vector expression. <code>prec_prod</code> computes the double
999precision product of the matrix and the vector expression.</p>
1000<h4>Definition</h4>
1001<p>Defined in the header matrix_expression.hpp.</p>
1002<h4>Type requirements</h4>
1003<ul>
1004<li><code>E1</code> is a model of <a href=
1005"expression_concept.htm#matrix_expression">Matrix Expression</a> or
1006<a href="expression_concept.htm#vector_expression">Vector Expression</a>
1007.</li>
1008<li><code>E2</code> is a model of <a href=
1009"expression_concept.htm#vector_expression">Vector Expression</a> or
1010<a href="expression_concept.htm#matrix_expression">Matrix Expression</a>
1011.</li>
1012</ul>
1013<h4>Preconditions</h4>
1014<ul>
1015<li><code>e1 ().size2 () == e2 ().size ()</code></li>
1016<li><code>e1 ().size () == e2 ().size1 ()</code></li>
1017</ul>
1018<h4>Complexity</h4>
1019<p>Quadratic depending from the size of the matrix expression.</p>
1020<h4>Examples</h4>
1021<pre>
1022#include &lt;boost/numeric/ublas/matrix.hpp&gt;
1023#include &lt;boost/numeric/ublas/io.hpp&gt;
1024
1025int main () {
1026    using namespace boost::numeric::ublas;
1027    matrix&lt;double&gt; m (3, 3);
1028    vector&lt;double&gt; v (3);
1029    for (unsigned i = 0; i &lt; std::min (m.size1 (), v.size ()); ++ i) {
1030        for (unsigned j = 0; j &lt; m.size2 (); ++ j)
1031            m (i, j) = 3 * i + j;
1032        v (i) = i;
1033    }
1034
1035    std::cout &lt;&lt; prod (m, v) &lt;&lt; std::endl;
1036    std::cout &lt;&lt; prod (v, m) &lt;&lt; std::endl;
1037}
1038</pre>
1039<h3>Triangular Solver</h3>
1040<h4>Prototypes</h4>
1041<pre>
1042<code>template&lt;class E1, class E2&gt;
1043    struct matrix_vector_solve_traits {
1044        typedef typename promote_traits&lt;typename E1::value_type, typename E2::value_type&gt;::promote_type promote_type;
1045        typedef vector&lt;promote_type&gt; result_type;
1046    };
1047
1048    template&lt;class E1, class E2&gt;
1049    void inplace_solve (const matrix_expression&lt;E1&gt; &amp;e1,
1050                         E2 &amp;e2,
1051                        lower_tag,
1052                        vector_tag);
1053    template&lt;class E1, class E2&gt;
1054    void inplace_solve (const matrix_expression&lt;E1&gt; &amp;e1,
1055                         E2 &amp;e2,
1056                        upper_tag,
1057                        vector_tag);
1058    template&lt;class E1, class E2&gt;
1059    void inplace_solve (const matrix_expression&lt;E1&gt; &amp;e1,
1060                         E2 &amp;e2,
1061                        unit_lower_tag,
1062                        vector_tag);
1063    template&lt;class E1, class E2&gt;
1064    void inplace_solve (const matrix_expression&lt;E1&gt; &amp;e1,
1065                         E2 &amp;e2,
1066                        unit_upper_tag,
1067                        vector_tag);
1068
1069    template&lt;class E1, class E2, class C&gt;
1070    typename matrix_vector_solve_traits&lt;E1, E2&gt;::result_type
1071    solve (const matrix_expression&lt;E1&gt; &amp;e1,
1072            const vector_expression&lt;E2&gt; &amp;e2,
1073           C);
1074
1075    template&lt;class E1, class E2&gt;
1076    void inplace_solve (E1 &amp;e1,
1077                        const matrix_expression&lt;E2&gt; &amp;e2,
1078                         vector_tag,
1079                         lower_tag);
1080    template&lt;class E1, class E2&gt;
1081    void inplace_solve (E1 &amp;e1,
1082                        const matrix_expression&lt;E2&gt; &amp;e2,
1083                         vector_tag,
1084                         upper_tag);
1085    template&lt;class E1, class E2&gt;
1086    void inplace_solve (E1 &amp;e1,
1087                        const matrix_expression&lt;E2&gt; &amp;e2,
1088                         vector_tag,
1089                         unit_lower_tag);
1090    template&lt;class E1, class E2&gt;
1091    void inplace_solve (E1 &amp;e1,
1092                        const matrix_expression&lt;E2&gt; &amp;e2,
1093                         vector_tag,
1094                         unit_upper_tag);
1095
1096    template&lt;class E1, class E2, class C&gt;
1097    typename matrix_vector_solve_traits&lt;E1, E2&gt;::result_type
1098    solve (const vector_expression&lt;E1&gt; &amp;e1,
1099            const matrix_expression&lt;E2&gt; &amp;e2,
1100           C);</code>
1101</pre>
1102<h4>Description</h4>
1103<p><code>solve</code> solves a linear equation for lower or upper
1104(unit) triangular matrices.</p>
1105<h4>Definition</h4>
1106<p>Defined in the header triangular.hpp.</p>
1107<h4>Type requirements</h4>
1108<ul>
1109<li><code>E1</code> is a model of <a href=
1110"expression_concept.htm#matrix_expression">Matrix Expression</a> or
1111<a href="expression_concept.htm#vector_expression">Vector Expression</a>
1112.</li>
1113<li><code>E2</code> is a model of <a href=
1114"expression_concept.htm#vector_expression">Vector Expression</a> or
1115<a href="expression_concept.htm#matrix_expression">Matrix Expression</a>
1116.</li>
1117</ul>
1118<h4>Preconditions</h4>
1119<ul>
1120<li><code>e1 ().size1 () == e1 ().size2 ()</code></li>
1121<li><code>e1 ().size2 () == e2 ().size ()</code></li>
1122<li><code>e1 ().size () == e2 ().size1 ()</code></li>
1123<li><code>e2 ().size1 () == e2 ().size2 ()</code></li>
1124</ul>
1125<h4>Complexity</h4>
1126<p>Quadratic depending from the size of the matrix expression.</p>
1127<h4>Examples</h4>
1128<pre>
1129#include &lt;boost/numeric/ublas/triangular.hpp&gt;
1130#include &lt;boost/numeric/ublas/io.hpp&gt;
1131
1132int main () {
1133    using namespace boost::numeric::ublas;
1134    matrix&lt;double&gt; m (3, 3);
1135    vector&lt;double&gt; v (3);
1136    for (unsigned i = 0; i &lt; std::min (m.size1 (), v.size ()); ++ i) {
1137        for (unsigned j = 0; j &lt;= i; ++ j)
1138            m (i, j) = 3 * i + j + 1;
1139        v (i) = i;
1140    }
1141
1142    std::cout &lt;&lt; solve (m, v, lower_tag ()) &lt;&lt; std::endl;
1143    std::cout &lt;&lt; solve (v, m, lower_tag ()) &lt;&lt; std::endl;
1144}
1145</pre>
1146<h2><a name="matrix_matrix_operations" id="matrix_matrix_operations"></a>Matrix Matrix Operations</h2>
1147<h3>Binary Operation Description</h3>
1148<h4>Description</h4>
1149<p>The templated class <code>matrix_matrix_binary&lt;E1, E2,
1150F&gt;</code> describes a binary matrix operation.</p>
1151<h4>Definition</h4>
1152<p>Defined in the header matrix_expression.hpp.</p>
1153<h4>Template parameters</h4>
1154<table border="1" summary="parameters">
1155<tbody>
1156<tr>
1157<th>Parameter</th>
1158<th>Description</th>
1159<th>Default</th>
1160</tr>
1161<tr>
1162<td><code>E1</code></td>
1163<td>The type of the first matrix expression.</td>
1164<td></td>
1165</tr>
1166<tr>
1167<td><code>E2</code></td>
1168<td>The type of the second matrix expression.</td>
1169<td></td>
1170</tr>
1171<tr>
1172<td><code>F</code></td>
1173<td>The type of the operation.</td>
1174<td></td>
1175</tr>
1176</tbody>
1177</table>
1178<h4>Model of</h4>
1179<p><a href="expression_concept.htm#matrix_expression">Matrix Expression</a>
1180.</p>
1181<h4>Type requirements</h4>
1182<p>None, except for those imposed by the requirements of <a href=
1183"expression_concept.htm#matrix_expression">Matrix Expression</a> .</p>
1184<h4>Public base classes</h4>
1185<p><code>matrix_expression&lt;matrix_matrix_binary&lt;E1, E2, F&gt;
1186&gt;</code> .</p>
1187<h4>Members</h4>
1188<table border="1" summary="members">
1189<tbody>
1190<tr>
1191<th>Member</th>
1192<th>Description</th>
1193</tr>
1194<tr>
1195<td><code>matrix_matrix_binary (const expression1_type &amp;e1,
1196const expression2_type &amp;e2)</code></td>
1197<td>Constructs a description of the expression.</td>
1198</tr>
1199<tr>
1200<td><code>size_type size1 () const</code></td>
1201<td>Returns the number of rows.</td>
1202</tr>
1203<tr>
1204<td><code>size_type size2 () const</code></td>
1205<td>Returns the number of columns.</td>
1206</tr>
1207<tr>
1208<td><code>const_reference operator () (size_type i, size_type j)
1209const</code></td>
1210<td>Returns the value of the <code>j</code>-th element in the
1211<code>i</code>-th row.</td>
1212</tr>
1213<tr>
1214<td><code>const_iterator1 begin1 () const</code></td>
1215<td>Returns a <code>const_iterator1</code> pointing to the
1216beginning of the expression.</td>
1217</tr>
1218<tr>
1219<td><code>const_iterator1 end1 () const</code></td>
1220<td>Returns a <code>const_iterator1</code> pointing to the end of
1221the expression.</td>
1222</tr>
1223<tr>
1224<td><code>const_iterator2 begin2 () const</code></td>
1225<td>Returns a <code>const_iterator2</code> pointing to the
1226beginning of the expression.</td>
1227</tr>
1228<tr>
1229<td><code>const_iterator2 end2 () const</code></td>
1230<td>Returns a <code>const_iterator2</code> pointing to the end of
1231the expression.</td>
1232</tr>
1233<tr>
1234<td><code>const_reverse_iterator1 rbegin1 () const</code></td>
1235<td>Returns a <code>const_reverse_iterator1</code> pointing to the
1236beginning of the reversed expression.</td>
1237</tr>
1238<tr>
1239<td><code>const_reverse_iterator1 rend1 () const</code></td>
1240<td>Returns a <code>const_reverse_iterator1</code> pointing to the
1241end of the reversed expression.</td>
1242</tr>
1243<tr>
1244<td><code>const_reverse_iterator2 rbegin2 () const</code></td>
1245<td>Returns a <code>const_reverse_iterator2</code> pointing to the
1246beginning of the reversed expression.</td>
1247</tr>
1248<tr>
1249<td><code>const_reverse_iterator2 rend2 () const</code></td>
1250<td>Returns a <code>const_reverse_iterator2</code> pointing to the
1251end of the reversed expression.</td>
1252</tr>
1253</tbody>
1254</table>
1255<h3>Binary Operations</h3>
1256<h4>Prototypes</h4>
1257<pre>
1258<code>template&lt;class T1, class E1, class T2, class E2&gt;
1259    struct matrix_matrix_binary_traits {
1260        typedef unknown_orientation_tag dispatch_category;
1261        typedef typename promote_traits&lt;T1, T2&gt;::promote_type promote_type;
1262        typedef matrix_matrix_binary&lt;typename E1::const_closure_type,
1263                                     typename E2::const_closure_type,
1264                                     matrix_matrix_prod&lt;T1, T2, promote_type&gt; &gt; expression_type;
1265        typedef expression_type result_type;
1266    };
1267
1268    template&lt;class E1, class E2&gt;
1269    typename matrix_matrix_binary_traits&lt;typename E1::value_type, E1,
1270                                         typename E2::value_type, E2&gt;::result_type
1271    prod (const matrix_expression&lt;E1&gt; &amp;e1,
1272          const matrix_expression&lt;E2&gt; &amp;e2,
1273          unknown_orientation_tag);
1274
1275    // Dispatcher
1276    template&lt;class E1, class E2&gt;
1277    typename matrix_matrix_binary_traits&lt;typename E1::value_type, E1,
1278                                         typename E2::value_type, E2&gt;::result_type
1279    prod (const matrix_expression&lt;E1&gt; &amp;e1,
1280          const matrix_expression&lt;E2&gt; &amp;e2);
1281
1282    template&lt;class E1, class E2&gt;
1283    typename matrix_matrix_binary_traits&lt;typename type_traits&lt;typename E1::value_type&gt;::precision_type, E1,
1284                                         typename type_traits&lt;typename E2::value_type&gt;::precision_type, E2&gt;::result_type
1285    prec_prod (const matrix_expression&lt;E1&gt; &amp;e1,
1286               const matrix_expression&lt;E2&gt; &amp;e2,
1287               unknown_orientation_tag);
1288
1289    // Dispatcher
1290    template&lt;class E1, class E2&gt;
1291    typename matrix_matrix_binary_traits&lt;typename type_traits&lt;typename E1::value_type&gt;::precision_type, E1,
1292                                         typename type_traits&lt;typename E2::value_type&gt;::precision_type, E2&gt;::result_type
1293    prec_prod (const matrix_expression&lt;E1&gt; &amp;e1,
1294               const matrix_expression&lt;E2&gt; &amp;e2);
1295
1296    template&lt;class M, class E1, class E2&gt;
1297    M
1298    prod (const matrix_expression&lt;E1&gt; &amp;e1,
1299          const matrix_expression&lt;E2&gt; &amp;e2);
1300
1301    template&lt;class M, class E1, class E2&gt;
1302    M
1303    prec_prod (const matrix_expression&lt;E1&gt; &amp;e1,
1304               const matrix_expression&lt;E2&gt; &amp;e2);</code>
1305</pre>
1306<h4>Description</h4>
1307<p><code>prod</code> computes the product of the matrix
1308expressions. <code>prec_prod</code> computes the double precision
1309product of the matrix expressions.</p>
1310<h4>Definition</h4>
1311<p>Defined in the header matrix_expression.hpp.</p>
1312<h4>Type requirements</h4>
1313<ul>
1314<li><code>E1</code> is a model of <a href=
1315"expression_concept.htm#matrix_expression">Matrix Expression</a> .</li>
1316<li><code>E2</code> is a model of <a href=
1317"expression_concept.htm#matrix_expression">Matrix Expression</a> .</li>
1318</ul>
1319<h4>Preconditions</h4>
1320<ul>
1321<li><code>e1 ().size2 () == e2 ().size1 ()</code></li>
1322</ul>
1323<h4>Complexity</h4>
1324<p>Cubic depending from the size of the matrix expression.</p>
1325<h4>Examples</h4>
1326<pre>
1327#include &lt;boost/numeric/ublas/matrix.hpp&gt;
1328#include &lt;boost/numeric/ublas/io.hpp&gt;
1329
1330int main () {
1331    using namespace boost::numeric::ublas;
1332    matrix&lt;double&gt; m1 (3, 3), m2 (3, 3);
1333    for (unsigned i = 0; i &lt; std::min (m1.size1 (), m2.size1 ()); ++ i)
1334        for (unsigned j = 0; j &lt; std::min (m1.size2 (), m2.size2 ()); ++ j)
1335            m1 (i, j) = m2 (i, j) = 3 * i + j;
1336
1337    std::cout &lt;&lt; prod (m1, m2) &lt;&lt; std::endl;
1338}
1339</pre>
1340<h3>Triangular Solvers</h3>
1341<h4>Prototypes</h4>
1342<pre>
1343<code>template&lt;class E1, class E2&gt;
1344    struct matrix_matrix_solve_traits {
1345        typedef typename promote_traits&lt;typename E1::value_type, typename E2::value_type&gt;::promote_type promote_type;
1346        typedef matrix&lt;promote_type&gt; result_type;
1347    };
1348
1349    template&lt;class E1, class E2&gt;
1350    void inplace_solve (const matrix_expression&lt;E1&gt; &amp;e1,
1351                        E2 &amp;e2,
1352                        lower_tag,
1353                        matrix_tag);
1354    template&lt;class E1, class E2&gt;
1355    void inplace_solve (const matrix_expression&lt;E1&gt; &amp;e1,
1356                        E2 &amp;e2,
1357                        upper_tag,
1358                        matrix_tag);
1359    template&lt;class E1, class E2&gt;
1360    void inplace_solve (const matrix_expression&lt;E1&gt; &amp;e1,
1361                        E2 &amp;e2,
1362                        unit_lower_tag,
1363                        matrix_tag);
1364    template&lt;class E1, class E2&gt;
1365    void inplace_solve (const matrix_expression&lt;E1&gt; &amp;e1,
1366                        E2 &amp;e2,
1367                        unit_upper_tag,
1368                        matrix_tag);
1369
1370    template&lt;class E1, class E2, class C&gt;
1371    typename matrix_matrix_solve_traits&lt;E1, E2&gt;::result_type
1372    solve (const matrix_expression&lt;E1&gt; &amp;e1,
1373           const matrix_expression&lt;E2&gt; &amp;e2,
1374           C);</code>
1375</pre>
1376<h4>Description</h4>
1377<p><code>solve</code> solves a linear equation for lower or upper
1378(unit) triangular matrices.</p>
1379<h4>Definition</h4>
1380<p>Defined in the header triangular.hpp.</p>
1381<h4>Type requirements</h4>
1382<ul>
1383<li><code>E1</code> is a model of <a href=
1384"expression_concept.htm#matrix_expression">Matrix Expression</a> .</li>
1385<li><code>E2</code> is a model of <a href=
1386"expression_concept.htm#matrix_expression">Matrix Expression</a> .</li>
1387</ul>
1388<h4>Preconditions</h4>
1389<ul>
1390<li><code>e1 ().size1 () == e1 ().size2 ()</code></li>
1391<li><code>e1 ().size2 () == e2 ().size1 ()</code></li>
1392</ul>
1393<h4>Complexity</h4>
1394<p>Cubic depending from the size of the matrix expressions.</p>
1395<h4>Examples</h4>
1396<pre>
1397#include &lt;boost/numeric/ublas/triangular.hpp&gt;
1398#include &lt;boost/numeric/ublas/io.hpp&gt;
1399
1400int main () {
1401    using namespace boost::numeric::ublas;
1402    matrix&lt;double&gt; m1 (3, 3), m2 (3, 3);
1403    for (unsigned i = 0; i &lt; std::min (m1.size1 (), m2.size1 ()); ++ i)
1404        for (unsigned j = 0; j &lt;= i; ++ j)
1405            m1 (i, j) = m2 (i, j) = 3 * i + j + 1;
1406
1407    std::cout &lt;&lt; solve (m1, m2, lower_tag ()) &lt;&lt; std::endl;
1408}
1409</pre>
1410<hr />
1411<p>Copyright (&copy;) 2000-2002 Joerg Walter, Mathias Koch<br />
1412Permission to copy, use, modify, sell and distribute this document
1413is granted provided this copyright notice appears in all copies.
1414This document is provided ``as is'' without express or implied
1415warranty, and with no claim as to its suitability for any
1416purpose.</p>
1417</body>
1418</html>
Note: See TracBrowser for help on using the repository browser.