Visual Servoing Platform  version 3.4.0
vpColVector.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Provide some simple operation on column vectors.
33  *
34  * Authors:
35  * Eric Marchand
36  *
37  *****************************************************************************/
38 
45 #include <assert.h>
46 #include <cmath> // std::fabs
47 #include <limits> // numeric_limits
48 #include <math.h>
49 #include <sstream>
50 #include <stdio.h>
51 #include <stdlib.h>
52 #include <string.h>
53 
54 #include <visp3/core/vpCPUFeatures.h>
55 #include <visp3/core/vpColVector.h>
56 #include <visp3/core/vpDebug.h>
57 #include <visp3/core/vpException.h>
58 #include <visp3/core/vpMath.h>
59 #include <visp3/core/vpRotationVector.h>
60 
61 #include <Simd/SimdLib.hpp>
62 
65 {
66  if (getRows() != v.getRows()) {
67  throw(vpException(vpException::dimensionError, "Cannot add (%dx1) column vector to (%dx1) column vector", getRows(),
68  v.getRows()));
69  }
71 
72  for (unsigned int i = 0; i < rowNum; i++)
73  r[i] = (*this)[i] + v[i];
74  return r;
75 }
98 {
99  if (getRows() != 3) {
100  throw(vpException(vpException::dimensionError, "Cannot add %d-dimension column vector to a translation vector",
101  getRows()));
102  }
104 
105  for (unsigned int i = 0; i < 3; i++)
106  s[i] = (*this)[i] + t[i];
107 
108  return s;
109 }
110 
113 {
114  if (getRows() != v.getRows()) {
115  throw(vpException(vpException::dimensionError, "Cannot add (%dx1) column vector to (%dx1) column vector", getRows(),
116  v.getRows()));
117  }
118 
119  for (unsigned int i = 0; i < rowNum; i++)
120  (*this)[i] += v[i];
121  return (*this);
122 }
125 {
126  if (getRows() != v.getRows()) {
127  throw(vpException(vpException::dimensionError, "Cannot substract (%dx1) column vector to (%dx1) column vector",
128  getRows(), v.getRows()));
129  }
130 
131  for (unsigned int i = 0; i < rowNum; i++)
132  (*this)[i] -= v[i];
133  return (*this);
134 }
135 
143 double vpColVector::operator*(const vpColVector &v) const
144 {
145  if (size() != v.size()) {
147  "Cannot compute the dot product between column vectors "
148  "with different dimensions (%d) and (%d)",
149  size(), v.size()));
150  }
151  double r = 0;
152 
153  for (unsigned int i = 0; i < rowNum; i++)
154  r += (*this)[i] * v[i];
155  return r;
156 }
157 
168 {
169  vpMatrix M(rowNum, v.getCols());
170  for (unsigned int i = 0; i < rowNum; i++) {
171  for (unsigned int j = 0; j < v.getCols(); j++) {
172  M[i][j] = (*this)[i] * v[j];
173  }
174  }
175  return M;
176 }
177 
180 {
181  if (getRows() != m.getRows()) {
183  "Bad size during vpColVector (%dx1) and vpColVector "
184  "(%dx1) substraction",
185  getRows(), m.getRows()));
186  }
187  vpColVector v(rowNum);
188 
189  for (unsigned int i = 0; i < rowNum; i++)
190  v[i] = (*this)[i] - m[i];
191  return v;
192 }
193 
207 vpColVector::vpColVector(const vpColVector &v, unsigned int r, unsigned int nrows) : vpArray2D<double>(nrows, 1)
208 {
209  init(v, r, nrows);
210 }
211 
249 void vpColVector::init(const vpColVector &v, unsigned int r, unsigned int nrows)
250 {
251  unsigned int rnrows = r + nrows;
252 
253  if (rnrows > v.getRows())
254  throw(vpException(vpException::dimensionError, "Bad row dimension (%d > %d) used to initialize vpColVector", rnrows,
255  v.getRows()));
256  resize(nrows, false);
257 
258  if (this->rowPtrs == NULL) // Fix coverity scan: explicit null dereferenced
259  return; // Nothing to do
260  for (unsigned int i = r; i < rnrows; i++)
261  (*this)[i - r] = v[i];
262 }
263 
265 {
266  for (unsigned int i = 0; i < v.size(); i++)
267  (*this)[i] = v[i];
268 }
269 
271 {
272  for (unsigned int i = 0; i < p.size(); i++)
273  (*this)[i] = p[i];
274 }
275 
277 {
278  for (unsigned int i = 0; i < v.size(); i++)
279  (*this)[i] = v[i];
280 }
281 
283 vpColVector::vpColVector(const vpMatrix &M, unsigned int j) : vpArray2D<double>(M.getRows(), 1)
284 {
285  for (unsigned int i = 0; i < M.getCols(); i++)
286  (*this)[i] = M[i][j];
287 }
288 
296 {
297  if (M.getCols() != 1) {
298  throw(vpException(vpException::dimensionError, "Cannot construct a (%dx1) row vector from a (%dx%d) matrix",
299  M.getRows(), M.getRows(), M.getCols()));
300  }
301 
302  for (unsigned int i = 0; i < M.getRows(); i++)
303  (*this)[i] = M[i][0];
304 }
305 
309 vpColVector::vpColVector(const std::vector<double> &v) : vpArray2D<double>((unsigned int)v.size(), 1)
310 {
311  for (unsigned int i = 0; i < v.size(); i++)
312  (*this)[i] = v[i];
313 }
317 vpColVector::vpColVector(const std::vector<float> &v) : vpArray2D<double>((unsigned int)v.size(), 1)
318 {
319  for (unsigned int i = 0; i < v.size(); i++)
320  (*this)[i] = (double)(v[i]);
321 }
322 
323 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
324 
328 {
329  rowNum = v.rowNum;
330  colNum = v.colNum;
331  rowPtrs = v.rowPtrs;
332  dsize = v.dsize;
333  data = v.data;
334 
335  v.rowNum = 0;
336  v.colNum = 0;
337  v.rowPtrs = NULL;
338  v.dsize = 0;
339  v.data = NULL;
340 }
341 #endif
342 
354 {
355  vpColVector A;
356  A.resize(rowNum, false);
357 
358  double *vd = A.data;
359  double *d = data;
360 
361  for (unsigned int i = 0; i < rowNum; i++)
362  *(vd++) = -(*d++);
363 
364  return A;
365 }
366 
388 {
389  vpColVector v(rowNum);
390 
391  double *vd = v.data;
392  double *d = data;
393 
394  for (unsigned int i = 0; i < rowNum; i++)
395  *(vd++) = (*d++) * x;
396  return v;
397 }
398 
418 {
419  for (unsigned int i = 0; i < rowNum; i++)
420  (*this)[i] *= x;
421  return (*this);
422 }
423 
442 {
443  for (unsigned int i = 0; i < rowNum; i++)
444  (*this)[i] /= x;
445  return (*this);
446 }
447 
468 {
469  vpColVector v(rowNum);
470 
471  double *vd = v.data;
472  double *d = data;
473 
474  for (unsigned int i = 0; i < rowNum; i++)
475  *(vd++) = (*d++) / x;
476  return v;
477 }
478 
485 {
486  if (M.getCols() != 1) {
487  throw(vpException(vpException::dimensionError, "Cannot transform a (%dx%d) matrix into a column vector",
488  M.getRows(), M.getCols()));
489  }
490 
491  resize(M.getRows(), false);
492  memcpy(data, M.data, rowNum * sizeof(double));
493 
494  return (*this);
495 }
496 
500 vpColVector &vpColVector::operator=(const std::vector<double> &v)
501 {
502  resize((unsigned int)v.size(), false);
503  for (unsigned int i = 0; i < v.size(); i++)
504  (*this)[i] = v[i];
505  return *this;
506 }
510 vpColVector &vpColVector::operator=(const std::vector<float> &v)
511 {
512  resize((unsigned int)v.size(), false);
513  for (unsigned int i = 0; i < v.size(); i++)
514  (*this)[i] = (float)v[i];
515  return *this;
516 }
517 
519 {
520  unsigned int k = v.rowNum;
521  if (rowNum != k) {
522  resize(k, false);
523  }
524 
525  memcpy(data, v.data, rowNum * sizeof(double));
526  return *this;
527 }
528 
533 {
534  unsigned int k = tv.getRows();
535  if (rowNum != k) {
536  resize(k, false);
537  }
538 
539  memcpy(data, tv.data, rowNum * sizeof(double));
540  return *this;
541 }
546 {
547  unsigned int k = rv.getRows();
548  if (rowNum != k) {
549  resize(k, false);
550  }
551 
552  memcpy(data, rv.data, rowNum * sizeof(double));
553  return *this;
554 }
559 {
560  unsigned int k = p.getRows();
561  if (rowNum != k) {
562  resize(k, false);
563  }
564 
565  memcpy(data, p.data, rowNum * sizeof(double));
566  return *this;
567 }
568 
590 {
591  *this = v;
592  return *this;
593 }
594 
620 {
621  for (unsigned int i = 0; i < rowNum; i++) {
622  for (unsigned int j = 0; j < colNum; j++) {
623  rowPtrs[i][j] = *x++;
624  }
625  }
626  return *this;
627 }
628 
648 {
649  resize(1, false);
650  data[0] = val;
651  return *this;
652 }
653 
673 {
674  resize(rowNum + 1, false);
675  data[rowNum - 1] = val;
676  return *this;
677 }
678 
681 {
682  double *d = data;
683 
684  for (unsigned int i = 0; i < rowNum; i++)
685  *(d++) = x;
686  return *this;
687 }
688 
693 std::vector<double> vpColVector::toStdVector()
694 {
695  std::vector<double> v(this->size());
696 
697  for (unsigned int i = 0; i < this->size(); i++)
698  v[i] = data[i];
699  return v;
700 }
701 
702 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
703 
707 {
708  if (this != &other) {
709  free(data);
710  free(rowPtrs);
711 
712  rowNum = other.rowNum;
713  colNum = other.colNum;
714  rowPtrs = other.rowPtrs;
715  dsize = other.dsize;
716  data = other.data;
717 
718  other.rowNum = 0;
719  other.colNum = 0;
720  other.rowPtrs = NULL;
721  other.dsize = 0;
722  other.data = NULL;
723  }
724 
725  return *this;
726 }
727 
751 vpColVector& vpColVector::operator=(const std::initializer_list<double> &list)
752 {
753  resize(static_cast<unsigned int>(list.size()), false);
754  std::copy(list.begin(), list.end(), data);
755  return *this;
756 }
757 #endif
758 
759 bool vpColVector::operator==(const vpColVector &v) const {
760  if (rowNum != v.rowNum ||
761  colNum != v.colNum /* should not happen */)
762  return false;
763 
764  for (unsigned int i = 0; i < rowNum; i++) {
765  if (!vpMath::equal(data[i], v.data[i], std::numeric_limits<double>::epsilon()))
766  return false;
767  }
768 
769  return true;
770 }
771 
772 bool vpColVector::operator!=(const vpColVector &v) const {
773  return !(*this == v);
774 }
775 
780 {
781  vpRowVector v(rowNum);
782  memcpy(v.data, data, rowNum * sizeof(double));
783  return v;
784 }
785 
790 vpRowVector vpColVector::transpose() const { return t(); }
791 
796 void vpColVector::transpose(vpRowVector &v) const { v = t(); }
797 
802 vpColVector operator*(const double &x, const vpColVector &v)
803 {
804  vpColVector vout;
805  vout = v * x;
806  return vout;
807 }
808 
816 double vpColVector::dotProd(const vpColVector &a, const vpColVector &b)
817 {
818  if (a.data == NULL) {
819  throw(vpException(vpException::fatalError, "Cannot compute the dot product: first vector empty"));
820  }
821  if (b.data == NULL) {
822  throw(vpException(vpException::fatalError, "Cannot compute the dot product: second vector empty"));
823  }
824  if (a.size() != b.size()) {
826  "Cannot compute the dot product between column vectors "
827  "with different dimensions (%d) and (%d)",
828  a.size(), b.size()));
829  }
830 
831  double *ad = a.data;
832  double *bd = b.data;
833 
834  double c = 0;
835  for (unsigned int i = 0; i < a.getRows(); i++)
836  c += *(ad++) * *(bd++);
837  // vpMatrix c = (a.t() * b);
838  // return c[0][0];
839  return c;
840 }
841 
850 {
851  x = x / sqrt(x.sumSquare());
852 
853  return x;
854 }
855 
864 {
865 
866  double sum_square = sumSquare();
867 
868  // if (sum != 0.0)
869  if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon())
870  *this /= sqrt(sum_square);
871 
872  // If sum = 0, we have a nul vector. So we return just.
873  return *this;
874 }
875 
905 {
906  if (v.data == NULL) {
907  throw(vpException(vpException::fatalError, "Cannot sort content of column vector: vector empty"));
908  }
909  vpColVector tab;
910  tab = v;
911  unsigned int nb_permutation = 1;
912  unsigned int i = 0;
913  while (nb_permutation != 0) {
914  nb_permutation = 0;
915  for (unsigned int j = v.getRows() - 1; j >= i + 1; j--) {
916  if ((tab[j] > tab[j - 1])) {
917  double tmp = tab[j];
918  tab[j] = tab[j - 1];
919  tab[j - 1] = tmp;
920  nb_permutation++;
921  }
922  }
923  i++;
924  }
925 
926  return tab;
927 }
928 
957 {
958  if (v.data == NULL) {
959  throw(vpException(vpException::fatalError, "Cannot sort content of column vector: vector empty"));
960  }
961  vpColVector tab;
962  tab = v;
963  unsigned int nb_permutation = 1;
964  unsigned int i = 0;
965  while (nb_permutation != 0) {
966  nb_permutation = 0;
967  for (unsigned int j = v.getRows() - 1; j >= i + 1; j--) {
968  if ((tab[j] < tab[j - 1])) {
969  double tmp = tab[j];
970  tab[j] = tab[j - 1];
971  tab[j - 1] = tmp;
972  nb_permutation++;
973  }
974  }
975  i++;
976  }
977 
978  return tab;
979 }
980 
997 void vpColVector::stack(double d)
998 {
999  this->resize(rowNum + 1, false);
1000  (*this)[rowNum - 1] = d;
1001 }
1002 
1022 void vpColVector::stack(const vpColVector &v) { *this = vpColVector::stack(*this, v); }
1023 
1043 {
1044  vpColVector C;
1045  vpColVector::stack(A, B, C);
1046  return C;
1047 }
1048 
1068 {
1069  unsigned int nrA = A.getRows();
1070  unsigned int nrB = B.getRows();
1071 
1072  if (nrA == 0 && nrB == 0) {
1073  C.resize(0);
1074  return;
1075  }
1076 
1077  if (nrB == 0) {
1078  C = A;
1079  return;
1080  }
1081 
1082  if (nrA == 0) {
1083  C = B;
1084  return;
1085  }
1086 
1087  // General case
1088  C.resize(nrA + nrB, false);
1089 
1090  for (unsigned int i = 0; i < nrA; i++)
1091  C[i] = A[i];
1092 
1093  for (unsigned int i = 0; i < nrB; i++)
1094  C[nrA + i] = B[i];
1095 }
1096 
1101 {
1102  if (v.data == NULL || v.size() == 0) {
1103  throw(vpException(vpException::dimensionError, "Cannot compute column vector mean: vector empty"));
1104  }
1105 
1106  // Use directly sum() function
1107  double mean = v.sum();
1108 
1109  // Old code used
1110  // double *vd = v.data;
1111  // for (unsigned int i=0 ; i < v.getRows() ; i++)
1112  // mean += *(vd++);
1113 
1114  return mean / v.getRows();
1115 }
1116 
1121 {
1122  if (v.data == NULL || v.size() == 0) {
1123  throw(vpException(vpException::dimensionError, "Cannot compute column vector median: vector empty"));
1124  }
1125 
1126  std::vector<double> vectorOfDoubles(v.data, v.data + v.rowNum);
1127 
1128  return vpMath::getMedian(vectorOfDoubles);
1129 }
1130 
1134 double vpColVector::stdev(const vpColVector &v, bool useBesselCorrection)
1135 {
1136  if (v.data == NULL || v.size() == 0) {
1137  throw(vpException(vpException::dimensionError, "Cannot compute column vector stdev: vector empty"));
1138  }
1139 
1140  return SimdVectorStdev(v.data, v.rowNum, useBesselCorrection);
1141 }
1142 
1158 {
1159  vpMatrix M;
1160  if (v.getRows() != 3) {
1161  throw(vpException(vpException::dimensionError, "Cannot compute skew vector of a non 3-dimention vector (%d)",
1162  v.getRows()));
1163  }
1164 
1165  M.resize(3, 3, false, false);
1166  M[0][0] = 0;
1167  M[0][1] = -v[2];
1168  M[0][2] = v[1];
1169  M[1][0] = v[2];
1170  M[1][1] = 0;
1171  M[1][2] = -v[0];
1172  M[2][0] = -v[1];
1173  M[2][1] = v[0];
1174  M[2][2] = 0;
1175 
1176  return M;
1177 }
1178 
1190 {
1191  if (a.getRows() != 3 || b.getRows() != 3) {
1193  "Cannot compute the cross product between column "
1194  "vector with dimension %d and %d",
1195  a.getRows(), b.getRows()));
1196  }
1197 
1198  return vpColVector::skew(a) * b;
1199 }
1200 
1209 vpMatrix vpColVector::reshape(unsigned int nrows, unsigned int ncols)
1210 {
1211  vpMatrix M(nrows, ncols);
1212  reshape(M, nrows, ncols);
1213  return M;
1214 }
1215 
1271 void vpColVector::reshape(vpMatrix &M, const unsigned int &nrows, const unsigned int &ncols)
1272 {
1273  if (dsize != nrows * ncols) {
1274  throw(vpException(vpException::dimensionError, "Cannot reshape (%dx1) column vector in (%dx%d) matrix", rowNum,
1275  M.getRows(), M.getCols()));
1276  }
1277  if ((M.getRows() != nrows) || (M.getCols() != ncols))
1278  M.resize(nrows, ncols, false, false);
1279 
1280  for (unsigned int j = 0; j < ncols; j++)
1281  for (unsigned int i = 0; i < nrows; i++)
1282  M[i][j] = data[j * nrows + i];
1283 }
1284 
1317 void vpColVector::insert(unsigned int i, const vpColVector &v)
1318 {
1319  if (i + v.size() > this->size())
1320  throw(vpException(vpException::dimensionError, "Unable to insert a column vector"));
1321 
1322  if (data != NULL && v.data != NULL && v.rowNum > 0) {
1323  memcpy(data + i, v.data, sizeof(double) * v.rowNum);
1324  }
1325 }
1326 
1346 int vpColVector::print(std::ostream &s, unsigned int length, char const *intro) const
1347 {
1348  typedef std::string::size_type size_type;
1349 
1350  unsigned int m = getRows();
1351  unsigned int n = 1;
1352 
1353  std::vector<std::string> values(m * n);
1354  std::ostringstream oss;
1355  std::ostringstream ossFixed;
1356  std::ios_base::fmtflags original_flags = oss.flags();
1357 
1358  // ossFixed <<std::fixed;
1359  ossFixed.setf(std::ios::fixed, std::ios::floatfield);
1360 
1361  size_type maxBefore = 0; // the length of the integral part
1362  size_type maxAfter = 0; // number of decimals plus
1363  // one place for the decimal point
1364  for (unsigned int i = 0; i < m; ++i) {
1365  oss.str("");
1366  oss << (*this)[i];
1367  if (oss.str().find("e") != std::string::npos) {
1368  ossFixed.str("");
1369  ossFixed << (*this)[i];
1370  oss.str(ossFixed.str());
1371  }
1372 
1373  values[i] = oss.str();
1374  size_type thislen = values[i].size();
1375  size_type p = values[i].find('.');
1376 
1377  if (p == std::string::npos) {
1378  maxBefore = vpMath::maximum(maxBefore, thislen);
1379  // maxAfter remains the same
1380  } else {
1381  maxBefore = vpMath::maximum(maxBefore, p);
1382  maxAfter = vpMath::maximum(maxAfter, thislen - p - 1);
1383  }
1384  }
1385 
1386  size_type totalLength = length;
1387  // increase totalLength according to maxBefore
1388  totalLength = vpMath::maximum(totalLength, maxBefore);
1389  // decrease maxAfter according to totalLength
1390  maxAfter = (std::min)(maxAfter, totalLength - maxBefore);
1391  if (maxAfter == 1)
1392  maxAfter = 0;
1393 
1394  // the following line is useful for debugging
1395  // std::cerr <<totalLength <<" " <<maxBefore <<" " <<maxAfter <<"\n";
1396 
1397  if (intro)
1398  s << intro;
1399  s << "[" << m << "," << n << "]=\n";
1400 
1401  for (unsigned int i = 0; i < m; i++) {
1402  s << " ";
1403  size_type p = values[i].find('.');
1404  s.setf(std::ios::right, std::ios::adjustfield);
1405  s.width((std::streamsize)maxBefore);
1406  s << values[i].substr(0, p).c_str();
1407 
1408  if (maxAfter > 0) {
1409  s.setf(std::ios::left, std::ios::adjustfield);
1410  if (p != std::string::npos) {
1411  s.width((std::streamsize)maxAfter);
1412  s << values[i].substr(p, maxAfter).c_str();
1413  } else {
1414  assert(maxAfter > 1);
1415  s.width((std::streamsize)maxAfter);
1416  s << ".0";
1417  }
1418  }
1419 
1420  s << ' ';
1421 
1422  s << std::endl;
1423  }
1424 
1425  s.flags(original_flags); // restore s to standard state
1426 
1427  return (int)(maxBefore + maxAfter);
1428 }
1429 
1435 double vpColVector::sum() const
1436 {
1437  return SimdVectorSum(data, rowNum);
1438 }
1439 
1447 {
1448  return SimdVectorSumSquare(data, rowNum);
1449 }
1450 
1462 {
1463  return frobeniusNorm();
1464 }
1465 
1475 {
1476  double norm = sumSquare();
1477 
1478  return sqrt(norm);
1479 }
1480 
1488 {
1489  if (v.getRows() != rowNum || v.getCols() != colNum) {
1490  throw(vpException(vpException::dimensionError, "Hadamard product: bad dimensions!"));
1491  }
1492 
1493  vpColVector out;
1494  out.resize(rowNum, false);
1495 
1496  SimdVectorHadamard(data, v.data, rowNum, out.data);
1497 
1498  return out;
1499 }
1500 
1513 {
1514  double norm = 0.0;
1515  for (unsigned int i = 0; i < rowNum; i++) {
1516  double x = fabs((*this)[i]);
1517  if (x > norm) {
1518  norm = x;
1519  }
1520  }
1521  return norm;
1522 }
1523 
1552 std::ostream &vpColVector::cppPrint(std::ostream &os, const std::string &matrixName, bool octet) const
1553 {
1554  os << "vpColVector " << matrixName << " (" << this->getRows() << "); " << std::endl;
1555 
1556  for (unsigned int i = 0; i < this->getRows(); ++i) {
1557 
1558  if (!octet) {
1559  os << matrixName << "[" << i << "] = " << (*this)[i] << "; " << std::endl;
1560  } else {
1561  for (unsigned int k = 0; k < sizeof(double); ++k) {
1562  os << "((unsigned char*)&(" << matrixName << "[" << i << "]) )[" << k << "] = 0x" << std::hex
1563  << (unsigned int)((unsigned char *)&((*this)[i]))[k] << "; " << std::endl;
1564  }
1565  }
1566  }
1567  std::cout << std::endl;
1568  return os;
1569 };
1570 
1597 std::ostream &vpColVector::csvPrint(std::ostream &os) const
1598 {
1599  for (unsigned int i = 0; i < this->getRows(); ++i) {
1600  os << (*this)[i];
1601 
1602  os << std::endl;
1603  }
1604  return os;
1605 };
1606 
1632 std::ostream &vpColVector::maplePrint(std::ostream &os) const
1633 {
1634  os << "([ " << std::endl;
1635  for (unsigned int i = 0; i < this->getRows(); ++i) {
1636  os << "[";
1637  os << (*this)[i] << ", ";
1638  os << "]," << std::endl;
1639  }
1640  os << "])" << std::endl;
1641  return os;
1642 };
1643 
1680 std::ostream &vpColVector::matlabPrint(std::ostream &os) const
1681 {
1682  os << "[ ";
1683  for (unsigned int i = 0; i < this->getRows(); ++i) {
1684  os << (*this)[i] << ", ";
1685  if (this->getRows() != i + 1) {
1686  os << ";" << std::endl;
1687  } else {
1688  os << "]" << std::endl;
1689  }
1690  }
1691  return os;
1692 };
1693 
1694 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
1695 
1709 void vpColVector::insert(const vpColVector &v, unsigned int r, unsigned int c)
1710 {
1711  (void)c;
1712  insert(r, v);
1713 }
1714 #endif // defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
bool operator==(const vpColVector &v) const
Comparison operator.
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:153
Implementation of a generic rotation vector.
double frobeniusNorm() const
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Definition: vpArray2D.h:304
vp_deprecated void init()
Definition: vpColVector.h:377
static vpColVector invSort(const vpColVector &v)
static vpColVector sort(const vpColVector &v)
vp_deprecated double euclideanNorm() const
Implementation of row vector and the associated operations.
Definition: vpRowVector.h:115
std::ostream & matlabPrint(std::ostream &os) const
static double getMedian(const std::vector< double > &v)
Definition: vpMath.cpp:220
vpColVector operator*(const double &x, const vpColVector &v)
static bool equal(double x, double y, double s=0.001)
Definition: vpMath.h:293
vpColVector & operator,(double val)
vpColVector operator+(const vpColVector &v) const
Operator that allows to add two column vectors.
Definition: vpColVector.cpp:64
error that can be emited by ViSP classes.
Definition: vpException.h:71
std::ostream & csvPrint(std::ostream &os) const
double * data
Address of the first element of the data array.
Definition: vpArray2D.h:145
Implementation of a generic 2D array used as base class for matrices and vectors. ...
Definition: vpArray2D.h:131
vpColVector & operator*=(double x)
unsigned int size() const
Return the number of elements of the 2D array.
Definition: vpArray2D.h:291
unsigned int getCols() const
Definition: vpArray2D.h:279
vpColVector operator-() const
static double median(const vpColVector &v)
static Type maximum(const Type &a, const Type &b)
Definition: vpMath.h:145
vpColVector & operator/=(double x)
int print(std::ostream &s, unsigned int length, char const *intro=0) const
bool operator!=(const vpColVector &v) const
unsigned int rowNum
Number of rows in the array.
Definition: vpArray2D.h:135
double infinityNorm() const
vpColVector & normalize()
vpColVector hadamard(const vpColVector &v) const
std::ostream & maplePrint(std::ostream &os) const
vpRowVector t() const
std::ostream & cppPrint(std::ostream &os, const std::string &matrixName="A", bool octet=false) const
vpColVector & operator<<(const vpColVector &v)
static double mean(const vpColVector &v)
vpColVector operator/(double x) const
unsigned int getRows() const
Definition: vpArray2D.h:289
vpColVector & operator-=(vpColVector v)
Operator that allows to substract two column vectors.
unsigned int colNum
Number of columns in the array.
Definition: vpArray2D.h:137
void insert(unsigned int i, const vpColVector &v)
double sumSquare() const
std::vector< double > toStdVector()
void resize(unsigned int i, bool flagNullify=true)
Definition: vpColVector.h:310
vpColVector & operator=(const vpColVector &v)
Copy operator. Allow operation such as A = v.
vpColVector & operator+=(vpColVector v)
Operator that allows to add two column vectors.
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
static double dotProd(const vpColVector &a, const vpColVector &b)
void stack(double d)
vpRowVector transpose() const
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:151
vpColVector()
Basic constructor that creates an empty 0-size column vector.
Definition: vpColVector.h:136
static vpMatrix skew(const vpColVector &v)
unsigned int dsize
Current array size (rowNum * colNum)
Definition: vpArray2D.h:141
void reshape(vpMatrix &M, const unsigned int &nrows, const unsigned int &ncols)
static double stdev(const vpColVector &v, bool useBesselCorrection=false)
static vpColVector crossProd(const vpColVector &a, const vpColVector &b)
double operator*(const vpColVector &x) const
Class that consider the case of a translation vector.
double ** rowPtrs
Address of the first element of each rows.
Definition: vpArray2D.h:139
double sum() const