/usr/include/itpp/base/vec.h is in libitpp-dev 4.3.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 | /*!
* \file
* \brief Templated Vector Class Definitions
* \author Tony Ottosson, Tobias Ringstrom, Adam Piatyszek and Conrad Sanderson
*
* -------------------------------------------------------------------------
*
* Copyright (C) 1995-2010 (see AUTHORS file for a list of contributors)
*
* This file is part of IT++ - a C++ library of mathematical, signal
* processing, speech processing, and communications classes and functions.
*
* IT++ is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* IT++ is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along
* with IT++. If not, see <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#ifndef VEC_H
#define VEC_H
#include <itpp/base/itassert.h>
#include <itpp/base/math/misc.h>
#include <itpp/base/copy_vector.h>
#include <itpp/base/factory.h>
#include <vector>
#include <itpp/itexports.h>
namespace itpp
{
// Declaration of Vec
template<class Num_T> class Vec;
// Declaration of Mat
template<class Num_T> class Mat;
// Declaration of bin
class bin;
//-----------------------------------------------------------------------------------
// Declaration of Vec Friends
//-----------------------------------------------------------------------------------
//! Addition of two vectors
template<class Num_T>
Vec<Num_T> operator+(const Vec<Num_T> &v1, const Vec<Num_T> &v2);
//! Addition of a vector and a scalar
template<class Num_T>
Vec<Num_T> operator+(const Vec<Num_T> &v, Num_T t);
//! Addition of a scalar and a vector
template<class Num_T>
Vec<Num_T> operator+(Num_T t, const Vec<Num_T> &v);
//! Subtraction of a vector from a vector
template<class Num_T>
Vec<Num_T> operator-(const Vec<Num_T> &v1, const Vec<Num_T> &v2);
//! Subtraction of a scalar from a vector
template<class Num_T>
Vec<Num_T> operator-(const Vec<Num_T> &v, Num_T t);
//! Subtraction of vector from scalar. Results in a vector
template<class Num_T>
Vec<Num_T> operator-(Num_T t, const Vec<Num_T> &v);
//! Negation of vector
template<class Num_T>
Vec<Num_T> operator-(const Vec<Num_T> &v);
//! Inner (dot) product of two vectors v1 and v2
template<class Num_T>
Num_T dot(const Vec<Num_T> &v1, const Vec<Num_T> &v2);
//! Inner (dot) product of two vectors v1 and v2
template<class Num_T>
Num_T operator*(const Vec<Num_T> &v1, const Vec<Num_T> &v2);
/*!
* \brief Outer product of two vectors v1 and v2
*
* When \a v1 and \a v2 are complex vectors (cvec), the third boolean
* argument \a hermitian can be set to \a true to conjugate \a v2
* (Matlab's v1 * v2' operation). This parameter is ignored for types
* other then cvec.
*/
template<class Num_T>
Mat<Num_T> outer_product(const Vec<Num_T> &v1, const Vec<Num_T> &v2,
bool hermitian = false);
//! Multiplication of a vector and a scalar
template<class Num_T>
Vec<Num_T> operator*(const Vec<Num_T> &v, Num_T t);
//! Multiplication of a scalar and a vector. Results in a vector
template<class Num_T>
Vec<Num_T> operator*(Num_T t, const Vec<Num_T> &v);
//! Element-wise multiplication of two vectors
template<class Num_T>
Vec<Num_T> elem_mult(const Vec<Num_T> &a, const Vec<Num_T> &b);
//! Element-wise multiplication of three vectors
template<class Num_T>
Vec<Num_T> elem_mult(const Vec<Num_T> &a, const Vec<Num_T> &b,
const Vec<Num_T> &c);
//! Element-wise multiplication of four vectors
template<class Num_T>
Vec<Num_T> elem_mult(const Vec<Num_T> &a, const Vec<Num_T> &b,
const Vec<Num_T> &c, const Vec<Num_T> &d);
//! Element-wise multiplication of two vectors, storing the result in vector \c out
template<class Num_T>
void elem_mult_out(const Vec<Num_T> &a, const Vec<Num_T> &b,
Vec<Num_T> &out);
//! Element-wise multiplication of three vectors, storing the result in vector \c out
template<class Num_T>
void elem_mult_out(const Vec<Num_T> &a, const Vec<Num_T> &b,
const Vec<Num_T> &c, Vec<Num_T> &out);
//! Element-wise multiplication of four vectors, storing the result in vector \c out
template<class Num_T>
void elem_mult_out(const Vec<Num_T> &a, const Vec<Num_T> &b,
const Vec<Num_T> &c, const Vec<Num_T> &d,
Vec<Num_T> &out);
//! In-place element-wise multiplication of two vectors. Faster version of b = elem_mult(a,b).
template<class Num_T>
void elem_mult_inplace(const Vec<Num_T> &a, Vec<Num_T> &b);
//! Element-wise multiplication of two vectors, followed by summation of the resultant elements. Fast version of sum(elem_mult(a,b)).
template<class Num_T>
Num_T elem_mult_sum(const Vec<Num_T> &a, const Vec<Num_T> &b);
//! Division of all elements in \c v with \c t
template<class Num_T>
Vec<Num_T> operator/(const Vec<Num_T> &v, Num_T t);
//! Division of \c t with all elements in \c v
template<class Num_T>
Vec<Num_T> operator/(Num_T t, const Vec<Num_T> &v);
//! Elementwise division of two vectors
template<class Num_T>
Vec<Num_T> elem_div(const Vec<Num_T> &a, const Vec<Num_T> &b);
//! This function is deprecated. Please use operator/(Num_T, const Vec<Num_T &) instead.
template<class Num_T>
Vec<Num_T> elem_div(Num_T t, const Vec<Num_T> &v);
//! Elementwise division of two vectors, storing the result in vector \c out
template<class Num_T>
void elem_div_out(const Vec<Num_T> &a, const Vec<Num_T> &b, Vec<Num_T> &out);
//! Elementwise division of two vectors, followed by summation of the resultant elements. Fast version of sum(elem_div(a,b))
template<class Num_T>
Num_T elem_div_sum(const Vec<Num_T> &a, const Vec<Num_T> &b);
//! Append element \c a to the end of the vector \c v
template<class Num_T>
Vec<Num_T> concat(const Vec<Num_T> &v, Num_T a);
//! Concat element \c a to the beginning of the vector \c v
template<class Num_T>
Vec<Num_T> concat(Num_T a, const Vec<Num_T> &v);
//! Concat vectors \c v1 and \c v2
template<class Num_T>
Vec<Num_T> concat(const Vec<Num_T> &v1, const Vec<Num_T> &v2);
//! Concat vectors \c v1, \c v2 and \c v3
template<class Num_T>
Vec<Num_T> concat(const Vec<Num_T> &v1, const Vec<Num_T> &v2,
const Vec<Num_T> &v3);
//! Concat vectors \c v1, \c v2, \c v3 and \c v4
template<class Num_T>
Vec<Num_T> concat(const Vec<Num_T> &v1, const Vec<Num_T> &v2,
const Vec<Num_T> &v3, const Vec<Num_T> &v4);
//! Concat vectors \c v1, \c v2 \c v3, \c v4 and \c v5
template<class Num_T>
Vec<Num_T> concat(const Vec<Num_T> &v1, const Vec<Num_T> &v2,
const Vec<Num_T> &v3, const Vec<Num_T> &v4,
const Vec<Num_T> &v5);
//-----------------------------------------------------------------------------------
// Declaration of Vec
//-----------------------------------------------------------------------------------
/*!
\ingroup arr_vec_mat
\brief Vector Class (Templated)
\author Tony Ottosson, Tobias Ringstrom, Adam Piatyszek and Conrad Sanderson
Vectors can be of arbitrary types, but conversions and functions are
prepared for \c bin, \c short, \c int, \c double, and \c complex<double>
vectors and these are predefined as: \c bvec, \c svec, \c ivec, \c vec,
and \c cvec. \c double and \c complex<double> are \c double and
\c complex<double> respectively.
Examples:
Vector Constructors:
When constructing a vector without a length (memory) use
\code vec temp; \endcode
For construction of a vector of a given length use
\code vec temp(length); \endcode
It is also possible to assign the constructed vector the value and size
of another vector by
\code vec temp(invector); \endcode
If you have explicit values you would like to assign to the vector it is
possible to do this using strings as:
\code
vec a("0 0.7 5 9.3"); // that is a = [0, 0.7, 5, 9.3]
vec a="0 0.7 5 9.3"; // the constructor is called implicitly
ivec b="0:5"; // that is, b = [0, 1, 2, 3, 4, 5]
vec c="3:2.5:13"; // that is, c = [3, 5.5, 8, 10.5, 13]
\endcode
It is also possible to change length by
\code temp.set_size(new_length, false); \endcode
where \c false is used to indicate that the old values in \c temp
are not copied. If you would like to preserve the values, use \c true.
There are a number of methods to access parts of a vector. Examples are
\code
a(5); // Element number 5
a(5,9); // Elements 5, 6, 7, 8, and 9
a.left(10); // The 10 leftmost elements (the first)
a.right(10); // The 10 rightmost elements (the last)
a.mid(5, 7); // 7 elements starting from element 5
\endcode
It is also possible to modify parts of a vector, as in e.g.
\code
a.del(5); // deletes element number 5
a.ins(3.4, 9); // inserts the element 3.4 at position 9
a.set_subvector(12, b); // replaces elements from 12 with the vector b
\endcode
It is, of course, also possible to perform common linear algebra
operations, such as addition, subtraction, and scalar product (*). Observe
though, that vectors are assumed to be column-vectors in operations with
matrices.
Most elementary functions such as sin(), cosh(), log(), abs(), ..., are
also available as operations on the individual elements of the vectors. Please
see the individual functions for more details.
By default, the Vec elements are created using the default constructor for
the element type. This can be changed by specifying a suitable Factory in
the Vec constructor call; see Detailed Description for Factory.
*/
template<class Num_T>
class Vec
{
public:
//! The type of the vector values
typedef Num_T value_type;
//! Default constructor. An element factory \c f can be specified.
explicit Vec(const Factory &f = DEFAULT_FACTORY);
//! Constructor with size parameter. An element factory \c f can be specified.
explicit Vec(int size, const Factory &f = DEFAULT_FACTORY);
//! Copy constructor
Vec(const Vec<Num_T> &v);
//! Copy constructor, which takes an element factory \c f as an additional argument.
Vec(const Vec<Num_T> &v, const Factory &f);
//! Constructor taking a char string as input. An element factory \c f can be specified.
Vec(const char *str, const Factory &f = DEFAULT_FACTORY);
//! Constructor taking a string as input. An element factory \c f can be specified.
Vec(const std::string &str, const Factory &f = DEFAULT_FACTORY);
//! Constructor taking a C-array as input. Copies all data. An element factory \c f can be specified.
Vec(const Num_T *c_array, int size, const Factory &f = DEFAULT_FACTORY);
//! Destructor
~Vec();
//! The size of the vector
int length() const { return datasize; }
//! The size of the vector
int size() const { return datasize; }
//! Set length of vector. if copy = true then keeping the old values
void set_size(int size, bool copy = false);
//! Set length of vector. if copy = true then keeping the old values
void set_length(int size, bool copy = false) { set_size(size, copy); }
//! Set the vector to the all zero vector
void zeros();
//! Set the vector to the all zero vector
void clear() { zeros(); }
//! Set the vector to the all one vector
void ones();
//! Set the vector equal to the values in the \c str string
void set(const char *str);
//! Set the vector equal to the values in the \c str string
void set(const std::string &str);
//! C-style index operator. First element is 0.
const Num_T &operator[](int i) const;
//! Index operator. First element is 0.
const Num_T &operator()(int i) const;
//! C-style index operator. First element is 0.
Num_T &operator[](int i);
//! Index operator. First element is 0.
Num_T &operator()(int i);
//! Sub-vector with elements from \c i1 to \c i2. Index -1 indicates the last element.
Vec<Num_T> operator()(int i1, int i2) const;
//! Sub-vector with elements given by the list of indices \c indexlist
Vec<Num_T> operator()(const Vec<int> &indexlist) const;
//! Sub-vector with elements with indexes where \c binlist is \c 1
Vec<Num_T> operator()(const Vec<bin> &binlist) const;
//! Accessor-style method. First element is 0.
const Num_T &get(int i) const;
//! Get the elements from \c i1 to \c i2. Index -1 indicates the last element.
Vec<Num_T> get(int i1, int i2) const;
//! Get the elements given by the list of indices \c indexlist
Vec<Num_T> get(const Vec<int> &indexlist) const;
//! Get the elements with indexes where \c binlist is \c 1
Vec<Num_T> get(const Vec<bin> &binlist) const;
//! Modifier-style method. First element is 0.
void set(int i, Num_T t);
//! Matrix transpose. Converts to a matrix with the vector in the first row
Mat<Num_T> transpose() const;
//! Matrix transpose. Converts to a matrix with the vector in the first row
Mat<Num_T> T() const { return this->transpose(); }
//! Hermitian matrix transpose. Converts to a matrix with the conjugate of the vector in the first row
Mat<Num_T> hermitian_transpose() const;
//! Hermitian matrix transpose. Converts to a matrix with the conjugate of the vector in the first row
Mat<Num_T> H() const { return this->hermitian_transpose(); }
//! Addition of vector
Vec<Num_T>& operator+=(const Vec<Num_T> &v);
//! Addition of scalar
Vec<Num_T>& operator+=(Num_T t);
//! Addition of two vectors
friend Vec<Num_T> operator+<>(const Vec<Num_T> &v1, const Vec<Num_T> &v2);
//! Addition of a vector and a scalar
friend Vec<Num_T> operator+<>(const Vec<Num_T> &v, Num_T t);
//! Addition of a scalar and a vector
friend Vec<Num_T> operator+<>(Num_T t, const Vec<Num_T> &v);
//! Subtraction of vector
Vec<Num_T>& operator-=(const Vec<Num_T> &v);
//! Subtraction of scalar
Vec<Num_T>& operator-=(Num_T t);
//! Subtraction of \c v2 from \c v1
friend Vec<Num_T> operator-<>(const Vec<Num_T> &v1, const Vec<Num_T> &v2);
//! Subtraction of scalar from vector
friend Vec<Num_T> operator-<>(const Vec<Num_T> &v, Num_T t);
//! Subtraction of vector from scalar
friend Vec<Num_T> operator-<>(Num_T t, const Vec<Num_T> &v);
//! Negation of vector
friend Vec<Num_T> operator-<>(const Vec<Num_T> &v);
//! Multiply with a scalar
Vec<Num_T>& operator*=(Num_T t);
//! Elementwise multiplication of vector and scalar
friend Vec<Num_T> operator*<>(const Vec<Num_T> &v, Num_T t);
//! Elementwise multiplication of vector and scalar
friend Vec<Num_T> operator*<>(Num_T t, const Vec<Num_T> &v);
//! Elementwise multiplication
friend Vec<Num_T> elem_mult<>(const Vec<Num_T> &a, const Vec<Num_T> &b);
//! Elementwise multiplication of three vectors
friend Vec<Num_T> elem_mult<>(const Vec<Num_T> &a, const Vec<Num_T> &b,
const Vec<Num_T> &c);
//! Elementwise multiplication of four vectors
friend Vec<Num_T> elem_mult<>(const Vec<Num_T> &a, const Vec<Num_T> &b,
const Vec<Num_T> &c, const Vec<Num_T> &d);
//! Elementwise multiplication, storing the result in vector \c out
friend void elem_mult_out<>(const Vec<Num_T> &a, const Vec<Num_T> &b,
Vec<Num_T> &out);
//! Elementwise multiplication of three vectors, storing the result in vector \c out
friend void elem_mult_out<>(const Vec<Num_T> &a, const Vec<Num_T> &b,
const Vec<Num_T> &c, Vec<Num_T> &out);
//! Elementwise multiplication of four vectors, storing the result in vector \c out
friend void elem_mult_out<>(const Vec<Num_T> &a, const Vec<Num_T> &b,
const Vec<Num_T> &c, const Vec<Num_T> &d,
Vec<Num_T> &out);
//! In-place element-wise multiplication of two vectors. Fast version of b = elem_mult(a,b).
friend void elem_mult_inplace<>(const Vec<Num_T> &a, Vec<Num_T> &b);
//! Element-wise multiplication of two vectors, followed by summation of the resultant elements. Fast version of sum(elem_mult(a,b))
friend Num_T elem_mult_sum<>(const Vec<Num_T> &a, const Vec<Num_T> &b);
//! Elementwise division
Vec<Num_T>& operator/=(Num_T t);
//! Elementwise division
Vec<Num_T>& operator/=(const Vec<Num_T> &v);
//! Elementwise division
friend Vec<Num_T> operator/<>(const Vec<Num_T> &v, Num_T t);
//! Elementwise division
friend Vec<Num_T> operator/<>(Num_T t, const Vec<Num_T> &v);
//! Elementwise division
friend Vec<Num_T> elem_div<>(const Vec<Num_T> &v1, const Vec<Num_T> &v2);
//! This function is deprecated. Please use operator/(Num_T, const Vec<Num_T> &) instead.
friend Vec<Num_T> elem_div<>(Num_T t, const Vec<Num_T> &v);
//! Elementwise division
friend void elem_div_out<>(const Vec<Num_T> &v1, const Vec<Num_T> &v2,
Vec<Num_T> &out);
//! Elementwise division, followed by summation of the resultant elements. Fast version of sum(elem_mult(a,b))
friend Num_T elem_div_sum<>(const Vec<Num_T> &a, const Vec<Num_T> &b);
//! Get the right \c nr elements from the vector
Vec<Num_T> right(int nr) const;
//! Get the left \c nr elements from the vector
Vec<Num_T> left(int nr) const;
//! Get the middle part of vector from \c start including \c nr elements
Vec<Num_T> mid(int start, int nr) const;
/*!
* \brief Split the vector into two parts at element \c pos.
*
* Return the first part containing elements 0 to \c pos-1, and keep the
* second part containing the remaining elements starting from \c pos
* (empty vector if \c pos is equal to the length of the vector).
*/
Vec<Num_T> split(int pos);
//! Shift in element \c t at position 0 \c n times
void shift_right(Num_T t, int n = 1);
//! Shift in vector \c v at position 0
void shift_right(const Vec<Num_T> &v);
//! Shift out the \c n left elements and at the same time shift in the element \c t at last position \c n times
void shift_left(Num_T t, int n = 1);
//! Shift in vector \c v at last positions
void shift_left(const Vec<Num_T> &v);
//! Append element \c t to the end of the vector \c v
friend Vec<Num_T> concat<>(const Vec<Num_T> &v, Num_T t);
//! Insert element \c t at the beginning of the vector \c v
friend Vec<Num_T> concat<>(Num_T t, const Vec<Num_T> &v);
//! Concatenate vectors \c v1 and \c v2
friend Vec<Num_T> concat<>(const Vec<Num_T> &v1, const Vec<Num_T> &v2);
//! Concatenate vectors \c v1, \c v2 and \c v3
friend Vec<Num_T> concat<>(const Vec<Num_T> &v1, const Vec<Num_T> &v2,
const Vec<Num_T> &v3);
//! Concatenate vectors \c v1, \c v2, \c v3 and \c v4
friend Vec<Num_T> concat<>(const Vec<Num_T> &v1, const Vec<Num_T> &v2,
const Vec<Num_T> &v3, const Vec<Num_T> &v4);
//! Concatenate vectors \c v1, \c v2, \c v3, \c v4 and \c v5
friend Vec<Num_T> concat<>(const Vec<Num_T> &v1, const Vec<Num_T> &v2,
const Vec<Num_T> &v3, const Vec<Num_T> &v4,
const Vec<Num_T> &v5);
//! This function is deprecated. Please use set_subvector(i, v) instead.
void set_subvector(int i1, int i2, const Vec<Num_T> &v);
//! Set subvector to elements of vector \c v starting from element \c i
void set_subvector(int i, const Vec<Num_T> &v);
//! Set subvector defined by indices \c i1 and \c i2 to \c t
void set_subvector(int i1, int i2, Num_T t);
//! An alias function of set_subvector(i, &v)
void replace_mid(int i, const Vec<Num_T> &v);
//! Delete element number \c i
void del(int i);
//! Delete elements from \c i1 to \c i2
void del(int i1, int i2);
//! Insert element \c t before element with index \c i (0 <= i <= datasize)
void ins(int i, Num_T t);
//! Insert vector \c v before element with index \c i (0 <= i <= datasize)
void ins(int i, const Vec<Num_T> &v);
//! Assign all elements in vector to \c t
Vec<Num_T>& operator=(Num_T t);
//! Assign vector the value and length of \c v
Vec<Num_T>& operator=(const Vec<Num_T> &v);
//! Assign vector equal to the 1-dimensional matrix \c m
Vec<Num_T>& operator=(const Mat<Num_T> &m);
//! Assign vector the values in the string \c str
Vec<Num_T>& operator=(const char *str);
//! Assign vector the values in the string \c str
Vec<Num_T>& operator=(const std::string &str);
//! Elementwise equal to the scalar \c t
Vec<bin> operator==(Num_T t) const;
//! Elementwise not-equal to the scalar \c t
Vec<bin> operator!=(Num_T t) const;
//! Elementwise less than the scalar \c t
Vec<bin> operator<(Num_T t) const;
//! Elementwise less than and equal to the scalar \c t
Vec<bin> operator<=(Num_T t) const;
//! Elementwise greater than the scalar \c t
Vec<bin> operator>(Num_T t) const;
//! Elementwise greater than and equal to the scalar \c t
Vec<bin> operator>=(Num_T t) const;
//! Compare with vector \c v. Return false if sizes or values differ.
bool operator==(const Vec<Num_T> &v) const;
//! Compare with vector \c v. Return true if sizes or values differ.
bool operator!=(const Vec<Num_T> &v) const;
//! Index operator without boundary check. Not recommended for use.
Num_T &_elem(int i) { return data[i]; }
//! Index operator without boundary check. Not recommended for use.
const Num_T &_elem(int i) const { return data[i]; }
//! Get the pointer to the internal structure. Not recommended for use.
Num_T *_data() { return data; }
//! Get the pointer to the internal structure. Not recommended for use.
const Num_T *_data() const { return data; }
protected:
//! Allocate storage for a vector of length \c size.
void alloc(int size);
//! Free the storage space allocated by the vector
void free();
//! The current number of elements in the vector
int datasize;
//! A pointer to the data area
Num_T *data;
//! Element factory (set to DEFAULT_FACTORY to use Num_T default constructors only)
const Factory &factory;
private:
// Clean up and tokenize input initialisation string
std::vector<std::string> tokenize(const std::string &str,
bool &abc_format) const;
// Parse double and integer values from string tokens
Num_T parse_token(const std::string &s) const;
// Parse \c a, \c b and \c c values from "a:b:c" format
void parse_abc_token(const std::string &s, Num_T &a, Num_T &b,
Num_T &c) const;
//! Check whether index \c i is in the allowed range
bool in_range(int i) const { return ((i < datasize) && (i >= 0)); }
};
//-----------------------------------------------------------------------------------
// Type definitions of vec, cvec, ivec, svec, and bvec
//-----------------------------------------------------------------------------------
/*!
\relates Vec
\brief Definition of double vector type
*/
typedef Vec<double> vec;
/*!
\relates Vec
\brief Definition of complex<double> vector type
*/
typedef Vec<std::complex<double> > cvec;
/*!
\relates Vec
\brief Definition of integer vector type
*/
typedef Vec<int> ivec;
/*!
\relates Vec
\brief Definition of short vector type
*/
typedef Vec<short int> svec;
/*!
\relates Vec
\brief Definition of binary vector type
*/
typedef Vec<bin> bvec;
} //namespace itpp
#include <itpp/base/mat.h>
namespace itpp
{
//-----------------------------------------------------------------------------------
// Declaration of input and output streams for Vec
//-----------------------------------------------------------------------------------
/*!
\relates Vec
\brief Stream output of vector
*/
template<class Num_T>
std::ostream &operator<<(std::ostream &os, const Vec<Num_T> &v);
/*!
\relates Vec
\brief Stream input of vector
The input can be on the form "1 2 3" or "[1 2 3]", i.e. with or without
brackets. The first form is compatible with the set method, while the
second form is compatible with the ostream operator. The elements can be
separated by blank space or commas. "[]" means an empty vector. "1:4"
means "1 2 3 4". "1:3:10" means every third integer from 1 to 10, i.e.
"1 4 7 10".
*/
template<class Num_T>
std::istream &operator>>(std::istream &is, Vec<Num_T> &v);
//-----------------------------------------------------------------------------------
// Implementation of templated Vec members and friends
//-----------------------------------------------------------------------------------
template<class Num_T> inline
void Vec<Num_T>::alloc(int size)
{
if (size > 0) {
create_elements(data, size, factory);
datasize = size;
}
else {
data = 0;
datasize = 0;
}
}
template<class Num_T> inline
void Vec<Num_T>::free()
{
destroy_elements(data, datasize);
datasize = 0;
}
template<class Num_T> inline
Vec<Num_T>::Vec(const Factory &f) : datasize(0), data(0), factory(f) {}
template<class Num_T> inline
Vec<Num_T>::Vec(int size, const Factory &f) : datasize(0), data(0), factory(f)
{
it_assert_debug(size >= 0, "Negative size in Vec::Vec(int)");
alloc(size);
}
template<class Num_T> inline
Vec<Num_T>::Vec(const Vec<Num_T> &v) : datasize(0), data(0), factory(v.factory)
{
alloc(v.datasize);
copy_vector(datasize, v.data, data);
}
template<class Num_T> inline
Vec<Num_T>::Vec(const Vec<Num_T> &v, const Factory &f) : datasize(0), data(0), factory(f)
{
alloc(v.datasize);
copy_vector(datasize, v.data, data);
}
template<class Num_T> inline
Vec<Num_T>::Vec(const char *str, const Factory &f) : datasize(0), data(0), factory(f)
{
set(std::string(str));
}
template<class Num_T> inline
Vec<Num_T>::Vec(const std::string &str, const Factory &f) : datasize(0), data(0), factory(f)
{
set(str);
}
template<class Num_T> inline
Vec<Num_T>::Vec(const Num_T *c_array, int size, const Factory &f) : datasize(0), data(0), factory(f)
{
alloc(size);
copy_vector(size, c_array, data);
}
template<class Num_T> inline
Vec<Num_T>::~Vec()
{
free();
}
template<class Num_T>
void Vec<Num_T>::set_size(int size, bool copy)
{
it_assert_debug(size >= 0, "Vec::set_size(): New size must not be negative");
if (datasize == size)
return;
if (copy) {
// create a temporary pointer to the allocated data
Num_T* tmp = data;
// store the current number of elements
int old_datasize = datasize;
// check how many elements we need to copy
int min = datasize < size ? datasize : size;
// allocate new memory
alloc(size);
// copy old elements into a new memory region
copy_vector(min, tmp, data);
// initialize the rest of resized vector
for (int i = min; i < size; ++i)
data[i] = Num_T(0);
// delete old elements
destroy_elements(tmp, old_datasize);
}
else {
free();
alloc(size);
}
}
template<class Num_T> inline
const Num_T& Vec<Num_T>::operator[](int i) const
{
it_assert_debug(in_range(i), "Vec<>::operator[]: Index out of range");
return data[i];
}
template<class Num_T> inline
const Num_T& Vec<Num_T>::operator()(int i) const
{
return (*this)[i];
}
template<class Num_T> inline
Num_T& Vec<Num_T>::operator[](int i)
{
it_assert_debug(in_range(i), "Vec<>::operator[]: Index out of range");
return data[i];
}
template<class Num_T> inline
Num_T& Vec<Num_T>::operator()(int i)
{
return (*this)[i];
}
template<class Num_T> inline
Vec<Num_T> Vec<Num_T>::operator()(int i1, int i2) const
{
if (i1 == -1) i1 = datasize - 1;
if (i2 == -1) i2 = datasize - 1;
it_assert_debug((i1 >= 0) && (i1 <= i2) && (i2 < datasize),
"Vec<>::operator()(i1, i2): Indexing out of range");
Vec<Num_T> s(i2 - i1 + 1);
copy_vector(s.datasize, data + i1, s.data);
return s;
}
template<class Num_T>
Vec<Num_T> Vec<Num_T>::operator()(const Vec<int> &indexlist) const
{
int size = indexlist.size();
Vec<Num_T> temp(size);
for (int i = 0; i < size; ++i) {
it_assert_debug(in_range(indexlist(i)), "Vec<>::operator()(ivec &): "
"Index i=" << i << " out of range");
temp(i) = data[indexlist(i)];
}
return temp;
}
template<class Num_T>
Vec<Num_T> Vec<Num_T>::operator()(const Vec<bin> &binlist) const
{
int size = binlist.size();
it_assert_debug(datasize == size, "Vec<>::operator()(bvec &): "
"Wrong size of binlist vector");
Vec<Num_T> temp(size);
int j = 0;
for (int i = 0; i < size; ++i)
if (binlist(i) == bin(1))
temp(j++) = data[i];
temp.set_size(j, true);
return temp;
}
template<class Num_T> inline
const Num_T& Vec<Num_T>::get(int i) const
{
return (*this)[i];
}
template<class Num_T> inline
Vec<Num_T> Vec<Num_T>::get(int i1, int i2) const
{
return (*this)(i1, i2);
}
template<class Num_T> inline
Vec<Num_T> Vec<Num_T>::get(const Vec<int> &indexlist) const
{
return (*this)(indexlist);
}
template<class Num_T> inline
Vec<Num_T> Vec<Num_T>::get(const Vec<bin> &binlist) const
{
return (*this)(binlist);
}
template<class Num_T> inline
void Vec<Num_T>::zeros()
{
for (int i = 0; i < datasize; i++)
data[i] = Num_T(0);
}
template<class Num_T> inline
void Vec<Num_T>::ones()
{
for (int i = 0; i < datasize; i++)
data[i] = Num_T(1);
}
template<class Num_T> inline
void Vec<Num_T>::set(int i, Num_T t)
{
it_assert_debug(in_range(i), "Vec<>::set(i, t): Index out of range");
data[i] = t;
}
template<class Num_T> inline
void Vec<Num_T>::set(const std::string &str)
{
it_error("Vec::set(): Only `double', `complex<double>', `int', "
"`short int' and `bin' types supported");
}
template<class Num_T> inline
void Vec<Num_T>::set(const char *str)
{
set(std::string(str));
}
//! \cond
template<>
ITPP_EXPORT void Vec<double>::set(const std::string &str);
template<>
ITPP_EXPORT void Vec<std::complex<double> >::set(const std::string &str);
template<>
ITPP_EXPORT void Vec<int>::set(const std::string &str);
template<>
ITPP_EXPORT void Vec<short int>::set(const std::string &str);
template<>
ITPP_EXPORT void Vec<bin>::set(const std::string &str);
//! \endcond
template<class Num_T>
Mat<Num_T> Vec<Num_T>::transpose() const
{
Mat<Num_T> temp(1, datasize);
copy_vector(datasize, data, temp._data());
return temp;
}
template<class Num_T>
Mat<Num_T> Vec<Num_T>::hermitian_transpose() const
{
Mat<Num_T> temp(1, datasize);
copy_vector(datasize, data, temp._data());
return temp;
}
//! \cond
template<>
ITPP_EXPORT Mat<std::complex<double> > Vec<std::complex<double> >::hermitian_transpose() const;
//! \endcond
template<class Num_T>
Vec<Num_T>& Vec<Num_T>::operator+=(const Vec<Num_T> &v)
{
if (datasize == 0) { // if not assigned a size.
if (this != &v) { // check for self addition
alloc(v.datasize);
copy_vector(datasize, v.data, data);
}
}
else {
it_assert_debug(datasize == v.datasize, "Vec::operator+=: Wrong sizes");
for (int i = 0; i < datasize; i++)
data[i] += v.data[i];
}
return *this;
}
template<class Num_T> inline
Vec<Num_T>& Vec<Num_T>::operator+=(Num_T t)
{
for (int i = 0;i < datasize;i++)
data[i] += t;
return *this;
}
template<class Num_T>
Vec<Num_T> operator+(const Vec<Num_T> &v1, const Vec<Num_T> &v2)
{
int i;
Vec<Num_T> r(v1.datasize);
it_assert_debug(v1.datasize == v2.datasize, "Vec::operator+: wrong sizes");
for (i = 0; i < v1.datasize; i++)
r.data[i] = v1.data[i] + v2.data[i];
return r;
}
template<class Num_T>
Vec<Num_T> operator+(const Vec<Num_T> &v, Num_T t)
{
int i;
Vec<Num_T> r(v.datasize);
for (i = 0; i < v.datasize; i++)
r.data[i] = v.data[i] + t;
return r;
}
template<class Num_T>
Vec<Num_T> operator+(Num_T t, const Vec<Num_T> &v)
{
int i;
Vec<Num_T> r(v.datasize);
for (i = 0; i < v.datasize; i++)
r.data[i] = t + v.data[i];
return r;
}
template<class Num_T>
Vec<Num_T>& Vec<Num_T>::operator-=(const Vec<Num_T> &v)
{
if (datasize == 0) { // if not assigned a size.
if (this != &v) { // check for self decrementation
alloc(v.datasize);
for (int i = 0; i < v.datasize; i++)
data[i] = -v.data[i];
}
}
else {
it_assert_debug(datasize == v.datasize, "Vec::operator-=: Wrong sizes");
for (int i = 0; i < datasize; i++)
data[i] -= v.data[i];
}
return *this;
}
template<class Num_T> inline
Vec<Num_T>& Vec<Num_T>::operator-=(Num_T t)
{
for (int i = 0;i < datasize;i++)
data[i] -= t;
return *this;
}
template<class Num_T>
Vec<Num_T> operator-(const Vec<Num_T> &v1, const Vec<Num_T> &v2)
{
int i;
Vec<Num_T> r(v1.datasize);
it_assert_debug(v1.datasize == v2.datasize, "Vec::operator-: wrong sizes");
for (i = 0; i < v1.datasize; i++)
r.data[i] = v1.data[i] - v2.data[i];
return r;
}
template<class Num_T>
Vec<Num_T> operator-(const Vec<Num_T> &v, Num_T t)
{
int i;
Vec<Num_T> r(v.datasize);
for (i = 0; i < v.datasize; i++)
r.data[i] = v.data[i] - t;
return r;
}
template<class Num_T>
Vec<Num_T> operator-(Num_T t, const Vec<Num_T> &v)
{
int i;
Vec<Num_T> r(v.datasize);
for (i = 0; i < v.datasize; i++)
r.data[i] = t - v.data[i];
return r;
}
template<class Num_T>
Vec<Num_T> operator-(const Vec<Num_T> &v)
{
int i;
Vec<Num_T> r(v.datasize);
for (i = 0; i < v.datasize; i++)
r.data[i] = -v.data[i];
return r;
}
template<class Num_T> inline
Vec<Num_T>& Vec<Num_T>::operator*=(Num_T t)
{
scal_vector(datasize, t, data);
return *this;
}
template<class Num_T> inline
Num_T operator*(const Vec<Num_T> &v1, const Vec<Num_T> &v2)
{
return dot(v1, v2);
}
template<class Num_T>
Num_T dot(const Vec<Num_T> &v1, const Vec<Num_T> &v2)
{
it_assert_debug(v1.length() == v2.length(), "Vec::dot(): Wrong sizes");
Num_T r = Num_T(0);
for (int i = 0; i < v1.length(); ++i)
r += v1._data()[i] * v2._data()[i];
return r;
}
//! \cond
template<>
ITPP_EXPORT double dot(const vec &v1, const vec &v2);
//! \endcond
template<class Num_T>
Mat<Num_T> outer_product(const Vec<Num_T> &v1, const Vec<Num_T> &v2, bool)
{
it_assert_debug((v1.length() > 0) && (v2.length() > 0),
"Vec::outer_product:: Input vector of zero size");
Mat<Num_T> r(v1.length(), v2.length());
for (int i = 0; i < v1.length(); ++i) {
for (int j = 0; j < v2.length(); ++j) {
r(i, j) = v1._data()[i] * v2._data()[j];
}
}
return r;
}
//! \cond
template<>
ITPP_EXPORT mat outer_product(const vec &v1, const vec &v2, bool);
template<>
ITPP_EXPORT cmat outer_product(const cvec &v1, const cvec &v2, bool hermitian);
//! \endcond
template<class Num_T>
Vec<Num_T> operator*(const Vec<Num_T> &v, Num_T t)
{
int i;
Vec<Num_T> r(v.datasize);
for (i = 0; i < v.datasize; i++)
r.data[i] = v.data[i] * t;
return r;
}
template<class Num_T> inline
Vec<Num_T> operator*(Num_T t, const Vec<Num_T> &v)
{
return operator*(v, t);
}
template<class Num_T> inline
Vec<Num_T> elem_mult(const Vec<Num_T> &a, const Vec<Num_T> &b)
{
Vec<Num_T> out;
elem_mult_out(a, b, out);
return out;
}
template<class Num_T> inline
Vec<Num_T> elem_mult(const Vec<Num_T> &a, const Vec<Num_T> &b,
const Vec<Num_T> &c)
{
Vec<Num_T> out;
elem_mult_out(a, b, c, out);
return out;
}
template<class Num_T> inline
Vec<Num_T> elem_mult(const Vec<Num_T> &a, const Vec<Num_T> &b,
const Vec<Num_T> &c, const Vec<Num_T> &d)
{
Vec<Num_T> out;
elem_mult_out(a, b, c, d, out);
return out;
}
template<class Num_T>
void elem_mult_out(const Vec<Num_T> &a, const Vec<Num_T> &b, Vec<Num_T> &out)
{
it_assert_debug(a.datasize == b.datasize,
"Vec<>::elem_mult_out(): Wrong sizes");
out.set_size(a.datasize);
for (int i = 0; i < a.datasize; i++)
out.data[i] = a.data[i] * b.data[i];
}
template<class Num_T>
void elem_mult_out(const Vec<Num_T> &a, const Vec<Num_T> &b,
const Vec<Num_T> &c, Vec<Num_T> &out)
{
it_assert_debug((a.datasize == b.datasize) && (a.datasize == c.datasize),
"Vec<>::elem_mult_out(): Wrong sizes");
out.set_size(a.datasize);
for (int i = 0; i < a.datasize; i++)
out.data[i] = a.data[i] * b.data[i] * c.data[i];
}
template<class Num_T>
void elem_mult_out(const Vec<Num_T> &a, const Vec<Num_T> &b,
const Vec<Num_T> &c, const Vec<Num_T> &d, Vec<Num_T> &out)
{
it_assert_debug((a.datasize == b.datasize) && (a.datasize == c.datasize)
&& (a.datasize == d.datasize),
"Vec<>::elem_mult_out(): Wrong sizes");
out.set_size(a.datasize);
for (int i = 0; i < a.datasize; i++)
out.data[i] = a.data[i] * b.data[i] * c.data[i] * d.data[i];
}
template<class Num_T>
#ifndef _MSC_VER
inline
#endif
void elem_mult_inplace(const Vec<Num_T> &a, Vec<Num_T> &b)
{
it_assert_debug(a.datasize == b.datasize,
"Vec<>::elem_mult_inplace(): Wrong sizes");
for (int i = 0; i < a.datasize; i++)
b.data[i] *= a.data[i];
}
template<class Num_T> inline
Num_T elem_mult_sum(const Vec<Num_T> &a, const Vec<Num_T> &b)
{
it_assert_debug(a.datasize == b.datasize,
"Vec<>::elem_mult_sum(): Wrong sizes");
Num_T acc = 0;
for (int i = 0; i < a.datasize; i++)
acc += a.data[i] * b.data[i];
return acc;
}
template<class Num_T>
Vec<Num_T> operator/(const Vec<Num_T> &v, Num_T t)
{
int i;
Vec<Num_T> r(v.datasize);
for (i = 0; i < v.datasize; i++)
r.data[i] = v.data[i] / t;
return r;
}
template<class Num_T>
Vec<Num_T> operator/(Num_T t, const Vec<Num_T> &v)
{
int i;
Vec<Num_T> r(v.datasize);
for (i = 0; i < v.datasize; i++)
r.data[i] = t / v.data[i];
return r;
}
template<class Num_T>
Vec<Num_T> elem_div(Num_T t, const Vec<Num_T> &v)
{
it_warning("Vec<>::elem_div(Num_T, const Vec<Num_T> &): This function is "
"deprecated and might be removed from future IT++ releases. "
"Please use Vec<>::operator/(Num_T, const Vec<Num_T> &) "
"instead.");
return operator/(t, v);
}
template<class Num_T> inline
Vec<Num_T>& Vec<Num_T>::operator/=(Num_T t)
{
for (int i = 0; i < datasize; ++i) {
data[i] /= t;
}
return *this;
}
template<class Num_T> inline
Vec<Num_T>& Vec<Num_T>::operator/=(const Vec<Num_T> &v)
{
it_assert_debug(datasize == v.datasize, "Vec::operator/=(): wrong sizes");
for (int i = 0; i < datasize; ++i) {
data[i] /= v.data[i];
}
return *this;
}
template<class Num_T> inline
Vec<Num_T> elem_div(const Vec<Num_T> &a, const Vec<Num_T> &b)
{
Vec<Num_T> out;
elem_div_out(a, b, out);
return out;
}
template<class Num_T>
void elem_div_out(const Vec<Num_T> &a, const Vec<Num_T> &b, Vec<Num_T> &out)
{
it_assert_debug(a.datasize == b.datasize, "Vecelem_div_out: wrong sizes");
out.set_size(a.size());
for (int i = 0; i < a.datasize; i++)
out.data[i] = a.data[i] / b.data[i];
}
template<class Num_T> inline
Num_T elem_div_sum(const Vec<Num_T> &a, const Vec<Num_T> &b)
{
it_assert_debug(a.datasize == b.datasize, "Vec::elem_div_sum: wrong sizes");
Num_T acc = 0;
for (int i = 0; i < a.datasize; i++)
acc += a.data[i] / b.data[i];
return acc;
}
template<class Num_T>
Vec<Num_T> Vec<Num_T>::right(int nr) const
{
it_assert_debug(nr <= datasize, "Vec::right(): index out of range");
Vec<Num_T> temp(nr);
if (nr > 0) {
copy_vector(nr, &data[datasize-nr], temp.data);
}
return temp;
}
template<class Num_T>
Vec<Num_T> Vec<Num_T>::left(int nr) const
{
it_assert_debug(nr <= datasize, "Vec::left(): index out of range");
Vec<Num_T> temp(nr);
if (nr > 0) {
copy_vector(nr, data, temp.data);
}
return temp;
}
template<class Num_T>
Vec<Num_T> Vec<Num_T>::mid(int start, int nr) const
{
it_assert_debug((start >= 0) && ((start + nr) <= datasize),
"Vec::mid(): indexing out of range");
Vec<Num_T> temp(nr);
if (nr > 0) {
copy_vector(nr, &data[start], temp.data);
}
return temp;
}
template<class Num_T>
Vec<Num_T> Vec<Num_T>::split(int pos)
{
it_assert_debug((pos >= 0) && (pos <= datasize),
"Vec<>::split(): Index out of range");
Vec<Num_T> temp1(pos);
if (pos > 0) {
copy_vector(pos, data, temp1.data);
if (pos < datasize) {
Vec<Num_T> temp2(datasize - pos);
copy_vector(datasize - pos, &data[pos], temp2.data);
(*this) = temp2;
}
else {
set_size(0);
}
}
return temp1;
}
template<class Num_T>
void Vec<Num_T>::shift_right(Num_T t, int n)
{
int i = datasize;
it_assert_debug(n >= 0, "Vec::shift_right: index out of range");
while (--i >= n)
data[i] = data[i-n];
while (i >= 0)
data[i--] = t;
}
template<class Num_T>
void Vec<Num_T>::shift_right(const Vec<Num_T> &v)
{
for (int i = datasize - 1; i >= v.datasize; i--)
data[i] = data[i-v.datasize];
for (int i = 0; i < v.datasize; i++)
data[i] = v[i];
}
template<class Num_T>
void Vec<Num_T>::shift_left(Num_T t, int n)
{
int i;
it_assert_debug(n >= 0, "Vec::shift_left: index out of range");
for (i = 0; i < datasize - n; i++)
data[i] = data[i+n];
while (i < datasize)
data[i++] = t;
}
template<class Num_T>
void Vec<Num_T>::shift_left(const Vec<Num_T> &v)
{
for (int i = 0; i < datasize - v.datasize; i++)
data[i] = data[i+v.datasize];
for (int i = datasize - v.datasize; i < datasize; i++)
data[i] = v[i-datasize+v.datasize];
}
template<class Num_T>
Vec<Num_T> concat(const Vec<Num_T> &v, Num_T t)
{
int size = v.size();
Vec<Num_T> temp(size + 1);
copy_vector(size, v.data, temp.data);
temp(size) = t;
return temp;
}
template<class Num_T>
Vec<Num_T> concat(Num_T t, const Vec<Num_T> &v)
{
int size = v.size();
Vec<Num_T> temp(size + 1);
temp(0) = t;
copy_vector(size, v.data, &temp.data[1]);
return temp;
}
template<class Num_T>
Vec<Num_T> concat(const Vec<Num_T> &v1, const Vec<Num_T> &v2)
{
int size1 = v1.size();
int size2 = v2.size();
Vec<Num_T> temp(size1 + size2);
copy_vector(size1, v1.data, temp.data);
copy_vector(size2, v2.data, &temp.data[size1]);
return temp;
}
template<class Num_T>
Vec<Num_T> concat(const Vec<Num_T> &v1, const Vec<Num_T> &v2,
const Vec<Num_T> &v3)
{
int size1 = v1.size();
int size2 = v2.size();
int size3 = v3.size();
Vec<Num_T> temp(size1 + size2 + size3);
copy_vector(size1, v1.data, temp.data);
copy_vector(size2, v2.data, &temp.data[size1]);
copy_vector(size3, v3.data, &temp.data[size1+size2]);
return temp;
}
template<class Num_T>
Vec<Num_T> concat(const Vec<Num_T> &v1, const Vec<Num_T> &v2,
const Vec<Num_T> &v3, const Vec<Num_T> &v4)
{
int size1 = v1.size();
int size2 = v2.size();
int size3 = v3.size();
int size4 = v4.size();
Vec<Num_T> temp(size1 + size2 + size3 + size4);
copy_vector(size1, v1.data, temp.data);
copy_vector(size2, v2.data, &temp.data[size1]);
copy_vector(size3, v3.data, &temp.data[size1+size2]);
copy_vector(size4, v4.data, &temp.data[size1+size2+size3]);
return temp;
}
template<class Num_T>
Vec<Num_T> concat(const Vec<Num_T> &v1, const Vec<Num_T> &v2,
const Vec<Num_T> &v3, const Vec<Num_T> &v4,
const Vec<Num_T> &v5)
{
int size1 = v1.size();
int size2 = v2.size();
int size3 = v3.size();
int size4 = v4.size();
int size5 = v5.size();
Vec<Num_T> temp(size1 + size2 + size3 + size4 + size5);
copy_vector(size1, v1.data, temp.data);
copy_vector(size2, v2.data, &temp.data[size1]);
copy_vector(size3, v3.data, &temp.data[size1+size2]);
copy_vector(size4, v4.data, &temp.data[size1+size2+size3]);
copy_vector(size5, v5.data, &temp.data[size1+size2+size3+size4]);
return temp;
}
template<class Num_T>
void Vec<Num_T>::set_subvector(int i1, int, const Vec<Num_T> &v)
{
it_warning("Vec<>::set_subvector(int, int, const Vec<> &): This function "
"is deprecated and might be removed from future IT++ releases. "
"Please use Vec<>::set_subvector(int, const Vec<> &) instead.");
set_subvector(i1, v);
}
template<class Num_T> inline
void Vec<Num_T>:: set_subvector(int i, const Vec<Num_T> &v)
{
it_assert_debug((i >= 0) && (i + v.datasize <= datasize),
"Vec<>::set_subvector(int, const Vec<> &): "
"Index out of range or too long input vector");
copy_vector(v.datasize, v.data, data + i);
}
template<class Num_T> inline
void Vec<Num_T>::set_subvector(int i1, int i2, Num_T t)
{
if (i1 == -1) i1 = datasize - 1;
if (i2 == -1) i2 = datasize - 1;
it_assert_debug((i1 >= 0) && (i1 <= i2) && (i2 < datasize),
"Vec<>::set_subvector(int, int, Num_T): Indexing out "
"of range");
for (int i = i1; i <= i2; i++)
data[i] = t;
}
template<class Num_T> inline
void Vec<Num_T>::replace_mid(int i, const Vec<Num_T> &v)
{
set_subvector(i, v);
}
template<class Num_T>
void Vec<Num_T>::del(int index)
{
it_assert_debug(in_range(index), "Vec<>::del(int): Index out of range");
Vec<Num_T> temp(*this);
set_size(datasize - 1, false);
copy_vector(index, temp.data, data);
copy_vector(datasize - index, &temp.data[index+1], &data[index]);
}
template<class Num_T>
void Vec<Num_T>::del(int i1, int i2)
{
if (i1 == -1) i1 = datasize - 1;
if (i2 == -1) i2 = datasize - 1;
it_assert_debug((i1 >= 0) && (i1 <= i2) && (i2 < datasize),
"Vec<>::del(int, int): Indexing out of range");
Vec<Num_T> temp(*this);
int new_size = datasize - (i2 - i1 + 1);
set_size(new_size, false);
copy_vector(i1, temp.data, data);
copy_vector(datasize - i1, &temp.data[i2+1], &data[i1]);
}
template<class Num_T>
void Vec<Num_T>::ins(int index, const Num_T t)
{
it_assert_debug((index >= 0) && (index <= datasize),
"Vec<>::ins(): Index out of range");
Vec<Num_T> Temp(*this);
set_size(datasize + 1, false);
copy_vector(index, Temp.data, data);
data[index] = t;
copy_vector(Temp.datasize - index, Temp.data + index, data + index + 1);
}
template<class Num_T>
void Vec<Num_T>::ins(int index, const Vec<Num_T> &v)
{
it_assert_debug((index >= 0) && (index <= datasize),
"Vec<>::ins(): Index out of range");
Vec<Num_T> Temp(*this);
set_size(datasize + v.length(), false);
copy_vector(index, Temp.data, data);
copy_vector(v.size(), v.data, &data[index]);
copy_vector(Temp.datasize - index, Temp.data + index, data + index + v.size());
}
template<class Num_T> inline
Vec<Num_T>& Vec<Num_T>::operator=(Num_T t)
{
for (int i = 0;i < datasize;i++)
data[i] = t;
return *this;
}
template<class Num_T> inline
Vec<Num_T>& Vec<Num_T>::operator=(const Vec<Num_T> &v)
{
if (this != &v) {
set_size(v.datasize, false);
copy_vector(datasize, v.data, data);
}
return *this;
}
template<class Num_T>
Vec<Num_T>& Vec<Num_T>::operator=(const Mat<Num_T> &m)
{
if (m.cols() == 1) {
set_size(m.rows(), false);
copy_vector(m.rows(), m._data(), data);
}
else if (m.rows() == 1) {
set_size(m.cols(), false);
copy_vector(m.cols(), m._data(), m.rows(), data, 1);
}
else
it_error("Vec<>::operator=(Mat<Num_T> &): Wrong size of input matrix");
return *this;
}
template<class Num_T> inline
Vec<Num_T>& Vec<Num_T>::operator=(const char *str)
{
set(std::string(str));
return *this;
}
template<class Num_T> inline
Vec<Num_T>& Vec<Num_T>::operator=(const std::string &str)
{
set(str);
return *this;
}
template<class Num_T>
bvec Vec<Num_T>::operator==(Num_T t) const
{
it_assert_debug(datasize > 0, "Vec<>::operator==(): Wrong size");
bvec temp(datasize);
for (int i = 0; i < datasize; i++)
temp(i) = (data[i] == t);
return temp;
}
template<class Num_T>
bvec Vec<Num_T>::operator!=(Num_T t) const
{
it_assert_debug(datasize > 0, "Vec<>::operator!=(): Wrong size");
bvec temp(datasize);
for (int i = 0; i < datasize; i++)
temp(i) = (data[i] != t);
return temp;
}
//! \cond
template<>
bvec Vec<std::complex<double> >::operator<(std::complex<double>) const;
//! \endcond
template<class Num_T>
bvec Vec<Num_T>::operator<(Num_T t) const
{
it_assert_debug(datasize > 0, "Vec<>::operator<(): Wrong size");
bvec temp(datasize);
for (int i = 0; i < datasize; i++)
temp(i) = (data[i] < t);
return temp;
}
template<class Num_T>
bvec Vec<Num_T>::operator<=(Num_T t) const
{
it_assert_debug(datasize > 0, "Vec<>::operator<=(): Wrong size");
bvec temp(datasize);
for (int i = 0; i < datasize; i++)
temp(i) = (data[i] <= t);
return temp;
}
//! \cond
template<>
ITPP_EXPORT bvec Vec<std::complex<double> >::operator<=(std::complex<double>) const;
//! \endcond
template<class Num_T>
bvec Vec<Num_T>::operator>(Num_T t) const
{
it_assert_debug(datasize > 0, "Vec<>::operator>(): Wrong size");
bvec temp(datasize);
for (int i = 0; i < datasize; i++)
temp(i) = (data[i] > t);
return temp;
}
//! \cond
template<>
ITPP_EXPORT bvec Vec<std::complex<double> >::operator>(std::complex<double>) const;
//! \endcond
template<class Num_T>
bvec Vec<Num_T>::operator>=(Num_T t) const
{
it_assert_debug(datasize > 0, "Vec<>::operator>=(): Wrong size");
bvec temp(datasize);
for (int i = 0; i < datasize; i++)
temp(i) = (data[i] >= t);
return temp;
}
//! \cond
template<>
ITPP_EXPORT bvec Vec<std::complex<double> >::operator>=(std::complex<double>) const;
//! \endcond
template<class Num_T>
bool Vec<Num_T>::operator==(const Vec<Num_T> &invector) const
{
// OBS ! if wrong size, return false
if (datasize != invector.datasize) return false;
for (int i = 0;i < datasize;i++) {
if (data[i] != invector.data[i]) return false;
}
return true;
}
template<class Num_T>
bool Vec<Num_T>::operator!=(const Vec<Num_T> &invector) const
{
if (datasize != invector.datasize) return true;
for (int i = 0;i < datasize;i++) {
if (data[i] != invector.data[i]) return true;
}
return false;
}
//! Output stream operator of a vector \c v
template<class Num_T>
std::ostream &operator<<(std::ostream &os, const Vec<Num_T> &v)
{
int i, sz = v.length();
os << "[" ;
for (i = 0; i < sz; i++) {
os << v(i) ;
if (i < sz - 1)
os << " ";
}
os << "]" ;
return os;
}
//! Input stream operator to read a vector
template<class Num_T>
std::istream &operator>>(std::istream &is, Vec<Num_T> &v)
{
std::ostringstream buffer;
bool started = false;
bool finished = false;
bool brackets = false;
char c = 0;
while (!finished) {
if (is.eof()) {
finished = true;
}
else {
is.get(c);
if (is.eof() || (c == '\n')) {
if (brackets) {
// Right bracket missing
is.setstate(std::ios_base::failbit);
finished = true;
}
else if (!((c == '\n') && !started)) {
finished = true;
}
}
else if ((c == ' ') || (c == '\t')) {
if (started) {
buffer << ' ';
}
}
else if (c == '[') {
if (started) {
// Unexpected left bracket
is.setstate(std::ios_base::failbit);
finished = true;
}
else {
started = true;
brackets = true;
}
}
else if (c == ']') {
if (!started || !brackets) {
// Unexpected right bracket
is.setstate(std::ios_base::failbit);
finished = true;
}
else {
finished = true;
}
while (!is.eof() && (((c = static_cast<char>(is.peek())) == ' ')
|| (c == '\t'))) {
is.get();
}
if (!is.eof() && (c == '\n')) {
is.get();
}
}
else {
started = true;
buffer << c;
}
}
}
if (!started) {
v.set_size(0, false);
}
else {
v.set(buffer.str());
}
return is;
}
//! \cond
// ----------------------------------------------------------------------
// Private functions
// ----------------------------------------------------------------------
template<class Num_T>
void Vec<Num_T>::parse_abc_token(const std::string &s, Num_T &a, Num_T &b,
Num_T &c) const
{
std::string::size_type beg = 0;
std::string::size_type end = s.find(':', 0);
a = parse_token(s.substr(beg, end-beg));
beg = end + 1;
end = s.find(':', beg);
if (end != std::string::npos) {
b = parse_token(s.substr(beg, end-beg));
c = parse_token(s.substr(end+1, s.size()-end));
}
else {
b = Num_T(1);
c = parse_token(s.substr(beg, end-beg-1));
}
}
template<class Num_T>
Num_T Vec<Num_T>::parse_token(const std::string &s) const
{
it_error("Vec::parse_token(): Only `double' and `int' types are supported");
return 0;
}
//! \cond
template<>
ITPP_EXPORT double Vec<double>::parse_token(const std::string &s) const;
template<>
ITPP_EXPORT int Vec<int>::parse_token(const std::string &s) const;
//! \endcond
template<class Num_T>
std::vector<std::string> Vec<Num_T>::tokenize(const std::string &str_in,
bool &abc_format) const
{
std::vector<std::string> vs; // vector for storing parsed tokens
std::string s; // currently processed token string
bool start = true;
bool space = false;
bool colon = false;
bool comma = false;
bool lparen = false;
abc_format = false;
for (std::string::size_type i = 0; i < str_in.size(); ++i) {
char c = str_in[i];
switch (c) {
case ' ': case '\t':
space = true; // set flag for whitespaces
break;
case ',':
if (lparen)
comma = true; // set flag for comma in "(re,im)" format
else
space = true; // otherwise treat comma as separator
break;
case ')':
s.push_back('i'); // replace right paren in "(re,im)" with 'i'
break;
case ':':
colon = true; // set flag for "a:b[:c]" format string
space = false; // reset flag for whitespaces
abc_format = true; // set external flag for "a:b[:c]" format
s.push_back(c);
break;
case '(':
lparen = true; // set flag for complex "(re,im)" format
break;
default:
if (colon) { // reset colon and space flags
colon = false; // to get rid of whitespaces around ":"
space = false;
}
else if (lparen && comma) { // support for "(re,im)" format
lparen = false;
comma = false;
space = false;
if ((c != '-') && (c != '+')) // if needed
s.push_back('+'); // insert '+' between "re" and "im"
}
else if (space) { // new token detected
space = false;
if (!start) { // if not at the beginning of the string
vs.push_back(s); // store already parsed token
s.clear(); // and start parsing the next token
}
}
s.push_back(c); // append next character to the current token
start = false; // reset the "beginning of the string" flag
break;
}
}
if (!s.empty()) // if the final token is not an empty string
vs.push_back(s); // store it in the output vector
return vs;
}
// ----------------------------------------------------------------------
// Instantiations
// ----------------------------------------------------------------------
ITPP_EXPORT_TEMPLATE template class ITPP_EXPORT Vec<double>;
ITPP_EXPORT_TEMPLATE template class ITPP_EXPORT Vec<int>;
ITPP_EXPORT_TEMPLATE template class ITPP_EXPORT Vec<short int>;
ITPP_EXPORT_TEMPLATE template class ITPP_EXPORT Vec<std::complex<double> >;
ITPP_EXPORT_TEMPLATE template class ITPP_EXPORT Vec<bin>;
// addition operator
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT vec operator+(const vec &v1, const vec &v2);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT cvec operator+(const cvec &v1, const cvec &v2);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT ivec operator+(const ivec &v1, const ivec &v2);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT svec operator+(const svec &v1, const svec &v2);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bvec operator+(const bvec &v1, const bvec &v2);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT vec operator+(const vec &v1, double t);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT cvec operator+(const cvec &v1, std::complex<double> t);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT ivec operator+(const ivec &v1, int t);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT svec operator+(const svec &v1, short t);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bvec operator+(const bvec &v1, bin t);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT vec operator+(double t, const vec &v1);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT cvec operator+(std::complex<double> t, const cvec &v1);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT ivec operator+(int t, const ivec &v1);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT svec operator+(short t, const svec &v1);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bvec operator+(bin t, const bvec &v1);
// subtraction operator
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT vec operator-(const vec &v1, const vec &v2);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT cvec operator-(const cvec &v1, const cvec &v2);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT ivec operator-(const ivec &v1, const ivec &v2);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT svec operator-(const svec &v1, const svec &v2);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bvec operator-(const bvec &v1, const bvec &v2);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT vec operator-(const vec &v, double t);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT cvec operator-(const cvec &v, std::complex<double> t);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT ivec operator-(const ivec &v, int t);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT svec operator-(const svec &v, short t);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bvec operator-(const bvec &v, bin t);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT vec operator-(double t, const vec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT cvec operator-(std::complex<double> t, const cvec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT ivec operator-(int t, const ivec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT svec operator-(short t, const svec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bvec operator-(bin t, const bvec &v);
// unary minus
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT vec operator-(const vec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT cvec operator-(const cvec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT ivec operator-(const ivec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT svec operator-(const svec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bvec operator-(const bvec &v);
// multiplication operator
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT std::complex<double> dot(const cvec &v1, const cvec &v2);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT int dot(const ivec &v1, const ivec &v2);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT short dot(const svec &v1, const svec &v2);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bin dot(const bvec &v1, const bvec &v2);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT double operator*(const vec &v1, const vec &v2);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT std::complex<double> operator*(const cvec &v1, const cvec &v2);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT int operator*(const ivec &v1, const ivec &v2);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT short operator*(const svec &v1, const svec &v2);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bin operator*(const bvec &v1, const bvec &v2);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT imat outer_product(const ivec &v1, const ivec &v2,
bool hermitian);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT smat outer_product(const svec &v1, const svec &v2,
bool hermitian);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bmat outer_product(const bvec &v1, const bvec &v2,
bool hermitian);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT vec operator*(const vec &v, double t);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT cvec operator*(const cvec &v, std::complex<double> t);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT ivec operator*(const ivec &v, int t);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT svec operator*(const svec &v, short t);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bvec operator*(const bvec &v, bin t);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT vec operator*(double t, const vec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT cvec operator*(std::complex<double> t, const cvec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT ivec operator*(int t, const ivec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT svec operator*(short t, const svec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bvec operator*(bin t, const bvec &v);
// elementwise multiplication
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT vec elem_mult(const vec &a, const vec &b);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT cvec elem_mult(const cvec &a, const cvec &b);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT ivec elem_mult(const ivec &a, const ivec &b);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT svec elem_mult(const svec &a, const svec &b);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bvec elem_mult(const bvec &a, const bvec &b);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_mult_out(const vec &a, const vec &b, vec &out);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_mult_out(const cvec &a, const cvec &b, cvec &out);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_mult_out(const ivec &a, const ivec &b, ivec &out);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_mult_out(const svec &a, const svec &b, svec &out);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_mult_out(const bvec &a, const bvec &b, bvec &out);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT vec elem_mult(const vec &a, const vec &b, const vec &c);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT cvec elem_mult(const cvec &a, const cvec &b, const cvec &c);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT ivec elem_mult(const ivec &a, const ivec &b, const ivec &c);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT svec elem_mult(const svec &a, const svec &b, const svec &c);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bvec elem_mult(const bvec &a, const bvec &b, const bvec &c);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_mult_out(const vec &a, const vec &b,
const vec &c, vec &out);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_mult_out(const cvec &a, const cvec &b,
const cvec &c, cvec &out);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_mult_out(const ivec &a, const ivec &b,
const ivec &c, ivec &out);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_mult_out(const svec &a, const svec &b,
const svec &c, svec &out);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_mult_out(const bvec &a, const bvec &b,
const bvec &c, bvec &out);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT vec elem_mult(const vec &a, const vec &b,
const vec &c, const vec &d);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT cvec elem_mult(const cvec &a, const cvec &b,
const cvec &c, const cvec &d);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT ivec elem_mult(const ivec &a, const ivec &b,
const ivec &c, const ivec &d);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT svec elem_mult(const svec &a, const svec &b,
const svec &c, const svec &d);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bvec elem_mult(const bvec &a, const bvec &b,
const bvec &c, const bvec &d);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_mult_out(const vec &a, const vec &b, const vec &c,
const vec &d, vec &out);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_mult_out(const cvec &a, const cvec &b,
const cvec &c, const cvec &d, cvec &out);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_mult_out(const ivec &a, const ivec &b,
const ivec &c, const ivec &d, ivec &out);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_mult_out(const svec &a, const svec &b,
const svec &c, const svec &d, svec &out);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_mult_out(const bvec &a, const bvec &b,
const bvec &c, const bvec &d, bvec &out);
// in-place elementwise multiplication
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_mult_inplace(const vec &a, vec &b);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_mult_inplace(const cvec &a, cvec &b);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_mult_inplace(const ivec &a, ivec &b);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_mult_inplace(const svec &a, svec &b);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_mult_inplace(const bvec &a, bvec &b);
// elementwise multiplication followed by summation
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT double elem_mult_sum(const vec &a, const vec &b);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT std::complex<double> elem_mult_sum(const cvec &a,
const cvec &b);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT int elem_mult_sum(const ivec &a, const ivec &b);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT short elem_mult_sum(const svec &a, const svec &b);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bin elem_mult_sum(const bvec &a, const bvec &b);
// division operator
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT vec operator/(const vec &v, double t);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT cvec operator/(const cvec &v, std::complex<double> t);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT ivec operator/(const ivec &v, int t);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT svec operator/(const svec &v, short t);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bvec operator/(const bvec &v, bin t);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT vec operator/(double t, const vec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT cvec operator/(std::complex<double> t, const cvec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT ivec operator/(int t, const ivec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT svec operator/(short t, const svec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bvec operator/(bin t, const bvec &v);
// elementwise division operator
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT vec elem_div(const vec &a, const vec &b);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT cvec elem_div(const cvec &a, const cvec &b);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT ivec elem_div(const ivec &a, const ivec &b);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT svec elem_div(const svec &a, const svec &b);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bvec elem_div(const bvec &a, const bvec &b);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT vec elem_div(double t, const vec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT cvec elem_div(std::complex<double> t, const cvec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT ivec elem_div(int t, const ivec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT svec elem_div(short t, const svec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bvec elem_div(bin t, const bvec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_div_out(const vec &a, const vec &b, vec &out);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_div_out(const cvec &a, const cvec &b, cvec &out);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_div_out(const ivec &a, const ivec &b, ivec &out);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_div_out(const svec &a, const svec &b, svec &out);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT void elem_div_out(const bvec &a, const bvec &b, bvec &out);
// elementwise division followed by summation
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT double elem_div_sum(const vec &a, const vec &b);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT std::complex<double> elem_div_sum(const cvec &a,
const cvec &b);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT int elem_div_sum(const ivec &a, const ivec &b);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT short elem_div_sum(const svec &a, const svec &b);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bin elem_div_sum(const bvec &a, const bvec &b);
// concat operator
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT vec concat(const vec &v, double a);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT cvec concat(const cvec &v, std::complex<double> a);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT ivec concat(const ivec &v, int a);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT svec concat(const svec &v, short a);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bvec concat(const bvec &v, bin a);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT vec concat(double a, const vec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT cvec concat(std::complex<double> a, const cvec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT ivec concat(int a, const ivec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT svec concat(short a, const svec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bvec concat(bin a, const bvec &v);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT vec concat(const vec &v1, const vec &v2);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT cvec concat(const cvec &v1, const cvec &v2);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT ivec concat(const ivec &v1, const ivec &v2);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT svec concat(const svec &v1, const svec &v2);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bvec concat(const bvec &v1, const bvec &v2);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT vec concat(const vec &v1, const vec &v2, const vec &v3);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT cvec concat(const cvec &v1, const cvec &v2, const cvec &v3);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT ivec concat(const ivec &v1, const ivec &v2, const ivec &v3);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT svec concat(const svec &v1, const svec &v2, const svec &v3);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bvec concat(const bvec &v1, const bvec &v2, const bvec &v3);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT vec concat(const vec &v1, const vec &v2,
const vec &v3, const vec &v4);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT cvec concat(const cvec &v1, const cvec &v2,
const cvec &v3, const cvec &v4);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT ivec concat(const ivec &v1, const ivec &v2,
const ivec &v3, const ivec &v4);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT svec concat(const svec &v1, const svec &v2,
const svec &v3, const svec &v4);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bvec concat(const bvec &v1, const bvec &v2,
const bvec &v3, const bvec &v4);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT vec concat(const vec &v1, const vec &v2, const vec &v3,
const vec &v4, const vec &v5);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT cvec concat(const cvec &v1, const cvec &v2, const cvec &v3,
const cvec &v4, const cvec &v5);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT ivec concat(const ivec &v1, const ivec &v2, const ivec &v3,
const ivec &v4, const ivec &v5);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT svec concat(const svec &v1, const svec &v2, const svec &v3,
const svec &v4, const svec &v5);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT bvec concat(const bvec &v1, const bvec &v2, const bvec &v3,
const bvec &v4, const bvec &v5);
// I/O streams
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT std::ostream &operator<<(std::ostream& os, const vec &vect);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT std::ostream &operator<<(std::ostream& os, const cvec &vect);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT std::ostream &operator<<(std::ostream& os, const svec &vect);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT std::ostream &operator<<(std::ostream& os, const ivec &vect);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT std::ostream &operator<<(std::ostream& os, const bvec &vect);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT std::istream &operator>>(std::istream& is, vec &vect);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT std::istream &operator>>(std::istream& is, cvec &vect);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT std::istream &operator>>(std::istream& is, svec &vect);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT std::istream &operator>>(std::istream& is, ivec &vect);
ITPP_EXPORT_TEMPLATE template ITPP_EXPORT std::istream &operator>>(std::istream& is, bvec &vect);
//! \endcond
} // namespace itpp
#endif // #ifndef VEC_H
|