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