Visual Servoing Platform  version 3.6.1 under development (2023-11-30)
vpColVector.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See https://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Provide some simple operation on column vectors.
32  */
33 
40 #include <assert.h>
41 #include <cmath> // std::fabs
42 #include <limits> // numeric_limits
43 #include <math.h>
44 #include <sstream>
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <string.h>
48 
49 #include <visp3/core/vpCPUFeatures.h>
50 #include <visp3/core/vpColVector.h>
51 #include <visp3/core/vpDebug.h>
52 #include <visp3/core/vpException.h>
53 #include <visp3/core/vpMath.h>
54 #include <visp3/core/vpRotationVector.h>
55 
56 #include <Simd/SimdLib.hpp>
57 
59 {
60  if (getRows() != v.getRows()) {
61  throw(vpException(vpException::dimensionError, "Cannot add (%dx1) column vector to (%dx1) column vector", getRows(),
62  v.getRows()));
63  }
65 
66  for (unsigned int i = 0; i < rowNum; i++)
67  r[i] = (*this)[i] + v[i];
68  return r;
69 }
70 
72 {
73  if (getRows() != 3) {
74  throw(vpException(vpException::dimensionError, "Cannot add %d-dimension column vector to a translation vector",
75  getRows()));
76  }
78 
79  for (unsigned int i = 0; i < 3; i++)
80  s[i] = (*this)[i] + t[i];
81 
82  return s;
83 }
84 
86 {
87  if (getRows() != v.getRows()) {
88  throw(vpException(vpException::dimensionError, "Cannot add (%dx1) column vector to (%dx1) column vector", getRows(),
89  v.getRows()));
90  }
91 
92  for (unsigned int i = 0; i < rowNum; i++)
93  (*this)[i] += v[i];
94  return (*this);
95 }
96 
98 {
99  if (getRows() != v.getRows()) {
100  throw(vpException(vpException::dimensionError, "Cannot subtract (%dx1) column vector to (%dx1) column vector",
101  getRows(), v.getRows()));
102  }
103 
104  for (unsigned int i = 0; i < rowNum; i++)
105  (*this)[i] -= v[i];
106  return (*this);
107 }
108 
109 double vpColVector::operator*(const vpColVector &v) const
110 {
111  if (size() != v.size()) {
113  "Cannot compute the dot product between column vectors "
114  "with different dimensions (%d) and (%d)",
115  size(), v.size()));
116  }
117  double r = 0;
118 
119  for (unsigned int i = 0; i < rowNum; i++)
120  r += (*this)[i] * v[i];
121  return r;
122 }
123 
125 {
126  vpMatrix M(rowNum, v.getCols());
127  for (unsigned int i = 0; i < rowNum; i++) {
128  for (unsigned int j = 0; j < v.getCols(); j++) {
129  M[i][j] = (*this)[i] * v[j];
130  }
131  }
132  return M;
133 }
134 
136 {
137  if (getRows() != m.getRows()) {
139  "Bad size during vpColVector (%dx1) and vpColVector "
140  "(%dx1) subtraction",
141  getRows(), m.getRows()));
142  }
143  vpColVector v(rowNum);
144 
145  for (unsigned int i = 0; i < rowNum; i++)
146  v[i] = (*this)[i] - m[i];
147  return v;
148 }
149 
150 vpColVector::vpColVector(const vpColVector &v, unsigned int r, unsigned int nrows) : vpArray2D<double>(nrows, 1)
151 {
152  init(v, r, nrows);
153 }
154 
155 void vpColVector::init(const vpColVector &v, unsigned int r, unsigned int nrows)
156 {
157  unsigned int rnrows = r + nrows;
158 
159  if (rnrows > v.getRows())
160  throw(vpException(vpException::dimensionError, "Bad row dimension (%d > %d) used to initialize vpColVector", rnrows,
161  v.getRows()));
162  resize(nrows, false);
163 
164  if (this->rowPtrs == nullptr) // Fix coverity scan: explicit null dereferenced
165  return; // Nothing to do
166  for (unsigned int i = r; i < rnrows; i++)
167  (*this)[i - r] = v[i];
168 }
169 
170 vpColVector::vpColVector(const vpRotationVector &v) : vpArray2D<double>(v.size(), 1)
171 {
172  for (unsigned int i = 0; i < v.size(); i++)
173  (*this)[i] = v[i];
174 }
175 
176 vpColVector::vpColVector(const vpPoseVector &p) : vpArray2D<double>(p.size(), 1)
177 {
178  for (unsigned int i = 0; i < p.size(); i++)
179  (*this)[i] = p[i];
180 }
181 
183 {
184  for (unsigned int i = 0; i < v.size(); i++)
185  (*this)[i] = v[i];
186 }
187 
188 vpColVector::vpColVector(const vpMatrix &M, unsigned int j) : vpArray2D<double>(M.getRows(), 1)
189 {
190  for (unsigned int i = 0; i < M.getCols(); i++)
191  (*this)[i] = M[i][j];
192 }
193 
194 vpColVector::vpColVector(const vpMatrix &M) : vpArray2D<double>(M.getRows(), 1)
195 {
196  if (M.getCols() != 1) {
197  throw(vpException(vpException::dimensionError, "Cannot construct a (%dx1) row vector from a (%dx%d) matrix",
198  M.getRows(), M.getRows(), M.getCols()));
199  }
200 
201  for (unsigned int i = 0; i < M.getRows(); i++)
202  (*this)[i] = M[i][0];
203 }
204 
205 vpColVector::vpColVector(const std::vector<double> &v) : vpArray2D<double>((unsigned int)v.size(), 1)
206 {
207  for (unsigned int i = 0; i < v.size(); i++)
208  (*this)[i] = v[i];
209 }
210 
211 vpColVector::vpColVector(const std::vector<float> &v) : vpArray2D<double>((unsigned int)v.size(), 1)
212 {
213  for (unsigned int i = 0; i < v.size(); i++)
214  (*this)[i] = (double)(v[i]);
215 }
216 
218 {
219  rowNum = v.rowNum;
220  colNum = v.colNum;
221  rowPtrs = v.rowPtrs;
222  dsize = v.dsize;
223  data = v.data;
224 
225  v.rowNum = 0;
226  v.colNum = 0;
227  v.rowPtrs = nullptr;
228  v.dsize = 0;
229  v.data = nullptr;
230 }
231 
233 {
234  vpColVector A;
235  A.resize(rowNum, false);
236 
237  double *vd = A.data;
238  double *d = data;
239 
240  for (unsigned int i = 0; i < rowNum; i++)
241  *(vd++) = -(*d++);
242 
243  return A;
244 }
245 
247 {
248  vpColVector v(rowNum);
249 
250  double *vd = v.data;
251  double *d = data;
252 
253  for (unsigned int i = 0; i < rowNum; i++)
254  *(vd++) = (*d++) * x;
255  return v;
256 }
257 
259 {
260  for (unsigned int i = 0; i < rowNum; i++)
261  (*this)[i] *= x;
262  return (*this);
263 }
264 
266 {
267  for (unsigned int i = 0; i < rowNum; i++)
268  (*this)[i] /= x;
269  return (*this);
270 }
271 
273 {
274  vpColVector v(rowNum);
275 
276  double *vd = v.data;
277  double *d = data;
278 
279  for (unsigned int i = 0; i < rowNum; i++)
280  *(vd++) = (*d++) / x;
281  return v;
282 }
283 
285 {
286  if (M.getCols() != 1) {
287  throw(vpException(vpException::dimensionError, "Cannot transform a (%dx%d) matrix into a column vector",
288  M.getRows(), M.getCols()));
289  }
290 
291  resize(M.getRows(), false);
292  memcpy(data, M.data, rowNum * sizeof(double));
293 
294  return (*this);
295 }
296 
297 vpColVector &vpColVector::operator=(const std::vector<double> &v)
298 {
299  resize((unsigned int)v.size(), false);
300  for (unsigned int i = 0; i < v.size(); i++)
301  (*this)[i] = v[i];
302  return *this;
303 }
304 
305 vpColVector &vpColVector::operator=(const std::vector<float> &v)
306 {
307  resize((unsigned int)v.size(), false);
308  for (unsigned int i = 0; i < v.size(); i++)
309  (*this)[i] = (float)v[i];
310  return *this;
311 }
312 
314 {
315  unsigned int k = v.rowNum;
316  if (rowNum != k) {
317  resize(k, false);
318  }
319 
320  memcpy(data, v.data, rowNum * sizeof(double));
321  return *this;
322 }
323 
325 {
326  unsigned int k = tv.getRows();
327  if (rowNum != k) {
328  resize(k, false);
329  }
330 
331  memcpy(data, tv.data, rowNum * sizeof(double));
332  return *this;
333 }
334 
336 {
337  unsigned int k = rv.getRows();
338  if (rowNum != k) {
339  resize(k, false);
340  }
341 
342  memcpy(data, rv.data, rowNum * sizeof(double));
343  return *this;
344 }
345 
347 {
348  unsigned int k = p.getRows();
349  if (rowNum != k) {
350  resize(k, false);
351  }
352 
353  memcpy(data, p.data, rowNum * sizeof(double));
354  return *this;
355 }
356 
358 {
359  *this = v;
360  return *this;
361 }
362 
364 {
365  for (unsigned int i = 0; i < rowNum; i++) {
366  for (unsigned int j = 0; j < colNum; j++) {
367  rowPtrs[i][j] = *x++;
368  }
369  }
370  return *this;
371 }
372 
374 {
375  resize(1, false);
376  data[0] = val;
377  return *this;
378 }
379 
381 {
382  resize(rowNum + 1, false);
383  data[rowNum - 1] = val;
384  return *this;
385 }
386 
388 {
389  double *d = data;
390 
391  for (unsigned int i = 0; i < rowNum; i++)
392  *(d++) = x;
393  return *this;
394 }
395 
396 std::vector<double> vpColVector::toStdVector() const
397 {
398  std::vector<double> v(this->size());
399 
400  for (unsigned int i = 0; i < this->size(); i++)
401  v[i] = data[i];
402  return v;
403 }
404 
406 {
407  if (this != &other) {
408  free(data);
409  free(rowPtrs);
410 
411  rowNum = other.rowNum;
412  colNum = other.colNum;
413  rowPtrs = other.rowPtrs;
414  dsize = other.dsize;
415  data = other.data;
416 
417  other.rowNum = 0;
418  other.colNum = 0;
419  other.rowPtrs = nullptr;
420  other.dsize = 0;
421  other.data = nullptr;
422  }
423 
424  return *this;
425 }
426 
427 vpColVector &vpColVector::operator=(const std::initializer_list<double> &list)
428 {
429  resize(static_cast<unsigned int>(list.size()), false);
430  std::copy(list.begin(), list.end(), data);
431  return *this;
432 }
433 
435 {
436  if (rowNum != v.rowNum || colNum != v.colNum /* should not happen */)
437  return false;
438 
439  for (unsigned int i = 0; i < rowNum; i++) {
440  if (!vpMath::equal(data[i], v.data[i], std::numeric_limits<double>::epsilon()))
441  return false;
442  }
443 
444  return true;
445 }
446 
447 bool vpColVector::operator==(double v) const
448 {
449  for (unsigned int i = 0; i < rowNum; i++) {
450  if (!vpMath::equal(data[i], v, std::numeric_limits<double>::epsilon()))
451  return false;
452  }
453 
454  return true;
455 }
456 
457 bool vpColVector::operator!=(const vpColVector &v) const { return !(*this == v); }
458 
459 bool vpColVector::operator!=(double v) const { return !(*this == v); }
460 
462 {
463  vpRowVector v(rowNum);
464  memcpy(v.data, data, rowNum * sizeof(double));
465  return v;
466 }
467 
468 vpRowVector vpColVector::transpose() const { return t(); }
469 
470 void vpColVector::transpose(vpRowVector &v) const { v = t(); }
471 
472 vpColVector operator*(const double &x, const vpColVector &v)
473 {
474  vpColVector vout;
475  vout = v * x;
476  return vout;
477 }
478 
479 double vpColVector::dotProd(const vpColVector &a, const vpColVector &b)
480 {
481  if (a.data == nullptr) {
482  throw(vpException(vpException::fatalError, "Cannot compute the dot product: first vector empty"));
483  }
484  if (b.data == nullptr) {
485  throw(vpException(vpException::fatalError, "Cannot compute the dot product: second vector empty"));
486  }
487  if (a.size() != b.size()) {
489  "Cannot compute the dot product between column vectors "
490  "with different dimensions (%d) and (%d)",
491  a.size(), b.size()));
492  }
493 
494  double *ad = a.data;
495  double *bd = b.data;
496 
497  double c = 0;
498  for (unsigned int i = 0; i < a.getRows(); i++)
499  c += *(ad++) * *(bd++);
500 
501  return c;
502 }
503 
504 
506 {
507  x /= sqrt(x.sumSquare());
508 
509  return x;
510 }
511 
513 {
514 
515  double sum_square = sumSquare();
516 
517  // if (sum != 0.0)
518  if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon())
519  *this /= sqrt(sum_square);
520 
521  // If sum = 0, we have a nul vector. So we return just.
522  return *this;
523 }
524 
526 {
527  if (v.data == nullptr) {
528  throw(vpException(vpException::fatalError, "Cannot sort content of column vector: vector empty"));
529  }
530  vpColVector tab;
531  tab = v;
532  unsigned int nb_permutation = 1;
533  unsigned int i = 0;
534  while (nb_permutation != 0) {
535  nb_permutation = 0;
536  for (unsigned int j = v.getRows() - 1; j >= i + 1; j--) {
537  if ((tab[j] > tab[j - 1])) {
538  double tmp = tab[j];
539  tab[j] = tab[j - 1];
540  tab[j - 1] = tmp;
541  nb_permutation++;
542  }
543  }
544  i++;
545  }
546 
547  return tab;
548 }
549 
551 {
552  if (v.data == nullptr) {
553  throw(vpException(vpException::fatalError, "Cannot sort content of column vector: vector empty"));
554  }
555  vpColVector tab;
556  tab = v;
557  unsigned int nb_permutation = 1;
558  unsigned int i = 0;
559  while (nb_permutation != 0) {
560  nb_permutation = 0;
561  for (unsigned int j = v.getRows() - 1; j >= i + 1; j--) {
562  if ((tab[j] < tab[j - 1])) {
563  double tmp = tab[j];
564  tab[j] = tab[j - 1];
565  tab[j - 1] = tmp;
566  nb_permutation++;
567  }
568  }
569  i++;
570  }
571 
572  return tab;
573 }
574 
575 void vpColVector::stack(double d)
576 {
577  this->resize(rowNum + 1, false);
578  (*this)[rowNum - 1] = d;
579 }
580 
581 void vpColVector::stack(const vpColVector &v) { *this = vpColVector::stack(*this, v); }
582 
584 {
585  vpColVector C;
586  vpColVector::stack(A, B, C);
587  return C;
588 }
589 
591 {
592  unsigned int nrA = A.getRows();
593  unsigned int nrB = B.getRows();
594 
595  if (nrA == 0 && nrB == 0) {
596  C.resize(0);
597  return;
598  }
599 
600  if (nrB == 0) {
601  C = A;
602  return;
603  }
604 
605  if (nrA == 0) {
606  C = B;
607  return;
608  }
609 
610  // General case
611  C.resize(nrA + nrB, false);
612 
613  for (unsigned int i = 0; i < nrA; i++)
614  C[i] = A[i];
615 
616  for (unsigned int i = 0; i < nrB; i++)
617  C[nrA + i] = B[i];
618 }
619 
621 {
622  if (v.data == nullptr || v.size() == 0) {
623  throw(vpException(vpException::dimensionError, "Cannot compute column vector mean: vector empty"));
624  }
625 
626  // Use directly sum() function
627  double mean = v.sum();
628 
629  return mean / v.getRows();
630 }
631 
633 {
634  if (v.data == nullptr || v.size() == 0) {
635  throw(vpException(vpException::dimensionError, "Cannot compute column vector median: vector empty"));
636  }
637 
638  std::vector<double> vectorOfDoubles(v.data, v.data + v.rowNum);
639 
640  return vpMath::getMedian(vectorOfDoubles);
641 }
642 
643 double vpColVector::stdev(const vpColVector &v, bool useBesselCorrection)
644 {
645  if (v.data == nullptr || v.size() == 0) {
646  throw(vpException(vpException::dimensionError, "Cannot compute column vector stdev: vector empty"));
647  }
648 
649  return SimdVectorStdev(v.data, v.rowNum, useBesselCorrection);
650 }
651 
653 {
654  vpMatrix M;
655  if (v.getRows() != 3) {
656  throw(vpException(vpException::dimensionError, "Cannot compute skew vector of a non 3-dimension vector (%d)",
657  v.getRows()));
658  }
659 
660  M.resize(3, 3, false, false);
661  M[0][0] = 0;
662  M[0][1] = -v[2];
663  M[0][2] = v[1];
664  M[1][0] = v[2];
665  M[1][1] = 0;
666  M[1][2] = -v[0];
667  M[2][0] = -v[1];
668  M[2][1] = v[0];
669  M[2][2] = 0;
670 
671  return M;
672 }
673 
675 {
676  if (a.getRows() != 3 || b.getRows() != 3) {
678  "Cannot compute the cross product between column "
679  "vector with dimension %d and %d",
680  a.getRows(), b.getRows()));
681  }
682 
683  return vpColVector::skew(a) * b;
684 }
685 
686 vpMatrix vpColVector::reshape(unsigned int nrows, unsigned int ncols)
687 {
688  vpMatrix M(nrows, ncols);
689  reshape(M, nrows, ncols);
690  return M;
691 }
692 
693 void vpColVector::reshape(vpMatrix &M, const unsigned int &nrows, const unsigned int &ncols)
694 {
695  if (dsize != nrows * ncols) {
696  throw(vpException(vpException::dimensionError, "Cannot reshape (%dx1) column vector in (%dx%d) matrix", rowNum,
697  M.getRows(), M.getCols()));
698  }
699  if ((M.getRows() != nrows) || (M.getCols() != ncols))
700  M.resize(nrows, ncols, false, false);
701 
702  for (unsigned int j = 0; j < ncols; j++)
703  for (unsigned int i = 0; i < nrows; i++)
704  M[i][j] = data[j * nrows + i];
705 }
706 
707 void vpColVector::insert(unsigned int i, const vpColVector &v)
708 {
709  if (i + v.size() > this->size())
710  throw(vpException(vpException::dimensionError, "Unable to insert a column vector"));
711 
712  if (data != nullptr && v.data != nullptr && v.rowNum > 0) {
713  memcpy(data + i, v.data, sizeof(double) * v.rowNum);
714  }
715 }
716 
717 int vpColVector::print(std::ostream &s, unsigned int length, char const *intro) const
718 {
719  typedef std::string::size_type size_type;
720 
721  unsigned int m = getRows();
722  unsigned int n = 1;
723 
724  std::vector<std::string> values(m * n);
725  std::ostringstream oss;
726  std::ostringstream ossFixed;
727  std::ios_base::fmtflags original_flags = oss.flags();
728 
729  // ossFixed <<std::fixed;
730  ossFixed.setf(std::ios::fixed, std::ios::floatfield);
731 
732  size_type maxBefore = 0; // the length of the integral part
733  size_type maxAfter = 0; // number of decimals plus
734  // one place for the decimal point
735  for (unsigned int i = 0; i < m; ++i) {
736  oss.str("");
737  oss << (*this)[i];
738  if (oss.str().find("e") != std::string::npos) {
739  ossFixed.str("");
740  ossFixed << (*this)[i];
741  oss.str(ossFixed.str());
742  }
743 
744  values[i] = oss.str();
745  size_type thislen = values[i].size();
746  size_type p = values[i].find('.');
747 
748  if (p == std::string::npos) {
749  maxBefore = vpMath::maximum(maxBefore, thislen);
750  // maxAfter remains the same
751  }
752  else {
753  maxBefore = vpMath::maximum(maxBefore, p);
754  maxAfter = vpMath::maximum(maxAfter, thislen - p - 1);
755  }
756  }
757 
758  size_type totalLength = length;
759  // increase totalLength according to maxBefore
760  totalLength = vpMath::maximum(totalLength, maxBefore);
761  // decrease maxAfter according to totalLength
762  maxAfter = (std::min)(maxAfter, totalLength - maxBefore);
763  if (maxAfter == 1)
764  maxAfter = 0;
765 
766  // the following line is useful for debugging
767  // std::cerr <<totalLength <<" " <<maxBefore <<" " <<maxAfter <<"\n";
768 
769  if (intro)
770  s << intro;
771  s << "[" << m << "," << n << "]=\n";
772 
773  for (unsigned int i = 0; i < m; i++) {
774  s << " ";
775  size_type p = values[i].find('.');
776  s.setf(std::ios::right, std::ios::adjustfield);
777  s.width((std::streamsize)maxBefore);
778  s << values[i].substr(0, p).c_str();
779 
780  if (maxAfter > 0) {
781  s.setf(std::ios::left, std::ios::adjustfield);
782  if (p != std::string::npos) {
783  s.width((std::streamsize)maxAfter);
784  s << values[i].substr(p, maxAfter).c_str();
785  }
786  else {
787  assert(maxAfter > 1);
788  s.width((std::streamsize)maxAfter);
789  s << ".0";
790  }
791  }
792 
793  s << ' ';
794 
795  s << std::endl;
796  }
797 
798  s.flags(original_flags); // restore s to standard state
799 
800  return (int)(maxBefore + maxAfter);
801 }
802 
803 double vpColVector::sum() const { return SimdVectorSum(data, rowNum); }
804 
805 double vpColVector::sumSquare() const { return SimdVectorSumSquare(data, rowNum); }
806 
808 {
809  double norm = sumSquare();
810 
811  return sqrt(norm);
812 }
813 
815 {
816  if (v.getRows() != rowNum || v.getCols() != colNum) {
817  throw(vpException(vpException::dimensionError, "Hadamard product: bad dimensions!"));
818  }
819 
820  vpColVector out;
821  out.resize(rowNum, false);
822 
823  SimdVectorHadamard(data, v.data, rowNum, out.data);
824 
825  return out;
826 }
827 
829 {
830  double norm = 0.0;
831  for (unsigned int i = 0; i < rowNum; i++) {
832  double x = fabs((*this)[i]);
833  if (x > norm) {
834  norm = x;
835  }
836  }
837  return norm;
838 }
839 
840 std::ostream &vpColVector::cppPrint(std::ostream &os, const std::string &matrixName, bool octet) const
841 {
842  os << "vpColVector " << matrixName << " (" << this->getRows() << "); " << std::endl;
843 
844  for (unsigned int i = 0; i < this->getRows(); ++i) {
845 
846  if (!octet) {
847  os << matrixName << "[" << i << "] = " << (*this)[i] << "; " << std::endl;
848  }
849  else {
850  for (unsigned int k = 0; k < sizeof(double); ++k) {
851  os << "((unsigned char*)&(" << matrixName << "[" << i << "]) )[" << k << "] = 0x" << std::hex
852  << (unsigned int)((unsigned char *)&((*this)[i]))[k] << "; " << std::endl;
853  }
854  }
855  }
856  std::cout << std::endl;
857  return os;
858 };
859 
860 std::ostream &vpColVector::csvPrint(std::ostream &os) const
861 {
862  for (unsigned int i = 0; i < this->getRows(); ++i) {
863  os << (*this)[i];
864 
865  os << std::endl;
866  }
867  return os;
868 };
869 
870 std::ostream &vpColVector::maplePrint(std::ostream &os) const
871 {
872  os << "([ " << std::endl;
873  for (unsigned int i = 0; i < this->getRows(); ++i) {
874  os << "[";
875  os << (*this)[i] << ", ";
876  os << "]," << std::endl;
877  }
878  os << "])" << std::endl;
879  return os;
880 };
881 
882 std::ostream &vpColVector::matlabPrint(std::ostream &os) const
883 {
884  os << "[ ";
885  for (unsigned int i = 0; i < this->getRows(); ++i) {
886  os << (*this)[i] << ", ";
887  if (this->getRows() != i + 1) {
888  os << ";" << std::endl;
889  }
890  else {
891  os << "]" << std::endl;
892  }
893  }
894  return os;
895 };
896 
897 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
898 
899 void vpColVector::insert(const vpColVector &v, unsigned int i)
900 {
901  insert(i, v);
902 }
903 
904 void vpColVector::insert(const vpColVector &v, unsigned int r, unsigned int c)
905 {
906  (void)c;
907  insert(r, v);
908 }
909 
910 double vpColVector::euclideanNorm() const { return frobeniusNorm(); }
911 #endif // defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
Implementation of a generic 2D array used as base class for matrices and vectors.
Definition: vpArray2D.h:125
unsigned int getCols() const
Definition: vpArray2D.h:257
double * data
Address of the first element of the data array.
Definition: vpArray2D.h:138
double ** rowPtrs
Address of the first element of each rows.
Definition: vpArray2D.h:132
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Definition: vpArray2D.h:282
unsigned int rowNum
Number of rows in the array.
Definition: vpArray2D.h:128
unsigned int dsize
Current array size (rowNum * colNum)
Definition: vpArray2D.h:134
unsigned int size() const
Return the number of elements of the 2D array.
Definition: vpArray2D.h:269
unsigned int getRows() const
Definition: vpArray2D.h:267
unsigned int colNum
Number of columns in the array.
Definition: vpArray2D.h:130
Implementation of column vector and the associated operations.
Definition: vpColVector.h:163
void reshape(vpMatrix &M, const unsigned int &nrows, const unsigned int &ncols)
double operator*(const vpColVector &v) const
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)
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
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:1348
vpColVector operator+(const vpColVector &v) const
Definition: vpColVector.cpp:58
std::vector< double > toStdVector() const
static double mean(const vpColVector &v)
vpColVector operator*(const double &x, const vpColVector &v)
vpColVector & operator+=(vpColVector v)
Definition: vpColVector.cpp:85
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)
Definition: vpColVector.cpp:97
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:1049
error that can be emitted by ViSP classes.
Definition: vpException.h:59
@ dimensionError
Bad dimension.
Definition: vpException.h:83
@ fatalError
Fatal error.
Definition: vpException.h:84
static double getMedian(const std::vector< double > &v)
Definition: vpMath.cpp:314
static Type maximum(const Type &a, const Type &b)
Definition: vpMath.h:252
static bool equal(double x, double y, double threshold=0.001)
Definition: vpMath.h:449
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:146
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:189
Implementation of a generic rotation vector.
Implementation of row vector and the associated operations.
Definition: vpRowVector.h:107
Class that consider the case of a translation vector.