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>Vector Expressions</title> |
| 14 | </head> |
| 15 | <body> |
| 16 | <h1><img src="../../../../boost.png" align="middle" />Vector Expressions</h1> |
| 17 | <div class="toc" id="toc"></div> |
| 18 | <h2><a name="vector_expression"></a>Vector Expression</h2> |
| 19 | <h4>Description</h4> |
| 20 | <p>The templated class <code>vector_expression<E></code> |
| 21 | is required to be a public base of all classes which model the Vector Expression concept.</p> |
| 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 vector expression.</td> |
| 35 | <td> </td> |
| 36 | </tr> |
| 37 | </tbody> |
| 38 | </table> |
| 39 | <h4>Model of</h4> |
| 40 | <p>None. <u>Not a Vector 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>range</code>, <code>slice</code> and <code>project</code> functions have been removed. Use the free functions defined in <a href="vector_proxy.html">vector proxy</a> instead.</p> |
| 66 | |
| 67 | <h2><a name="vector_container"></a>Vector Container</h2> |
| 68 | <h4>Description</h4> |
| 69 | <p>The templated class <code>vector_container<C></code> |
| 70 | is required to be a public base of all classes which model the Vector concept. |
| 71 | This includes the class <code>vector</code> itself.</p> |
| 72 | <h4>Definition</h4> |
| 73 | <p>Defined in the header expression_types.hpp.</p> |
| 74 | <h4>Template parameters</h4> |
| 75 | <table border="1" summary="parameters"> |
| 76 | <tbody> |
| 77 | <tr> |
| 78 | <th>Parameter</th> |
| 79 | <th>Description</th> |
| 80 | <th>Default</th> |
| 81 | </tr> |
| 82 | <tr> |
| 83 | <td><code>C</code></td> |
| 84 | <td>The type of the vector container.</td> |
| 85 | <td> </td> |
| 86 | </tr> |
| 87 | </tbody> |
| 88 | </table> |
| 89 | <h4>Model of</h4> |
| 90 | <p>None. <u>Not a Vector Expression OR Vector</u>! |
| 91 | </p> |
| 92 | <h4>Type requirements</h4> |
| 93 | <p>None.</p> |
| 94 | <h4>Public base classes</h4> |
| 95 | <p><code>vector_expression<C></code></p> |
| 96 | <h4>Members</h4> |
| 97 | <table border="1" summary="members"> |
| 98 | <tbody> |
| 99 | <tr> |
| 100 | <th>Member</th> |
| 101 | <th>Description</th> |
| 102 | </tr> |
| 103 | <tr> |
| 104 | <td><code>const container_type &operator () () |
| 105 | const</code></td> |
| 106 | <td>Returns a <code>const</code> reference of the container.</td> |
| 107 | </tr> |
| 108 | <tr> |
| 109 | <td><code>container_type &operator () ()</code></td> |
| 110 | <td>Returns a reference of the container.</td> |
| 111 | </tr> |
| 112 | </tbody> |
| 113 | </table> |
| 114 | |
| 115 | <h2><a name="vector_references"></a>Vector References</h2> |
| 116 | <h3>Reference</h3> |
| 117 | <h4>Description</h4> |
| 118 | <p>The templated class <code>vector_reference<E></code> |
| 119 | contains a reference to a vector expression.</p> |
| 120 | <h4>Definition</h4> |
| 121 | <p>Defined in the header vector_expression.hpp.</p> |
| 122 | <h4>Template parameters</h4> |
| 123 | <table border="1" summary="parameters"> |
| 124 | <tbody> |
| 125 | <tr> |
| 126 | <th>Parameter</th> |
| 127 | <th>Description</th> |
| 128 | <th>Default</th> |
| 129 | </tr> |
| 130 | <tr> |
| 131 | <td><code>E</code></td> |
| 132 | <td>The type of the vector expression.</td> |
| 133 | <td> </td> |
| 134 | </tr> |
| 135 | </tbody> |
| 136 | </table> |
| 137 | <h4>Model of</h4> |
| 138 | <p><a href="expression_concept.html#vector_expression">Vector Expression</a> |
| 139 | .</p> |
| 140 | <h4>Type requirements</h4> |
| 141 | <p>None, except for those imposed by the requirements of <a href= |
| 142 | "expression_concept.html#vector_expression">Vector Expression</a> .</p> |
| 143 | <h4>Public base classes</h4> |
| 144 | <p><code>vector_expression<vector_reference<E> |
| 145 | ></code></p> |
| 146 | <h4>Members</h4> |
| 147 | <table border="1" summary="members"> |
| 148 | <tbody> |
| 149 | <tr> |
| 150 | <th>Member</th> |
| 151 | <th>Description</th> |
| 152 | </tr> |
| 153 | <tr> |
| 154 | <td><code>vector_reference (expression_type &e)</code></td> |
| 155 | <td>Constructs a reference of the expression.</td> |
| 156 | </tr> |
| 157 | <tr> |
| 158 | <td><code>void resize (size_type size)</code></td> |
| 159 | <td>Resizes the expression to hold at most <code>size</code> |
| 160 | elements.</td> |
| 161 | </tr> |
| 162 | <tr> |
| 163 | <td><code>size_type size () const</code></td> |
| 164 | <td>Returns the size of the expression.</td> |
| 165 | </tr> |
| 166 | <tr> |
| 167 | <td><code>const_reference operator () (size_type i) |
| 168 | const</code></td> |
| 169 | <td>Returns the value of the <code>i</code>-th element.</td> |
| 170 | </tr> |
| 171 | <tr> |
| 172 | <td><code>reference operator () (size_type i)</code></td> |
| 173 | <td>Returns a reference of the <code>i</code>-th element.</td> |
| 174 | </tr> |
| 175 | <tr> |
| 176 | <td><code>const_iterator begin () const</code></td> |
| 177 | <td>Returns a <code>const_iterator</code> pointing to the beginning |
| 178 | of the expression.</td> |
| 179 | </tr> |
| 180 | <tr> |
| 181 | <td><code>const_iterator end () const</code></td> |
| 182 | <td>Returns a <code>const_iterator</code> pointing to the end of |
| 183 | the expression.</td> |
| 184 | </tr> |
| 185 | <tr> |
| 186 | <td><code>iterator begin ()</code></td> |
| 187 | <td>Returns a <code>iterator</code> pointing to the beginning of |
| 188 | the expression.</td> |
| 189 | </tr> |
| 190 | <tr> |
| 191 | <td><code>iterator end ()</code></td> |
| 192 | <td>Returns a <code>iterator</code> pointing to the end of the |
| 193 | expression.</td> |
| 194 | </tr> |
| 195 | <tr> |
| 196 | <td><code>const_reverse_iterator rbegin () const</code></td> |
| 197 | <td>Returns a <code>const_reverse_iterator</code> pointing to the |
| 198 | beginning of the reversed expression.</td> |
| 199 | </tr> |
| 200 | <tr> |
| 201 | <td><code>const_reverse_iterator rend () const</code></td> |
| 202 | <td>Returns a <code>const_reverse_iterator</code> pointing to the |
| 203 | end of the reversed expression.</td> |
| 204 | </tr> |
| 205 | <tr> |
| 206 | <td><code>reverse_iterator rbegin ()</code></td> |
| 207 | <td>Returns a <code>reverse_iterator</code> pointing to the |
| 208 | beginning of the reversed expression.</td> |
| 209 | </tr> |
| 210 | <tr> |
| 211 | <td><code>reverse_iterator rend ()</code></td> |
| 212 | <td>Returns a <code>reverse_iterator</code> pointing to the end of |
| 213 | the reversed expression.</td> |
| 214 | </tr> |
| 215 | </tbody> |
| 216 | </table> |
| 217 | <h2><a name="vector_operations"></a>Vector Operations</h2> |
| 218 | <h3>Unary Operation Description</h3> |
| 219 | <h4>Description</h4> |
| 220 | <p>The templated class <code>vector_unary<E, F></code> |
| 221 | describes a unary vector operation.</p> |
| 222 | <h4>Definition</h4> |
| 223 | <p>Defined in the header vector_expression.hpp.</p> |
| 224 | <h4>Template parameters</h4> |
| 225 | <table border="1" summary="parameters"> |
| 226 | <tbody> |
| 227 | <tr> |
| 228 | <th>Parameter</th> |
| 229 | <th>Description</th> |
| 230 | <th>Default</th> |
| 231 | </tr> |
| 232 | <tr> |
| 233 | <td><code>E</code></td> |
| 234 | <td>The type of the vector expression.</td> |
| 235 | <td> </td> |
| 236 | </tr> |
| 237 | <tr> |
| 238 | <td><code>F</code></td> |
| 239 | <td>The type of the operation.</td> |
| 240 | <td> </td> |
| 241 | </tr> |
| 242 | </tbody> |
| 243 | </table> |
| 244 | <h4>Model of</h4> |
| 245 | <p><a href="expression_concept.html#vector_expression">Vector Expression</a> |
| 246 | .</p> |
| 247 | <h4>Type requirements</h4> |
| 248 | <p>None, except for those imposed by the requirements of <a href= |
| 249 | "expression_concept.html#vector_expression">Vector Expression</a> .</p> |
| 250 | <h4>Public base classes</h4> |
| 251 | <p><code>vector_expression<vector_unary<E, F> |
| 252 | ></code></p> |
| 253 | <h4>Members</h4> |
| 254 | <table border="1" summary="members"> |
| 255 | <tbody> |
| 256 | <tr> |
| 257 | <th>Member</th> |
| 258 | <th>Description</th> |
| 259 | </tr> |
| 260 | <tr> |
| 261 | <td><code>vector_unary (const expression_type &e)</code></td> |
| 262 | <td>Constructs a description of the expression.</td> |
| 263 | </tr> |
| 264 | <tr> |
| 265 | <td><code>size_type size () const</code></td> |
| 266 | <td>Returns the size of the expression.</td> |
| 267 | </tr> |
| 268 | <tr> |
| 269 | <td><code>const_reference operator () (size_type i) |
| 270 | const</code></td> |
| 271 | <td>Returns the value of the <code>i</code>-th element.</td> |
| 272 | </tr> |
| 273 | <tr> |
| 274 | <td><code>const_iterator begin () const</code></td> |
| 275 | <td>Returns a <code>const_iterator</code> pointing to the beginning |
| 276 | of the expression.</td> |
| 277 | </tr> |
| 278 | <tr> |
| 279 | <td><code>const_iterator end () const</code></td> |
| 280 | <td>Returns a <code>const_iterator</code> pointing to the end of |
| 281 | the expression.</td> |
| 282 | </tr> |
| 283 | <tr> |
| 284 | <td><code>const_reverse_iterator rbegin () const</code></td> |
| 285 | <td>Returns a <code>const_reverse_iterator</code> pointing to the |
| 286 | beginning of the reversed expression.</td> |
| 287 | </tr> |
| 288 | <tr> |
| 289 | <td><code>const_reverse_iterator rend () const</code></td> |
| 290 | <td>Returns a <code>const_reverse_iterator</code> pointing to the |
| 291 | end of the reversed expression.</td> |
| 292 | </tr> |
| 293 | </tbody> |
| 294 | </table> |
| 295 | <h3>Unary Operations</h3> |
| 296 | <h4>Prototypes</h4> |
| 297 | <pre> |
| 298 | <code>template<class E, class F> |
| 299 | struct vector_unary_traits { |
| 300 | typedef vector_unary<typename E::const_closure_type, F> expression_type; |
| 301 | typedef expression_type result_type; |
| 302 | }; |
| 303 | |
| 304 | // (- v) [i] = - v [i] |
| 305 | template<class E> |
| 306 | typename vector_unary_traits<E, scalar_negate<typename E::value_type> >::result_type |
| 307 | operator - (const vector_expression<E> &e); |
| 308 | |
| 309 | // (conj v) [i] = conj (v [i]) |
| 310 | template<class E> |
| 311 | typename vector_unary_traits<E, scalar_conj<typename E::value_type> >::result_type |
| 312 | conj (const vector_expression<E> &e); |
| 313 | |
| 314 | // (real v) [i] = real (v [i]) |
| 315 | template<class E> |
| 316 | typename vector_unary_traits<E, scalar_real<typename E::value_type> >::result_type |
| 317 | real (const vector_expression<E> &e); |
| 318 | |
| 319 | // (imag v) [i] = imag (v [i]) |
| 320 | template<class E> |
| 321 | typename vector_unary_traits<E, scalar_imag<typename E::value_type> >::result_type |
| 322 | imag (const vector_expression<E> &e); |
| 323 | |
| 324 | // (trans v) [i] = v [i] |
| 325 | template<class E> |
| 326 | typename vector_unary_traits<E, scalar_identity<typename E::value_type> >::result_type |
| 327 | trans (const vector_expression<E> &e); |
| 328 | |
| 329 | // (herm v) [i] = conj (v [i]) |
| 330 | template<class E> |
| 331 | typename vector_unary_traits<E, scalar_conj<typename E::value_type> >::result_type |
| 332 | herm (const vector_expression<E> &e);</code> |
| 333 | </pre> |
| 334 | <h4>Description</h4> |
| 335 | <p><code>operator -</code> computes the additive inverse of a |
| 336 | vector expression. <code>conj</code> computes the complex conjugate |
| 337 | of a vector expression. <code>real</code> and <code>imag</code> |
| 338 | compute the real and imaginary parts of a vector expression. |
| 339 | <code>trans</code> computes the transpose of a vector expression. |
| 340 | <code>herm</code> computes the hermitian, i.e. the complex |
| 341 | conjugate of the transpose of a vector expression.</p> |
| 342 | <h4>Definition</h4> |
| 343 | <p>Defined in the header vector_expression.hpp.</p> |
| 344 | <h4>Type requirements</h4> |
| 345 | <ul> |
| 346 | <li><code>E</code> is a model of <a href= |
| 347 | "expression_concept.html#vector_expression">Vector Expression</a> .</li> |
| 348 | </ul> |
| 349 | <h4>Preconditions</h4> |
| 350 | <p>None.</p> |
| 351 | <h4>Complexity</h4> |
| 352 | <p>Linear depending from the size of the vector expression.</p> |
| 353 | <h4>Examples</h4> |
| 354 | <pre> |
| 355 | #include <boost/numeric/ublas/vector.hpp> |
| 356 | #include <boost/numeric/ublas/io.hpp> |
| 357 | |
| 358 | int main () { |
| 359 | using namespace boost::numeric::ublas; |
| 360 | vector<std::complex<double> > v (3); |
| 361 | for (unsigned i = 0; i < v.size (); ++ i) |
| 362 | v (i) = std::complex<double> (i, i); |
| 363 | |
| 364 | std::cout << - v << std::endl; |
| 365 | std::cout << conj (v) << std::endl; |
| 366 | std::cout << real (v) << std::endl; |
| 367 | std::cout << imag (v) << std::endl; |
| 368 | std::cout << trans (v) << std::endl; |
| 369 | std::cout << herm (v) << std::endl; |
| 370 | } |
| 371 | </pre> |
| 372 | <h3>Binary Operation Description</h3> |
| 373 | <h4>Description</h4> |
| 374 | <p>The templated class <code>vector_binary<E1, E2, F></code> |
| 375 | describes a binary vector operation.</p> |
| 376 | <h4>Definition</h4> |
| 377 | <p>Defined in the header vector_expression.hpp.</p> |
| 378 | <h4>Template parameters</h4> |
| 379 | <table border="1" summary="parameters"> |
| 380 | <tbody> |
| 381 | <tr> |
| 382 | <th>Parameter</th> |
| 383 | <th>Description</th> |
| 384 | <th>Default</th> |
| 385 | </tr> |
| 386 | <tr> |
| 387 | <td><code>E1</code></td> |
| 388 | <td>The type of the first vector expression.</td> |
| 389 | <td></td> |
| 390 | </tr> |
| 391 | <tr> |
| 392 | <td><code>E2</code></td> |
| 393 | <td>The type of the second vector expression.</td> |
| 394 | <td></td> |
| 395 | </tr> |
| 396 | <tr> |
| 397 | <td><code>F</code></td> |
| 398 | <td>The type of the operation.</td> |
| 399 | <td></td> |
| 400 | </tr> |
| 401 | </tbody> |
| 402 | </table> |
| 403 | <h4>Model of</h4> |
| 404 | <p><a href="expression_concept.html#vector_expression">Vector Expression</a> |
| 405 | .</p> |
| 406 | <h4>Type requirements</h4> |
| 407 | <p>None, except for those imposed by the requirements of <a href= |
| 408 | "expression_concept.html#vector_expression">Vector Expression</a> .</p> |
| 409 | <h4>Public base classes</h4> |
| 410 | <p><code>vector_expression<vector_binary<E1, E2, F> |
| 411 | ></code></p> |
| 412 | <h4>Members</h4> |
| 413 | <table border="1" summary="members"> |
| 414 | <tbody> |
| 415 | <tr> |
| 416 | <th>Member</th> |
| 417 | <th>Description</th> |
| 418 | </tr> |
| 419 | <tr> |
| 420 | <td><code>vector_binary (const expression1_type &e1, const |
| 421 | expression2_type &e2)</code></td> |
| 422 | <td>Constructs a description of the expression.</td> |
| 423 | </tr> |
| 424 | <tr> |
| 425 | <td><code>size_type size () const</code></td> |
| 426 | <td>Returns the size of the expression.</td> |
| 427 | </tr> |
| 428 | <tr> |
| 429 | <td><code>const_reference operator () (size_type i) |
| 430 | const</code></td> |
| 431 | <td>Returns the value of the <code>i</code>-th element.</td> |
| 432 | </tr> |
| 433 | <tr> |
| 434 | <td><code>const_iterator begin () const</code></td> |
| 435 | <td>Returns a <code>const_iterator</code> pointing to the beginning |
| 436 | of the expression.</td> |
| 437 | </tr> |
| 438 | <tr> |
| 439 | <td><code>const_iterator end () const</code></td> |
| 440 | <td>Returns a <code>const_iterator</code> pointing to the end of |
| 441 | the expression.</td> |
| 442 | </tr> |
| 443 | <tr> |
| 444 | <td><code>const_reverse_iterator rbegin () const</code></td> |
| 445 | <td>Returns a <code>const_reverse_iterator</code> pointing to the |
| 446 | beginning of the reversed expression.</td> |
| 447 | </tr> |
| 448 | <tr> |
| 449 | <td><code>const_reverse_iterator rend () const</code></td> |
| 450 | <td>Returns a <code>const_reverse_iterator</code> pointing to the |
| 451 | end of the reversed expression.</td> |
| 452 | </tr> |
| 453 | </tbody> |
| 454 | </table> |
| 455 | <h3>Binary Operations</h3> |
| 456 | <h4>Prototypes</h4> |
| 457 | <pre> |
| 458 | <code>template<class E1, class E2, class F> |
| 459 | struct vector_binary_traits { |
| 460 | typedef vector_binary<typename E1::const_closure_type, |
| 461 | typename E2::const_closure_type, F> expression_type; |
| 462 | typedef expression_type result_type; |
| 463 | }; |
| 464 | |
| 465 | // (v1 + v2) [i] = v1 [i] + v2 [i] |
| 466 | template<class E1, class E2> |
| 467 | typename vector_binary_traits<E1, E2, scalar_plus<typename E1::value_type, |
| 468 | typename E2::value_type> >::result_type |
| 469 | operator + (const vector_expression<E1> &e1, |
| 470 | const vector_expression<E2> &e2); |
| 471 | |
| 472 | // (v1 - v2) [i] = v1 [i] - v2 [i] |
| 473 | template<class E1, class E2> |
| 474 | typename vector_binary_traits<E1, E2, scalar_minus<typename E1::value_type, |
| 475 | typename E2::value_type> >::result_type |
| 476 | operator - (const vector_expression<E1> &e1, |
| 477 | const vector_expression<E2> &e2);</code> |
| 478 | </pre> |
| 479 | <h4>Description</h4> |
| 480 | <p><code>operator +</code> computes the sum of two vector |
| 481 | expressions. <code>operator -</code> computes the difference of two |
| 482 | vector expressions.</p> |
| 483 | <h4>Definition</h4> |
| 484 | <p>Defined in the header vector_expression.hpp.</p> |
| 485 | <h4>Type requirements</h4> |
| 486 | <ul> |
| 487 | <li><code>E1</code> is a model of <a href= |
| 488 | "expression_concept.html#vector_expression">Vector Expression</a> .</li> |
| 489 | <li><code>E2</code> is a model of <a href= |
| 490 | "expression_concept.html#vector_expression">Vector Expression</a> .</li> |
| 491 | </ul> |
| 492 | <h4>Preconditions</h4> |
| 493 | <ul> |
| 494 | <li><code>e1 ().size () == e2 ().size ()</code></li> |
| 495 | </ul> |
| 496 | <h4>Complexity</h4> |
| 497 | <p>Linear depending from the size of the vector expressions.</p> |
| 498 | <h4>Examples</h4> |
| 499 | <pre> |
| 500 | #include <boost/numeric/ublas/vector.hpp> |
| 501 | #include <boost/numeric/ublas/io.hpp> |
| 502 | |
| 503 | int main () { |
| 504 | using namespace boost::numeric::ublas; |
| 505 | vector<double> v1 (3), v2 (3); |
| 506 | for (unsigned i = 0; i < std::min (v1.size (), v2.size ()); ++ i) |
| 507 | v1 (i) = v2 (i) = i; |
| 508 | |
| 509 | std::cout << v1 + v2 << std::endl; |
| 510 | std::cout << v1 - v2 << std::endl; |
| 511 | } |
| 512 | </pre> |
| 513 | <h3>Binary Outer Operation Description</h3> |
| 514 | <h4>Description</h4> |
| 515 | <p>The templated class <code>vector_matrix_binary<E1, E2, |
| 516 | F></code> describes a binary outer vector operation.</p> |
| 517 | <h4>Definition</h4> |
| 518 | <p>Defined in the header matrix_expression.hpp.</p> |
| 519 | <h4>Template parameters</h4> |
| 520 | <table border="1" summary="parameters"> |
| 521 | <tbody> |
| 522 | <tr> |
| 523 | <th>Parameter</th> |
| 524 | <th>Description</th> |
| 525 | <th>Default</th> |
| 526 | </tr> |
| 527 | <tr> |
| 528 | <td><code>E1</code></td> |
| 529 | <td>The type of the first vector expression.</td> |
| 530 | <td></td> |
| 531 | </tr> |
| 532 | <tr> |
| 533 | <td><code>E2</code></td> |
| 534 | <td>The type of the second vector expression.</td> |
| 535 | <td></td> |
| 536 | </tr> |
| 537 | <tr> |
| 538 | <td><code>F</code></td> |
| 539 | <td>The type of the operation.</td> |
| 540 | <td></td> |
| 541 | </tr> |
| 542 | </tbody> |
| 543 | </table> |
| 544 | <h4>Model of</h4> |
| 545 | <p><a href="expression_concept.html#matrix_expression">Matrix Expression</a> |
| 546 | .</p> |
| 547 | <h4>Type requirements</h4> |
| 548 | <p>None, except for those imposed by the requirements of <a href= |
| 549 | "expression_concept.html#matrix_expression">Matrix Expression</a> .</p> |
| 550 | <h4>Public base classes</h4> |
| 551 | <p><code>matrix_expression<vector_matrix_binary<E1, E2, F> |
| 552 | ></code></p> |
| 553 | <h4>Members</h4> |
| 554 | <table border="1" summary="members"> |
| 555 | <tbody> |
| 556 | <tr> |
| 557 | <th>Member</th> |
| 558 | <th>Description</th> |
| 559 | </tr> |
| 560 | <tr> |
| 561 | <td><code>vector_matrix_binary (const expression1_type &e1, |
| 562 | const expression2_type &e2)</code></td> |
| 563 | <td>Constructs a description of the expression.</td> |
| 564 | </tr> |
| 565 | <tr> |
| 566 | <td><code>size_type size1 () const</code></td> |
| 567 | <td>Returns the number of rows.</td> |
| 568 | </tr> |
| 569 | <tr> |
| 570 | <td><code>size_type size2 () const</code></td> |
| 571 | <td>Returns the number of columns.</td> |
| 572 | </tr> |
| 573 | <tr> |
| 574 | <td><code>const_reference operator () (size_type i, size_type j) |
| 575 | const</code></td> |
| 576 | <td>Returns the value of the <code>j</code>-th element in the |
| 577 | <code>i</code>-th row.</td> |
| 578 | </tr> |
| 579 | <tr> |
| 580 | <td><code>const_iterator1 begin1 () const</code></td> |
| 581 | <td>Returns a <code>const_iterator1</code> pointing to the |
| 582 | beginning of the expression.</td> |
| 583 | </tr> |
| 584 | <tr> |
| 585 | <td><code>const_iterator1 end1 () const</code></td> |
| 586 | <td>Returns a <code>const_iterator1</code> pointing to the end of |
| 587 | the expression.</td> |
| 588 | </tr> |
| 589 | <tr> |
| 590 | <td><code>const_iterator2 begin2 () const</code></td> |
| 591 | <td>Returns a <code>const_iterator2</code> pointing to the |
| 592 | beginning of the expression.</td> |
| 593 | </tr> |
| 594 | <tr> |
| 595 | <td><code>const_iterator2 end2 () const</code></td> |
| 596 | <td>Returns a <code>const_iterator2</code> pointing to the end of |
| 597 | the expression.</td> |
| 598 | </tr> |
| 599 | <tr> |
| 600 | <td><code>const_reverse_iterator1 rbegin1 () const</code></td> |
| 601 | <td>Returns a <code>const_reverse_iterator1</code> pointing to the |
| 602 | beginning of the reversed expression.</td> |
| 603 | </tr> |
| 604 | <tr> |
| 605 | <td><code>const_reverse_iterator1 rend1 () const</code></td> |
| 606 | <td>Returns a <code>const_reverse_iterator1</code> pointing to the |
| 607 | end of the reversed expression.</td> |
| 608 | </tr> |
| 609 | <tr> |
| 610 | <td><code>const_reverse_iterator2 rbegin2 () const</code></td> |
| 611 | <td>Returns a <code>const_reverse_iterator2</code> pointing to the |
| 612 | beginning of the reversed expression.</td> |
| 613 | </tr> |
| 614 | <tr> |
| 615 | <td><code>const_reverse_iterator2 rend2 () const</code></td> |
| 616 | <td>Returns a <code>const_reverse_iterator2</code> pointing to the |
| 617 | end of the reversed expression.</td> |
| 618 | </tr> |
| 619 | </tbody> |
| 620 | </table> |
| 621 | <h3>Binary Outer Operations</h3> |
| 622 | <h4>Prototypes</h4> |
| 623 | <pre> |
| 624 | <code>template<class E1, class E2, class F> |
| 625 | struct vector_matrix_binary_traits { |
| 626 | typedef vector_matrix_binary<typename E1::const_closure_type, |
| 627 | typename E2::const_closure_type, F> expression_type; |
| 628 | typedef expression_type result_type; |
| 629 | }; |
| 630 | |
| 631 | // (outer_prod (v1, v2)) [i] [j] = v1 [i] * v2 [j] |
| 632 | template<class E1, class E2> |
| 633 | typename vector_matrix_binary_traits<E1, E2, scalar_multiplies<typename E1::value_type, typename E2::value_type> >::result_type |
| 634 | outer_prod (const vector_expression<E1> &e1, |
| 635 | const vector_expression<E2> &e2);</code> |
| 636 | </pre> |
| 637 | <h4>Description</h4> |
| 638 | <p><code>outer_prod</code> computes the outer product of two vector |
| 639 | expressions.</p> |
| 640 | <h4>Definition</h4> |
| 641 | <p>Defined in the header matrix_expression.hpp.</p> |
| 642 | <h4>Type requirements</h4> |
| 643 | <ul> |
| 644 | <li><code>E1</code> is a model of <a href= |
| 645 | "expression_concept.html#vector_expression">Vector Expression</a> .</li> |
| 646 | <li><code>E2</code> is a model of <a href= |
| 647 | "expression_concept.html#vector_expression">Vector Expression</a> .</li> |
| 648 | </ul> |
| 649 | <h4>Preconditions</h4> |
| 650 | <p>None.</p> |
| 651 | <h4>Complexity</h4> |
| 652 | <p>Quadratic depending from the size of the vector expressions.</p> |
| 653 | <h4>Examples</h4> |
| 654 | <pre> |
| 655 | #include <boost/numeric/ublas/matrix.hpp> |
| 656 | #include <boost/numeric/ublas/io.hpp> |
| 657 | |
| 658 | int main () { |
| 659 | using namespace boost::numeric::ublas; |
| 660 | vector<double> v1 (3), v2 (3); |
| 661 | for (unsigned i = 0; i < std::min (v1.size (), v2.size ()); ++ i) |
| 662 | v1 (i) = v2 (i) = i; |
| 663 | |
| 664 | std::cout << outer_prod (v1, v2) << std::endl; |
| 665 | } |
| 666 | </pre> |
| 667 | <h3>Scalar Vector Operation Description</h3> |
| 668 | <h4>Description</h4> |
| 669 | <p>The templated classes <code>vector_binary_scalar1<E1, E2, |
| 670 | F></code> and <code>vector_binary_scalar2<E1, E2, |
| 671 | F></code> describe binary operations between a scalar and a |
| 672 | vector.</p> |
| 673 | <h4>Definition</h4> |
| 674 | <p>Defined in the header vector_expression.hpp.</p> |
| 675 | <h4>Template parameters</h4> |
| 676 | <table border="1" summary="parameters"> |
| 677 | <tbody> |
| 678 | <tr> |
| 679 | <th>Parameter</th> |
| 680 | <th>Description</th> |
| 681 | <th>Default</th> |
| 682 | </tr> |
| 683 | <tr> |
| 684 | <td><code>E1/E2</code></td> |
| 685 | <td>The type of the scalar expression.</td> |
| 686 | <td></td> |
| 687 | </tr> |
| 688 | <tr> |
| 689 | <td><code>E2/E1</code></td> |
| 690 | <td>The type of the vector expression.</td> |
| 691 | <td></td> |
| 692 | </tr> |
| 693 | <tr> |
| 694 | <td><code>F</code></td> |
| 695 | <td>The type of the operation.</td> |
| 696 | <td></td> |
| 697 | </tr> |
| 698 | </tbody> |
| 699 | </table> |
| 700 | <h4>Model of</h4> |
| 701 | <p><a href="expression_concept.html#vector_expression">Vector Expression</a> |
| 702 | .</p> |
| 703 | <h4>Type requirements</h4> |
| 704 | <p>None, except for those imposed by the requirements of <a href= |
| 705 | "expression_concept.html#vector_expression">Vector Expression</a> .</p> |
| 706 | <h4>Public base classes</h4> |
| 707 | <p><code>vector_expression<vector_binary_scalar1<E1, E2, |
| 708 | F> ></code> and |
| 709 | <code>vector_expression<vector_binary_scalar2<E1, E2, F> |
| 710 | ></code> resp.</p> |
| 711 | <h4>Members</h4> |
| 712 | <table border="1" summary="members"> |
| 713 | <tbody> |
| 714 | <tr> |
| 715 | <th>Member</th> |
| 716 | <th>Description</th> |
| 717 | </tr> |
| 718 | <tr> |
| 719 | <td><code>vector_binary_scalar1 (const expression1_type &e1, |
| 720 | const expression2_type &e2)</code></td> |
| 721 | <td>Constructs a description of the expression.</td> |
| 722 | </tr> |
| 723 | <tr> |
| 724 | <td><code>vector_binary_scalar2 (const expression1_type &e1, |
| 725 | const expression2_type &e2)</code></td> |
| 726 | <td>Constructs a description of the expression.</td> |
| 727 | </tr> |
| 728 | <tr> |
| 729 | <td><code>size_type size () const</code></td> |
| 730 | <td>Returns the size of the expression.</td> |
| 731 | </tr> |
| 732 | <tr> |
| 733 | <td><code>const_reference operator () (size_type i) |
| 734 | const</code></td> |
| 735 | <td>Returns the value of the <code>i</code>-th element.</td> |
| 736 | </tr> |
| 737 | <tr> |
| 738 | <td><code>const_iterator begin () const</code></td> |
| 739 | <td>Returns a <code>const_iterator</code> pointing to the beginning |
| 740 | of the expression.</td> |
| 741 | </tr> |
| 742 | <tr> |
| 743 | <td><code>const_iterator end () const</code></td> |
| 744 | <td>Returns a <code>const_iterator</code> pointing to the end of |
| 745 | the expression.</td> |
| 746 | </tr> |
| 747 | <tr> |
| 748 | <td><code>const_reverse_iterator rbegin () const</code></td> |
| 749 | <td>Returns a <code>const_reverse_iterator</code> pointing to the |
| 750 | beginning of the reversed expression.</td> |
| 751 | </tr> |
| 752 | <tr> |
| 753 | <td><code>const_reverse_iterator rend () const</code></td> |
| 754 | <td>Returns a <code>const_reverse_iterator</code> pointing to the |
| 755 | end of the reversed expression.</td> |
| 756 | </tr> |
| 757 | </tbody> |
| 758 | </table> |
| 759 | <h3>Scalar Vector Operations</h3> |
| 760 | <h4>Prototypes</h4> |
| 761 | <pre> |
| 762 | <code>template<class T1, class E2, class F> |
| 763 | struct vector_binary_scalar1_traits { |
| 764 | typedef vector_binary_scalar1<scalar_const_reference<T1>, |
| 765 | typename E2::const_closure_type, F> expression_type; |
| 766 | typedef expression_type result_type; |
| 767 | }; |
| 768 | |
| 769 | // (t * v) [i] = t * v [i] |
| 770 | template<class T1, class E2> |
| 771 | typename vector_binary_scalar1_traits<T1, E2, scalar_multiplies<T1, typename E2::value_type> >::result_type |
| 772 | operator * (const T1 &e1, |
| 773 | const vector_expression<E2> &e2); |
| 774 | |
| 775 | template<class E1, class T2, class F> |
| 776 | struct vector_binary_scalar2_traits { |
| 777 | typedef vector_binary_scalar2<typename E1::const_closure_type, |
| 778 | scalar_const_reference<T2>, F> expression_type; |
| 779 | typedef expression_type result_type; |
| 780 | }; |
| 781 | |
| 782 | // (v * t) [i] = v [i] * t |
| 783 | template<class E1, class T2> |
| 784 | typename vector_binary_scalar2_traits<E1, T2, scalar_multiplies<typename E1::value_type, T2> >::result_type |
| 785 | operator * (const vector_expression<E1> &e1, |
| 786 | const T2 &e2); |
| 787 | |
| 788 | // (v / t) [i] = v [i] / t |
| 789 | template<class E1, class T2> |
| 790 | typename vector_binary_scalar2_traits<E1, T2, scalar_divides<typename E1::value_type, T2> >::result_type |
| 791 | operator / (const vector_expression<E1> &e1, |
| 792 | const T2 &e2);</code> |
| 793 | </pre> |
| 794 | <h4>Description</h4> |
| 795 | <p><code>operator *</code> computes the product of a scalar and a |
| 796 | vector expression. <code>operator /</code> multiplies the vector |
| 797 | with the reciprocal of the scalar.</p> |
| 798 | <h4>Definition</h4> |
| 799 | <p>Defined in the header vector_expression.hpp.</p> |
| 800 | <h4>Type requirements</h4> |
| 801 | <ul> |
| 802 | <li><code>T1/T2</code> is a model of <a href= |
| 803 | "expression_concept.html#scalar_expression">Scalar Expression</a> .</li> |
| 804 | <li><code>E2/E1</code> is a model of <a href= |
| 805 | "expression_concept.html#vector_expression">Vector Expression</a> .</li> |
| 806 | </ul> |
| 807 | <h4>Preconditions</h4> |
| 808 | <p>None.</p> |
| 809 | <h4>Complexity</h4> |
| 810 | <p>Linear depending from the size of the vector expression.</p> |
| 811 | <h4>Examples</h4> |
| 812 | <pre> |
| 813 | #include <boost/numeric/ublas/vector.hpp> |
| 814 | #include <boost/numeric/ublas/io.hpp> |
| 815 | |
| 816 | int main () { |
| 817 | using namespace boost::numeric::ublas; |
| 818 | vector<double> v (3); |
| 819 | for (unsigned i = 0; i < v.size (); ++ i) |
| 820 | v (i) = i; |
| 821 | |
| 822 | std::cout << 2.0 * v << std::endl; |
| 823 | std::cout << v * 2.0 << std::endl; |
| 824 | } |
| 825 | </pre> |
| 826 | <h2><a name="vector_reductions"></a>Vector Reductions</h2> |
| 827 | <h3>Unary Reductions</h3> |
| 828 | <h4>Prototypes</h4> |
| 829 | <pre> |
| 830 | <code>template<class E, class F> |
| 831 | struct vector_scalar_unary_traits { |
| 832 | typedef typename F::result_type result_type; |
| 833 | }; |
| 834 | |
| 835 | // sum v = sum (v [i]) |
| 836 | template<class E> |
| 837 | typename vector_scalar_unary_traits<E, vector_sum<typename E::value_type> >::result_type |
| 838 | sum (const vector_expression<E> &e); |
| 839 | |
| 840 | // norm_1 v = sum (abs (v [i])) |
| 841 | template<class E> |
| 842 | typename vector_scalar_unary_traits<E, vector_norm_1<typename E::value_type> >::result_type |
| 843 | norm_1 (const vector_expression<E> &e); |
| 844 | |
| 845 | // norm_2 v = sqrt (sum (v [i] * v [i])) |
| 846 | template<class E> |
| 847 | typename vector_scalar_unary_traits<E, vector_norm_2<typename E::value_type> >::result_type |
| 848 | norm_2 (const vector_expression<E> &e); |
| 849 | |
| 850 | // norm_inf v = max (abs (v [i])) |
| 851 | template<class E> |
| 852 | typename vector_scalar_unary_traits<E, vector_norm_inf<typename E::value_type> >::result_type |
| 853 | norm_inf (const vector_expression<E> &e); |
| 854 | |
| 855 | // index_norm_inf v = min (i: abs (v [i]) == max (abs (v [i]))) |
| 856 | template<class E> |
| 857 | typename vector_scalar_unary_traits<E, vector_index_norm_inf<typename E::value_type> >::result_type |
| 858 | index_norm_inf (const vector_expression<E> &e);</code> |
| 859 | </pre> |
| 860 | <h4>Description</h4> |
| 861 | <p><code>sum</code> computes the sum of the vector expression's |
| 862 | elements. <code>norm_1</code>, <code>norm_2</code> and |
| 863 | <code>norm_inf</code> compute the corresponding |
| 864 | <em>||.||</em><sub><em>1</em></sub>, |
| 865 | <em>||.||</em><sub><em>2</em></sub> and |
| 866 | <em>||.||</em><sub><em>inf</em></sub> vector norms. |
| 867 | <code>index_norm_1</code> computes the index of the vector |
| 868 | expression's first element having maximal absolute value.</p> |
| 869 | <h4>Definition</h4> |
| 870 | <p>Defined in the header vector_expression.hpp.</p> |
| 871 | <h4>Type requirements</h4> |
| 872 | <ul> |
| 873 | <li><code>E</code> is a model of <a href= |
| 874 | "#vector_expression">Vector Expression</a> .</li> |
| 875 | </ul> |
| 876 | <h4>Preconditions</h4> |
| 877 | <p>None.</p> |
| 878 | <h4>Complexity</h4> |
| 879 | <p>Linear depending from the size of the vector expression.</p> |
| 880 | <h4>Examples</h4> |
| 881 | <pre> |
| 882 | #include <boost/numeric/ublas/vector.hpp> |
| 883 | |
| 884 | int main () { |
| 885 | using namespace boost::numeric::ublas; |
| 886 | vector<double> v (3); |
| 887 | for (unsigned i = 0; i < v.size (); ++ i) |
| 888 | v (i) = i; |
| 889 | |
| 890 | std::cout << sum (v) << std::endl; |
| 891 | std::cout << norm_1 (v) << std::endl; |
| 892 | std::cout << norm_2 (v) << std::endl; |
| 893 | std::cout << norm_inf (v) << std::endl; |
| 894 | std::cout << index_norm_inf (v) << std::endl; |
| 895 | } |
| 896 | </pre> |
| 897 | <h3>Binary Reductions</h3> |
| 898 | <h4>Prototypes</h4> |
| 899 | <pre> |
| 900 | <code>template<class E1, class E2, class F> |
| 901 | struct vector_scalar_binary_traits { |
| 902 | typedef typename F::result_type result_type; |
| 903 | }; |
| 904 | |
| 905 | // inner_prod (v1, v2) = sum (v1 [i] * v2 [i]) |
| 906 | template<class E1, class E2> |
| 907 | typename vector_scalar_binary_traits<E1, E2, vector_inner_prod<typename E1::value_type, |
| 908 | typename E2::value_type, |
| 909 | typename promote_traits<typename E1::value_type, |
| 910 | typename E2::value_type>::promote_type> >::result_type |
| 911 | inner_prod (const vector_expression<E1> &e1, |
| 912 | const vector_expression<E2> &e2); |
| 913 | |
| 914 | template<class E1, class E2> |
| 915 | typename vector_scalar_binary_traits<E1, E2, vector_inner_prod<typename E1::value_type, |
| 916 | typename E2::value_type, |
| 917 | typename type_traits<typename promote_traits<typename E1::value_type, |
| 918 | typename E2::value_type>::promote_type>::precision_type> >::result_type |
| 919 | prec_inner_prod (const vector_expression<E1> &e1, |
| 920 | const vector_expression<E2> &e2);</code> |
| 921 | </pre> |
| 922 | <h4>Description</h4> |
| 923 | <p><code>inner_prod</code> computes the inner product of the vector |
| 924 | expressions. <code>prec_inner_prod</code> computes the double |
| 925 | precision inner product of the vector expressions<code>.</code></p> |
| 926 | <h4>Definition</h4> |
| 927 | <p>Defined in the header vector_expression.hpp.</p> |
| 928 | <h4>Type requirements</h4> |
| 929 | <ul> |
| 930 | <li><code>E1</code> is a model of <a href= |
| 931 | "#vector_expression">Vector Expression</a> .</li> |
| 932 | <li><code>E2</code> is a model of <a href= |
| 933 | "#vector_expression">Vector Expression</a> .</li> |
| 934 | </ul> |
| 935 | <h4>Preconditions</h4> |
| 936 | <ul> |
| 937 | <li><code>e1 ().size () == e2 ().size ()</code></li> |
| 938 | </ul> |
| 939 | <h4>Complexity</h4> |
| 940 | <p>Linear depending from the size of the vector expressions.</p> |
| 941 | <h4>Examples</h4> |
| 942 | <pre> |
| 943 | #include <boost/numeric/ublas/vector.hpp> |
| 944 | |
| 945 | int main () { |
| 946 | using namespace boost::numeric::ublas; |
| 947 | vector<double> v1 (3), v2 (3); |
| 948 | for (unsigned i = 0; i < std::min (v1.size (), v2.size ()); ++ i) |
| 949 | v1 (i) = v2 (i) = i; |
| 950 | |
| 951 | std::cout << inner_prod (v1, v2) << std::endl; |
| 952 | } |
| 953 | </pre> |
| 954 | <hr /> |
| 955 | <p>Copyright (©) 2000-2002 Joerg Walter, Mathias Koch<br /> |
| 956 | Use, modification and distribution are subject to the |
| 957 | Boost Software License, Version 1.0. |
| 958 | (See accompanying file LICENSE_1_0.txt |
| 959 | or copy at <a href="http://www.boost.org/LICENSE_1_0.txt"> |
| 960 | http://www.boost.org/LICENSE_1_0.txt |
| 961 | </a>). |
| 962 | </p> |
| 963 | <script type="text/javascript"> |
| 964 | (function($) { |
| 965 | $('#toc').toc(); |
| 966 | })(jQuery); |
| 967 | </script> |
| 968 | </body> |
| 969 | </html> |