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" /> |
---|
14 | Matrix 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<E></code> |
---|
18 | is 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> </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 &operator () () |
---|
52 | const</code></td> |
---|
53 | <td>Returns a <code>const</code> reference of the expression.</td> |
---|
54 | </tr> |
---|
55 | <tr> |
---|
56 | <td><code>expression_type &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<C></code> |
---|
66 | is required to be a public base of all classes which model the Matrix concept. |
---|
67 | This 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> </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<C></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 &operator () () |
---|
101 | const</code></td> |
---|
102 | <td>Returns a <code>const</code> reference of the container.</td> |
---|
103 | </tr> |
---|
104 | <tr> |
---|
105 | <td><code>container_type &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<E></code> |
---|
114 | contains 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> </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<matrix_reference<E> |
---|
140 | ></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 &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 |
---|
155 | of <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) |
---|
167 | const</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 |
---|
173 | j)</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 |
---|
180 | beginning 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 |
---|
185 | the 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 |
---|
190 | the 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 |
---|
195 | expression.</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 |
---|
200 | beginning 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 |
---|
205 | the 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 |
---|
210 | the 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 |
---|
215 | expression.</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 |
---|
220 | beginning 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 |
---|
225 | end 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 |
---|
230 | beginning 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 |
---|
235 | the 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 |
---|
240 | beginning 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 |
---|
245 | end 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 |
---|
250 | beginning 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 |
---|
255 | the 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<E, F></code> and |
---|
263 | <code>matrix_unary2<E, F></code> describe unary matrix |
---|
264 | operations.</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> </td> |
---|
279 | </tr> |
---|
280 | <tr> |
---|
281 | <td><code>F</code></td> |
---|
282 | <td>The type of the operation.</td> |
---|
283 | <td> </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<matrix_unary1<E, F> ></code> |
---|
295 | and <code>matrix_expression<matrix_unary2<E, F> |
---|
296 | ></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 &e)</code></td> |
---|
306 | <td>Constructs a description of the expression.</td> |
---|
307 | </tr> |
---|
308 | <tr> |
---|
309 | <td><code>matrix_unary2 (const expression_type &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) |
---|
322 | const</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 |
---|
329 | beginning 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 |
---|
334 | the 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 |
---|
339 | beginning 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 |
---|
344 | the 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 |
---|
349 | beginning 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 |
---|
354 | end 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 |
---|
359 | beginning 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 |
---|
364 | end 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<class E, class F> |
---|
372 | struct matrix_unary1_traits { |
---|
373 | typedef matrix_unary1<typename E::const_closure_type, F> expression_type; |
---|
374 | typedef expression_type result_type; |
---|
375 | }; |
---|
376 | |
---|
377 | // (- m) [i] [j] = - m [i] [j] |
---|
378 | template<class E> |
---|
379 | typename matrix_unary1_traits<E, scalar_negate<typename E::value_type> >::result_type |
---|
380 | operator - (const matrix_expression<E> &e); |
---|
381 | |
---|
382 | // (conj m) [i] [j] = conj (m [i] [j]) |
---|
383 | template<class E> |
---|
384 | typename matrix_unary1_traits<E, scalar_conj<typename E::value_type> >::result_type |
---|
385 | conj (const matrix_expression<E> &e); |
---|
386 | |
---|
387 | // (real m) [i] [j] = real (m [i] [j]) |
---|
388 | template<class E> |
---|
389 | typename matrix_unary1_traits<E, scalar_real<typename E::value_type> >::result_type |
---|
390 | real (const matrix_expression<E> &e); |
---|
391 | |
---|
392 | // (imag m) [i] [j] = imag (m [i] [j]) |
---|
393 | template<class E> |
---|
394 | typename matrix_unary1_traits<E, scalar_imag<typename E::value_type> >::result_type |
---|
395 | imag (const matrix_expression<E> &e); |
---|
396 | |
---|
397 | template<class E, class F> |
---|
398 | struct matrix_unary2_traits { |
---|
399 | typedef matrix_unary2<typename E::const_closure_type, F> expression_type; |
---|
400 | typedef expression_type result_type; |
---|
401 | }; |
---|
402 | |
---|
403 | // (trans m) [i] [j] = m [j] [i] |
---|
404 | template<class E> |
---|
405 | typename matrix_unary2_traits<E, scalar_identity<typename E::value_type> >::result_type |
---|
406 | trans (const matrix_expression<E> &e); |
---|
407 | |
---|
408 | // (herm m) [i] [j] = conj (m [j] [i]) |
---|
409 | template<class E> |
---|
410 | typename matrix_unary2_traits<E, scalar_conj<typename E::value_type> >::result_type |
---|
411 | herm (const matrix_expression<E> &e);</code> |
---|
412 | </pre> |
---|
413 | <h4>Description</h4> |
---|
414 | <p><code>operator -</code> computes the additive inverse of a |
---|
415 | matrix expression. <code>conj</code> computes the complex conjugate |
---|
416 | of a matrix expression. <code>real</code> and <code>imag</code> |
---|
417 | compute 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 |
---|
420 | conjugate 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 <boost/numeric/ublas/matrix.hpp> |
---|
435 | #include <boost/numeric/ublas/io.hpp> |
---|
436 | |
---|
437 | int main () { |
---|
438 | using namespace boost::numeric::ublas; |
---|
439 | matrix<std::complex<double> > m (3, 3); |
---|
440 | for (unsigned i = 0; i < m.size1 (); ++ i) |
---|
441 | for (unsigned j = 0; j < m.size2 (); ++ j) |
---|
442 | m (i, j) = std::complex<double> (3 * i + j, 3 * i + j); |
---|
443 | |
---|
444 | std::cout << - m << std::endl; |
---|
445 | std::cout << conj (m) << std::endl; |
---|
446 | std::cout << real (m) << std::endl; |
---|
447 | std::cout << imag (m) << std::endl; |
---|
448 | std::cout << trans (m) << std::endl; |
---|
449 | std::cout << herm (m) << std::endl; |
---|
450 | } |
---|
451 | </pre> |
---|
452 | <h3>Binary Operation Description</h3> |
---|
453 | <h4>Description</h4> |
---|
454 | <p>The templated class <code>matrix_binary<E1, E2, F></code> |
---|
455 | describes 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<matrix_binary<E1, E2, F> |
---|
491 | ></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 &e1, const |
---|
501 | expression2_type &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) |
---|
514 | const</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 |
---|
521 | beginning 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 |
---|
526 | the 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 |
---|
531 | beginning 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 |
---|
536 | the 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 |
---|
541 | beginning 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 |
---|
546 | end 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 |
---|
551 | beginning 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 |
---|
556 | end 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<class E1, class E2, class F> |
---|
564 | struct matrix_binary_traits { |
---|
565 | typedef matrix_binary<typename E1::const_closure_type, |
---|
566 | typename E2::const_closure_type, F> expression_type; |
---|
567 | typedef expression_type result_type; |
---|
568 | }; |
---|
569 | |
---|
570 | // (m1 + m2) [i] [j] = m1 [i] [j] + m2 [i] [j] |
---|
571 | template<class E1, class E2> |
---|
572 | typename matrix_binary_traits<E1, E2, scalar_plus<typename E1::value_type, |
---|
573 | typename E2::value_type> >::result_type |
---|
574 | operator + (const matrix_expression<E1> &e1, |
---|
575 | const matrix_expression<E2> &e2); |
---|
576 | |
---|
577 | // (m1 - m2) [i] [j] = m1 [i] [j] - m2 [i] [j] |
---|
578 | template<class E1, class E2> |
---|
579 | typename matrix_binary_traits<E1, E2, scalar_minus<typename E1::value_type, |
---|
580 | typename E2::value_type> >::result_type |
---|
581 | operator - (const matrix_expression<E1> &e1, |
---|
582 | const matrix_expression<E2> &e2);</code> |
---|
583 | </pre> |
---|
584 | <h4>Description</h4> |
---|
585 | <p><code>operator +</code> computes the sum of two matrix |
---|
586 | expressions. <code>operator -</code> computes the difference of two |
---|
587 | matrix 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 <boost/numeric/ublas/matrix.hpp> |
---|
607 | #include <boost/numeric/ublas/io.hpp> |
---|
608 | |
---|
609 | int main () { |
---|
610 | using namespace boost::numeric::ublas; |
---|
611 | matrix<double> m1 (3, 3), m2 (3, 3); |
---|
612 | for (unsigned i = 0; i < std::min (m1.size1 (), m2.size1 ()); ++ i) |
---|
613 | for (unsigned j = 0; j < std::min (m1.size2 (), m2.size2 ()); ++ j) |
---|
614 | m1 (i, j) = m2 (i, j) = 3 * i + j; |
---|
615 | |
---|
616 | std::cout << m1 + m2 << std::endl; |
---|
617 | std::cout << m1 - m2 << 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<E1, E2, |
---|
623 | F></code> and <code>matrix_binary_scalar2<E1, E2, |
---|
624 | F></code> describe binary operations between a scalar and a |
---|
625 | matrix.</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<matrix_binary_scalar1<E1, E2, |
---|
661 | F> ></code> and |
---|
662 | <code>matrix_expression<matrix_binary_scalar2<E1, E2, F> |
---|
663 | ></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 &e1, |
---|
673 | const expression2_type &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 &e1, |
---|
678 | const expression2_type &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) |
---|
691 | const</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 |
---|
698 | beginning 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 |
---|
703 | the 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 |
---|
708 | beginning 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 |
---|
713 | the 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 |
---|
718 | beginning 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 |
---|
723 | end 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 |
---|
728 | beginning 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 |
---|
733 | end 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<class T1, class E2, class F> |
---|
741 | struct matrix_binary_scalar1_traits { |
---|
742 | typedef matrix_binary_scalar1<scalar_const_reference<T1>, |
---|
743 | typename E2::const_closure_type, F> expression_type; |
---|
744 | typedef expression_type result_type; |
---|
745 | }; |
---|
746 | |
---|
747 | // (t * m) [i] [j] = t * m [i] [j] |
---|
748 | template<class T1, class E2> |
---|
749 | typename matrix_binary_scalar1_traits<T1, E2, scalar_multiplies<T1, typename E2::value_type> >::result_type |
---|
750 | operator * (const T1 &e1, |
---|
751 | const matrix_expression<E2> &e2); |
---|
752 | |
---|
753 | template<class E1, class T2, class F> |
---|
754 | struct matrix_binary_scalar2_traits { |
---|
755 | typedef matrix_binary_scalar2<typename E1::const_closure_type, |
---|
756 | scalar_const_reference<T2>, F> expression_type; |
---|
757 | typedef expression_type result_type; |
---|
758 | }; |
---|
759 | |
---|
760 | // (m * t) [i] [j] = m [i] [j] * t |
---|
761 | template<class E1, class T2> |
---|
762 | typename matrix_binary_scalar2_traits<E1, T2, scalar_multiplies<typename E1::value_type, T2> >::result_type |
---|
763 | operator * (const matrix_expression<E1> &e1, |
---|
764 | const T2 &e2); |
---|
765 | |
---|
766 | // (m / t) [i] [j] = m [i] [j] / t |
---|
767 | template<class E1, class T2> |
---|
768 | typename matrix_binary_scalar2_traits<E1, T2, scalar_divides<typename E1::value_type, T2> >::result_type |
---|
769 | operator / (const matrix_expression<E1> &e1, |
---|
770 | const T2 &e2);</code> |
---|
771 | </pre> |
---|
772 | <h4>Description</h4> |
---|
773 | <p><code>operator *</code> computes the product of a scalar and a |
---|
774 | matrix expression. <code>operator /</code> multiplies the matrix |
---|
775 | with 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 <boost/numeric/ublas/matrix.hpp> |
---|
792 | #include <boost/numeric/ublas/io.hpp> |
---|
793 | |
---|
794 | int main () { |
---|
795 | using namespace boost::numeric::ublas; |
---|
796 | matrix<double> m (3, 3); |
---|
797 | for (unsigned i = 0; i < m.size1 (); ++ i) |
---|
798 | for (unsigned j = 0; j < m.size2 (); ++ j) |
---|
799 | m (i, j) = 3 * i + j; |
---|
800 | |
---|
801 | std::cout << 2.0 * m << std::endl; |
---|
802 | std::cout << m * 2.0 << 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<E1, E2, |
---|
809 | F></code> and <code>matrix_vector_binary2<E1, E2, |
---|
810 | F></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<matrix_vector_binary1<E1, E2, |
---|
846 | F> ></code> and |
---|
847 | <code>vector_expression<matrix_vector_binary2<E1, E2, F> |
---|
848 | ></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 &e1, |
---|
858 | const expression2_type &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 &e1, |
---|
863 | const expression2_type &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) |
---|
872 | const</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 |
---|
878 | of 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 |
---|
883 | the 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 |
---|
888 | beginning 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 |
---|
893 | end 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<class T1, class E1, class T2, class E2> |
---|
901 | struct matrix_vector_binary1_traits { |
---|
902 | typedef row_major_tag dispatch_category; |
---|
903 | typedef typename promote_traits<T1, T2>::promote_type promote_type; |
---|
904 | typedef matrix_vector_binary1<typename E1::const_closure_type, |
---|
905 | typename E2::const_closure_type, |
---|
906 | matrix_vector_prod1<T1, T2, promote_type> > expression_type; |
---|
907 | typedef expression_type result_type; |
---|
908 | }; |
---|
909 | |
---|
910 | template<class E1, class E2> |
---|
911 | typename matrix_vector_binary1_traits<typename E1::value_type, E1, |
---|
912 | typename E2::value_type, E2>::result_type |
---|
913 | prod (const matrix_expression<E1> &e1, |
---|
914 | const vector_expression<E2> &e2, |
---|
915 | row_major_tag); |
---|
916 | |
---|
917 | // Dispatcher |
---|
918 | template<class E1, class E2> |
---|
919 | typename matrix_vector_binary1_traits<typename E1::value_type, E1, |
---|
920 | typename E2::value_type, E2>::result_type |
---|
921 | prod (const matrix_expression<E1> &e1, |
---|
922 | const vector_expression<E2> &e2); |
---|
923 | |
---|
924 | template<class E1, class E2> |
---|
925 | typename matrix_vector_binary1_traits<typename type_traits<typename E1::value_type>::precision_type, E1, |
---|
926 | typename type_traits<typename E2::value_type>::precision_type, E2>::result_type |
---|
927 | prec_prod (const matrix_expression<E1> &e1, |
---|
928 | const vector_expression<E2> &e2, |
---|
929 | row_major_tag); |
---|
930 | |
---|
931 | // Dispatcher |
---|
932 | template<class E1, class E2> |
---|
933 | typename matrix_vector_binary1_traits<typename type_traits<typename E1::value_type>::precision_type, E1, |
---|
934 | typename type_traits<typename E2::value_type>::precision_type, E2>::result_type |
---|
935 | prec_prod (const matrix_expression<E1> &e1, |
---|
936 | const vector_expression<E2> &e2); |
---|
937 | |
---|
938 | template<class V, class E1, class E2> |
---|
939 | V |
---|
940 | prod (const matrix_expression<E1> &e1, |
---|
941 | const vector_expression<E2> &e2); |
---|
942 | |
---|
943 | template<class V, class E1, class E2> |
---|
944 | V |
---|
945 | prec_prod (const matrix_expression<E1> &e1, |
---|
946 | const vector_expression<E2> &e2); |
---|
947 | |
---|
948 | template<class T1, class E1, class T2, class E2> |
---|
949 | struct matrix_vector_binary2_traits { |
---|
950 | typedef column_major_tag dispatch_category; |
---|
951 | typedef typename promote_traits<T1, T2>::promote_type promote_type; |
---|
952 | typedef matrix_vector_binary2<typename E1::const_closure_type, |
---|
953 | typename E2::const_closure_type, |
---|
954 | matrix_vector_prod2<T1, T2, promote_type> > expression_type; |
---|
955 | typedef expression_type result_type; |
---|
956 | }; |
---|
957 | |
---|
958 | template<class E1, class E2> |
---|
959 | typename matrix_vector_binary2_traits<typename E1::value_type, E1, |
---|
960 | typename E2::value_type, E2>::result_type |
---|
961 | prod (const vector_expression<E1> &e1, |
---|
962 | const matrix_expression<E2> &e2, |
---|
963 | column_major_tag); |
---|
964 | |
---|
965 | // Dispatcher |
---|
966 | template<class E1, class E2> |
---|
967 | typename matrix_vector_binary2_traits<typename E1::value_type, E1, |
---|
968 | typename E2::value_type, E2>::result_type |
---|
969 | prod (const vector_expression<E1> &e1, |
---|
970 | const matrix_expression<E2> &e2); |
---|
971 | |
---|
972 | template<class E1, class E2> |
---|
973 | typename matrix_vector_binary2_traits<typename type_traits<typename E1::value_type>::precision_type, E1, |
---|
974 | typename type_traits<typename E2::value_type>::precision_type, E2>::result_type |
---|
975 | prec_prod (const vector_expression<E1> &e1, |
---|
976 | const matrix_expression<E2> &e2, |
---|
977 | column_major_tag); |
---|
978 | |
---|
979 | // Dispatcher |
---|
980 | template<class E1, class E2> |
---|
981 | typename matrix_vector_binary2_traits<typename type_traits<typename E1::value_type>::precision_type, E1, |
---|
982 | typename type_traits<typename E2::value_type>::precision_type, E2>::result_type |
---|
983 | prec_prod (const vector_expression<E1> &e1, |
---|
984 | const matrix_expression<E2> &e2); |
---|
985 | |
---|
986 | template<class V, class E1, class E2> |
---|
987 | V |
---|
988 | prod (const vector_expression<E1> &e1, |
---|
989 | const matrix_expression<E2> &e2); |
---|
990 | |
---|
991 | template<class V, class E1, class E2> |
---|
992 | V |
---|
993 | prec_prod (const vector_expression<E1> &e1, |
---|
994 | const matrix_expression<E2> &e2);</code> |
---|
995 | </pre> |
---|
996 | <h4>Description</h4> |
---|
997 | <p><code>prod</code> computes the product of the matrix and the |
---|
998 | vector expression. <code>prec_prod</code> computes the double |
---|
999 | precision 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 <boost/numeric/ublas/matrix.hpp> |
---|
1023 | #include <boost/numeric/ublas/io.hpp> |
---|
1024 | |
---|
1025 | int main () { |
---|
1026 | using namespace boost::numeric::ublas; |
---|
1027 | matrix<double> m (3, 3); |
---|
1028 | vector<double> v (3); |
---|
1029 | for (unsigned i = 0; i < std::min (m.size1 (), v.size ()); ++ i) { |
---|
1030 | for (unsigned j = 0; j < m.size2 (); ++ j) |
---|
1031 | m (i, j) = 3 * i + j; |
---|
1032 | v (i) = i; |
---|
1033 | } |
---|
1034 | |
---|
1035 | std::cout << prod (m, v) << std::endl; |
---|
1036 | std::cout << prod (v, m) << std::endl; |
---|
1037 | } |
---|
1038 | </pre> |
---|
1039 | <h3>Triangular Solver</h3> |
---|
1040 | <h4>Prototypes</h4> |
---|
1041 | <pre> |
---|
1042 | <code>template<class E1, class E2> |
---|
1043 | struct matrix_vector_solve_traits { |
---|
1044 | typedef typename promote_traits<typename E1::value_type, typename E2::value_type>::promote_type promote_type; |
---|
1045 | typedef vector<promote_type> result_type; |
---|
1046 | }; |
---|
1047 | |
---|
1048 | template<class E1, class E2> |
---|
1049 | void inplace_solve (const matrix_expression<E1> &e1, |
---|
1050 | E2 &e2, |
---|
1051 | lower_tag, |
---|
1052 | vector_tag); |
---|
1053 | template<class E1, class E2> |
---|
1054 | void inplace_solve (const matrix_expression<E1> &e1, |
---|
1055 | E2 &e2, |
---|
1056 | upper_tag, |
---|
1057 | vector_tag); |
---|
1058 | template<class E1, class E2> |
---|
1059 | void inplace_solve (const matrix_expression<E1> &e1, |
---|
1060 | E2 &e2, |
---|
1061 | unit_lower_tag, |
---|
1062 | vector_tag); |
---|
1063 | template<class E1, class E2> |
---|
1064 | void inplace_solve (const matrix_expression<E1> &e1, |
---|
1065 | E2 &e2, |
---|
1066 | unit_upper_tag, |
---|
1067 | vector_tag); |
---|
1068 | |
---|
1069 | template<class E1, class E2, class C> |
---|
1070 | typename matrix_vector_solve_traits<E1, E2>::result_type |
---|
1071 | solve (const matrix_expression<E1> &e1, |
---|
1072 | const vector_expression<E2> &e2, |
---|
1073 | C); |
---|
1074 | |
---|
1075 | template<class E1, class E2> |
---|
1076 | void inplace_solve (E1 &e1, |
---|
1077 | const matrix_expression<E2> &e2, |
---|
1078 | vector_tag, |
---|
1079 | lower_tag); |
---|
1080 | template<class E1, class E2> |
---|
1081 | void inplace_solve (E1 &e1, |
---|
1082 | const matrix_expression<E2> &e2, |
---|
1083 | vector_tag, |
---|
1084 | upper_tag); |
---|
1085 | template<class E1, class E2> |
---|
1086 | void inplace_solve (E1 &e1, |
---|
1087 | const matrix_expression<E2> &e2, |
---|
1088 | vector_tag, |
---|
1089 | unit_lower_tag); |
---|
1090 | template<class E1, class E2> |
---|
1091 | void inplace_solve (E1 &e1, |
---|
1092 | const matrix_expression<E2> &e2, |
---|
1093 | vector_tag, |
---|
1094 | unit_upper_tag); |
---|
1095 | |
---|
1096 | template<class E1, class E2, class C> |
---|
1097 | typename matrix_vector_solve_traits<E1, E2>::result_type |
---|
1098 | solve (const vector_expression<E1> &e1, |
---|
1099 | const matrix_expression<E2> &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 <boost/numeric/ublas/triangular.hpp> |
---|
1130 | #include <boost/numeric/ublas/io.hpp> |
---|
1131 | |
---|
1132 | int main () { |
---|
1133 | using namespace boost::numeric::ublas; |
---|
1134 | matrix<double> m (3, 3); |
---|
1135 | vector<double> v (3); |
---|
1136 | for (unsigned i = 0; i < std::min (m.size1 (), v.size ()); ++ i) { |
---|
1137 | for (unsigned j = 0; j <= i; ++ j) |
---|
1138 | m (i, j) = 3 * i + j + 1; |
---|
1139 | v (i) = i; |
---|
1140 | } |
---|
1141 | |
---|
1142 | std::cout << solve (m, v, lower_tag ()) << std::endl; |
---|
1143 | std::cout << solve (v, m, lower_tag ()) << 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<E1, E2, |
---|
1150 | F></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<matrix_matrix_binary<E1, E2, F> |
---|
1186 | ></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 &e1, |
---|
1196 | const expression2_type &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) |
---|
1209 | const</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 |
---|
1216 | beginning 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 |
---|
1221 | the 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 |
---|
1226 | beginning 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 |
---|
1231 | the 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 |
---|
1236 | beginning 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 |
---|
1241 | end 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 |
---|
1246 | beginning 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 |
---|
1251 | end 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<class T1, class E1, class T2, class E2> |
---|
1259 | struct matrix_matrix_binary_traits { |
---|
1260 | typedef unknown_orientation_tag dispatch_category; |
---|
1261 | typedef typename promote_traits<T1, T2>::promote_type promote_type; |
---|
1262 | typedef matrix_matrix_binary<typename E1::const_closure_type, |
---|
1263 | typename E2::const_closure_type, |
---|
1264 | matrix_matrix_prod<T1, T2, promote_type> > expression_type; |
---|
1265 | typedef expression_type result_type; |
---|
1266 | }; |
---|
1267 | |
---|
1268 | template<class E1, class E2> |
---|
1269 | typename matrix_matrix_binary_traits<typename E1::value_type, E1, |
---|
1270 | typename E2::value_type, E2>::result_type |
---|
1271 | prod (const matrix_expression<E1> &e1, |
---|
1272 | const matrix_expression<E2> &e2, |
---|
1273 | unknown_orientation_tag); |
---|
1274 | |
---|
1275 | // Dispatcher |
---|
1276 | template<class E1, class E2> |
---|
1277 | typename matrix_matrix_binary_traits<typename E1::value_type, E1, |
---|
1278 | typename E2::value_type, E2>::result_type |
---|
1279 | prod (const matrix_expression<E1> &e1, |
---|
1280 | const matrix_expression<E2> &e2); |
---|
1281 | |
---|
1282 | template<class E1, class E2> |
---|
1283 | typename matrix_matrix_binary_traits<typename type_traits<typename E1::value_type>::precision_type, E1, |
---|
1284 | typename type_traits<typename E2::value_type>::precision_type, E2>::result_type |
---|
1285 | prec_prod (const matrix_expression<E1> &e1, |
---|
1286 | const matrix_expression<E2> &e2, |
---|
1287 | unknown_orientation_tag); |
---|
1288 | |
---|
1289 | // Dispatcher |
---|
1290 | template<class E1, class E2> |
---|
1291 | typename matrix_matrix_binary_traits<typename type_traits<typename E1::value_type>::precision_type, E1, |
---|
1292 | typename type_traits<typename E2::value_type>::precision_type, E2>::result_type |
---|
1293 | prec_prod (const matrix_expression<E1> &e1, |
---|
1294 | const matrix_expression<E2> &e2); |
---|
1295 | |
---|
1296 | template<class M, class E1, class E2> |
---|
1297 | M |
---|
1298 | prod (const matrix_expression<E1> &e1, |
---|
1299 | const matrix_expression<E2> &e2); |
---|
1300 | |
---|
1301 | template<class M, class E1, class E2> |
---|
1302 | M |
---|
1303 | prec_prod (const matrix_expression<E1> &e1, |
---|
1304 | const matrix_expression<E2> &e2);</code> |
---|
1305 | </pre> |
---|
1306 | <h4>Description</h4> |
---|
1307 | <p><code>prod</code> computes the product of the matrix |
---|
1308 | expressions. <code>prec_prod</code> computes the double precision |
---|
1309 | product 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 <boost/numeric/ublas/matrix.hpp> |
---|
1328 | #include <boost/numeric/ublas/io.hpp> |
---|
1329 | |
---|
1330 | int main () { |
---|
1331 | using namespace boost::numeric::ublas; |
---|
1332 | matrix<double> m1 (3, 3), m2 (3, 3); |
---|
1333 | for (unsigned i = 0; i < std::min (m1.size1 (), m2.size1 ()); ++ i) |
---|
1334 | for (unsigned j = 0; j < std::min (m1.size2 (), m2.size2 ()); ++ j) |
---|
1335 | m1 (i, j) = m2 (i, j) = 3 * i + j; |
---|
1336 | |
---|
1337 | std::cout << prod (m1, m2) << std::endl; |
---|
1338 | } |
---|
1339 | </pre> |
---|
1340 | <h3>Triangular Solvers</h3> |
---|
1341 | <h4>Prototypes</h4> |
---|
1342 | <pre> |
---|
1343 | <code>template<class E1, class E2> |
---|
1344 | struct matrix_matrix_solve_traits { |
---|
1345 | typedef typename promote_traits<typename E1::value_type, typename E2::value_type>::promote_type promote_type; |
---|
1346 | typedef matrix<promote_type> result_type; |
---|
1347 | }; |
---|
1348 | |
---|
1349 | template<class E1, class E2> |
---|
1350 | void inplace_solve (const matrix_expression<E1> &e1, |
---|
1351 | E2 &e2, |
---|
1352 | lower_tag, |
---|
1353 | matrix_tag); |
---|
1354 | template<class E1, class E2> |
---|
1355 | void inplace_solve (const matrix_expression<E1> &e1, |
---|
1356 | E2 &e2, |
---|
1357 | upper_tag, |
---|
1358 | matrix_tag); |
---|
1359 | template<class E1, class E2> |
---|
1360 | void inplace_solve (const matrix_expression<E1> &e1, |
---|
1361 | E2 &e2, |
---|
1362 | unit_lower_tag, |
---|
1363 | matrix_tag); |
---|
1364 | template<class E1, class E2> |
---|
1365 | void inplace_solve (const matrix_expression<E1> &e1, |
---|
1366 | E2 &e2, |
---|
1367 | unit_upper_tag, |
---|
1368 | matrix_tag); |
---|
1369 | |
---|
1370 | template<class E1, class E2, class C> |
---|
1371 | typename matrix_matrix_solve_traits<E1, E2>::result_type |
---|
1372 | solve (const matrix_expression<E1> &e1, |
---|
1373 | const matrix_expression<E2> &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 <boost/numeric/ublas/triangular.hpp> |
---|
1398 | #include <boost/numeric/ublas/io.hpp> |
---|
1399 | |
---|
1400 | int main () { |
---|
1401 | using namespace boost::numeric::ublas; |
---|
1402 | matrix<double> m1 (3, 3), m2 (3, 3); |
---|
1403 | for (unsigned i = 0; i < std::min (m1.size1 (), m2.size1 ()); ++ i) |
---|
1404 | for (unsigned j = 0; j <= i; ++ j) |
---|
1405 | m1 (i, j) = m2 (i, j) = 3 * i + j + 1; |
---|
1406 | |
---|
1407 | std::cout << solve (m1, m2, lower_tag ()) << std::endl; |
---|
1408 | } |
---|
1409 | </pre> |
---|
1410 | <hr /> |
---|
1411 | <p>Copyright (©) 2000-2002 Joerg Walter, Mathias Koch<br /> |
---|
1412 | Permission to copy, use, modify, sell and distribute this document |
---|
1413 | is granted provided this copyright notice appears in all copies. |
---|
1414 | This document is provided ``as is'' without express or implied |
---|
1415 | warranty, and with no claim as to its suitability for any |
---|
1416 | purpose.</p> |
---|
1417 | </body> |
---|
1418 | </html> |
---|