Visual Servoing Platform  version 3.5.1 under development (2022-09-30)
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 subtract (%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) subtraction",
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 
264 vpColVector::vpColVector(const vpRotationVector &v) : vpArray2D<double>(v.size(), 1)
265 {
266  for (unsigned int i = 0; i < v.size(); i++)
267  (*this)[i] = v[i];
268 }
269 
270 vpColVector::vpColVector(const vpPoseVector &p) : vpArray2D<double>(p.size(), 1)
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 
295 vpColVector::vpColVector(const vpMatrix &M) : vpArray2D<double>(M.getRows(), 1)
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)
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() const
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)
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 
760 {
761  if (rowNum != v.rowNum || 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 { return !(*this == v); }
773 
778 {
779  vpRowVector v(rowNum);
780  memcpy(v.data, data, rowNum * sizeof(double));
781  return v;
782 }
783 
788 vpRowVector vpColVector::transpose() const { return t(); }
789 
794 void vpColVector::transpose(vpRowVector &v) const { v = t(); }
795 
800 vpColVector operator*(const double &x, const vpColVector &v)
801 {
802  vpColVector vout;
803  vout = v * x;
804  return vout;
805 }
806 
814 double vpColVector::dotProd(const vpColVector &a, const vpColVector &b)
815 {
816  if (a.data == NULL) {
817  throw(vpException(vpException::fatalError, "Cannot compute the dot product: first vector empty"));
818  }
819  if (b.data == NULL) {
820  throw(vpException(vpException::fatalError, "Cannot compute the dot product: second vector empty"));
821  }
822  if (a.size() != b.size()) {
824  "Cannot compute the dot product between column vectors "
825  "with different dimensions (%d) and (%d)",
826  a.size(), b.size()));
827  }
828 
829  double *ad = a.data;
830  double *bd = b.data;
831 
832  double c = 0;
833  for (unsigned int i = 0; i < a.getRows(); i++)
834  c += *(ad++) * *(bd++);
835  // vpMatrix c = (a.t() * b);
836  // return c[0][0];
837  return c;
838 }
839 
852 {
853  x /= sqrt(x.sumSquare());
854 
855  return x;
856 }
857 
869 {
870 
871  double sum_square = sumSquare();
872 
873  // if (sum != 0.0)
874  if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon())
875  *this /= sqrt(sum_square);
876 
877  // If sum = 0, we have a nul vector. So we return just.
878  return *this;
879 }
880 
910 {
911  if (v.data == NULL) {
912  throw(vpException(vpException::fatalError, "Cannot sort content of column vector: vector empty"));
913  }
914  vpColVector tab;
915  tab = v;
916  unsigned int nb_permutation = 1;
917  unsigned int i = 0;
918  while (nb_permutation != 0) {
919  nb_permutation = 0;
920  for (unsigned int j = v.getRows() - 1; j >= i + 1; j--) {
921  if ((tab[j] > tab[j - 1])) {
922  double tmp = tab[j];
923  tab[j] = tab[j - 1];
924  tab[j - 1] = tmp;
925  nb_permutation++;
926  }
927  }
928  i++;
929  }
930 
931  return tab;
932 }
933 
962 {
963  if (v.data == NULL) {
964  throw(vpException(vpException::fatalError, "Cannot sort content of column vector: vector empty"));
965  }
966  vpColVector tab;
967  tab = v;
968  unsigned int nb_permutation = 1;
969  unsigned int i = 0;
970  while (nb_permutation != 0) {
971  nb_permutation = 0;
972  for (unsigned int j = v.getRows() - 1; j >= i + 1; j--) {
973  if ((tab[j] < tab[j - 1])) {
974  double tmp = tab[j];
975  tab[j] = tab[j - 1];
976  tab[j - 1] = tmp;
977  nb_permutation++;
978  }
979  }
980  i++;
981  }
982 
983  return tab;
984 }
985 
1002 void vpColVector::stack(double d)
1003 {
1004  this->resize(rowNum + 1, false);
1005  (*this)[rowNum - 1] = d;
1006 }
1007 
1027 void vpColVector::stack(const vpColVector &v) { *this = vpColVector::stack(*this, v); }
1028 
1048 {
1049  vpColVector C;
1050  vpColVector::stack(A, B, C);
1051  return C;
1052 }
1053 
1073 {
1074  unsigned int nrA = A.getRows();
1075  unsigned int nrB = B.getRows();
1076 
1077  if (nrA == 0 && nrB == 0) {
1078  C.resize(0);
1079  return;
1080  }
1081 
1082  if (nrB == 0) {
1083  C = A;
1084  return;
1085  }
1086 
1087  if (nrA == 0) {
1088  C = B;
1089  return;
1090  }
1091 
1092  // General case
1093  C.resize(nrA + nrB, false);
1094 
1095  for (unsigned int i = 0; i < nrA; i++)
1096  C[i] = A[i];
1097 
1098  for (unsigned int i = 0; i < nrB; i++)
1099  C[nrA + i] = B[i];
1100 }
1101 
1106 {
1107  if (v.data == NULL || v.size() == 0) {
1108  throw(vpException(vpException::dimensionError, "Cannot compute column vector mean: vector empty"));
1109  }
1110 
1111  // Use directly sum() function
1112  double mean = v.sum();
1113 
1114  // Old code used
1115  // double *vd = v.data;
1116  // for (unsigned int i=0 ; i < v.getRows() ; i++)
1117  // mean += *(vd++);
1118 
1119  return mean / v.getRows();
1120 }
1121 
1126 {
1127  if (v.data == NULL || v.size() == 0) {
1128  throw(vpException(vpException::dimensionError, "Cannot compute column vector median: vector empty"));
1129  }
1130 
1131  std::vector<double> vectorOfDoubles(v.data, v.data + v.rowNum);
1132 
1133  return vpMath::getMedian(vectorOfDoubles);
1134 }
1135 
1139 double vpColVector::stdev(const vpColVector &v, bool useBesselCorrection)
1140 {
1141  if (v.data == NULL || v.size() == 0) {
1142  throw(vpException(vpException::dimensionError, "Cannot compute column vector stdev: vector empty"));
1143  }
1144 
1145  return SimdVectorStdev(v.data, v.rowNum, useBesselCorrection);
1146 }
1147 
1163 {
1164  vpMatrix M;
1165  if (v.getRows() != 3) {
1166  throw(vpException(vpException::dimensionError, "Cannot compute skew vector of a non 3-dimention vector (%d)",
1167  v.getRows()));
1168  }
1169 
1170  M.resize(3, 3, false, false);
1171  M[0][0] = 0;
1172  M[0][1] = -v[2];
1173  M[0][2] = v[1];
1174  M[1][0] = v[2];
1175  M[1][1] = 0;
1176  M[1][2] = -v[0];
1177  M[2][0] = -v[1];
1178  M[2][1] = v[0];
1179  M[2][2] = 0;
1180 
1181  return M;
1182 }
1183 
1194 {
1195  if (a.getRows() != 3 || b.getRows() != 3) {
1197  "Cannot compute the cross product between column "
1198  "vector with dimension %d and %d",
1199  a.getRows(), b.getRows()));
1200  }
1201 
1202  return vpColVector::skew(a) * b;
1203 }
1204 
1213 vpMatrix vpColVector::reshape(unsigned int nrows, unsigned int ncols)
1214 {
1215  vpMatrix M(nrows, ncols);
1216  reshape(M, nrows, ncols);
1217  return M;
1218 }
1219 
1275 void vpColVector::reshape(vpMatrix &M, const unsigned int &nrows, const unsigned int &ncols)
1276 {
1277  if (dsize != nrows * ncols) {
1278  throw(vpException(vpException::dimensionError, "Cannot reshape (%dx1) column vector in (%dx%d) matrix", rowNum,
1279  M.getRows(), M.getCols()));
1280  }
1281  if ((M.getRows() != nrows) || (M.getCols() != ncols))
1282  M.resize(nrows, ncols, false, false);
1283 
1284  for (unsigned int j = 0; j < ncols; j++)
1285  for (unsigned int i = 0; i < nrows; i++)
1286  M[i][j] = data[j * nrows + i];
1287 }
1288 
1321 void vpColVector::insert(unsigned int i, const vpColVector &v)
1322 {
1323  if (i + v.size() > this->size())
1324  throw(vpException(vpException::dimensionError, "Unable to insert a column vector"));
1325 
1326  if (data != NULL && v.data != NULL && v.rowNum > 0) {
1327  memcpy(data + i, v.data, sizeof(double) * v.rowNum);
1328  }
1329 }
1330 
1350 int vpColVector::print(std::ostream &s, unsigned int length, char const *intro) const
1351 {
1352  typedef std::string::size_type size_type;
1353 
1354  unsigned int m = getRows();
1355  unsigned int n = 1;
1356 
1357  std::vector<std::string> values(m * n);
1358  std::ostringstream oss;
1359  std::ostringstream ossFixed;
1360  std::ios_base::fmtflags original_flags = oss.flags();
1361 
1362  // ossFixed <<std::fixed;
1363  ossFixed.setf(std::ios::fixed, std::ios::floatfield);
1364 
1365  size_type maxBefore = 0; // the length of the integral part
1366  size_type maxAfter = 0; // number of decimals plus
1367  // one place for the decimal point
1368  for (unsigned int i = 0; i < m; ++i) {
1369  oss.str("");
1370  oss << (*this)[i];
1371  if (oss.str().find("e") != std::string::npos) {
1372  ossFixed.str("");
1373  ossFixed << (*this)[i];
1374  oss.str(ossFixed.str());
1375  }
1376 
1377  values[i] = oss.str();
1378  size_type thislen = values[i].size();
1379  size_type p = values[i].find('.');
1380 
1381  if (p == std::string::npos) {
1382  maxBefore = vpMath::maximum(maxBefore, thislen);
1383  // maxAfter remains the same
1384  } else {
1385  maxBefore = vpMath::maximum(maxBefore, p);
1386  maxAfter = vpMath::maximum(maxAfter, thislen - p - 1);
1387  }
1388  }
1389 
1390  size_type totalLength = length;
1391  // increase totalLength according to maxBefore
1392  totalLength = vpMath::maximum(totalLength, maxBefore);
1393  // decrease maxAfter according to totalLength
1394  maxAfter = (std::min)(maxAfter, totalLength - maxBefore);
1395  if (maxAfter == 1)
1396  maxAfter = 0;
1397 
1398  // the following line is useful for debugging
1399  // std::cerr <<totalLength <<" " <<maxBefore <<" " <<maxAfter <<"\n";
1400 
1401  if (intro)
1402  s << intro;
1403  s << "[" << m << "," << n << "]=\n";
1404 
1405  for (unsigned int i = 0; i < m; i++) {
1406  s << " ";
1407  size_type p = values[i].find('.');
1408  s.setf(std::ios::right, std::ios::adjustfield);
1409  s.width((std::streamsize)maxBefore);
1410  s << values[i].substr(0, p).c_str();
1411 
1412  if (maxAfter > 0) {
1413  s.setf(std::ios::left, std::ios::adjustfield);
1414  if (p != std::string::npos) {
1415  s.width((std::streamsize)maxAfter);
1416  s << values[i].substr(p, maxAfter).c_str();
1417  } else {
1418  assert(maxAfter > 1);
1419  s.width((std::streamsize)maxAfter);
1420  s << ".0";
1421  }
1422  }
1423 
1424  s << ' ';
1425 
1426  s << std::endl;
1427  }
1428 
1429  s.flags(original_flags); // restore s to standard state
1430 
1431  return (int)(maxBefore + maxAfter);
1432 }
1433 
1439 double vpColVector::sum() const { return SimdVectorSum(data, rowNum); }
1440 
1447 double vpColVector::sumSquare() const { return SimdVectorSumSquare(data, rowNum); }
1448 
1459 double vpColVector::euclideanNorm() const { return frobeniusNorm(); }
1460 
1470 {
1471  double norm = sumSquare();
1472 
1473  return sqrt(norm);
1474 }
1475 
1483 {
1484  if (v.getRows() != rowNum || v.getCols() != colNum) {
1485  throw(vpException(vpException::dimensionError, "Hadamard product: bad dimensions!"));
1486  }
1487 
1488  vpColVector out;
1489  out.resize(rowNum, false);
1490 
1491  SimdVectorHadamard(data, v.data, rowNum, out.data);
1492 
1493  return out;
1494 }
1495 
1508 {
1509  double norm = 0.0;
1510  for (unsigned int i = 0; i < rowNum; i++) {
1511  double x = fabs((*this)[i]);
1512  if (x > norm) {
1513  norm = x;
1514  }
1515  }
1516  return norm;
1517 }
1518 
1547 std::ostream &vpColVector::cppPrint(std::ostream &os, const std::string &matrixName, bool octet) const
1548 {
1549  os << "vpColVector " << matrixName << " (" << this->getRows() << "); " << std::endl;
1550 
1551  for (unsigned int i = 0; i < this->getRows(); ++i) {
1552 
1553  if (!octet) {
1554  os << matrixName << "[" << i << "] = " << (*this)[i] << "; " << std::endl;
1555  } else {
1556  for (unsigned int k = 0; k < sizeof(double); ++k) {
1557  os << "((unsigned char*)&(" << matrixName << "[" << i << "]) )[" << k << "] = 0x" << std::hex
1558  << (unsigned int)((unsigned char *)&((*this)[i]))[k] << "; " << std::endl;
1559  }
1560  }
1561  }
1562  std::cout << std::endl;
1563  return os;
1564 };
1565 
1592 std::ostream &vpColVector::csvPrint(std::ostream &os) const
1593 {
1594  for (unsigned int i = 0; i < this->getRows(); ++i) {
1595  os << (*this)[i];
1596 
1597  os << std::endl;
1598  }
1599  return os;
1600 };
1601 
1627 std::ostream &vpColVector::maplePrint(std::ostream &os) const
1628 {
1629  os << "([ " << std::endl;
1630  for (unsigned int i = 0; i < this->getRows(); ++i) {
1631  os << "[";
1632  os << (*this)[i] << ", ";
1633  os << "]," << std::endl;
1634  }
1635  os << "])" << std::endl;
1636  return os;
1637 };
1638 
1675 std::ostream &vpColVector::matlabPrint(std::ostream &os) const
1676 {
1677  os << "[ ";
1678  for (unsigned int i = 0; i < this->getRows(); ++i) {
1679  os << (*this)[i] << ", ";
1680  if (this->getRows() != i + 1) {
1681  os << ";" << std::endl;
1682  } else {
1683  os << "]" << std::endl;
1684  }
1685  }
1686  return os;
1687 };
1688 
1689 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
1704 void vpColVector::insert(const vpColVector &v, unsigned int r, unsigned int c)
1705 {
1706  (void)c;
1707  insert(r, v);
1708 }
1709 #endif // defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
Implementation of a generic 2D array used as base class for matrices and vectors.
Definition: vpArray2D.h:132
unsigned int getCols() const
Definition: vpArray2D.h:281
double * data
Address of the first element of the data array.
Definition: vpArray2D.h:145
double ** rowPtrs
Address of the first element of each rows.
Definition: vpArray2D.h:139
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Definition: vpArray2D.h:306
unsigned int rowNum
Number of rows in the array.
Definition: vpArray2D.h:135
unsigned int dsize
Current array size (rowNum * colNum)
Definition: vpArray2D.h:141
unsigned int size() const
Return the number of elements of the 2D array.
Definition: vpArray2D.h:293
unsigned int getRows() const
Definition: vpArray2D.h:291
unsigned int colNum
Number of columns in the array.
Definition: vpArray2D.h:137
Implementation of column vector and the associated operations.
Definition: vpColVector.h:131
void reshape(vpMatrix &M, const unsigned int &nrows, const unsigned int &ncols)
static double dotProd(const vpColVector &a, const vpColVector &b)
vpColVector operator-() const
vpColVector & operator*=(double x)
std::ostream & matlabPrint(std::ostream &os) const
vp_deprecated double euclideanNorm() const
vpColVector & operator=(const vpColVector &v)
Copy operator. Allow operation such as A = v.
vpColVector operator/(double x) const
vpColVector & normalize()
static double median(const vpColVector &v)
vpColVector hadamard(const vpColVector &v) const
double sumSquare() const
std::ostream & csvPrint(std::ostream &os) const
std::ostream & maplePrint(std::ostream &os) const
vpColVector & operator,(double val)
int print(std::ostream &s, unsigned int length, char const *intro=0) const
bool operator==(const vpColVector &v) const
Comparison operator.
vpColVector & operator/=(double x)
static vpColVector invSort(const vpColVector &v)
void stack(double d)
bool operator!=(const vpColVector &v) const
static vpMatrix skew(const vpColVector &v)
vp_deprecated void init()
Definition: vpColVector.h:380
double operator*(const vpColVector &x) const
vpColVector()
Basic constructor that creates an empty 0-size column vector.
Definition: vpColVector.h:136
vpColVector operator+(const vpColVector &v) const
Operator that allows to add two column vectors.
Definition: vpColVector.cpp:64
std::vector< double > toStdVector() const
static double mean(const vpColVector &v)
vpColVector operator*(const double &x, const vpColVector &v)
vpColVector & operator+=(vpColVector v)
Operator that allows to add two column vectors.
vpRowVector t() const
static vpColVector crossProd(const vpColVector &a, const vpColVector &b)
double infinityNorm() const
vpColVector & operator<<(const vpColVector &v)
vpRowVector transpose() const
static double stdev(const vpColVector &v, bool useBesselCorrection=false)
std::ostream & cppPrint(std::ostream &os, const std::string &matrixName="A", bool octet=false) const
double frobeniusNorm() const
vpColVector & operator-=(vpColVector v)
Operator that allows to subtract two column vectors.
static vpColVector sort(const vpColVector &v)
void insert(unsigned int i, const vpColVector &v)
double sum() const
void resize(unsigned int i, bool flagNullify=true)
Definition: vpColVector.h:314
error that can be emited by ViSP classes.
Definition: vpException.h:72
@ dimensionError
Bad dimension.
Definition: vpException.h:95
@ fatalError
Fatal error.
Definition: vpException.h:96
static double getMedian(const std::vector< double > &v)
Definition: vpMath.cpp:262
static Type maximum(const Type &a, const Type &b)
Definition: vpMath.h:171
static bool equal(double x, double y, double s=0.001)
Definition: vpMath.h:364
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:154
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:152
Implementation of a generic rotation vector.
Implementation of row vector and the associated operations.
Definition: vpRowVector.h:116
Class that consider the case of a translation vector.