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