/usr/include/vigra/tinyvector.hxx is in libvigraimpex-dev 1.10.0+dfsg-3ubuntu2.
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 | /************************************************************************/
/* */
/* Copyright 1998-2002 by Ullrich Koethe */
/* */
/* This file is part of the VIGRA computer vision library. */
/* The VIGRA Website is */
/* http://hci.iwr.uni-heidelberg.de/vigra/ */
/* Please direct questions, bug reports, and contributions to */
/* ullrich.koethe@iwr.uni-heidelberg.de or */
/* vigra@informatik.uni-hamburg.de */
/* */
/* Permission is hereby granted, free of charge, to any person */
/* obtaining a copy of this software and associated documentation */
/* files (the "Software"), to deal in the Software without */
/* restriction, including without limitation the rights to use, */
/* copy, modify, merge, publish, distribute, sublicense, and/or */
/* sell copies of the Software, and to permit persons to whom the */
/* Software is furnished to do so, subject to the following */
/* conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the */
/* Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
/* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
/* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
/* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
/* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
/* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
/* OTHER DEALINGS IN THE SOFTWARE. */
/* */
/************************************************************************/
#ifndef VIGRA_TINYVECTOR_HXX
#define VIGRA_TINYVECTOR_HXX
namespace lemon {
struct Invalid;
} // namespace lemon
#include <cmath> // abs(double)
#include <cstdlib> // abs(int)
#include <iosfwd> // ostream
#include <algorithm>
#include "config.hxx"
#include "error.hxx"
#include "metaprogramming.hxx"
#include "numerictraits.hxx"
#include "memory.hxx"
#include "mathutil.hxx"
#include "diff2d.hxx"
#ifdef VIGRA_CHECK_BOUNDS
#define VIGRA_ASSERT_INSIDE(diff) \
vigra_precondition(diff >= 0, "Index out of bounds");\
vigra_precondition(diff < SIZE, "Index out of bounds");
#else
#define VIGRA_ASSERT_INSIDE(diff)
#endif
namespace vigra {
// mask cl.exe shortcomings [begin]
#if defined(_MSC_VER)
#pragma warning( push )
#pragma warning( disable : 4503 )
#endif
using VIGRA_CSTD::abs;
using VIGRA_CSTD::ceil;
using VIGRA_CSTD::floor;
using VIGRA_CSTD::sqrt;
template <class V1, int SIZE, class D1, class D2>
class TinyVectorBase;
template <class V1, int SIZE, class D1, class D2>
inline
typename TinyVectorBase<V1, SIZE, D1, D2>::SquaredNormType
squaredNorm(TinyVectorBase<V1, SIZE, D1, D2> const & t);
namespace detail {
#define VIGRA_EXEC_LOOP(NAME, OPER) \
template <class T1, class T2> \
static void NAME(T1 * left, T2 const * right) \
{ \
for(int i=0; i<LEVEL; ++i) \
(left[i]) OPER (right[i]); \
}
#define VIGRA_EXEC_LOOP_MINMAX(NAME, OPER) \
template <class T1, class T2> \
static void NAME(T1 * left, T2 const * right) \
{ \
for(int i=0; i<LEVEL; ++i) \
if(left[i] OPER right[i]) \
left[i] = right[i]; \
}
#define VIGRA_EXEC_LOOP_SCALAR(NAME, OPER) \
template <class T1, class T2> \
static void NAME(T1 * left, T2 right) \
{ \
for(int i=0; i<LEVEL; ++i) \
(left[i]) = detail::RequiresExplicitCast<T1>::cast((left[i]) OPER (right)); \
}
template <int LEVEL>
struct ExecLoop
{
template <class T1, class T2>
static void assignCast(T1 * left, T2 const * right)
{
for(int i=0; i<LEVEL; ++i)
left[i] = detail::RequiresExplicitCast<T1>::cast(right[i]);
}
template <class T1, class T2>
static void reverseAssign(T1 * left, T2 const * right)
{
for(int i=0; i<LEVEL; ++i)
left[i] = right[-i];
}
template <class T1, class T2>
static void assignScalar(T1 * left, T2 right)
{
for(int i=0; i<LEVEL; ++i)
left[i] = detail::RequiresExplicitCast<T1>::cast(right);
}
template <class T1, class T2>
static void power(T1 * left, T2 right)
{
for(int i=0; i<LEVEL; ++i)
left[i] = detail::RequiresExplicitCast<T1>::cast(pow(left, right));
}
VIGRA_EXEC_LOOP(assign, =)
VIGRA_EXEC_LOOP(add, +=)
VIGRA_EXEC_LOOP(sub, -=)
VIGRA_EXEC_LOOP(mul, *=)
VIGRA_EXEC_LOOP(div, /=)
VIGRA_EXEC_LOOP(mod, %=)
VIGRA_EXEC_LOOP(neg, = -)
VIGRA_EXEC_LOOP(abs, = vigra::abs)
VIGRA_EXEC_LOOP(floor, = vigra::floor)
VIGRA_EXEC_LOOP(ceil, = vigra::ceil)
VIGRA_EXEC_LOOP(round, = vigra::round)
VIGRA_EXEC_LOOP(sqrt, = vigra::sqrt)
VIGRA_EXEC_LOOP(fromPromote, = NumericTraits<T1>::fromPromote)
VIGRA_EXEC_LOOP(fromRealPromote, = NumericTraits<T1>::fromRealPromote)
VIGRA_EXEC_LOOP_SCALAR(mulScalar, *)
VIGRA_EXEC_LOOP_SCALAR(divScalar, /)
VIGRA_EXEC_LOOP_MINMAX(min, >)
VIGRA_EXEC_LOOP_MINMAX(max, <)
template <class T>
static T const & minimum(T const * p)
{
return *std::min_element(p, p+LEVEL);
}
template <class T>
static T const & maximum(T const * p)
{
return *std::max_element(p, p+LEVEL);
}
template <class T>
static bool all(T const * p, T const & zero)
{
for(int i=0; i<LEVEL; ++i)
if(p[i] == zero)
return false;
return true;
}
template <class T>
static bool any(T const * p, T const & zero)
{
for(int i=0; i<LEVEL; ++i)
if(p[i] != zero)
return true;
return false;
}
template <class T1, class T2>
static bool notEqual(T1 const * left, T2 const * right)
{
for(int i=0; i<LEVEL; ++i)
if(left[i] != right[i])
return true;
return false;
}
template <class T1, class T2>
static bool less(T1 const * left, T2 const * right)
{
for(int i=0; i<LEVEL; ++i)
{
if(left[i] < right[i])
return true;
if(right[i] < left[i])
return false;
}
return false;
}
template <class T>
static bool closeAtTolerance(T const * left, T const * right, T epsilon)
{
bool res = true;
for(int i=0; i<LEVEL; ++i)
{
res = res && vigra::closeAtTolerance(left[i], right[i], epsilon);
}
return res;
}
template <class T>
static typename NumericTraits<T>::Promote
dot(T const * d)
{
typename NumericTraits<T>::Promote res(*d * *d);
for(int i=1; i<LEVEL; ++i)
res += d[i] * d[i];
return res;
}
template <class T1, class T2>
static typename PromoteTraits<T1, T2>::Promote
dot(T1 const * left, T2 const * right)
{
typename PromoteTraits<T1, T2>::Promote res(*left * *right);
for(int i=1; i<LEVEL; ++i)
res += left[i] * right[i];
return res;
}
template <class T>
static typename NormTraits<T>::SquaredNormType
squaredNorm(T const * d)
{
typename NormTraits<T>::SquaredNormType res = vigra::squaredNorm(*d);
for(int i=1; i<LEVEL; ++i)
res += vigra::squaredNorm(d[i]);
return res;
}
};
template <int LEVEL>
struct UnrollScalarResult
{
template <class T>
static typename NumericTraits<T>::Promote
dot(T const * d)
{
return *d * *d + UnrollScalarResult<LEVEL-1>::dot(d+1);
}
template <class T1, class T2>
static typename PromoteTraits<T1, T2>::Promote
dot(T1 const * left, T2 const * right)
{
return *left * *right + UnrollScalarResult<LEVEL-1>::dot(left+1, right+1);
}
template <class T>
static typename NormTraits<T>::SquaredNormType
squaredNorm(T const * d)
{
return vigra::squaredNorm(*d) + UnrollScalarResult<LEVEL-1>::squaredNorm(d+1);
}
static std::ptrdiff_t
squaredNorm(std::ptrdiff_t const * d)
{
return (*d)*(*d) + UnrollScalarResult<LEVEL-1>::squaredNorm(d+1);
}
template <class T>
static T const & minimum(T const * p)
{
T const & m = UnrollScalarResult<LEVEL - 1>::minimum(p+1);
return *p < m
? *p
: m;
}
template <class T>
static T const & maximum(T const * p)
{
T const & m = UnrollScalarResult<LEVEL - 1>::maximum(p+1);
return *p > m
? *p
: m;
}
template <class T>
static bool all(T const * p, T const & zero)
{
return *p != zero && UnrollScalarResult<LEVEL - 1>::all(p+1, zero);
}
template <class T>
static bool any(T const * p, T const & zero)
{
return *p != zero || UnrollScalarResult<LEVEL - 1>::any(p+1, zero);
}
};
template <>
struct UnrollScalarResult<1>
{
template <class T>
static typename NumericTraits<T>::Promote
dot(T const * d)
{
return *d * *d ;
}
template <class T1, class T2>
static typename PromoteTraits<T1, T2>::Promote
dot(T1 const * left, T2 const * right)
{
return *left * *right;
}
template <class T>
static typename NormTraits<T>::SquaredNormType
squaredNorm(T const * d)
{
return vigra::squaredNorm(*d);
}
static std::ptrdiff_t
squaredNorm(std::ptrdiff_t const * d)
{
return (*d)*(*d);
}
template <class T>
static T const & minimum(T const * p)
{
return *p;
}
template <class T>
static T const & maximum(T const * p)
{
return *p;
}
template <class T>
static bool all(T const * p, T const & zero)
{
return *p != zero;
}
template <class T>
static bool any(T const * p, T const & zero)
{
return *p != zero;
}
};
#undef VIGRA_EXEC_LOOP
#undef VIGRA_EXEC_LOOP_MINMAX
#undef VIGRA_EXEC_LOOP_SCALAR
#define VIGRA_UNROLL_LOOP(NAME, OPER) \
template <class T1, class T2> \
static void NAME(T1 * left, T2 const * right) \
{ \
(*left) OPER (*right); \
UnrollLoop<LEVEL-1>::NAME(left+1, right+1); \
}
#define VIGRA_UNROLL_LOOP_MINMAX(NAME, OPER) \
template <class T1, class T2> \
static void NAME(T1 * left, T2 const * right) \
{ \
if(*left OPER *right) \
*left = *right; \
UnrollLoop<LEVEL-1>::NAME(left+1, right+1); \
}
#define VIGRA_UNROLL_LOOP_SCALAR(NAME, OPER) \
template <class T1, class T2> \
static void NAME(T1 * left, T2 right) \
{ \
(*left) = detail::RequiresExplicitCast<T1>::cast((*left) OPER (right)); \
UnrollLoop<LEVEL-1>::NAME(left+1, right); \
}
template <int LEVEL>
struct UnrollLoop
{
template <class T1, class T2>
static void reverseAssign(T1 * left, T2 const * right)
{
*left = *right;
UnrollLoop<LEVEL-1>::reverseAssign(left+1, right-1);
}
template <class T1, class T2>
static void assignCast(T1 * left, T2 const * right)
{
*left = detail::RequiresExplicitCast<T1>::cast(*right);
UnrollLoop<LEVEL-1>::assignCast(left+1, right+1);
}
template <class T1, class T2>
static void assignScalar(T1 * left, T2 right)
{
*left = detail::RequiresExplicitCast<T1>::cast(right);
UnrollLoop<LEVEL-1>::assignScalar(left+1, right);
}
template <class T1, class T2>
static void power(T1 * left, T2 right)
{
*left = detail::RequiresExplicitCast<T1>::cast(pow(*left, right));
UnrollLoop<LEVEL-1>::power(left+1, right);
}
VIGRA_UNROLL_LOOP(assign, =)
VIGRA_UNROLL_LOOP(add, +=)
VIGRA_UNROLL_LOOP(sub, -=)
VIGRA_UNROLL_LOOP(mul, *=)
VIGRA_UNROLL_LOOP(div, /=)
VIGRA_UNROLL_LOOP(mod, %=)
VIGRA_UNROLL_LOOP(neg, = -)
VIGRA_UNROLL_LOOP(abs, = vigra::abs)
VIGRA_UNROLL_LOOP(floor, = vigra::floor)
VIGRA_UNROLL_LOOP(ceil, = vigra::ceil)
VIGRA_UNROLL_LOOP(round, = vigra::round)
VIGRA_UNROLL_LOOP(sqrt, = vigra::sqrt)
VIGRA_UNROLL_LOOP(fromPromote, = NumericTraits<T1>::fromPromote)
VIGRA_UNROLL_LOOP(fromRealPromote, = NumericTraits<T1>::fromRealPromote)
VIGRA_UNROLL_LOOP_SCALAR(mulScalar, *)
VIGRA_UNROLL_LOOP_SCALAR(divScalar, /)
VIGRA_UNROLL_LOOP_MINMAX(min, >)
VIGRA_UNROLL_LOOP_MINMAX(max, <)
template <class T>
static T const & minimum(T const * p)
{
return UnrollScalarResult<LEVEL>::minimum(p);
}
template <class T>
static T const & maximum(T const * p)
{
return UnrollScalarResult<LEVEL>::maximum(p);
}
template <class T>
static bool all(T const * p, T const & zero)
{
return UnrollScalarResult<LEVEL>::all(p, zero);
}
template <class T>
static bool any(T const * p, T const & zero)
{
return UnrollScalarResult<LEVEL>::any(p, zero);
}
template <class T1, class T2>
static bool notEqual(T1 const * left, T2 const * right)
{
return (*left != *right) || UnrollLoop<LEVEL - 1>::notEqual(left+1, right+1);
}
template <class T1, class T2>
static bool less(T1 const * left, T2 const * right)
{
if(*left < *right)
return true;
if(*right < *left)
return false;
return UnrollLoop<LEVEL - 1>::less(left+1, right+1);
}
template <class T>
static bool closeAtTolerance(T const * left, T const * right, T epsilon)
{
return vigra::closeAtTolerance(*left, *right, epsilon) &&
UnrollLoop<LEVEL - 1>::closeAtTolerance(left+1, right+1, epsilon);
}
template <class T>
static typename NumericTraits<T>::Promote
dot(T const * d)
{
return UnrollScalarResult<LEVEL>::dot(d);
}
template <class T1, class T2>
static typename PromoteTraits<T1, T2>::Promote
dot(T1 const * left, T2 const * right)
{
return UnrollScalarResult<LEVEL>::dot(left, right);
}
template <class T>
static typename NormTraits<T>::SquaredNormType
squaredNorm(T const * d)
{
return UnrollScalarResult<LEVEL>::squaredNorm(d);
}
};
#undef VIGRA_UNROLL_LOOP
#undef VIGRA_UNROLL_LOOP_MINMAX
#undef VIGRA_UNROLL_LOOP_SCALAR
template <>
struct UnrollLoop<0>
{
template <class T1, class T2>
static void reverseAssign(T1, T2) {}
template <class T1, class T2>
static void assignCast(T1, T2) {}
template <class T1, class T2>
static void assign(T1, T2) {}
template <class T1, class T2>
static void assignScalar(T1, T2) {}
template <class T1, class T2>
static void power(T1, T2) {}
template <class T1, class T2>
static void add(T1, T2) {}
template <class T1, class T2>
static void sub(T1, T2) {}
template <class T1, class T2>
static void mul(T1, T2) {}
template <class T1, class T2>
static void mulScalar(T1, T2) {}
template <class T1, class T2>
static void div(T1, T2) {}
template <class T1, class T2>
static void mod(T1, T2) {}
template <class T1, class T2>
static void divScalar(T1, T2) {}
template <class T1, class T2>
static void fromPromote(T1, T2) {}
template <class T1, class T2>
static void fromRealPromote(T1, T2) {}
template <class T1, class T2>
static void neg(T1, T2) {}
template <class T1, class T2>
static void abs(T1, T2) {}
template <class T1, class T2>
static void floor(T1, T2) {}
template <class T1, class T2>
static void ceil(T1, T2) {}
template <class T1, class T2>
static void round(T1, T2) {}
template <class T1, class T2>
static void sqrt(T1, T2) {}
template <class T1, class T2>
static bool notEqual(T1, T2) { return false; }
template <class T1, class T2>
static bool less(T1, T2) { return false; }
template <class T1, class T2>
static void min(T1, T2) {}
template <class T1, class T2>
static void max(T1, T2) {}
template <class T>
static T minimum(T const *) { return NumericTraits<T>::max(); }
template <class T>
static T maximum(T const *) { return NumericTraits<T>::min(); }
template <class T>
static bool all(T const *, T const &) { return true; }
template <class T>
static bool any(T const *, T const &) { return false; }
template <class T>
static bool closeAtTolerance(T const *, T const *, T) { return true; }
};
template <int SIZE>
struct LoopType
{
static const int MaxUnrollSize = 5;
typedef typename IfBool<(SIZE <= MaxUnrollSize), UnrollLoop<SIZE>, ExecLoop<SIZE> >::type type;
};
struct DontInit {};
inline DontInit dontInit() {return DontInit(); }
} // namespace detail
template <class T, int SIZE>
class TinyVector;
template <class T, int SIZE>
class TinyVectorView;
/********************************************************/
/* */
/* TinyVectorBase */
/* */
/********************************************************/
/** \brief Base class for fixed size vectors.
This class contains functionality shared by
\ref TinyVector and \ref TinyVectorView, and enables these classes
to be freely mixed within expressions. It is typically not used directly.
<b>\#include</b> \<vigra/tinyvector.hxx\><br>
Namespace: vigra
**/
template <class VALUETYPE, int SIZE, class DATA, class DERIVED>
class TinyVectorBase
{
TinyVectorBase(TinyVectorBase const &); // do not use
TinyVectorBase & operator=(TinyVectorBase const & other); // do not use
protected:
typedef typename detail::LoopType<SIZE>::type Loop;
TinyVectorBase()
{}
public:
/** STL-compatible definition of valuetype
*/
typedef VALUETYPE value_type;
/** reference (return of operator[]).
*/
typedef VALUETYPE & reference;
/** const reference (return of operator[] const).
*/
typedef VALUETYPE const & const_reference;
/** pointer (return of operator->).
*/
typedef VALUETYPE * pointer;
/** const pointer (return of operator-> const).
*/
typedef VALUETYPE const * const_pointer;
/** STL-compatible definition of iterator
*/
typedef value_type * iterator;
/** STL-compatible definition of const iterator
*/
typedef value_type const * const_iterator;
/** STL-compatible definition of size_type
*/
typedef unsigned int size_type;
/** STL-compatible definition of difference_type
*/
typedef std::ptrdiff_t difference_type;
/** the scalar type for the outer product
*/
typedef double scalar_multiplier;
/** the vector's squared norm type
*/
typedef typename NormTraits<VALUETYPE>::SquaredNormType SquaredNormType;
/** the vector's norm type
*/
typedef typename SquareRootTraits<SquaredNormType>::SquareRootResult NormType;
/** the vector's size
*/
enum { static_size = SIZE };
/** Initialize from another sequence (must have length SIZE!)
*/
template <class Iterator>
void init(Iterator i, Iterator end)
{
vigra_precondition(end-i == SIZE,
"TinyVector::init(): Sequence has wrong size.");
Loop::assignCast(data_, i);
}
/** Initialize with constant value
*/
void init(value_type initial)
{
Loop::assignScalar(data_, initial);
}
/** Component-wise add-assignment
*/
template <class T1, class D1, class D2>
DERIVED & operator+=(TinyVectorBase<T1, SIZE, D1, D2> const & r)
{
Loop::add(data_, r.begin());
return static_cast<DERIVED &>(*this);
}
/** Component-wise subtract-assignment
*/
template <class T1, class D1, class D2>
DERIVED & operator-=(TinyVectorBase<T1, SIZE, D1, D2> const & r)
{
Loop::sub(data_, r.begin());
return static_cast<DERIVED &>(*this);
}
/** Component-wise multiply-assignment
*/
template <class T1, class D1, class D2>
DERIVED & operator*=(TinyVectorBase<T1, SIZE, D1, D2> const & r)
{
Loop::mul(data_, r.begin());
return static_cast<DERIVED &>(*this);
}
/** Component-wise divide-assignment
*/
template <class T1, class D1, class D2>
DERIVED & operator/=(TinyVectorBase<T1, SIZE, D1, D2> const & r)
{
Loop::div(data_, r.begin());
return static_cast<DERIVED &>(*this);
}
/** Component-wise modulo-assignment
*/
template <class T1, class D1, class D2>
DERIVED & operator%=(TinyVectorBase<T1, SIZE, D1, D2> const & r)
{
Loop::mod(data_, r.begin());
return static_cast<DERIVED &>(*this);
}
/** Component-wise scalar multiply-assignment
*/
DERIVED & operator*=(double r)
{
Loop::mulScalar(data_, r);
return static_cast<DERIVED &>(*this);
}
/** Component-wise scalar divide-assignment
*/
DERIVED & operator/=(double r)
{
Loop::divScalar(data_, r);
return static_cast<DERIVED &>(*this);
}
/** Calculate magnitude.
*/
NormType magnitude() const
{
return sqrt(static_cast<typename
SquareRootTraits<SquaredNormType>::SquareRootArgument>(squaredMagnitude()));
}
/** Calculate squared magnitude.
*/
SquaredNormType squaredMagnitude() const
{
return Loop::squaredNorm(data_);
}
/** Return the minimal element.
*/
VALUETYPE const & minimum() const
{
return Loop::minimum(data_);
}
/** Return the maximal element.
*/
VALUETYPE const & maximum() const
{
return Loop::maximum(data_);
}
/** Check that all elements of this vector are non-zero (or 'true' if T is bool).
*/
bool all() const
{
return Loop::all(data_, VALUETYPE());
}
/** Check that at least one element of this vector is non-zero (or 'true' if T is bool).
*/
bool any() const
{
return Loop::any(data_, VALUETYPE());
}
/** Access component by index.
*/
reference operator[](difference_type i)
{
VIGRA_ASSERT_INSIDE(i);
return data_[i];
}
/** Get component by index.
*/
const_reference operator[](difference_type i) const
{
VIGRA_ASSERT_INSIDE(i);
return data_[i];
}
/** Get random access iterator to begin of vector.
*/
iterator begin() { return data_; }
/** Get random access iterator past-the-end of vector.
*/
iterator end() { return data_ + SIZE; }
/** Get const random access iterator to begin of vector.
*/
const_iterator begin() const { return data_; }
/** Get const random access iterator past-the-end of vector.
*/
const_iterator end() const { return data_ + SIZE; }
/** Get a view to the subarray with length <tt>(TO-FROM)</tt> starting at <tt>FROM</tt>.
The bounds must fullfill <tt>0 <= FROM < TO <= SIZE</tt>, but this is only
checked when <tt>VIGRA_CHECK_BOUNDS</tt> is \#define'd.
*/
template <int FROM, int TO>
TinyVectorView<VALUETYPE, TO-FROM> subarray() const
{
#ifdef VIGRA_CHECK_BOUNDS
vigra_precondition(FROM >= 0, "Index out of bounds");
vigra_precondition(FROM < TO, "Index out of bounds");
vigra_precondition(TO <=SIZE, "Index out of bounds");
#endif
return TinyVectorView<VALUETYPE, TO-FROM>(data_+FROM);
}
/** Size of TinyVector vector always equals the template parameter SIZE.
*/
size_type size() const { return SIZE; }
pointer data() { return data_; }
const_pointer data() const { return data_; }
static TinyVector<VALUETYPE, SIZE> unitVector(int k)
{
VIGRA_ASSERT_INSIDE(k);
TinyVector<VALUETYPE, SIZE> ret;
ret[k] = 1;
return ret;
}
protected:
DATA data_;
};
/** \brief Class for fixed size vectors.
\ingroup RangesAndPoints
This class contains an array of size SIZE of the specified VALUETYPE.
The interface conforms to STL vector, except that there are no functions
that change the size of a TinyVector.
\ref TinyVectorOperators "Arithmetic operations"
on TinyVectors are defined as component-wise applications of these
operations. Addition and subtraction of two TinyVectors
(+=, -=, +, -, unary -), multiplication and division of an
TinyVector with a double, and NumericTraits/PromoteTraits are defined,
so that TinyVector fulfills the requirements of \ref LinearAlgebraConcept "Linear Algebra".
VIGRA algorithms typically use \ref vigra::VectorAccessor to access
TinyVectors as a whole, or specific components of them.
See also:<br>
<UL style="list-style-image:url(documents/bullet.gif)">
<LI> \ref vigra::TinyVectorBase
<LI> \ref vigra::TinyVectorView
<LI> \ref TinyVectorTraits
<LI> \ref TinyVectorOperators
</UL>
<b>\#include</b> \<vigra/tinyvector.hxx\><br>
Namespace: vigra
**/
template <class T, int SIZE>
class TinyVector
: public TinyVectorBase<T, SIZE, T[SIZE], TinyVector<T, SIZE> >
{
typedef TinyVectorBase<T, SIZE, T[SIZE], TinyVector<T, SIZE> > BaseType;
typedef typename BaseType::Loop Loop;
public:
typedef typename BaseType::value_type value_type;
typedef typename BaseType::reference reference;
typedef typename BaseType::const_reference const_reference;
typedef typename BaseType::pointer pointer;
typedef typename BaseType::const_pointer const_pointer;
typedef typename BaseType::iterator iterator;
typedef typename BaseType::const_iterator const_iterator;
typedef typename BaseType::size_type size_type;
typedef typename BaseType::difference_type difference_type;
typedef typename BaseType::scalar_multiplier scalar_multiplier;
typedef typename BaseType::SquaredNormType SquaredNormType;
typedef typename BaseType::NormType NormType;
enum ReverseCopyTag { ReverseCopy };
/** Construction with constant value.
Initializes all vector elements with the given value.
*/
explicit TinyVector(value_type const & initial)
: BaseType()
{
Loop::assignScalar(BaseType::begin(), initial);
}
/** Construction from lemon::Invalid.
Initializes all vector elements with -1.
*/
TinyVector(lemon::Invalid const &)
: BaseType()
{
Loop::assignScalar(BaseType::begin(), -1);
}
/** Construction with Diff2D.
Use only when <tt>SIZE == 2</tt>.
*/
explicit TinyVector(Diff2D const & initial)
: BaseType()
{
BaseType::data_[0] = detail::RequiresExplicitCast<T>::cast(initial.x);
BaseType::data_[1] = detail::RequiresExplicitCast<T>::cast(initial.y);
}
/** Construction with explicit values.
Call only if SIZE == 2
*/
TinyVector(value_type const & i1, value_type const & i2)
: BaseType()
{
BaseType::data_[0] = i1;
BaseType::data_[1] = i2;
}
/** Construction with explicit values.
Call only if SIZE == 3
*/
TinyVector(value_type const & i1, value_type const & i2, value_type const & i3)
: BaseType()
{
BaseType::data_[0] = i1;
BaseType::data_[1] = i2;
BaseType::data_[2] = i3;
}
/** Construction with explicit values.
Call only if SIZE == 4
*/
TinyVector(value_type const & i1, value_type const & i2,
value_type const & i3, value_type const & i4)
: BaseType()
{
BaseType::data_[0] = i1;
BaseType::data_[1] = i2;
BaseType::data_[2] = i3;
BaseType::data_[3] = i4;
}
/** Construction with explicit values.
Call only if SIZE == 5
*/
TinyVector(value_type const & i1, value_type const & i2,
value_type const & i3, value_type const & i4,
value_type const & i5)
: BaseType()
{
BaseType::data_[0] = i1;
BaseType::data_[1] = i2;
BaseType::data_[2] = i3;
BaseType::data_[3] = i4;
BaseType::data_[4] = i5;
}
/** Default constructor (initializes all elements with zero).
*/
TinyVector()
: BaseType()
{
Loop::assignScalar(BaseType::data_, value_type());
}
/** Construct without initializing the vector elements.
*/
explicit TinyVector(SkipInitializationTag)
: BaseType()
{}
explicit TinyVector(detail::DontInit)
: BaseType()
{}
/** Copy constructor.
*/
TinyVector(TinyVector const & r)
: BaseType()
{
Loop::assign(BaseType::data_, r.data_);
}
/** Constructor from C array.
*/
template <class U>
explicit TinyVector(U const * data)
: BaseType()
{
Loop::assign(BaseType::data_, data);
}
/** Constructor by reverse copy from C array.
Usage:
\code
TinyVector<int, 3> v(1,2,3);
TinyVector<int, 3> reversed(v.begin(), TinyVector<int, 3>::ReverseCopy);
\endcode
*/
explicit TinyVector(const_pointer data, ReverseCopyTag)
: BaseType()
{
Loop::reverseAssign(BaseType::data_, data+SIZE-1);
}
/** Copy with type conversion.
*/
template <class U, class DATA, class DERIVED>
TinyVector(TinyVectorBase<U, SIZE, DATA, DERIVED> const & r)
: BaseType()
{
Loop::assignCast(BaseType::data_, r.begin());
}
/** Copy assignment.
*/
TinyVector & operator=(TinyVector const & r)
{
Loop::assign(BaseType::data_, r.data_);
return *this;
}
/** Copy assignment with type conversion.
*/
template <class U, class DATA, class DERIVED>
TinyVector & operator=(TinyVectorBase<U, SIZE, DATA, DERIVED> const & r)
{
Loop::assignCast(BaseType::data_, r.begin());
return *this;
}
/** Assignment from Diff2D.
Use only when <tt>SIZE == 2</tt>.
*/
TinyVector & operator=(Diff2D const & r)
{
BaseType::data_[0] = detail::RequiresExplicitCast<T>::cast(r.x);
BaseType::data_[1] = detail::RequiresExplicitCast<T>::cast(r.y);
return *this;
}
/** Assignment from scalar. Will set all entries to the given value.
*/
TinyVector & operator=(value_type const & v)
{
Loop::assignScalar(BaseType::begin(), v);
return *this;
}
/** Copy from a TinyVector with a different number of elements.
Only the first <tt>min(SIZE, USIZE)</tt> elements are copied.
*/
template <class U, int USIZE, class DATA, class DERIVED>
TinyVector & copy(TinyVectorBase<U, USIZE, DATA, DERIVED> const & r)
{
static const int minSize = USIZE < SIZE
? USIZE
: SIZE;
typedef typename detail::LoopType<minSize>::type MinLoop;
MinLoop::assignCast(BaseType::data_, r.begin());
return *this;
}
};
/** \brief Wrapper for fixed size vectors.
This class wraps an array of size SIZE of the specified VALUETYPE.
Thus, the array can be accessed with an interface similar to
that of std::vector (except that there are no functions
that change the size of a TinyVectorView). The TinyVectorView
does <em>not</em> assume ownership of the given memory.
\ref TinyVectorOperators "Arithmetic operations"
on TinyVectorViews are defined as component-wise applications of these
operations. Addition and subtraction of two TinyVectorViews
(+=, -=, +, -, unary -), multiplication and division of an
TinyVectorViews with a double, and NumericTraits/PromoteTraits are defined,
so that TinyVectorView fulfills the requirements of \ref LinearAlgebraConcept "Linear Algebra".
VIGRA algorithms typically use \ref vigra::VectorAccessor to access
TinyVectorViews as a whole, or specific components of them.
<b>See also:</b>
<ul>
<li> \ref vigra::TinyVectorBase
<li> \ref vigra::TinyVector
<li> \ref TinyVectorTraits
<li> \ref TinyVectorOperators
</ul>
<b>\#include</b> \<vigra/tinyvector.hxx\><br>
Namespace: vigra
**/
template <class T, int SIZE>
class TinyVectorView
: public TinyVectorBase<T, SIZE, T *, TinyVectorView<T, SIZE> >
{
typedef TinyVectorBase<T, SIZE, T *, TinyVectorView<T, SIZE> > BaseType;
typedef typename BaseType::Loop Loop;
public:
typedef typename BaseType::value_type value_type;
typedef typename BaseType::reference reference;
typedef typename BaseType::const_reference const_reference;
typedef typename BaseType::pointer pointer;
typedef typename BaseType::const_pointer const_pointer;
typedef typename BaseType::iterator iterator;
typedef typename BaseType::const_iterator const_iterator;
typedef typename BaseType::size_type size_type;
typedef typename BaseType::difference_type difference_type;
typedef typename BaseType::scalar_multiplier scalar_multiplier;
typedef typename BaseType::SquaredNormType SquaredNormType;
typedef typename BaseType::NormType NormType;
/** Default constructor
(pointer to wrapped data is NULL).
*/
TinyVectorView()
: BaseType()
{
BaseType::data_ = 0;
}
/** Construct view for given data array
*/
TinyVectorView(const_pointer data)
: BaseType()
{
BaseType::data_ = const_cast<pointer>(data);
}
/** Copy constructor (shallow copy).
*/
TinyVectorView(TinyVectorView const & other)
: BaseType()
{
BaseType::data_ = const_cast<pointer>(other.data_);
}
/** Construct view from other TinyVector.
*/
template <class DATA, class DERIVED>
TinyVectorView(TinyVectorBase<T, SIZE, DATA, DERIVED> const & other)
: BaseType()
{
BaseType::data_ = const_cast<pointer>(other.data());
}
/** Copy the data (not the pointer) of the rhs.
*/
TinyVectorView & operator=(TinyVectorView const & r)
{
Loop::assign(BaseType::data_, r.begin());
return *this;
}
/** Copy the data of the rhs with cast.
*/
template <class U, class DATA, class DERIVED>
TinyVectorView & operator=(TinyVectorBase<U, SIZE, DATA, DERIVED> const & r)
{
Loop::assignCast(BaseType::data_, r.begin());
return *this;
}
};
/********************************************************/
/* */
/* TinyVector Comparison */
/* */
/********************************************************/
/** \addtogroup TinyVectorOperators Functions for TinyVector
\brief Implement basic arithmetic and equality for TinyVector.
These functions fulfill the requirements of a Linear Space (vector space).
Return types are determined according to \ref TinyVectorTraits.
<b>\#include</b> \<vigra/tinyvector.hxx\><br>
Namespace: vigra
*/
//@{
/// component-wise equal
template <class V1, int SIZE, class D1, class D2, class V2, class D3, class D4>
inline bool
operator==(TinyVectorBase<V1, SIZE, D1, D2> const & l,
TinyVectorBase<V2, SIZE, D3, D4> const & r)
{
return !(l != r);
}
/// component-wise not equal
template <class V1, int SIZE, class D1, class D2, class V2, class D3, class D4>
inline bool
operator!=(TinyVectorBase<V1, SIZE, D1, D2> const & l,
TinyVectorBase<V2, SIZE, D3, D4> const & r)
{
typedef typename detail::LoopType<SIZE>::type ltype;
return ltype::notEqual(l.begin(), r.begin());
}
/// lexicographical comparison
template <class V1, int SIZE, class D1, class D2, class V2, class D3, class D4>
inline bool
operator<(TinyVectorBase<V1, SIZE, D1, D2> const & l,
TinyVectorBase<V2, SIZE, D3, D4> const & r)
{
typedef typename detail::LoopType<SIZE>::type ltype;
return ltype::less(l.begin(), r.begin());
}
template <class V, int SIZE, class D1, class D2, class D3, class D4>
bool
closeAtTolerance(TinyVectorBase<V, SIZE, D1, D2> const & l,
TinyVectorBase<V, SIZE, D3, D4> const & r,
V epsilon = NumericTraits<V>::epsilon())
{
typedef typename detail::LoopType<SIZE>::type ltype;
return ltype::closeAtTolerance(l.begin(), r.begin(), epsilon);
}
template <class V, int SIZE>
bool
closeAtTolerance(TinyVector<V, SIZE> const & l,
TinyVector<V, SIZE> const & r,
V epsilon = NumericTraits<V>::epsilon())
{
typedef typename detail::LoopType<SIZE>::type ltype;
return ltype::closeAtTolerance(l.begin(), r.begin(), epsilon);
}
/********************************************************/
/* */
/* TinyVector Output */
/* */
/********************************************************/
/// stream output
template <class V1, int SIZE, class DATA, class DERIVED>
std::ostream &
operator<<(std::ostream & out, TinyVectorBase<V1, SIZE, DATA, DERIVED> const & l)
{
out << "(";
int i;
for(i=0; i<SIZE-1; ++i)
out << l[i] << ", ";
out << l[i] << ")";
return out;
}
//@}
/********************************************************/
/* */
/* TinyVector-Traits */
/* */
/********************************************************/
/** \page TinyVectorTraits Numeric and Promote Traits of TinyVector
The numeric and promote traits for TinyVectors follow
the general specifications for \ref NumericPromotionTraits.
They are implemented in terms of the traits of the basic types by
partial template specialization:
\code
template <class T, int SIZE>
struct NumericTraits<TinyVector<T, SIZE> >
{
typedef TinyVector<typename NumericTraits<T>::Promote, SIZE> Promote;
typedef TinyVector<typename NumericTraits<T>::RealPromote, SIZE> RealPromote;
typedef typename NumericTraits<T>::isIntegral isIntegral;
typedef VigraFalseType isScalar;
typedef typename NumericTraits<T>::isSigned isSigned;
// etc.
};
template <class T, int SIZE>
struct NormTraits<TinyVector<T, SIZE> >
{
typedef TinyVector<T, SIZE> Type;
typedef typename Type::SquaredNormType SquaredNormType;
typedef typename Type::NormType NormType;
};
template <class T1, class T2, SIZE>
struct PromoteTraits<TinyVector<T1, SIZE>, TinyVector<T2, SIZE> >
{
typedef TinyVector<typename PromoteTraits<T1, T2>::Promote, SIZE> Promote;
};
\endcode
<b>\#include</b> \<vigra/tinyvector.hxx\><br>
Namespace: vigra
On compilers that don't support partial template specialization (e.g.
MS VisualC++), the traits classes are explicitly specialized for
<TT>TinyVector<VALUETYPE, SIZE></TT> with
<TT>VALUETYPE = unsigned char | int | float | double</TT> and <TT>SIZE = 2 | 3 | 4</TT>.
*/
#if !defined(NO_PARTIAL_TEMPLATE_SPECIALIZATION)
template <class T, int SIZE>
struct NumericTraits<TinyVector<T, SIZE> >
{
typedef TinyVector<T, SIZE> Type;
typedef TinyVector<typename NumericTraits<T>::Promote, SIZE> Promote;
typedef TinyVector<typename NumericTraits<T>::RealPromote, SIZE> RealPromote;
typedef TinyVector<typename NumericTraits<T>::ComplexPromote, SIZE> ComplexPromote;
typedef T ValueType;
typedef typename NumericTraits<T>::isIntegral isIntegral;
typedef VigraFalseType isScalar;
typedef typename NumericTraits<T>::isSigned isSigned;
typedef VigraTrueType isOrdered;
typedef VigraFalseType isComplex;
static TinyVector<T, SIZE> zero()
{
return TinyVector<T, SIZE>(NumericTraits<T>::zero());
}
static TinyVector<T, SIZE> one()
{
return TinyVector<T, SIZE>(NumericTraits<T>::one());
}
static TinyVector<T, SIZE> nonZero()
{
return TinyVector<T, SIZE>(NumericTraits<T>::nonZero());
}
static TinyVector<T, SIZE> min()
{
return TinyVector<T, SIZE>(NumericTraits<T>::min());
}
static TinyVector<T, SIZE> max()
{
return TinyVector<T, SIZE>(NumericTraits<T>::max());
}
template <class D1, class D2>
static Promote toPromote(TinyVectorBase<T, SIZE, D1, D2> const & v)
{
return Promote(v);
}
template <class D1, class D2>
static RealPromote toRealPromote(TinyVectorBase<T, SIZE, D1, D2> const & v)
{
return RealPromote(v);
}
template <class D1, class D2>
static TinyVector<T, SIZE>
fromPromote(TinyVectorBase<typename NumericTraits<T>::Promote, SIZE, D1, D2> const & v)
{
TinyVector<T, SIZE> res(detail::dontInit());
typedef typename detail::LoopType<SIZE>::type ltype;
ltype::fromPromote(res.begin(), v.begin());
return res;
}
template <class D1, class D2>
static TinyVector<T, SIZE>
fromRealPromote(TinyVectorBase<typename NumericTraits<T>::RealPromote, SIZE, D1, D2> const & v)
{
TinyVector<T, SIZE> res(detail::dontInit());
typedef typename detail::LoopType<SIZE>::type ltype;
ltype::fromRealPromote(res.begin(), v.begin());
return res;
}
};
template <class T, int SIZE>
struct NumericTraits<TinyVectorView<T, SIZE> >
: public NumericTraits<TinyVector<T, SIZE> >
{
typedef TinyVector<T, SIZE> Type;
typedef TinyVector<typename NumericTraits<T>::Promote, SIZE> Promote;
typedef TinyVector<typename NumericTraits<T>::RealPromote, SIZE> RealPromote;
typedef TinyVector<typename NumericTraits<T>::ComplexPromote, SIZE> ComplexPromote;
typedef T ValueType;
typedef typename NumericTraits<T>::isIntegral isIntegral;
typedef VigraFalseType isScalar;
typedef typename NumericTraits<T>::isSigned isSigned;
typedef VigraFalseType isOrdered;
typedef VigraFalseType isComplex;
};
template <class T, int SIZE>
struct NormTraits<TinyVector<T, SIZE> >
{
typedef TinyVector<T, SIZE> Type;
typedef typename Type::SquaredNormType SquaredNormType;
typedef typename Type::NormType NormType;
};
template <class T, int SIZE>
struct NormTraits<TinyVectorView<T, SIZE> >
{
typedef TinyVector<T, SIZE> Type;
typedef typename Type::SquaredNormType SquaredNormType;
typedef typename Type::NormType NormType;
};
template <class T1, class T2, int SIZE>
struct PromoteTraits<TinyVector<T1, SIZE>, TinyVector<T2, SIZE> >
{
typedef TinyVector<typename PromoteTraits<T1, T2>::Promote, SIZE> Promote;
};
template <class T1, class T2, int SIZE>
struct PromoteTraits<TinyVectorView<T1, SIZE>, TinyVectorView<T2, SIZE> >
{
typedef TinyVector<typename PromoteTraits<T1, T2>::Promote, SIZE> Promote;
};
template <class T1, class T2, int SIZE>
struct PromoteTraits<TinyVectorView<T1, SIZE>, TinyVector<T2, SIZE> >
{
typedef TinyVector<typename PromoteTraits<T1, T2>::Promote, SIZE> Promote;
};
template <class T1, class T2, int SIZE>
struct PromoteTraits<TinyVector<T1, SIZE>, TinyVectorView<T2, SIZE> >
{
typedef TinyVector<typename PromoteTraits<T1, T2>::Promote, SIZE> Promote;
};
template <class T, int SIZE>
struct PromoteTraits<TinyVector<T, SIZE>, double >
{
typedef TinyVector<typename NumericTraits<T>::RealPromote, SIZE> Promote;
};
template <class T, int SIZE>
struct PromoteTraits<double, TinyVector<T, SIZE> >
{
typedef TinyVector<typename NumericTraits<T>::RealPromote, SIZE> Promote;
};
template <class T, int SIZE>
struct PromoteTraits<TinyVectorView<T, SIZE>, double >
{
typedef TinyVector<typename NumericTraits<T>::RealPromote, SIZE> Promote;
};
template <class T, int SIZE>
struct PromoteTraits<double, TinyVectorView<T, SIZE> >
{
typedef TinyVector<typename NumericTraits<T>::RealPromote, SIZE> Promote;
};
template<class T, int SIZE>
struct CanSkipInitialization<TinyVectorView<T, SIZE> >
{
typedef typename CanSkipInitialization<T>::type type;
static const bool value = type::asBool;
};
template<class T, int SIZE>
struct CanSkipInitialization<TinyVector<T, SIZE> >
{
typedef typename CanSkipInitialization<T>::type type;
static const bool value = type::asBool;
};
#else // NO_PARTIAL_TEMPLATE_SPECIALIZATION
#define TINYVECTOR_NUMTRAITS(T, SIZE) \
template<>\
struct NumericTraits<TinyVector<T, SIZE> >\
{\
typedef TinyVector<T, SIZE> Type;\
typedef TinyVector<NumericTraits<T>::Promote, SIZE> Promote;\
typedef TinyVector<NumericTraits<T>::RealPromote, SIZE> RealPromote;\
typedef TinyVector<NumericTraits<T>::ComplexPromote, SIZE> ComplexPromote;\
typedef T ValueType; \
typedef NumericTraits<T>::isIntegral isIntegral;\
typedef VigraFalseType isScalar;\
typedef NumericTraits<T>::isSigned isSigned; \
typedef VigraFalseType isOrdered;\
typedef VigraFalseType isComplex;\
\
static TinyVector<T, SIZE> zero() { \
return TinyVector<T, SIZE>(NumericTraits<T>::zero()); \
}\
static TinyVector<T, SIZE> one() { \
return TinyVector<T, SIZE>(NumericTraits<T>::one()); \
}\
static TinyVector<T, SIZE> nonZero() { \
return TinyVector<T, SIZE>(NumericTraits<T>::nonZero()); \
}\
\
static Promote toPromote(TinyVector<T, SIZE> const & v) { \
return Promote(v); \
}\
static RealPromote toRealPromote(TinyVector<T, SIZE> const & v) { \
return RealPromote(v); \
}\
static TinyVector<T, SIZE> fromPromote(Promote const & v) { \
TinyVector<T, SIZE> res;\
TinyVector<T, SIZE>::iterator d = res.begin(), dend = res.end();\
Promote::const_iterator s = v.begin();\
for(; d != dend; ++d, ++s)\
*d = NumericTraits<T>::fromPromote(*s);\
return res;\
}\
static TinyVector<T, SIZE> fromRealPromote(RealPromote const & v) {\
TinyVector<T, SIZE> res;\
TinyVector<T, SIZE>::iterator d = res.begin(), dend = res.end();\
RealPromote::const_iterator s = v.begin();\
for(; d != dend; ++d, ++s)\
*d = NumericTraits<T>::fromRealPromote(*s);\
return res;\
}\
}; \
template<>\
struct NormTraits<TinyVector<T, SIZE> >\
{\
typedef TinyVector<T, SIZE> Type;\
typedef Type::SquaredNormType SquaredNormType; \
typedef Type::NormType NormType; \
};
#define TINYVECTOR_PROMTRAITS1(type1, SIZE) \
template<> \
struct PromoteTraits<TinyVector<type1, SIZE>, TinyVector<type1, SIZE> > \
{ \
typedef TinyVector<PromoteTraits<type1, type1>::Promote, SIZE> Promote; \
static Promote toPromote(TinyVector<type1, SIZE> const & v) { \
return static_cast<Promote>(v); } \
};
#define TINYVECTOR_PROMTRAITS2(type1, type2, SIZE) \
template<> \
struct PromoteTraits<TinyVector<type1, SIZE>, TinyVector<type2, SIZE> > \
{ \
typedef TinyVector<PromoteTraits<type1, type2>::Promote, SIZE> Promote; \
static Promote toPromote(TinyVector<type1, SIZE> const & v) { \
return static_cast<Promote>(v); } \
static Promote toPromote(TinyVector<type2, SIZE> const & v) { \
return static_cast<Promote>(v); } \
};
#define TINYVECTOR_TRAITS(SIZE) \
TINYVECTOR_NUMTRAITS(unsigned char, SIZE)\
TINYVECTOR_NUMTRAITS(int, SIZE)\
TINYVECTOR_NUMTRAITS(float, SIZE)\
TINYVECTOR_NUMTRAITS(double, SIZE)\
TINYVECTOR_PROMTRAITS1(unsigned char, SIZE)\
TINYVECTOR_PROMTRAITS1(int, SIZE)\
TINYVECTOR_PROMTRAITS1(float, SIZE)\
TINYVECTOR_PROMTRAITS1(double, SIZE)\
TINYVECTOR_PROMTRAITS2(float, unsigned char, SIZE)\
TINYVECTOR_PROMTRAITS2(unsigned char, float, SIZE)\
TINYVECTOR_PROMTRAITS2(int, unsigned char, SIZE)\
TINYVECTOR_PROMTRAITS2(unsigned char, int, SIZE)\
TINYVECTOR_PROMTRAITS2(int, float, SIZE)\
TINYVECTOR_PROMTRAITS2(float, int, SIZE)\
TINYVECTOR_PROMTRAITS2(double, unsigned char, SIZE)\
TINYVECTOR_PROMTRAITS2(unsigned char, double, SIZE)\
TINYVECTOR_PROMTRAITS2(int, double, SIZE)\
TINYVECTOR_PROMTRAITS2(double, int, SIZE)\
TINYVECTOR_PROMTRAITS2(double, float, SIZE)\
TINYVECTOR_PROMTRAITS2(float, double, SIZE)
TINYVECTOR_TRAITS(2)
TINYVECTOR_TRAITS(3)
TINYVECTOR_TRAITS(4)
#undef TINYVECTOR_NUMTRAITS
#undef TINYVECTOR_PROMTRAITS1
#undef TINYVECTOR_PROMTRAITS2
#undef TINYVECTOR_TRAITS
#endif // NO_PARTIAL_TEMPLATE_SPECIALIZATION
/********************************************************/
/* */
/* TinyVector-Arithmetic */
/* */
/********************************************************/
/** \addtogroup TinyVectorOperators
*/
//@{
/// component-wise addition
template <class V1, int SIZE, class D1, class D2, class V2, class D3, class D4>
inline
typename PromoteTraits<TinyVector<V1, SIZE>, TinyVector<V2, SIZE> >::Promote
operator+(TinyVectorBase<V1, SIZE, D1, D2> const & l,
TinyVectorBase<V2, SIZE, D3, D4> const & r)
{
return typename PromoteTraits<TinyVector<V1, SIZE>, TinyVector<V2 , SIZE> >::Promote(l) += r;
}
/// component-wise subtraction
template <class V1, int SIZE, class D1, class D2, class V2, class D3, class D4>
inline
typename PromoteTraits<TinyVector<V1, SIZE>, TinyVector<V2, SIZE> >::Promote
operator-(TinyVectorBase<V1, SIZE, D1, D2> const & l,
TinyVectorBase<V2, SIZE, D3, D4> const & r)
{
return typename PromoteTraits<TinyVector<V1, SIZE>, TinyVector<V2 , SIZE> >::Promote(l) -= r;
}
/// component-wise multiplication
template <class V1, int SIZE, class D1, class D2, class V2, class D3, class D4>
inline
typename PromoteTraits<TinyVector<V1, SIZE>, TinyVector<V2, SIZE> >::Promote
operator*(TinyVectorBase<V1, SIZE, D1, D2> const & l,
TinyVectorBase<V2, SIZE, D3, D4> const & r)
{
return typename PromoteTraits<TinyVector<V1, SIZE>, TinyVector<V2 , SIZE> >::Promote(l) *= r;
}
/// component-wise division
template <class V1, int SIZE, class D1, class D2, class V2, class D3, class D4>
inline
typename PromoteTraits<TinyVector<V1, SIZE>, TinyVector<V2, SIZE> >::Promote
operator/(TinyVectorBase<V1, SIZE, D1, D2> const & l,
TinyVectorBase<V2, SIZE, D3, D4> const & r)
{
return typename PromoteTraits<TinyVector<V1, SIZE>, TinyVector<V2 , SIZE> >::Promote(l) /= r;
}
/// component-wise modulo
template <class V1, int SIZE, class D1, class D2, class V2, class D3, class D4>
inline
typename PromoteTraits<TinyVector<V1, SIZE>, TinyVector<V2, SIZE> >::Promote
operator%(TinyVectorBase<V1, SIZE, D1, D2> const & l,
TinyVectorBase<V2, SIZE, D3, D4> const & r)
{
return typename PromoteTraits<TinyVector<V1, SIZE>, TinyVector<V2 , SIZE> >::Promote(l) %= r;
}
/// component-wise left scalar multiplication
template <class V, int SIZE, class D1, class D2>
inline
typename NumericTraits<TinyVector<V, SIZE> >::RealPromote
operator*(double v, TinyVectorBase<V, SIZE, D1, D2> const & r)
{
return typename NumericTraits<TinyVector<V, SIZE> >::RealPromote(r) *= v;
}
/// component-wise right scalar multiplication
template <class V, int SIZE, class D1, class D2>
inline
typename NumericTraits<TinyVector<V, SIZE> >::RealPromote
operator*(TinyVectorBase<V, SIZE, D1, D2> const & l, double v)
{
return typename NumericTraits<TinyVector<V, SIZE> >::RealPromote(l) *= v;
}
/// component-wise scalar division
template <class V, int SIZE, class D1, class D2>
inline
typename NumericTraits<TinyVector<V, SIZE> >::RealPromote
operator/(TinyVectorBase<V, SIZE, D1, D2> const & l, double v)
{
return typename NumericTraits<TinyVector<V, SIZE> >::RealPromote(l) /= v;
}
/// component-wise scalar division without type promotion
template <class V, int SIZE, class D1, class D2>
inline
TinyVector<V, SIZE>
div(TinyVectorBase<V, SIZE, D1, D2> const & l, V v)
{
TinyVector<V, SIZE> result(l);
typedef typename detail::LoopType<SIZE>::type Loop;
Loop::divScalar(result.data(), v);
return result;
}
/** Unary negation (construct TinyVector with negative values)
*/
template <class V, int SIZE, class D1, class D2>
inline
TinyVector<V, SIZE>
operator-(TinyVectorBase<V, SIZE, D1, D2> const & v)
{
TinyVector<V, SIZE> res(detail::dontInit());
typedef typename detail::LoopType<SIZE>::type ltype;
ltype::neg(res.begin(), v.begin());
return res;
}
/// component-wise absolute value
template <class V, int SIZE, class D1, class D2>
inline
TinyVector<V, SIZE>
abs(TinyVectorBase<V, SIZE, D1, D2> const & v)
{
TinyVector<V, SIZE> res(detail::dontInit());
typedef typename detail::LoopType<SIZE>::type ltype;
ltype::abs(res.begin(), v.begin());
return res;
}
/** Apply ceil() function to each vector component.
*/
template <class V, int SIZE, class D1, class D2>
inline
TinyVector<V, SIZE>
ceil(TinyVectorBase<V, SIZE, D1, D2> const & v)
{
TinyVector<V, SIZE> res(detail::dontInit());
typedef typename detail::LoopType<SIZE>::type ltype;
ltype::ceil(res.begin(), v.begin());
return res;
}
/** Apply floor() function to each vector component.
*/
template <class V, int SIZE, class D1, class D2>
inline
TinyVector<V, SIZE>
floor(TinyVectorBase<V, SIZE, D1, D2> const & v)
{
TinyVector<V, SIZE> res(detail::dontInit());
typedef typename detail::LoopType<SIZE>::type ltype;
ltype::floor(res.begin(), v.begin());
return res;
}
/** Apply round() function to each vector component.
*/
template <class V, int SIZE, class D1, class D2>
inline
TinyVector<V, SIZE>
round(TinyVectorBase<V, SIZE, D1, D2> const & v)
{
TinyVector<V, SIZE> res(detail::dontInit());
typedef typename detail::LoopType<SIZE>::type ltype;
ltype::round(res.begin(), v.begin());
return res;
}
/** Apply sqrt() function to each vector component.
*/
template <class V, int SIZE, class D1, class D2>
inline
TinyVector<V, SIZE>
sqrt(TinyVectorBase<V, SIZE, D1, D2> const & v)
{
TinyVector<V, SIZE> res(detail::dontInit());
typedef typename detail::LoopType<SIZE>::type ltype;
ltype::sqrt(res.begin(), v.begin());
return res;
}
using std::pow;
/** Apply pow() function to each vector component.
*/
template <class V, int SIZE, class D1, class D2, class E>
inline
TinyVector<V, SIZE>
pow(TinyVectorBase<V, SIZE, D1, D2> const & v, E exponent)
{
TinyVector<V, SIZE> res(v);
typedef typename detail::LoopType<SIZE>::type ltype;
ltype::power(res.begin(), exponent);
return res;
}
/// cross product
template <class V1, class D1, class D2, class V2, class D3, class D4>
inline
TinyVector<typename PromoteTraits<V1, V2>::Promote, 3>
cross(TinyVectorBase<V1, 3, D1, D2> const & r1,
TinyVectorBase<V2, 3, D3, D4> const & r2)
{
typedef TinyVector<typename PromoteTraits<V1, V2>::Promote, 3>
Res;
return Res(r1[1]*r2[2] - r1[2]*r2[1],
r1[2]*r2[0] - r1[0]*r2[2],
r1[0]*r2[1] - r1[1]*r2[0]);
}
/// dot product
template <class V1, int SIZE, class D1, class D2, class V2, class D3, class D4>
inline
typename PromoteTraits<V1, V2>::Promote
dot(TinyVectorBase<V1, SIZE, D1, D2> const & l,
TinyVectorBase<V2, SIZE, D3, D4> const & r)
{
typedef typename detail::LoopType<SIZE>::type ltype;
return ltype::dot(l.begin(), r.begin());
}
/// sum of the vector's elements
template <class V, int SIZE, class D1, class D2>
inline
typename NumericTraits<V>::Promote
sum(TinyVectorBase<V, SIZE, D1, D2> const & l)
{
typename NumericTraits<V>::Promote res = l[0];
for(int k=1; k<SIZE; ++k)
res += l[k];
return res;
}
/// cumulative sum of the vector's elements
template <class V, int SIZE, class D1, class D2>
inline
TinyVector<typename NumericTraits<V>::Promote, SIZE>
cumsum(TinyVectorBase<V, SIZE, D1, D2> const & l)
{
TinyVector<typename NumericTraits<V>::Promote, SIZE> res(l);
for(int k=1; k<SIZE; ++k)
res[k] += res[k-1];
return res;
}
/// product of the vector's elements
template <class V, int SIZE, class D1, class D2>
inline
typename NumericTraits<V>::Promote
prod(TinyVectorBase<V, SIZE, D1, D2> const & l)
{
typename NumericTraits<V>::Promote res = l[0];
for(int k=1; k<SIZE; ++k)
res *= l[k];
return res;
}
/// cumulative product of the vector's elements
template <class V, int SIZE, class D1, class D2>
inline
TinyVector<typename NumericTraits<V>::Promote, SIZE>
cumprod(TinyVectorBase<V, SIZE, D1, D2> const & l)
{
TinyVector<typename NumericTraits<V>::Promote, SIZE> res(l);
for(int k=1; k<SIZE; ++k)
res[k] *= res[k-1];
return res;
}
using std::min;
/// element-wise minimum
template <class V1, int SIZE, class D1, class D2, class V2, class D3, class D4>
inline
TinyVector<typename PromoteTraits<V1, V2>::Promote, SIZE>
min(TinyVectorBase<V1, SIZE, D1, D2> const & l,
TinyVectorBase<V2, SIZE, D3, D4> const & r)
{
typedef typename detail::LoopType<SIZE>::type ltype;
TinyVector<typename PromoteTraits<V1, V2>::Promote, SIZE> res(l);
ltype::min(res.begin(), r.begin());
return res;
}
// we also have to overload min for like-typed argument to prevent match of std::min()
template <class V1, int SIZE, class D1, class D2>
inline
TinyVector<V1, SIZE>
min(TinyVectorBase<V1, SIZE, D1, D2> const & l,
TinyVectorBase<V1, SIZE, D1, D2> const & r)
{
typedef typename detail::LoopType<SIZE>::type ltype;
TinyVector<V1, SIZE> res(l);
ltype::min(res.begin(), r.begin());
return res;
}
template <class V1, int SIZE>
inline
TinyVector<V1, SIZE>
min(TinyVector<V1, SIZE> const & l,
TinyVector<V1, SIZE> const & r)
{
typedef typename detail::LoopType<SIZE>::type ltype;
TinyVector<V1, SIZE> res(l);
ltype::min(res.begin(), r.begin());
return res;
}
/// minimum element
template <class V, int SIZE, class D1, class D2>
inline
V const &
min(TinyVectorBase<V, SIZE, D1, D2> const & l)
{
return l.minimum();
}
using std::max;
/// element-wise maximum
template <class V1, int SIZE, class D1, class D2, class V2, class D3, class D4>
inline
TinyVector<typename PromoteTraits<V1, V2>::Promote, SIZE>
max(TinyVectorBase<V1, SIZE, D1, D2> const & l,
TinyVectorBase<V2, SIZE, D3, D4> const & r)
{
typedef typename detail::LoopType<SIZE>::type ltype;
TinyVector<typename PromoteTraits<V1, V2>::Promote, SIZE> res(l);
ltype::max(res.begin(), r.begin());
return res;
}
// we also have to overload max for like-typed argument to prevent match of std::max()
template <class V1, int SIZE, class D1, class D2>
inline
TinyVector<V1, SIZE>
max(TinyVectorBase<V1, SIZE, D1, D2> const & l,
TinyVectorBase<V1, SIZE, D1, D2> const & r)
{
typedef typename detail::LoopType<SIZE>::type ltype;
TinyVector<V1, SIZE> res(l);
ltype::max(res.begin(), r.begin());
return res;
}
template <class V1, int SIZE>
inline
TinyVector<V1, SIZE>
max(TinyVector<V1, SIZE> const & l,
TinyVector<V1, SIZE> const & r)
{
typedef typename detail::LoopType<SIZE>::type ltype;
TinyVector<V1, SIZE> res(l);
ltype::max(res.begin(), r.begin());
return res;
}
/// maximum element
template <class V, int SIZE, class D1, class D2>
inline
V const &
max(TinyVectorBase<V, SIZE, D1, D2> const & l)
{
return l.maximum();
}
/// squared norm
template <class V1, int SIZE, class D1, class D2>
inline
typename TinyVectorBase<V1, SIZE, D1, D2>::SquaredNormType
squaredNorm(TinyVectorBase<V1, SIZE, D1, D2> const & t)
{
return t.squaredMagnitude();
}
/// squared norm
template <class V, int SIZE>
inline
typename TinyVector<V, SIZE>::SquaredNormType
squaredNorm(TinyVector<V, SIZE> const & t)
{
return t.squaredMagnitude();
}
using std::reverse;
/// reversed copy
template <class V, int SIZE>
inline
TinyVector<V, SIZE>
reverse(TinyVector<V, SIZE> const & t)
{
return TinyVector<V, SIZE>(t.begin(), TinyVector<V, SIZE>::ReverseCopy);
}
//@}
// mask cl.exe shortcomings [end]
#if defined(_MSC_VER)
#pragma warning( pop )
#endif
} // namespace vigra
#undef VIGRA_ASSERT_INSIDE
#endif // VIGRA_TINYVECTOR_HXX
|