SLIP  1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KVector.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 
73 #ifndef KVECTOR_HPP
74 #define KVECTOR_HPP
75 
76 #include <iterator>
77 #include <iostream>
78 #include <numeric>
79 #include <algorithm>
80 #include <string>
81 #include <cstddef>
82 #include "Range.hpp"
83 #include "stride_iterator.hpp"
84 #include "norms.hpp"
85 #include "apply.hpp"
86 #include "Block.hpp"
87 #include "complex_cast.hpp"
88 #include "linear_algebra.hpp"
90 
91 #include <boost/serialization/access.hpp>
92 #include <boost/serialization/split_member.hpp>
93 #include <boost/serialization/complex.hpp>
94 #include <boost/serialization/version.hpp>
95 
96 namespace slip
97 {
98 
99 template <class T, std::size_t N>
100 struct kvector;
101 
102 template <typename T, std::size_t N>
103 std::ostream& operator<<(std::ostream & out,
104  const kvector<T,N>& b);
105 
106 template <typename T, std::size_t N>
107 bool operator==(const kvector<T,N>& x,
108  const kvector<T,N>& y);
109 
110 template <typename T, std::size_t N>
111 bool operator!=(const kvector<T,N>& x,
112  const kvector<T,N>& y);
113 
114 template <typename T, std::size_t N>
115 bool operator<(const kvector<T,N>& x,
116  const kvector<T,N>& y);
117 
118 template <typename T, std::size_t N>
119 bool operator>(const kvector<T,N>& x,
120  const kvector<T,N>& y);
121 
122 template <typename T, std::size_t N>
123 bool operator<=(const kvector<T,N>& x,
124  const kvector<T,N>& y);
125 
126 template <typename T, std::size_t N>
127 bool operator>=(const kvector<T,N>& x,
128  const kvector<T,N>& y);
129 
147 template <class T, std::size_t N>
148 struct kvector{
149 
150  typedef T value_type;
151  typedef kvector<T,N> self;
152  typedef const kvector<T,N> const_self;
153 
154  typedef value_type* pointer;
155  typedef const value_type* const_pointer;
157  typedef const value_type& const_reference;
158 
159  typedef ptrdiff_t difference_type;
160  typedef std::size_t size_type;
161 
162  typedef pointer iterator;
166 
167  typedef std::reverse_iterator<iterator> reverse_iterator;
168  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
169 
170  typedef std::reverse_iterator<iterator_range> reverse_iterator_range;
171  typedef std::reverse_iterator<const_iterator_range> const_reverse_iterator_range;
172 
174 
175 
176  //default iterator of the container
179 
180  static const std::size_t SIZE = N;
181  static const std::size_t DIM = 1;
186 
187 
196  iterator begin(){return this->data;}
197 
198 
207  const_iterator begin() const {return this->data;}
208 
217  iterator end(){return this->data + N;}
218 
227  const_iterator end() const {return this->data + N;}
228 
229 
249  {
250  assert(range.is_valid());
251  assert(range.start() >= 0);
252  assert(range.stop() >= 0);
253  assert(range.start() < int(this->size()));
254  assert(range.stop() < int(this->size()));
255  return iterator_range(this->begin() + range.start(),range.stride());
256  }
257 
277  {
278  assert(range.is_valid());
279  assert(range.start() >= 0);
280  assert(range.stop() >= 0);
281  assert(range.start() < int(this->size()));
282  assert(range.stop() < int(this->size()));
283  return const_iterator_range(this->begin() + range.start(),range.stride());
284  }
285 
304  {
305  return this->begin(range) + (range.iterations() + 1);
306  }
307 
327  {
328  return this->begin(range) + (range.iterations() + 1);
329  }
330 
331 
341 
351 
361 
362 
372 
373 
393  {
394  return reverse_iterator_range(this->end(range));
395  }
396 
416  {
417  return const_reverse_iterator_range(this->end(range));
418  }
419 
420 
439  {
440  return reverse_iterator_range(this->begin(range));
441  }
442 
462  {
463  return const_reverse_iterator_range(this->begin(range));
464  }
465 
472 
478  friend std::ostream& operator<< <>(std::ostream & out,
479  const kvector<T,N>& b);
480 
488 
489 
496  {
497  if(this != &rhs)
498  {
499  std::copy(rhs.begin(),rhs.end(),this->begin());
500  }
501  return *this;
502  }
503 
509  kvector<T,N>& operator=(const T& val)
510  {
511  this->fill(val);
512  return *this;
513  }
514 
515 
516 
521  void fill(const T& value)
522  {
523  std::fill_n(this->begin(),N,value);
524  }
525 
531  void fill(const T* value)
532  {
533  std::copy(value,value + N, this->begin());
534  }
535 
544  template<typename InputIterator>
545  void fill(InputIterator first,
546  InputIterator last)
547  {
548  std::copy(first,last, this->begin());
549  }
562  friend bool operator== <>(const kvector<T,N>& x,
563  const kvector<T,N>& y);
564 
571  friend bool operator!= <>(const kvector<T,N>& x,
572  const kvector<T,N>& y);
573 
581  friend bool operator< <>(const kvector<T,N>& x,
582  const kvector<T,N>& y);
583 
591  friend bool operator> <>(const kvector<T,N>& x,
592  const kvector<T,N>& y);
593 
601  friend bool operator<= <>(const kvector<T,N>& x,
602  const kvector<T,N>& y);
603 
611  friend bool operator>= <>(const kvector<T,N>& x,
612  const kvector<T,N>& y);
613 
614 
633  reference operator[](const size_type n){return *(this->data + n);}
634 
646  const_reference operator[](const size_type n) const {return *(this->data + n);}
647 
659  reference operator()(const size_type n) {return *(this->data + n);}
660 
661 
673  const_reference operator()(const size_type n) const {return *(this->data + n);}
674 
681 
687  self& operator+=(const T& val)
688  {
689  std::transform(this->begin(),this->end(),this->begin(),std::bind2nd(std::plus<T>(),val));
690  return *this;
691  }
692 
693  self& operator-=(const T& val)
694  {
695  std::transform(this->begin(),this->end(),this->begin(),std::bind2nd(std::minus<T>(),val));
696  return *this;
697  }
698 
699  self& operator*=(const T& val)
700  {
701  std::transform(this->begin(),this->end(),this->begin(),std::bind2nd(std::multiplies<T>(),val));
702  return *this;
703  }
704 
705  self& operator/=(const T& val)
706  {
707  std::transform(this->begin(),this->end(),this->begin(),std::bind2nd(std::divides<T>(),val));
708  return *this;
709  }
710  // self& operator%=(const T& val);
711  // self& operator^=(const T& val);
712  // self& operator&=(const T& val);
713  // self& operator|=(const T& val);
714  // self& operator<<=(const T& val);
715  // self& operator>>=(const T& val);
716 
717  self operator-() const
718  {
719  self tmp = *this;
720  std::transform(this->begin(),this->end(),tmp.begin(),std::negate<T>());
721  return tmp;
722  }
723  //self operator!() const;
724 
725  self& operator+=(const self& rhs)
726  {
727  assert(this->size() == rhs.size());
728  std::transform(this->begin(),this->end(),rhs.begin(),this->begin(),std::plus<T>());
729  return *this;
730  }
731 
732  self& operator-=(const self& rhs)
733  {
734  assert(this->size() == rhs.size());
735  std::transform(this->begin(),this->end(),rhs.begin(),this->begin(),std::minus<T>());
736  return *this;
737  }
738 
739  self& operator*=(const self& rhs)
740  {
741  assert(this->size() == rhs.size());
742  std::transform(this->begin(),this->end(),rhs.begin(),this->begin(),std::multiplies<T>());
743  return *this;
744  }
745 
746  self& operator/=(const self& rhs)
747  {
748  assert(this->size() == rhs.size());
749  std::transform(this->begin(),this->end(),rhs.begin(),this->begin(),std::divides<T>());
750  return *this;
751  }
752 
753 
760  std::string name() const {return "kvector";}
761 
762 
766  size_type size() const {return N;}
767 
772  {
773  return size_type(-1)/sizeof(value_type);
774  }
775 
779  bool empty() const {return N == 0;}
780 
785  void swap(kvector& x)
786  {
787  std::swap_ranges(this->begin(),this->end(),x.begin());
788  }
789 
790 
800  T& min()
801  {
802  assert(this->size() != 0);
803  return *std::min_element(this->begin(),this->end(),std::less<T>());
804  }
805 
806 
812  T& max()
813  {
814  assert(this->size() != 0);
815  return *std::max_element(this->begin(),this->end(),std::less<T>());
816  }
817 
822  T sum() const
823  {
824  assert(this->size() != 0);
825  return std::accumulate(this->begin(),this->end(),T(0));
826  }
827 
833  {
834  assert(this->size() != 0);
835  return std::sqrt(slip::L22_norm_cplx(this->begin(),this->end()));
836  }
837 
843  {
844  assert(this->size() != 0);
845  return this->Euclidean_norm();
846  }
847 
848 
854  {
855  assert(this->size() != 0);
856  return slip::L1_norm<norm_type>(this->begin(),this->end());
857  }
858 
864  {
865  assert(this->size() != 0);
866  return slip::L22_norm_cplx(this->begin(),this->end());
867  }
868 
874  {
875  assert(this->size() != 0);
876  return slip::infinite_norm<norm_type>(this->begin(),this->end());
877  }
878 
884  template<typename Real>
885  Real dot(const self& other)
886  {
887  return std::inner_product(this->begin(),this->end(),other.begin(),
888  Real());
889  }
890 
906  kvector<T,N>& apply(T (*fun)(T))
907  {
908  slip::apply(this->begin(),this->end(),this->begin(),fun);
909  return *this;
910  }
911 
927  kvector<T,N>& apply(T (*fun)(const T&))
928  {
929  slip::apply(this->begin(),this->end(),this->begin(),fun);
930  return *this;
931  }
934  T data[N];
936 
937  protected:
938  friend class boost::serialization::access;
939  template<class Archive>
940  void save(Archive & ar, const unsigned int version) const
941  {
942  ar & data;
943  }
944  template<class Archive>
945  void load(Archive & ar, const unsigned int version)
946  {
947  ar & data;
948  }
949  BOOST_SERIALIZATION_SPLIT_MEMBER()
950 };
951 
952 
960 template<typename T, std::size_t N>
961 kvector<T,N> operator+(const kvector<T,N>& V1,
962  const kvector<T,N>& V2);
963 
970 template<typename T, std::size_t N>
971 kvector<T,N> operator+(const kvector<T,N>& V,
972  const T& val);
973 
980 template<typename T, std::size_t N>
981 kvector<T,N> operator+(const T& val,
982  const kvector<T,N>& V);
983 
984 
992 template<typename T, std::size_t N>
993 kvector<T,N> operator-(const kvector<T,N>& V1,
994  const kvector<T,N>& V2);
995 
1002 template<typename T, std::size_t N>
1003 kvector<T,N> operator-(const kvector<T,N>& V,
1004  const T& val);
1005 
1012 template<typename T, std::size_t N>
1013 kvector<T,N> operator-(const T& val,
1014  const kvector<T,N>& V);
1015 
1023 template<typename T, std::size_t N>
1024 kvector<T,N> operator*(const kvector<T,N>& V1,
1025  const kvector<T,N>& V2);
1026 
1033 template<typename T, std::size_t N>
1034 kvector<T,N> operator*(const kvector<T,N>& V,
1035  const T& val);
1036 
1043 template<typename T, std::size_t N>
1044 kvector<T,N> operator*(const T& val,
1045  const kvector<T,N>& V);
1046 
1054  template<typename T, std::size_t N>
1055  kvector<T,N> operator/(const kvector<T,N>& V1,
1056  const kvector<T,N>& V2);
1057 
1064  template<typename T, std::size_t N>
1065  kvector<T,N> operator/(const kvector<T,N>& V,
1066  const T& val);
1067 
1068 // /*!
1069 // ** \brief division of a scalar to each element of a %kvector
1070 // ** \param val The scalar
1071 // ** \param V The %kvector
1072 // ** \return resulting %kvector
1073 // */
1074 // template<typename T, std::size_t N>
1075 // kvector<T,N> operator/(const T& val,
1076 // const kvector<T,N>& V);
1077 
1078  //de m�me pour atan2, pow,
1079  //^, &, |, <<, >>, &&, ||
1080 
1088  template<typename T, std::size_t N>
1089  T& min(kvector<T,N>& M1);
1090 
1098  template<typename T, std::size_t N>
1099  T& max(kvector<T,N>& M1);
1100 
1101 
1108  template<typename T, std::size_t N>
1109  kvector<typename slip::lin_alg_traits<T>::value_type,N> abs(const kvector<T,N>& V);
1110 
1117  template<typename T, std::size_t N>
1118  kvector<T,N> sqrt(const kvector<T,N>& V);
1119 
1126  template<typename T, std::size_t N>
1127  kvector<T,N> cos(const kvector<T,N>& V);
1128 
1129 
1136  template<std::size_t N>
1137  kvector<float,N> acos(const kvector<float,N>& V);
1138 
1145  template<std::size_t N>
1146  kvector<double,N> acos(const kvector<double,N>& V);
1147 
1154  template<std::size_t N>
1155  kvector<long double,N> acos(const kvector<long double,N>& V);
1156 
1163  template<typename T, std::size_t N>
1164  kvector<T,N> sin(const kvector<T,N>& V);
1165 
1166 
1173  template<std::size_t N>
1174  kvector<float,N> asin(const kvector<float,N>& V);
1175 
1182  template<std::size_t N>
1183  kvector<double,N> asin(const kvector<double,N>& V);
1184 
1191  template<std::size_t N>
1192  kvector<long double,N> asin(const kvector<long double,N>& V);
1193 
1194 
1201  template<typename T, std::size_t N>
1202  kvector<T,N> tan(const kvector<T,N>& V);
1203 
1204 
1211  template<std::size_t N>
1212  kvector<float,N> atan(const kvector<float,N>& V);
1213 
1220  template<std::size_t N>
1221  kvector<double,N> atan(const kvector<double,N>& V);
1222 
1229  template<std::size_t N>
1230  kvector<long double,N> atan(const kvector<long double,N>& V);
1231 
1232 
1239  template<typename T, std::size_t N>
1240  kvector<T,N> exp(const kvector<T,N>& V);
1241 
1248  template<typename T, std::size_t N>
1249  kvector<T,N> log(const kvector<T,N>& V);
1250 
1257  template<typename T, std::size_t N>
1258  kvector<T,N> cosh(const kvector<T,N>& V);
1259 
1266  template<typename T, std::size_t N>
1267  kvector<T,N> sinh(const kvector<T,N>& V);
1268 
1275  template<typename T, std::size_t N>
1276  kvector<T,N> tanh(const kvector<T,N>& V);
1277 
1284  template<typename T, std::size_t N>
1285  kvector<T,N> log10(const kvector<T,N>& V);
1286 
1287 }//slip::
1288 
1289 namespace slip
1290 {
1291 
1292 template <typename T, std::size_t N>
1293 std::ostream& operator<<(std::ostream & out,
1294  const kvector<T,N>& b)
1295  {
1296  out<<"(";
1297  for(std::size_t n = 0; n < N - 1; ++n)
1298  {
1299  out<<b.data[n]<<",";
1300  }
1301  out<<b.data[N-1];
1302  out<<")";
1303  return out;
1304  }
1305 
1306 template<typename T, std::size_t N>
1307 inline
1309  const kvector<T,N>& V2)
1310 {
1311  kvector<T,N> tmp;
1312  std::transform(V1.begin(),V1.end(),V2.begin(),tmp.begin(),std::plus<T>());
1313  return tmp;
1314 }
1315 
1316 template<typename T, std::size_t N>
1317 inline
1319  const T& val)
1320 {
1321  kvector<T,N> tmp = V1;
1322  tmp+=val;
1323  return tmp;
1324 }
1325 
1326 template<typename T, std::size_t N>
1327 inline
1329  const kvector<T,N>& V1)
1330 {
1331  return V1 + val;
1332 }
1333 
1334 template<typename T, std::size_t N>
1335 inline
1337  const kvector<T,N>& V2)
1338 {
1339  kvector<T,N> tmp;
1340  std::transform(V1.begin(),V1.end(),V2.begin(),tmp.begin(),std::minus<T>());
1341  return tmp;
1342 }
1343 
1344 template<typename T, std::size_t N>
1345 inline
1347  const T& val)
1348 {
1349  kvector<T,N> tmp = V1;
1350  tmp-=val;
1351  return tmp;
1352 }
1353 
1354 template<typename T, std::size_t N>
1355 inline
1357  const kvector<T,N>& V1)
1358 {
1359  return -(V1 - val);
1360 }
1361 
1362 template<typename T, std::size_t N>
1363 inline
1365  const kvector<T,N>& V2)
1366 {
1367  kvector<T,N> tmp;
1368  std::transform(V1.begin(),V1.end(),V2.begin(),tmp.begin(),std::multiplies<T>());
1369  return tmp;
1370 }
1371 
1372 template<typename T, std::size_t N>
1373 inline
1375  const T& val)
1376 {
1377  kvector<T,N> tmp = V1;
1378  tmp*=val;
1379  return tmp;
1380 }
1381 
1382 template<typename T, std::size_t N>
1383 inline
1385  const kvector<T,N>& V1)
1386 {
1387  return V1 * val;
1388 }
1389 
1390 template<typename T, std::size_t N>
1391 inline
1393  const kvector<T,N>& V2)
1394 {
1395  kvector<T,N> tmp;
1396  std::transform(V1.begin(),V1.end(),V2.begin(),tmp.begin(),std::divides<T>());
1397  return tmp;
1398 }
1399 
1400 template<typename T, std::size_t N>
1401 inline
1403  const T& val)
1404 {
1405  kvector<T,N> tmp = V1;
1406  tmp/=val;
1407  return tmp;
1408 }
1409 
1410 // template<typename T, std::size_t N>
1411 // inline
1412 // kvector<T,N> operator/(const T& val,
1413 // const kvector<T,N>& V1)
1414 // {
1415 // return V1 / val;
1416 // }
1417 
1418 
1419 template<typename T, std::size_t N>
1420 inline
1422 {
1423  return V1.min();
1424 }
1425 
1426 template<typename T, std::size_t N>
1427 inline
1429 {
1430  return V1.max();
1431 }
1432 
1433 template<typename T, std::size_t N>
1434 inline
1436 {
1437 
1439  slip::apply(V.begin(),V.end(),tmp.begin(),std::abs);
1440  return tmp;
1441 }
1442 
1443 template<typename T, std::size_t N>
1444 inline
1446 {
1447  kvector<T,N> tmp;
1448  slip::apply(V.begin(),V.end(),tmp.begin(),std::sqrt);
1449  return tmp;
1450 }
1451 
1452 template<typename T, std::size_t N>
1453 inline
1455 {
1456  kvector<T,N> tmp;
1457  slip::apply(V.begin(),V.end(),tmp.begin(),std::cos);
1458  return tmp;
1459 }
1460 
1461 
1462 template<std::size_t N>
1463 inline
1465 {
1466  kvector<float,N> tmp;
1467  slip::apply(V.begin(),V.end(),tmp.begin(),std::acos);
1468  return tmp;
1469 }
1470 
1471 template<std::size_t N>
1472 inline
1474 {
1475  kvector<double,N> tmp;
1476  slip::apply(V.begin(),V.end(),tmp.begin(),std::acos);
1477  return tmp;
1478 }
1479 
1480 template<std::size_t N>
1481 inline
1483 {
1485  slip::apply(V.begin(),V.end(),tmp.begin(),std::acos);
1486  return tmp;
1487 }
1488 
1489 template<typename T, std::size_t N>
1490 inline
1492 {
1493  kvector<T,N> tmp;
1494  slip::apply(V.begin(),V.end(),tmp.begin(),std::sin);
1495  return tmp;
1496 }
1497 
1498 
1499 template<std::size_t N>
1500 inline
1502 {
1503  kvector<float,N> tmp;
1504  slip::apply(V.begin(),V.end(),tmp.begin(),std::asin);
1505  return tmp;
1506 }
1507 
1508 template<std::size_t N>
1509 inline
1511 {
1512  kvector<double,N> tmp;
1513  slip::apply(V.begin(),V.end(),tmp.begin(),std::asin);
1514  return tmp;
1515 }
1516 
1517 template<std::size_t N>
1518 inline
1520 {
1522  slip::apply(V.begin(),V.end(),tmp.begin(),std::asin);
1523  return tmp;
1524 }
1525 
1526 template<typename T, std::size_t N>
1527 inline
1529 {
1530  kvector<T,N> tmp;
1531  slip::apply(V.begin(),V.end(),tmp.begin(),std::tan);
1532  return tmp;
1533 }
1534 
1535 
1536 
1537 template<std::size_t N>
1538 inline
1540 {
1541  kvector<float,N> tmp;
1542  slip::apply(V.begin(),V.end(),tmp.begin(),std::atan);
1543  return tmp;
1544 }
1545 
1546 template<std::size_t N>
1547 inline
1549 {
1550  kvector<double,N> tmp;
1551  slip::apply(V.begin(),V.end(),tmp.begin(),std::atan);
1552  return tmp;
1553 }
1554 
1555 template<std::size_t N>
1556 inline
1558 {
1560  slip::apply(V.begin(),V.end(),tmp.begin(),std::atan);
1561  return tmp;
1562 }
1563 
1564 template<typename T, std::size_t N>
1565 inline
1567 {
1568  kvector<T,N> tmp;
1569  slip::apply(V.begin(),V.end(),tmp.begin(),std::exp);
1570  return tmp;
1571 }
1572 
1573 template<typename T, std::size_t N>
1574 inline
1576 {
1577  kvector<T,N> tmp;
1578  slip::apply(V.begin(),V.end(),tmp.begin(),std::log);
1579  return tmp;
1580 }
1581 
1582 template<typename T, std::size_t N>
1583 inline
1585 {
1586  kvector<T,N> tmp;
1587  slip::apply(V.begin(),V.end(),tmp.begin(),std::cosh);
1588  return tmp;
1589 }
1590 
1591 template<typename T, std::size_t N>
1592 inline
1594 {
1595  kvector<T,N> tmp;
1596  slip::apply(V.begin(),V.end(),tmp.begin(),std::sinh);
1597  return tmp;
1598 }
1599 
1600 template<typename T, std::size_t N>
1601 inline
1603 {
1604  kvector<T,N> tmp;
1605  slip::apply(V.begin(),V.end(),tmp.begin(),std::tanh);
1606  return tmp;
1607 }
1608 
1609 template<typename T, std::size_t N>
1610 inline
1612 {
1613  kvector<T,N> tmp;
1614  slip::apply(V.begin(),V.end(),tmp.begin(),std::log10);
1615  return tmp;
1616 }
1617 
1618 
1619 template <typename T, std::size_t N>
1620 inline
1621 bool operator==(const kvector<T,N>& x,
1622  const kvector<T,N>& y)
1623 {
1624  return ( x.size() == y.size()
1625  && std::equal(x.begin(),x.end(),y.begin()));
1626 }
1627 
1628 template <typename T, std::size_t N>
1629 inline
1630 bool operator!=(const kvector<T,N>& x,
1631  const kvector<T,N>& y)
1632 {
1633  return !(x == y);
1634 }
1635 
1636 
1637 template <typename T, std::size_t N>
1638 inline
1639 bool operator<(const kvector<T,N>& x,
1640  const kvector<T,N>& y)
1641 {
1642  return std::lexicographical_compare(x.begin(), x.end(),
1643  y.begin(), y.end());
1644 }
1645 
1646 template <typename T, std::size_t N>
1647 inline
1648 bool operator>(const kvector<T,N>& x,
1649  const kvector<T,N>& y)
1650 {
1651  return (y < x);
1652 }
1653 
1654 
1655 template <typename T, std::size_t N>
1656 inline
1657 bool operator<=(const kvector<T,N>& x,
1658  const kvector<T,N>& y)
1659 {
1660  return !(y < x);
1661 }
1662 
1663 
1664 template <typename T, std::size_t N>
1665 inline
1666 bool operator>=(const kvector<T,N>& x,
1667  const kvector<T,N>& y)
1668 {
1669  return !(x < y);
1670 }
1671 }//slip::
1672 
1673 #endif //KVECTOR_HPP
void fill(const T &value)
Fills the container range [begin(),begin()+N) with copies of value.
Definition: KVector.hpp:521
HyperVolume< T > tanh(const HyperVolume< T > &M)
bool operator!=(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1448
self & operator-=(const self &rhs)
Definition: KVector.hpp:732
std::size_t iterations() const
Rerturns the number of iterations of the range.
Definition: Range.hpp:305
kvector< T, N > exp(const kvector< T, N > &V)
Definition: KVector.hpp:1566
const value_type * const_pointer
Definition: KVector.hpp:155
const_iterator_range end(const slip::Range< int > &range) const
Returns a read-only (constant) iterator_range that points one past the last element in the kvector...
Definition: KVector.hpp:326
const_reverse_iterator rbegin() const
Returns a read-only (constant) reverse iterator that points to the last element in the kvector...
Definition: KVector.hpp:350
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: KVector.hpp:168
const_reverse_iterator rend() const
Returns a read-only (constant) reverse iterator that points to one before the first element in the kv...
Definition: KVector.hpp:371
iterator_range end(const slip::Range< int > &range)
Returns a read/write iterator_range that points one past the last element in the kvector. Iteration is done in ordinary element order according to the Range.
Definition: KVector.hpp:303
kvector< T, N > sinh(const kvector< T, N > &V)
Definition: KVector.hpp:1593
This is a linear (one-dimensional) static vector. This container statisfies the RandomAccessContainer...
Definition: KVector.hpp:100
kvector< T, N > & operator=(const kvector< T, N > &rhs)
Assigns all the element of the kvector by the kvector rhs.
Definition: KVector.hpp:495
norm_type infinite_norm() const
Returns the infinite norm ( ) of the elements of the kvector.
Definition: KVector.hpp:873
void load(Archive &ar, const unsigned int version)
Definition: KVector.hpp:945
norm_type L1_norm() const
Returns the L1 norm ( ) of the elements of the kvector.
Definition: KVector.hpp:853
kvector< long double, N > acos(const kvector< long double, N > &V)
Definition: KVector.hpp:1482
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)
norm_type Euclidean_norm() const
Returns the Euclidean norm of the elements of the kvector.
Definition: KVector.hpp:832
value_type * pointer
Definition: KVector.hpp:154
T & min(const GrayscaleImage< T > &M1)
Returns the min element of a GrayscaleImage.
kvector< T, N > log10(const kvector< T, N > &V)
Definition: KVector.hpp:1611
kvector< T, N > cosh(const kvector< T, N > &V)
Definition: KVector.hpp:1584
const_iterator const_default_iterator
Definition: KVector.hpp:178
self & operator+=(const self &rhs)
Definition: KVector.hpp:725
Color< T > operator+(const Color< T > &V1, const Color< T > &V2)
Definition: Color.hpp:602
kvector< T, N > & operator=(const T &val)
Assigns all the element of the kvector by val.
Definition: KVector.hpp:509
norm_type L22_norm() const
Returns the L22 norm ( ) of the elements of the kvector.
Definition: KVector.hpp:863
kvector< T, N > sin(const kvector< T, N > &V)
Definition: KVector.hpp:1491
HyperVolume< T > atan(const HyperVolume< T > &M)
T & min()
Returns the min element of the kvector according to the operator <, if T is std::complex, it returns the element of minimum magnitude.
Definition: KVector.hpp:800
kvector< T, N > tanh(const kvector< T, N > &V)
Definition: KVector.hpp:1602
reference operator()(const size_type n)
Subscript access to the data contained in the kvector.
Definition: KVector.hpp:659
norm_type L2_norm() const
Returns the Euclidean norm of the elements of the kvector.
Definition: KVector.hpp:842
HyperVolume< T > exp(const HyperVolume< T > &M)
Provides common linear algebra algorithms.
std::size_t size_type
Definition: KVector.hpp:160
size_type max_size() const
Returns the maximal size (number of elements) in the kvector.
Definition: KVector.hpp:771
iterator default_iterator
Definition: KVector.hpp:177
kvector< long double, N > atan(const kvector< long double, N > &V)
Definition: KVector.hpp:1557
const value_type & const_reference
Definition: KVector.hpp:157
self & operator/=(const T &val)
Definition: KVector.hpp:705
const kvector< T, N > const_self
Definition: KVector.hpp:152
const_reference operator()(const size_type n) const
Subscript access to the data contained in the kvector.
Definition: KVector.hpp:673
HyperVolume< T > abs(const HyperVolume< T > &M)
bool operator>(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1469
kvector< T, N > & apply(T(*fun)(T))
Applys the one-parameter C-function fun to each element of the kvector.
Definition: KVector.hpp:906
const_reference operator[](const size_type n) const
Subscript access to the data contained in the kvector.
Definition: KVector.hpp:646
HyperVolume< T > sin(const HyperVolume< T > &M)
Provides a class to manipulate 1d static and generic arrays.
HyperVolume< T > cos(const HyperVolume< T > &M)
reverse_iterator_range rend(const slip::Range< int > &range)
Returns a read/write reverse_iterator_range that points one previous the first element in the Range...
Definition: KVector.hpp:438
self & operator-=(const T &val)
Definition: KVector.hpp:693
reference operator[](const size_type n)
Subscript access to the data contained in the kvector.
Definition: KVector.hpp:633
slip::stride_iterator< pointer > iterator_range
Definition: KVector.hpp:164
Real dot(const self &other)
Computes the dot product with another kvector other.
Definition: KVector.hpp:885
self & operator+=(const T &val)
Add val to each element of the kvector.
Definition: KVector.hpp:687
iterator_range begin(const slip::Range< int > &range)
Returns a read/write iterator_range that points the first element within the Range. Iteration is done in ordinary element order according to the Range.
Definition: KVector.hpp:248
static const std::size_t DIM
Definition: KVector.hpp:181
iterator begin()
Returns a read/write iterator that points to the first element in the kvector. Iteration is done in o...
Definition: KVector.hpp:196
kvector< T, N > cos(const kvector< T, N > &V)
Definition: KVector.hpp:1454
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.
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
void fill(InputIterator first, InputIterator last)
Fills the container range [begin(),begin()+N) with a copy of the range [first,last) ...
Definition: KVector.hpp:545
T sum() const
Returns the sum of the elements of the kvector.
Definition: KVector.hpp:822
const_pointer const_iterator
Definition: KVector.hpp:163
self & operator/=(const self &rhs)
Definition: KVector.hpp:746
value_type & reference
Definition: KVector.hpp:156
void fill(const T *value)
Fills the container range [begin(),begin()+N) with a copy of the value array.
Definition: KVector.hpp:531
HyperVolume< T > sqrt(const HyperVolume< T > &M)
size_type size() const
Returns the number of elements in the kvector.
Definition: KVector.hpp:766
HyperVolume< T > sinh(const HyperVolume< T > &M)
kvector< typename slip::lin_alg_traits< T >::value_type, N > abs(const kvector< T, N > &V)
Definition: KVector.hpp:1435
reverse_iterator rend()
Returns a read/write reverse iterator that points to one before the first element in the kvector...
Definition: KVector.hpp:360
slip::lin_alg_traits< value_type >::value_type norm_type
Definition: KVector.hpp:173
kvector< T, N > log(const kvector< T, N > &V)
Definition: KVector.hpp:1575
self & operator*=(const T &val)
Definition: KVector.hpp:699
const_reverse_iterator_range rbegin(const slip::Range< int > &range) const
Returns a read-only (constant) reverse_iterator_range that points the end element within the Range...
Definition: KVector.hpp:415
std::reverse_iterator< iterator > reverse_iterator
Definition: KVector.hpp:167
std::string name() const
Returns the name of the class.
Definition: KVector.hpp:760
std::ostream & operator<<(std::ostream &out, const Array< T > &a)
Definition: Array.hpp:1282
iterator end()
Returns a read/write iterator that points one past the last element in the kvector. Iteration is done in ordinary element order.
Definition: KVector.hpp:217
HyperVolume< T > log(const HyperVolume< T > &M)
ptrdiff_t difference_type
Definition: KVector.hpp:159
reverse_iterator_range rbegin(const slip::Range< int > &range)
Returns a read/write reverse_iterator_range that points the end element within the Range...
Definition: KVector.hpp:392
std::iterator_traits< RandomAccessIterator1 >::value_type inner_product(RandomAccessIterator1 first1, RandomAccessIterator1 last1, RandomAccessIterator2 first2, typename std::iterator_traits< RandomAccessIterator1 >::value_type init=typename std::iterator_traits< RandomAccessIterator1 >::value_type())
Computes the inner_product of two ranges X and Y: .
HyperVolume< T > acos(const HyperVolume< T > &M)
std::reverse_iterator< iterator_range > reverse_iterator_range
Definition: KVector.hpp:170
HyperVolume< T > log10(const HyperVolume< T > &M)
pointer iterator
Definition: KVector.hpp:162
int stride() const
Accessor of the stride of the Range.
Definition: Range.hpp:298
slip::stride_iterator< const_pointer > const_iterator_range
Definition: KVector.hpp:165
self operator-() const
Definition: KVector.hpp:717
Provides some algorithms to apply C like functions to ranges.
const_iterator begin() const
Returns a read-only (constant) iterator that points to the first element in the kvector. Iteration is done in ordinary element order.
Definition: KVector.hpp:207
kvector< T, N > & apply(T(*fun)(const T &))
Applys the one-parameter C-function fun to each element of the kvector.
Definition: KVector.hpp:927
kvector< long double, N > asin(const kvector< long double, N > &V)
Definition: KVector.hpp:1519
std::reverse_iterator< const_iterator_range > const_reverse_iterator_range
Definition: KVector.hpp:171
Provides a class to iterate a 1d range according to a step.
bool empty() const
Returns true if the kvector is empty. (Thus size == 0)
Definition: KVector.hpp:779
const_iterator_range begin(const slip::Range< int > &range) const
Returns a read-only (constant) iterator_range that points the first element within the Range...
Definition: KVector.hpp:276
HyperVolume< T > tan(const HyperVolume< T > &M)
const_reverse_iterator_range rend(const slip::Range< int > &range) const
Returns a read-only (constant) reverse_iterator_range that points one previous the first element in t...
Definition: KVector.hpp:461
bool operator==(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1439
kvector< T, N > tan(const kvector< T, N > &V)
Definition: KVector.hpp:1528
const_iterator end() const
Returns a read-only (constant) iterator that points one past the last element in the kvector...
Definition: KVector.hpp:227
HyperVolume< T > asin(const HyperVolume< T > &M)
T & max()
Returns the max element of the kvector according to the operator >, if T is std::complex, it returns the element of maximum magnitude.
Definition: KVector.hpp:812
Color< T > operator*(const Color< T > &V1, const Color< T > &V2)
Definition: Color.hpp:658
T data[N]
Data array storage of the kvector.
Definition: KVector.hpp:935
Provides a class to manipulate Ranges.
self & operator*=(const self &rhs)
Definition: KVector.hpp:739
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
Color< T > operator/(const Color< T > &V1, const Color< T > &V2)
Definition: Color.hpp:686
void swap(kvector &x)
Swaps data with another kvector.
Definition: KVector.hpp:785
bool operator>=(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1485
Color< T > operator-(const Color< T > &V1, const Color< T > &V2)
Definition: Color.hpp:630
void save(Archive &ar, const unsigned int version) const
Definition: KVector.hpp:940
Provides some algorithms to compute norms.
kvector< T, N > sqrt(const kvector< T, N > &V)
Definition: KVector.hpp:1445
static const std::size_t SIZE
Definition: KVector.hpp:180
reverse_iterator rbegin()
Returns a read/write reverse iterator that points to the last element in the kvector. Iteration is done in reverse element order.
Definition: KVector.hpp:340