SLIP  1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Vector.hpp
Go to the documentation of this file.
1 /*
2  * Copyright(c):
3  * Signal Image and Communications (SIC) Department
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * - University of Poitiers, France http://www.univ-poitiers.fr
6  * - XLIM Institute UMR CNRS 7252 http://www.xlim.fr/
7  *
8  * and
9  *
10  * D2 Fluid, Thermic and Combustion
11  * - University of Poitiers, France http://www.univ-poitiers.fr
12  * - PPRIME Institute - UPR CNRS 3346 http://www.pprime.fr
13  * - ISAE-ENSMA http://www.ensma.fr
14  *
15  * Contributor(s):
16  * The SLIP team,
17  * Benoit Tremblais <tremblais_AT_sic.univ-poitiers.fr>,
18  * Laurent David <laurent.david_AT_lea.univ-poitiers.fr>,
19  * Ludovic Chatellier <ludovic.chatellier_AT_univ-poitiers.fr>,
20  * Lionel Thomas <lionel.thomas_AT_univ-poitiers.fr>,
21  * Denis Arrivault <arrivault_AT_sic.univ-poitiers.fr>,
22  * Julien Dombre <julien.dombre_AT_univ-poitiers.fr>.
23  *
24  * Description:
25  * The Simple Library of Image Processing (SLIP) is a new image processing
26  * library. It is written in the C++ language following as much as possible
27  * the ISO/ANSI C++ standard. It is consequently compatible with any system
28  * satisfying the ANSI C++ complience. It works on different Unix , Linux ,
29  * Mircrosoft Windows and Mac OS X plateforms. SLIP is a research library that
30  * was created by the Signal, Image and Communications (SIC) departement of
31  * the XLIM, UMR 7252 CNRS Institute in collaboration with the Fluids, Thermic
32  * and Combustion departement of the P', UPR 3346 CNRS Institute of the
33  * University of Poitiers.
34  *
35  * The SLIP Library source code has been registered to the APP (French Agency
36  * for the Protection of Programs) by the University of Poitiers and CNRS,
37  * under registration number IDDN.FR.001.300034.000.S.P.2010.000.21000.
38 
39  * http://www.sic.sp2mi.univ-poitiers.fr/slip/
40  *
41  * This software is governed by the CeCILL-C license under French law and
42  * abiding by the rules of distribution of free software. You can use,
43  * modify and/ or redistribute the software under the terms of the CeCILL-C
44  * license as circulated by CEA, CNRS and INRIA at the following URL
45  * http://www.cecill.info.
46  * As a counterpart to the access to the source code and rights to copy,
47  * modify and redistribute granted by the license, users are provided only
48  * with a limited warranty and the software's author, the holder of the
49  * economic rights, and the successive licensors have only limited
50  * liability.
51  *
52  * In this respect, the user's attention is drawn to the risks associated
53  * with loading, using, modifying and/or developing or reproducing the
54  * software by the user in light of its specific status of free software,
55  * that may mean that it is complicated to manipulate, and that also
56  * therefore means that it is reserved for developers and experienced
57  * professionals having in-depth computer knowledge. Users are therefore
58  * encouraged to load and test the software's suitability as regards their
59  * requirements in conditions enabling the security of their systems and/or
60  * data to be ensured and, more generally, to use and operate it in the
61  * same conditions as regards security.
62  *
63  * The fact that you are presently reading this means that you have had
64  * knowledge of the CeCILL-C license and that you accept its terms.
65  */
66 
67 
74 #ifndef SLIP_VECTOR_HPP
75 #define SLIP_VECTOR_HPP
76 
77 #include <iostream>
78 #include <iterator>
79 #include <cassert>
80 #include <numeric>
81 #include <algorithm>
82 #include <cmath>
83 #include <cstddef>
84 #include <string>
85 #include "Array.hpp"
86 #include "Box1d.hpp"
87 #include "stride_iterator.hpp"
88 #include "apply.hpp"
89 #include "norms.hpp"
91 #include "linear_algebra.hpp"
92 #include "complex_cast.hpp"
93 
94 #include <boost/serialization/access.hpp>
95 #include <boost/serialization/split_member.hpp>
96 #include <boost/serialization/string.hpp>
97 #include <boost/serialization/complex.hpp>
98 #include <boost/serialization/version.hpp>
99 
100 namespace slip
101 {
102 
103 template <typename T>
104 class Vector;
105 
106 template <typename T>
107 std::ostream& operator<<(std::ostream & out,
108  const Vector<T>& v);
109 
110 template<typename T>
111 bool operator==(const Vector<T>& x,
112  const Vector<T>& y);
113 
114 template<typename T>
115 bool operator!=(const Vector<T>& x,
116  const Vector<T>& y);
117 
118 template<typename T>
119 bool operator<(const Vector<T>& x,
120  const Vector<T>& y);
121 
122 template<typename T>
123 bool operator>(const Vector<T>& x,
124  const Vector<T>& y);
125 
126 template<typename T>
127 bool operator<=(const Vector<T>& x,
128  const Vector<T>& y);
129 
130 template<typename T>
131 bool operator>=(const Vector<T>& x,
132  const Vector<T>& y);
152 template <typename T>
153 class Vector
154 {
155 public :
156 
157  typedef T value_type;
158  typedef Vector<T> self;
159  typedef const Vector<T> const_self;
160 
161  typedef value_type* pointer;
162  typedef const value_type* const_pointer;
164  typedef const value_type& const_reference;
165 
166  typedef ptrdiff_t difference_type;
167  typedef std::size_t size_type;
168 
169  typedef pointer iterator;
171 
174 
175  typedef std::reverse_iterator<iterator> reverse_iterator;
176  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
177 
178  typedef std::reverse_iterator<iterator_range> reverse_iterator_range;
179  typedef std::reverse_iterator<const_iterator_range> const_reverse_iterator_range;
180 
182 
183  //default iterator of the container
186 
187 
188  static const std::size_t DIM = 1;
189 
190 public:
195 
199  Vector();
200 
205  Vector(const size_type n);
206 
212  Vector(const size_type n,
213  const T& val);
214 
220  Vector(const size_type n,
221  const T* val);
222 
231  template<typename InputIterator>
232  Vector(InputIterator first,
233  InputIterator last)
234  {
235  array_ = new Array<T>((size_type)(last - first),first,last);
236  }
237 
241  Vector(const self& rhs);
242 
246  ~Vector();
247 
248 
257  void resize(const size_type new_n,
258  const T& val = T());
259 
260 
265 
274  iterator begin();
275 
284  const_iterator begin() const;
285 
294  iterator end();
295 
304  const_iterator end() const;
305 
315 
325 
335 
346 
347 
366  iterator_range begin(const slip::Range<int>& range);
367 
386  const_iterator_range begin(const slip::Range<int>& range) const;
387 
405  iterator_range end(const slip::Range<int>& range);
406 
425  const_iterator_range end(const slip::Range<int>& range) const;
426 
427 
428 
446  iterator begin(const slip::Box1d<int>& box);
447 
465  const_iterator begin(const slip::Box1d<int>& box) const;
466 
484  iterator end(const slip::Box1d<int>& box);
485 
503  const_iterator end(const slip::Box1d<int>& box) const;
504 
505  //
525 
545 
564 
584 
585 
586 
605 
624 
643 
661  const_reverse_iterator rend(const slip::Box1d<int>& box) const;
673  friend std::ostream& operator<< <>(std::ostream & out,
674  const self& v);
690  self& operator=(const self & rhs);
691 
697  self& operator=(const T& val);
698 
704  void fill(const T& value)
705  {
706  std::fill_n(this->begin(),this->size(),value);
707  }
708 
715  void fill(const T* value)
716  {
717  std::copy(value,value + this->size(), this->begin());
718  }
719 
728  template<typename InputIterator>
729  void fill(InputIterator first,
730  InputIterator last)
731  {
732  std::copy(first,last, this->begin());
733  }
747  friend bool operator== <>(const Vector<T>& x,
748  const Vector<T>& y);
749 
756  friend bool operator!= <>(const Vector<T>& x,
757  const Vector<T>& y);
758 
765  friend bool operator< <>(const Vector<T>& x,
766  const Vector<T>& y);
767 
774  friend bool operator> <>(const Vector<T>& x,
775  const Vector<T>& y);
776 
783  friend bool operator<= <>(const Vector<T>& x,
784  const Vector<T>& y);
785 
792  friend bool operator>= <>(const Vector<T>& x,
793  const Vector<T>& y);
794 
795 
813  reference operator[](const size_type i);
814 
825  const_reference operator[](const size_type i) const;
826 
837  reference operator()(const size_type i);
838 
849  const_reference operator()(const size_type i) const;
850 
863 
876 
888  self operator()(const slip::Range<int>& range);
889 
897 
903  self& operator+=(const T& val);
904  self& operator-=(const T& val);
905  self& operator*=(const T& val);
906  self& operator/=(const T& val);
907  // self& operator%=(const T& val);
908  // self& operator^=(const T& val);
909  // self& operator&=(const T& val);
910  // self& operator|=(const T& val);
911  // self& operator<<=(const T& val);
912  // self& operator>>=(const T& val);
913 
914  self operator-() const;
915  //self operator!() const;
916 
917  self& operator+=(const self& rhs);
918  self& operator-=(const self& rhs);
919  self& operator*=(const self& rhs);
920  self& operator/=(const self& rhs);
921 
922 
929  std::string name() const;
930 
934  size_type size() const;
935 
939  size_type max_size() const;
940 
944  bool empty()const;
945 
950  void swap(self& M);
951 
957  T& min() const;
958 
959 
965  T& max() const;
966 
971  T sum() const;
972 
978  {
979  assert(this->size() != 0);
980  return std::sqrt(slip::L22_norm_cplx(this->begin(),this->end()));
981  }
982 
988  {
989  assert(this->size() != 0);
990  return this->Euclidean_norm();
991  }
992 
998  {
999  assert(this->size() != 0);
1000  return slip::L1_norm<norm_type>(this->begin(),this->end());
1001  }
1002 
1008  {
1009  assert(this->size() != 0);
1010  return slip::L22_norm_cplx(this->begin(),this->end());
1011  }
1012 
1018  {
1019  assert(this->size() != 0);
1020  return slip::infinite_norm<norm_type>(this->begin(),this->end());
1021  }
1037  Vector<T>& apply(T (*fun)(T));
1038 
1054  Vector<T>& apply(T (*fun)(const T&));
1055 
1056  private:
1057  Array<T>* array_;
1058 
1059 private:
1060  friend class boost::serialization::access;
1061  template<class Archive>
1062  void save(Archive & ar, const unsigned int version) const
1063  {
1064  ar & this->array_ ;
1065  }
1066  template<class Archive>
1067  void load(Archive & ar, const unsigned int version)
1068  {
1069  ar & this->array_ ;
1070  }
1071  BOOST_SERIALIZATION_SPLIT_MEMBER();
1072 
1073 }; // end of MathematicalContainer group
1075 
1096 
1104 template<typename T>
1105 Vector<T> operator+(const Vector<T>& V1,
1106  const Vector<T>& V2);
1107 
1114 template<typename T>
1115 Vector<T> operator+(const Vector<T>& V,
1116  const T& val);
1117 
1124 template<typename T>
1125 Vector<T> operator+(const T& val,
1126  const Vector<T>& V);
1127 
1128 
1136 template<typename T>
1137 Vector<T> operator-(const Vector<T>& V1,
1138  const Vector<T>& V2);
1139 
1146 template<typename T>
1147 Vector<T> operator-(const Vector<T>& V,
1148  const T& val);
1149 
1156 template<typename T>
1157 Vector<T> operator-(const T& val,
1158  const Vector<T>& V);
1159 
1167 template<typename T>
1168 Vector<T> operator*(const Vector<T>& V1,
1169  const Vector<T>& V2);
1170 
1177 template<typename T>
1178 Vector<T> operator*(const Vector<T>& V,
1179  const T& val);
1180 
1187 template<typename T>
1188 Vector<T> operator*(const T& val,
1189  const Vector<T>& V);
1190 
1198  template<typename T>
1199  Vector<T> operator/(const Vector<T>& V1,
1200  const Vector<T>& V2);
1201 
1208  template<typename T>
1209  Vector<T> operator/(const Vector<T>& V,
1210  const T& val);
1211 
1212 
1213 
1221  template<typename T>
1222  T& min(const Vector<T>& M1);
1223 
1231  template<typename T>
1232  T& max(const Vector<T>& M1);
1233 
1234 
1241  template<typename T>
1243 
1250  template<typename T>
1251  Vector<T> sqrt(const Vector<T>& V);
1252 
1259  template<typename T>
1260  Vector<T> cos(const Vector<T>& V);
1261 
1268  Vector<float> acos(const Vector<float>& V);
1283 
1290  template<typename T>
1291  Vector<T> sin(const Vector<T>& V);
1292 
1299  Vector<float> asin(const Vector<float>& V);
1314 
1321  template<typename T>
1322  Vector<T> tan(const Vector<T>& V);
1323 
1330  Vector<float> atan(const Vector<float>& V);
1345 
1346 
1353  template<typename T>
1354  Vector<T> exp(const Vector<T>& V);
1355 
1362  template<typename T>
1363  Vector<T> log(const Vector<T>& V);
1364 
1371  template<typename T>
1372  Vector<T> cosh(const Vector<T>& V);
1373 
1380  template<typename T>
1381  Vector<T> sinh(const Vector<T>& V);
1382 
1389  template<typename T>
1390  Vector<T> tanh(const Vector<T>& V);
1391 
1398  template<typename T>
1399  Vector<T> log10(const Vector<T>& V);
1400 
1401 }//slip::
1402 
1403 namespace slip
1404 {
1405  template<typename T>
1406  inline
1408  array_(new slip::Array<T>())
1409  {}
1410 
1411  template<typename T>
1412  inline
1414  array_(new slip::Array<T>(n))
1415  {}
1416 
1417  template<typename T>
1418  inline
1420  const T& val):
1421  array_(new slip::Array<T>(n,val))
1422  {}
1423 
1424  template<typename T>
1425  inline
1427  const T* val):
1428  array_(new slip::Array<T>(n,val))
1429  {}
1430 
1431  template<typename T>
1432  inline
1434  array_(new slip::Array<T>((*rhs.array_)))
1435  {}
1436 
1437  template<typename T>
1438  inline
1440  {
1441  if(this != &rhs)
1442  {
1443  *array_ = *(rhs.array_);
1444  }
1445  return *this;
1446  }
1447 
1448  template<typename T>
1449  inline
1451  {
1452  delete array_;
1453  }
1454 
1455  template<typename T>
1456  inline
1458  {
1459  array_->operator=(val);
1460  return *this;
1461  }
1462 
1463  template<typename T>
1464  inline
1465  void Vector<T>::resize(typename Vector<T>::size_type new_size,
1466  const T& val)
1467  {
1468  array_->resize(new_size,val);
1469  }
1470 
1471 
1472  template<typename T>
1473  inline
1475  {
1476  return array_->begin();
1477  }
1478 
1479  template<typename T>
1480  inline
1482  {
1483  return array_->end();
1484  }
1485 
1486  template<typename T>
1487  inline
1489  {
1490  slip::Array<T> const * tp(array_);
1491  return tp->begin();
1492  }
1493 
1494  template<typename T>
1495  inline
1497  {
1498  slip::Array<T> const * tp(array_);
1499  return tp->end();
1500  }
1501 
1502 
1503  template<typename T>
1504  inline
1506  {
1507  return array_->rbegin();
1508  }
1509 
1510  template<typename T>
1511  inline
1513  {
1514  return array_->rend();
1515  }
1516 
1517  template<typename T>
1518  inline
1520  {
1521  slip::Array<T> const * tp(array_);
1522  return tp->rbegin();
1523  }
1524 
1525  template<typename T>
1526  inline
1528  {
1529  slip::Array<T> const * tp(array_);
1530  return tp->rend();
1531  }
1532 
1533  //
1534  template<typename T>
1535  inline
1536  typename Vector<T>::iterator_range
1538  {
1539  return array_->begin(range);
1540  }
1541 
1542  template<typename T>
1543  inline
1544  typename Vector<T>::iterator_range
1546  {
1547  return array_->end(range);
1548  }
1549 
1550  template<typename T>
1551  inline
1554  {
1555  slip::Array<T> const * tp(array_);
1556  return tp->begin(range);
1557  }
1558 
1559  template<typename T>
1560  inline
1562  Vector<T>::end(const slip::Range<int>& range) const
1563  {
1564  slip::Array<T> const * tp(array_);
1565  return tp->end(range);
1566  }
1567 
1568  //
1569  template<typename T>
1570  inline
1571  typename Vector<T>::iterator
1573  {
1574  return array_->begin(box);
1575  }
1576 
1577  template<typename T>
1578  inline
1579  typename Vector<T>::iterator
1581  {
1582  return array_->end(box);
1583  }
1584 
1585  template<typename T>
1586  inline
1587  typename Vector<T>::const_iterator
1589  {
1590  slip::Array<T> const * tp(array_);
1591  return tp->begin(box);
1592  }
1593 
1594  template<typename T>
1595  inline
1596  typename Vector<T>::const_iterator
1598  {
1599  slip::Array<T> const * tp(array_);
1600  return tp->end(box);
1601  }
1602 
1603  //
1604  template<typename T>
1605  inline
1607  {
1608  return array_->rbegin(box);
1609  }
1610 
1611  template<typename T>
1612  inline
1613  typename Vector<T>::reverse_iterator
1615  {
1616  return array_->rend(box);
1617  }
1618 
1619  template<typename T>
1620  inline
1623  {
1624  slip::Array<T> const * tp(array_);
1625  return tp->rbegin(box);
1626  }
1627 
1628  template<typename T>
1629  inline
1632  {
1633  slip::Array<T> const * tp(array_);
1634  return tp->rend(box);
1635  }
1636  //
1637  template<typename T>
1638  inline
1640  {
1641  return array_->rbegin(range);
1642  }
1643 
1644  template<typename T>
1645  inline
1648  {
1649  return array_->rend(range);
1650  }
1651 
1652  template<typename T>
1653  inline
1656  {
1657  slip::Array<T> const * tp(array_);
1658  return tp->rbegin(range);
1659  }
1660 
1661  template<typename T>
1662  inline
1664  Vector<T>::rend(const slip::Range<int>& range) const
1665  {
1666  slip::Array<T> const * tp(array_);
1667  return tp->rend(range);
1668  }
1669 
1670 
1671  template <typename T>
1672  inline
1673  std::ostream& operator<<(std::ostream & out,
1674  const Vector<T>& v)
1675  {
1676  out<<*(v.array_);
1677  return out;
1678  }
1679 
1680  template<typename T>
1681  inline
1682  typename Vector<T>::reference Vector<T>::operator[](typename Vector<T>::size_type i)
1683  {
1684  return (*array_)[i];
1685  }
1686 
1687  template<typename T>
1688  inline
1689  typename Vector<T>::const_reference Vector<T>::operator[](typename Vector<T>::size_type i) const
1690  {
1691  return (*array_)[i];
1692  }
1693 
1694  template<typename T>
1695  inline
1696  typename Vector<T>::reference Vector<T>::operator()(typename Vector<T>::size_type i)
1697  {
1698  return (*array_)(i);
1699  }
1700 
1701  template<typename T>
1702  inline
1703  typename Vector<T>::const_reference Vector<T>::operator()(typename Vector<T>::size_type i) const
1704  {
1705  return (*array_)(i);
1706  }
1707 
1708  template <typename T>
1709  inline
1710  typename Vector<T>::reference
1711  Vector<T>::operator()(const slip::Point1d<typename Vector<T>::size_type>& p)
1712  {
1713  return (*array_)(p);
1714  }
1715 
1716  template <typename T>
1717  inline
1718  typename Vector<T>::const_reference
1719  Vector<T>::operator()(const slip::Point1d<typename Vector<T>::size_type>& p) const
1720  {
1721  return (*array_)(p);
1722  }
1723 
1724  template<typename T>
1725  inline
1727  {
1728  assert(this->array_ != 0);
1729  assert(range.is_valid());
1730  assert(range.start() < (int)this->size());
1731  assert(range.stop() < (int)this->size());
1732  return Vector<T>(array_->begin(range),array_->end(range));
1733 
1734  }
1735 
1736  template<typename T>
1737  inline
1738  std::string
1739  Vector<T>::name() const {return "Vector";}
1740 
1741  template<typename T>
1742  inline
1743  typename Vector<T>::size_type Vector<T>::size() const {return array_->size();}
1744 
1745  template<typename T>
1746  inline
1748  {
1749  return typename Vector<T>::size_type(-1)/sizeof(T);
1750  }
1751 
1752  template<typename T>
1753  inline
1754  bool Vector<T>::empty()const {return array_->empty();}
1755 
1756  template<typename T>
1757  inline
1759  {
1760  array_->swap(*(V.array_));
1761  }
1762 
1763 
1764  template<typename T>
1765  inline
1767  {
1768  std::transform(array_->begin(),array_->end(),array_->begin(),std::bind2nd(std::plus<T>(),val));
1769  return *this;
1770  }
1771 
1772  template<typename T>
1773  inline
1775  {
1776  std::transform(array_->begin(),array_->end(),array_->begin(),std::bind2nd(std::minus<T>(),val));
1777  return *this;
1778  }
1779 
1780  template<typename T>
1781  inline
1783  {
1784  std::transform(array_->begin(),array_->end(),array_->begin(),std::bind2nd(std::multiplies<T>(),val));
1785  return *this;
1786  }
1787 
1788  template<typename T>
1789  inline
1791  {
1792  std::transform(array_->begin(),array_->end(),array_->begin(),std::bind2nd(std::multiplies<T>(),T(1)/val));
1793  return *this;
1794  }
1795 
1796 
1797  template<typename T>
1798  inline
1800  {
1801  Vector<T> tmp(*this);
1802  std::transform(array_->begin(),array_->end(),tmp.begin(),std::negate<T>());
1803  return tmp;
1804  }
1805 
1806  template<typename T>
1807  inline
1809  {
1810  assert(this->size() == rhs.size());
1811  std::transform(array_->begin(),array_->end(),(*(rhs.array_)).begin(),array_->begin(),std::plus<T>());
1812  return *this;
1813  }
1814 
1815  template<typename T>
1816  inline
1818  {
1819  assert(this->size() == rhs.size());
1820  std::transform(array_->begin(),array_->end(),(*(rhs.array_)).begin(),array_->begin(),std::minus<T>());
1821  return *this;
1822  }
1823 
1824  template<typename T>
1825  inline
1827  {
1828  assert(this->size() == rhs.size());
1829  std::transform(array_->begin(),array_->end(),(*(rhs.array_)).begin(),array_->begin(),std::multiplies<T>());
1830  return *this;
1831  }
1832 
1833  template<typename T>
1834  inline
1836  {
1837  assert(this->size() == rhs.size());
1838  std::transform(array_->begin(),array_->end(),(*(rhs.array_)).begin(),array_->begin(),std::divides<T>());
1839  return *this;
1840  }
1841 
1842  template<typename T>
1843  inline
1844  T& Vector<T>::min() const
1845  {
1846  assert(array_->size() != 0);
1847  return *std::min_element(array_->begin(),array_->end(),std::less<T>());
1848  }
1849 
1850  template<typename T>
1851  inline
1852  T& Vector<T>::max() const
1853  {
1854  assert(array_->size() != 0);
1855  return *std::max_element(array_->begin(),array_->end(),std::less<T>());
1856  }
1857 
1858  template<typename T>
1859  inline
1860  T Vector<T>::sum() const
1861  {
1862  assert(array_->size() != 0);
1863  return std::accumulate(array_->begin(),array_->end(),T(0));
1864  }
1865 
1866  template<typename T>
1867  inline
1869  {
1870  slip::apply(this->begin(),this->end(),this->begin(),fun);
1871  return *this;
1872  }
1873 
1874  template<typename T>
1875  inline
1876  Vector<T>& Vector<T>::apply(T (*fun)(const T&))
1877  {
1878  slip::apply(this->begin(),this->end(),this->begin(),fun);
1879  return *this;
1880  }
1881 
1882 
1883 
1885  /* @{ */
1886 template<typename T>
1887 inline
1889  const Vector<T>& V2)
1890 {
1891  assert(V1.size() == V2.size());
1892  Vector<T> tmp(V1.size());
1893  std::transform(V1.begin(),V1.end(),V2.begin(),tmp.begin(),std::plus<T>());
1894 
1895  return tmp;
1896 }
1897 
1898 template<typename T>
1899 inline
1901  const T& val)
1902 {
1903  Vector<T> tmp(V1);
1904  tmp+=val;
1905  return tmp;
1906 }
1907 
1908 template<typename T>
1909 inline
1910 Vector<T> operator+(const T& val,
1911  const Vector<T>& V1)
1912 {
1913  return V1 + val;
1914 }
1915 
1916 template<typename T>
1917 inline
1919  const Vector<T>& V2)
1920 {
1921  assert(V1.size() == V2.size());
1922  Vector<T> tmp(V1.size());
1923  std::transform(V1.begin(),V1.end(),V2.begin(),tmp.begin(),std::minus<T>());
1924  return tmp;
1925 }
1926 
1927 template<typename T>
1928 inline
1930  const T& val)
1931 {
1932  Vector<T> tmp(V1);
1933  tmp-=val;
1934  return tmp;
1935 }
1936 
1937 template<typename T>
1938 inline
1939 Vector<T> operator-(const T& val,
1940  const Vector<T>& V1)
1941 {
1942  return -(V1 - val);
1943 }
1944 
1945 template<typename T>
1946 inline
1948  const Vector<T>& V2)
1949 {
1950  assert(V1.size() == V2.size());
1951  Vector<T> tmp(V1.size());
1952  std::transform(V1.begin(),V1.end(),V2.begin(),tmp.begin(),std::multiplies<T>());
1953  return tmp;
1954 }
1955 
1956 template<typename T>
1957 inline
1959  const T& val)
1960 {
1961  Vector<T> tmp(V1);
1962  tmp*=val;
1963  return tmp;
1964 }
1965 
1966 template<typename T>
1967 inline
1968 Vector<T> operator*(const T& val,
1969  const Vector<T>& V1)
1970 {
1971  return V1 * val;
1972 }
1973 
1974 template<typename T>
1975 inline
1977  const Vector<T>& V2)
1978 {
1979  assert(V1.size() == V2.size());
1980  Vector<T> tmp(V1.size());
1981  std::transform(V1.begin(),V1.end(),V2.begin(),tmp.begin(),std::divides<T>());
1982  return tmp;
1983 }
1984 
1985 template<typename T>
1986 inline
1988  const T& val)
1989 {
1990  Vector<T> tmp(V1);
1991  tmp/=val;
1992  return tmp;
1993 }
1994 
1995 /* @} */
1996 
1997 template<typename T>
1998 inline
1999 T& min(const Vector<T>& V1)
2000 {
2001  return V1.min();
2002 }
2003 
2004 template<typename T>
2005 inline
2006 T& max(const Vector<T>& V1)
2007 {
2008  return V1.max();
2009 }
2010 
2011 template<typename T>
2012 inline
2014 {
2015 
2017  slip::apply(V.begin(),V.end(),tmp.begin(),std::abs);
2018  return tmp;
2019 }
2020 
2021 template<typename T>
2022 inline
2024 {
2025  Vector<T> tmp(V.size());
2026  slip::apply(V.begin(),V.end(),tmp.begin(),std::sqrt);
2027  return tmp;
2028 }
2029 
2030 template<typename T>
2031 inline
2033 {
2034  Vector<T> tmp(V.size());
2035  slip::apply(V.begin(),V.end(),tmp.begin(),std::cos);
2036  return tmp;
2037 }
2038 
2039 
2040 inline
2042 {
2043  Vector<float> tmp(V.size());
2044  slip::apply(V.begin(),V.end(),tmp.begin(),std::acos);
2045  return tmp;
2046 }
2047 
2048 inline
2050 {
2051  Vector<double> tmp(V.size());
2052  slip::apply(V.begin(),V.end(),tmp.begin(),std::acos);
2053  return tmp;
2054 }
2055 
2056 inline
2058 {
2059  Vector<long double> tmp(V.size());
2060  slip::apply(V.begin(),V.end(),tmp.begin(),std::acos);
2061  return tmp;
2062 }
2063 
2064 template<typename T>
2065 inline
2067 {
2068  Vector<T> tmp(V.size());
2069  slip::apply(V.begin(),V.end(),tmp.begin(),std::sin);
2070  return tmp;
2071 }
2072 
2073 
2074 
2075 inline
2077 {
2078  Vector<float> tmp(V.size());
2079  slip::apply(V.begin(),V.end(),tmp.begin(),std::asin);
2080  return tmp;
2081 }
2082 
2083 inline
2085 {
2086  Vector<double> tmp(V.size());
2087  slip::apply(V.begin(),V.end(),tmp.begin(),std::asin);
2088  return tmp;
2089 }
2090 
2091 inline
2093 {
2094  Vector<long double> tmp(V.size());
2095  slip::apply(V.begin(),V.end(),tmp.begin(),std::asin);
2096  return tmp;
2097 }
2098 
2099 template<typename T>
2100 inline
2102 {
2103  Vector<T> tmp(V.size());
2104  slip::apply(V.begin(),V.end(),tmp.begin(),std::tan);
2105  return tmp;
2106 }
2107 
2108 inline
2110 {
2111  Vector<float> tmp(V.size());
2112  slip::apply(V.begin(),V.end(),tmp.begin(),std::atan);
2113  return tmp;
2114 }
2115 
2116 inline
2118 {
2119  Vector<double> tmp(V.size());
2120  slip::apply(V.begin(),V.end(),tmp.begin(),std::atan);
2121  return tmp;
2122 }
2123 
2124 inline
2126 {
2127  Vector<long double> tmp(V.size());
2128  slip::apply(V.begin(),V.end(),tmp.begin(),std::atan);
2129  return tmp;
2130 }
2131 
2132 template<typename T>
2133 inline
2135 {
2136  Vector<T> tmp(V.size());
2137  slip::apply(V.begin(),V.end(),tmp.begin(),std::exp);
2138  return tmp;
2139 }
2140 
2141 template<typename T>
2142 inline
2144 {
2145  Vector<T> tmp(V.size());
2146  slip::apply(V.begin(),V.end(),tmp.begin(),std::log);
2147  return tmp;
2148 }
2149 
2150 template<typename T>
2151 inline
2153 {
2154  Vector<T> tmp(V.size());
2155  slip::apply(V.begin(),V.end(),tmp.begin(),std::cosh);
2156  return tmp;
2157 }
2158 
2159 template<typename T>
2160 inline
2162 {
2163  Vector<T> tmp(V.size());
2164  slip::apply(V.begin(),V.end(),tmp.begin(),std::sinh);
2165  return tmp;
2166 }
2167 
2168 template<typename T>
2169 inline
2171 {
2172  Vector<T> tmp(V.size());
2173  slip::apply(V.begin(),V.end(),tmp.begin(),std::tanh);
2174  return tmp;
2175 }
2176 
2177 template<typename T>
2178 inline
2180 {
2181  Vector<T> tmp(V.size());
2182  slip::apply(V.begin(),V.end(),tmp.begin(),std::log10);
2183  return tmp;
2184 }
2185 
2187  /* @{ */
2188 template<typename T>
2189 inline
2190 bool operator==(const Vector<T>& x,
2191  const Vector<T>& y)
2192 {
2193  return *(x.array_) == *(y.array_);
2194 }
2195 
2196 template<typename T>
2197 inline
2198 bool operator!=(const Vector<T>& x,
2199  const Vector<T>& y)
2200 {
2201  return !(x == y);
2202 }
2203 /* @} */
2205  /* @{ */
2206 template<typename T>
2207 inline
2208 bool operator<(const Vector<T>& x,
2209  const Vector<T>& y)
2210 {
2211  return *(x.array_) < *(y.array_);
2212 }
2213 
2214 template<typename T>
2215 inline
2216 bool operator>(const Vector<T>& x,
2217  const Vector<T>& y)
2218 {
2219  return (y < x);
2220 }
2221 
2222 template<typename T>
2223 inline
2224 bool operator<=(const Vector<T>& x,
2225  const Vector<T>& y)
2226 {
2227  return !(y < x);
2228 }
2229 
2230 template<typename T>
2231 inline
2232 bool operator>=(const Vector<T>& x,
2233  const Vector<T>& y)
2234 {
2235  return !(x < y);
2236 }
2237 /* @} */
2238 }//slip::
2239 
2240 #endif //SLIP_VECTOR_HPP
HyperVolume< T > tanh(const HyperVolume< T > &M)
ptrdiff_t difference_type
Definition: Vector.hpp:166
bool operator!=(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1448
~Vector()
Destructor of the Vector.
Definition: Vector.hpp:1450
norm_type L22_norm() const
Returns the L22 norm ( ) of the elements of the Vector.
Definition: Vector.hpp:1007
Vector()
Constructs a Vector.
Definition: Vector.hpp:1407
norm_type infinite_norm() const
Returns the infinite norm ( ) of the elements of the Vector.
Definition: Vector.hpp:1017
slip::Vector< unsigned long > Vector_ul
unsigned long alias
Definition: Vector.hpp:1083
Vector< long double > atan(const Vector< long double > &V)
Definition: Vector.hpp:2125
self & operator-=(const T &val)
Definition: Vector.hpp:1774
self & operator/=(const T &val)
Definition: Vector.hpp:1790
Vector< T > cos(const Vector< T > &V)
Definition: Vector.hpp:2032
T sum() const
Returns the sum of the elements of the Vector.
Definition: Vector.hpp:1860
reverse_iterator rend()
Returns a read/write reverse iterator that points to one before the first element in the Array...
Definition: Array.hpp:1195
T & min() const
Returns the min element of the Vector according to the operator < if T is std::complex, it returns the element of minimum magnitude.
Definition: Vector.hpp:1844
slip::stride_iterator< const_pointer > const_iterator_range
Definition: Vector.hpp:173
iterator end()
Returns a read/write iterator that points one past the last element in the Vector. Iteration is done in ordinary element order.
Definition: Vector.hpp:1481
const_pointer const_iterator
Definition: Vector.hpp:170
slip::Vector< short > Vector_s
short alias
Definition: Vector.hpp:1085
slip::lin_alg_traits< typename std::iterator_traits< InputIterator >::value_type >::value_type L22_norm_cplx(InputIterator first, InputIterator last)
Computes the L22 norm of a complex container.
HyperVolume< T > cosh(const HyperVolume< T > &M)
T & min(const GrayscaleImage< T > &M1)
Returns the min element of a GrayscaleImage.
Color< T > operator+(const Color< T > &V1, const Color< T > &V2)
Definition: Color.hpp:602
iterator begin()
Returns a read/write iterator that points to the first element in the Array. Iteration is done in ord...
Definition: Array.hpp:1077
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: Vector.hpp:176
slip::Vector< double > Vector_d
double alias
Definition: Vector.hpp:1077
norm_type L1_norm() const
Returns the L1 norm ( ) of the elements of the Vector.
Definition: Vector.hpp:997
HyperVolume< T > atan(const HyperVolume< T > &M)
norm_type Euclidean_norm() const
Returns the Euclidean norm of the elements of the Vector.
Definition: Vector.hpp:977
Vector< T > log10(const Vector< T > &V)
Definition: Vector.hpp:2179
slip::Vector< float > Vector_f
float alias
Definition: Vector.hpp:1079
iterator default_iterator
Definition: Vector.hpp:184
HyperVolume< T > exp(const HyperVolume< T > &M)
Vector< T > exp(const Vector< T > &V)
Definition: Vector.hpp:2134
static const std::size_t DIM
Definition: Vector.hpp:188
Provides common linear algebra algorithms.
Vector< T > & apply(T(*fun)(T))
Applys the one-parameter C-function fun to each element of the Vector.
Definition: Vector.hpp:1868
HyperVolume< T > abs(const HyperVolume< T > &M)
bool operator>(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1469
std::string name() const
Returns the name of the class.
Definition: Vector.hpp:1739
HyperVolume< T > sin(const HyperVolume< T > &M)
Provides a class to manipulate 1d dynamic and generic arrays.
HyperVolume< T > cos(const HyperVolume< T > &M)
Vector(InputIterator first, InputIterator last)
Contructs a Vector from a range.
Definition: Vector.hpp:232
std::reverse_iterator< const_iterator_range > const_reverse_iterator_range
Definition: Vector.hpp:179
slip::Vector< unsigned short > Vector_us
unsigned long alias
Definition: Vector.hpp:1087
std::reverse_iterator< iterator > reverse_iterator
Definition: Vector.hpp:175
Vector< T > sinh(const Vector< T > &V)
Definition: Vector.hpp:2161
This is a point1d class, a specialized version of Point<CoordType,DIM> with DIM = 1...
Definition: Point1d.hpp:101
iterator end()
Returns a read/write iterator that points one past the last element in the Array. Iteration is done i...
Definition: Array.hpp:1084
pointer iterator
Definition: Vector.hpp:169
size_type size() const
Returns the number of elements in the Vector.
Definition: Vector.hpp:1743
void fill(const T *value)
Fills the container range [begin(),begin()+size()) with a copy of the value array.
Definition: Vector.hpp:715
void fill(const T &value)
Fills the container range [begin(),begin()+size()) with copies of value.
Definition: Vector.hpp:704
const_iterator const_default_iterator
Definition: Vector.hpp:185
slip::Vector< unsigned char > Vector_uc
unsigned char alias
Definition: Vector.hpp:1095
This is a Box1d class, a specialized version of slip::Box<CoordType,DIM> with DIM = 1...
Definition: Box1d.hpp:110
void copy(_II first, _II last, _OI output_first)
Copy algorithm optimized for slip iterators.
Definition: copy_ext.hpp:177
Provides some macros which are used for using complex as real.
Vector< long double > asin(const Vector< long double > &V)
Definition: Vector.hpp:2092
bool is_valid() const
Returns true if the range is valid :
Definition: Range.hpp:322
SubType start() const
Accessor of the start subscript of the Range.
Definition: Range.hpp:284
Numerical Vector class. This container statisfies the RandomAccessContainer concepts of the Standard ...
Definition: Vector.hpp:104
slip::Vector< unsigned int > Vector_ui
unsigned int alias
Definition: Vector.hpp:1091
HyperVolume< T > sqrt(const HyperVolume< T > &M)
const value_type & const_reference
Definition: Vector.hpp:164
std::size_t size_type
Definition: Vector.hpp:167
self & operator+=(const T &val)
Add val to each element of the Vector.
Definition: Vector.hpp:1766
value_type & reference
Definition: Vector.hpp:163
HyperVolume< T > sinh(const HyperVolume< T > &M)
void resize(const size_type new_n, const T &val=T())
Resizes a Vector.
Definition: Vector.hpp:1465
Vector< T > sin(const Vector< T > &V)
Definition: Vector.hpp:2066
const value_type * const_pointer
Definition: Vector.hpp:162
Vector< T > cosh(const Vector< T > &V)
Definition: Vector.hpp:2152
Vector< T > log(const Vector< T > &V)
Definition: Vector.hpp:2143
reverse_iterator rbegin()
Returns a read/write reverse iterator that points to the last element in the Vector. Iteration is done in reverse element order.
Definition: Vector.hpp:1505
std::ostream & operator<<(std::ostream &out, const Array< T > &a)
Definition: Array.hpp:1282
reference operator()(const size_type i)
Subscript access to the data contained in the Vector.
bool empty() const
Returns true if the Vector is empty. (Thus size() == 0)
Definition: Vector.hpp:1754
slip::Vector< long > Vector_l
long alias
Definition: Vector.hpp:1081
reverse_iterator rend()
Returns a read/write reverse iterator that points to one before the first element in the Vector...
Definition: Vector.hpp:1512
HyperVolume< T > log(const HyperVolume< T > &M)
Vector< T > tan(const Vector< T > &V)
Definition: Vector.hpp:2101
Vector< long double > acos(const Vector< long double > &V)
Definition: Vector.hpp:2057
HyperVolume< T > acos(const HyperVolume< T > &M)
HyperVolume< T > log10(const HyperVolume< T > &M)
size_type max_size() const
Returns the maximal size (number of elements) in the Vector.
Definition: Vector.hpp:1747
T & max() const
Returns the max element of the Vector according to the operator >, if T is std::complex, it returns the element of maximum magnitude.
Definition: Vector.hpp:1852
void fill(InputIterator first, InputIterator last)
Fills the container range [begin(),begin()+size()) with a copy of the range [first,last)
Definition: Vector.hpp:729
slip::Vector< char > Vector_c
char alias
Definition: Vector.hpp:1093
slip::lin_alg_traits< value_type >::value_type norm_type
Definition: Vector.hpp:181
slip::stride_iterator< pointer > iterator_range
Definition: Vector.hpp:172
Provides some algorithms to apply C like functions to ranges.
Vector< T > sqrt(const Vector< T > &V)
Definition: Vector.hpp:2023
Provides a class to iterate a 1d range according to a step.
norm_type L2_norm() const
Returns the Euclidean norm of the elements of the Vector.
Definition: Vector.hpp:987
HyperVolume< T > tan(const HyperVolume< T > &M)
value_type * pointer
Definition: Vector.hpp:161
reference operator[](const size_type i)
Subscript access to the data contained in the Vector.
self operator-() const
Definition: Vector.hpp:1799
bool operator==(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1439
std::reverse_iterator< iterator_range > reverse_iterator_range
Definition: Vector.hpp:178
HyperVolume< T > asin(const HyperVolume< T > &M)
This is a linear (one-dimensional) dynamic template container. This container statisfies the RandomAc...
Definition: Array.hpp:94
reverse_iterator rbegin()
Returns a read/write reverse iterator that points to the last element in the Array. Iteration is done in reverse element order.
Definition: Array.hpp:1188
self & operator*=(const T &val)
Definition: Vector.hpp:1782
Vector< typename slip::lin_alg_traits< T >::value_type > abs(const Vector< T > &V)
Definition: Vector.hpp:2013
Color< T > operator*(const Color< T > &V1, const Color< T > &V2)
Definition: Color.hpp:658
void swap(self &M)
Swaps data with another Vector.
Definition: Vector.hpp:1758
Provides a class to manipulate 1d box.
void apply(InputIterator first, InputIterator last, OutputIterator result, typename std::iterator_traits< OutputIterator >::value_type(*function)(typename std::iterator_traits< InputIterator >::value_type))
Applies a C-function to each element of a range.
Definition: apply.hpp:128
T & max(const GrayscaleImage< T > &M1)
Returns the max element of a GrayscaleImage.
SubType stop() const
Accessor of the stop subscript of the Range.
Definition: Range.hpp:291
iterator begin()
Returns a read/write iterator that points to the first element in the Vector. Iteration is done in or...
Definition: Vector.hpp:1474
Color< T > operator/(const Color< T > &V1, const Color< T > &V2)
Definition: Color.hpp:686
const Vector< T > const_self
Definition: Vector.hpp:159
bool operator>=(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1485
slip::Vector< int > Vector_i
int alias
Definition: Vector.hpp:1089
Color< T > operator-(const Color< T > &V1, const Color< T > &V2)
Definition: Color.hpp:630
self & operator=(const self &rhs)
Assign a Vector.
Definition: Vector.hpp:1439
Provides some algorithms to compute norms.
Vector< T > tanh(const Vector< T > &V)
Definition: Vector.hpp:2170