Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
vpColVector.cpp
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2023 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 https://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*****************************************************************************/
35
42#include <assert.h>
43#include <cmath> // std::fabs
44#include <limits> // numeric_limits
45#include <math.h>
46#include <sstream>
47#include <stdio.h>
48#include <stdlib.h>
49#include <string.h>
50
51#include <visp3/core/vpCPUFeatures.h>
52#include <visp3/core/vpColVector.h>
53#include <visp3/core/vpDebug.h>
54#include <visp3/core/vpException.h>
55#include <visp3/core/vpMath.h>
56#include <visp3/core/vpRotationVector.h>
57
58#include <Simd/SimdLib.hpp>
59
62{
63 if (getRows() != v.getRows()) {
64 throw(vpException(vpException::dimensionError, "Cannot add (%dx1) column vector to (%dx1) column vector", getRows(),
65 v.getRows()));
66 }
68
69 for (unsigned int i = 0; i < rowNum; i++)
70 r[i] = (*this)[i] + v[i];
71 return r;
72}
95{
96 if (getRows() != 3) {
97 throw(vpException(vpException::dimensionError, "Cannot add %d-dimension column vector to a translation vector",
98 getRows()));
99 }
101
102 for (unsigned int i = 0; i < 3; i++)
103 s[i] = (*this)[i] + t[i];
104
105 return s;
106}
107
110{
111 if (getRows() != v.getRows()) {
112 throw(vpException(vpException::dimensionError, "Cannot add (%dx1) column vector to (%dx1) column vector", getRows(),
113 v.getRows()));
114 }
115
116 for (unsigned int i = 0; i < rowNum; i++)
117 (*this)[i] += v[i];
118 return (*this);
119}
122{
123 if (getRows() != v.getRows()) {
124 throw(vpException(vpException::dimensionError, "Cannot subtract (%dx1) column vector to (%dx1) column vector",
125 getRows(), v.getRows()));
126 }
127
128 for (unsigned int i = 0; i < rowNum; i++)
129 (*this)[i] -= v[i];
130 return (*this);
131}
132
141{
142 if (size() != v.size()) {
144 "Cannot compute the dot product between column vectors "
145 "with different dimensions (%d) and (%d)",
146 size(), v.size()));
147 }
148 double r = 0;
149
150 for (unsigned int i = 0; i < rowNum; i++)
151 r += (*this)[i] * v[i];
152 return r;
153}
154
165{
166 vpMatrix M(rowNum, v.getCols());
167 for (unsigned int i = 0; i < rowNum; i++) {
168 for (unsigned int j = 0; j < v.getCols(); j++) {
169 M[i][j] = (*this)[i] * v[j];
170 }
171 }
172 return M;
173}
174
177{
178 if (getRows() != m.getRows()) {
180 "Bad size during vpColVector (%dx1) and vpColVector "
181 "(%dx1) subtraction",
182 getRows(), m.getRows()));
183 }
185
186 for (unsigned int i = 0; i < rowNum; i++)
187 v[i] = (*this)[i] - m[i];
188 return v;
189}
190
204vpColVector::vpColVector(const vpColVector &v, unsigned int r, unsigned int nrows) : vpArray2D<double>(nrows, 1)
205{
206 init(v, r, nrows);
207}
208
246void vpColVector::init(const vpColVector &v, unsigned int r, unsigned int nrows)
247{
248 unsigned int rnrows = r + nrows;
249
250 if (rnrows > v.getRows())
251 throw(vpException(vpException::dimensionError, "Bad row dimension (%d > %d) used to initialize vpColVector", rnrows,
252 v.getRows()));
253 resize(nrows, false);
254
255 if (this->rowPtrs == NULL) // Fix coverity scan: explicit null dereferenced
256 return; // Nothing to do
257 for (unsigned int i = r; i < rnrows; i++)
258 (*this)[i - r] = v[i];
259}
260
262{
263 for (unsigned int i = 0; i < v.size(); i++)
264 (*this)[i] = v[i];
265}
266
267vpColVector::vpColVector(const vpPoseVector &p) : vpArray2D<double>(p.size(), 1)
268{
269 for (unsigned int i = 0; i < p.size(); i++)
270 (*this)[i] = p[i];
271}
272
274{
275 for (unsigned int i = 0; i < v.size(); i++)
276 (*this)[i] = v[i];
277}
278
280vpColVector::vpColVector(const vpMatrix &M, unsigned int j) : vpArray2D<double>(M.getRows(), 1)
281{
282 for (unsigned int i = 0; i < M.getCols(); i++)
283 (*this)[i] = M[i][j];
284}
285
292vpColVector::vpColVector(const vpMatrix &M) : vpArray2D<double>(M.getRows(), 1)
293{
294 if (M.getCols() != 1) {
295 throw(vpException(vpException::dimensionError, "Cannot construct a (%dx1) row vector from a (%dx%d) matrix",
296 M.getRows(), M.getRows(), M.getCols()));
297 }
298
299 for (unsigned int i = 0; i < M.getRows(); i++)
300 (*this)[i] = M[i][0];
301}
302
306vpColVector::vpColVector(const std::vector<double> &v) : vpArray2D<double>((unsigned int)v.size(), 1)
307{
308 for (unsigned int i = 0; i < v.size(); i++)
309 (*this)[i] = v[i];
310}
314vpColVector::vpColVector(const std::vector<float> &v) : vpArray2D<double>((unsigned int)v.size(), 1)
315{
316 for (unsigned int i = 0; i < v.size(); i++)
317 (*this)[i] = (double)(v[i]);
318}
319
320#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
325{
326 rowNum = v.rowNum;
327 colNum = v.colNum;
328 rowPtrs = v.rowPtrs;
329 dsize = v.dsize;
330 data = v.data;
331
332 v.rowNum = 0;
333 v.colNum = 0;
334 v.rowPtrs = NULL;
335 v.dsize = 0;
336 v.data = NULL;
337}
338#endif
339
351{
352 vpColVector A;
353 A.resize(rowNum, false);
354
355 double *vd = A.data;
356 double *d = data;
357
358 for (unsigned int i = 0; i < rowNum; i++)
359 *(vd++) = -(*d++);
360
361 return A;
362}
363
385{
387
388 double *vd = v.data;
389 double *d = data;
390
391 for (unsigned int i = 0; i < rowNum; i++)
392 *(vd++) = (*d++) * x;
393 return v;
394}
395
415{
416 for (unsigned int i = 0; i < rowNum; i++)
417 (*this)[i] *= x;
418 return (*this);
419}
420
439{
440 for (unsigned int i = 0; i < rowNum; i++)
441 (*this)[i] /= x;
442 return (*this);
443}
444
465{
467
468 double *vd = v.data;
469 double *d = data;
470
471 for (unsigned int i = 0; i < rowNum; i++)
472 *(vd++) = (*d++) / x;
473 return v;
474}
475
482{
483 if (M.getCols() != 1) {
484 throw(vpException(vpException::dimensionError, "Cannot transform a (%dx%d) matrix into a column vector",
485 M.getRows(), M.getCols()));
486 }
487
488 resize(M.getRows(), false);
489 memcpy(data, M.data, rowNum * sizeof(double));
490
491 return (*this);
492}
493
497vpColVector &vpColVector::operator=(const std::vector<double> &v)
498{
499 resize((unsigned int)v.size(), false);
500 for (unsigned int i = 0; i < v.size(); i++)
501 (*this)[i] = v[i];
502 return *this;
503}
507vpColVector &vpColVector::operator=(const std::vector<float> &v)
508{
509 resize((unsigned int)v.size(), false);
510 for (unsigned int i = 0; i < v.size(); i++)
511 (*this)[i] = (float)v[i];
512 return *this;
513}
514
516{
517 unsigned int k = v.rowNum;
518 if (rowNum != k) {
519 resize(k, false);
520 }
521
522 memcpy(data, v.data, rowNum * sizeof(double));
523 return *this;
524}
525
530{
531 unsigned int k = tv.getRows();
532 if (rowNum != k) {
533 resize(k, false);
534 }
535
536 memcpy(data, tv.data, rowNum * sizeof(double));
537 return *this;
538}
543{
544 unsigned int k = rv.getRows();
545 if (rowNum != k) {
546 resize(k, false);
547 }
548
549 memcpy(data, rv.data, rowNum * sizeof(double));
550 return *this;
551}
556{
557 unsigned int k = p.getRows();
558 if (rowNum != k) {
559 resize(k, false);
560 }
561
562 memcpy(data, p.data, rowNum * sizeof(double));
563 return *this;
564}
565
587{
588 *this = v;
589 return *this;
590}
591
617{
618 for (unsigned int i = 0; i < rowNum; i++) {
619 for (unsigned int j = 0; j < colNum; j++) {
620 rowPtrs[i][j] = *x++;
621 }
622 }
623 return *this;
624}
625
645{
646 resize(1, false);
647 data[0] = val;
648 return *this;
649}
650
670{
671 resize(rowNum + 1, false);
672 data[rowNum - 1] = val;
673 return *this;
674}
675
678{
679 double *d = data;
680
681 for (unsigned int i = 0; i < rowNum; i++)
682 *(d++) = x;
683 return *this;
684}
685
690std::vector<double> vpColVector::toStdVector() const
691{
692 std::vector<double> v(this->size());
693
694 for (unsigned int i = 0; i < this->size(); i++)
695 v[i] = data[i];
696 return v;
697}
698
699#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
704{
705 if (this != &other) {
706 free(data);
707 free(rowPtrs);
708
709 rowNum = other.rowNum;
710 colNum = other.colNum;
711 rowPtrs = other.rowPtrs;
712 dsize = other.dsize;
713 data = other.data;
714
715 other.rowNum = 0;
716 other.colNum = 0;
717 other.rowPtrs = NULL;
718 other.dsize = 0;
719 other.data = NULL;
720 }
721
722 return *this;
723}
724
748vpColVector &vpColVector::operator=(const std::initializer_list<double> &list)
749{
750 resize(static_cast<unsigned int>(list.size()), false);
751 std::copy(list.begin(), list.end(), data);
752 return *this;
753}
754#endif
755
763{
764 if (rowNum != v.rowNum || colNum != v.colNum /* should not happen */)
765 return false;
766
767 for (unsigned int i = 0; i < rowNum; i++) {
768 if (!vpMath::equal(data[i], v.data[i], std::numeric_limits<double>::epsilon()))
769 return false;
770 }
771
772 return true;
773}
774
781bool vpColVector::operator==(double v) const
782{
783 for (unsigned int i = 0; i < rowNum; i++) {
784 if (!vpMath::equal(data[i], v, std::numeric_limits<double>::epsilon()))
785 return false;
786 }
787
788 return true;
789}
790
796bool vpColVector::operator!=(const vpColVector &v) const { return !(*this == v); }
797
804bool vpColVector::operator!=(double v) const { return !(*this == v); }
805
810{
812 memcpy(v.data, data, rowNum * sizeof(double));
813 return v;
814}
815
821
826void vpColVector::transpose(vpRowVector &v) const { v = t(); }
827
832vpColVector operator*(const double &x, const vpColVector &v)
833{
834 vpColVector vout;
835 vout = v * x;
836 return vout;
837}
838
847{
848 if (a.data == NULL) {
849 throw(vpException(vpException::fatalError, "Cannot compute the dot product: first vector empty"));
850 }
851 if (b.data == NULL) {
852 throw(vpException(vpException::fatalError, "Cannot compute the dot product: second vector empty"));
853 }
854 if (a.size() != b.size()) {
856 "Cannot compute the dot product between column vectors "
857 "with different dimensions (%d) and (%d)",
858 a.size(), b.size()));
859 }
860
861 double *ad = a.data;
862 double *bd = b.data;
863
864 double c = 0;
865 for (unsigned int i = 0; i < a.getRows(); i++)
866 c += *(ad++) * *(bd++);
867 // vpMatrix c = (a.t() * b);
868 // return c[0][0];
869 return c;
870}
871
884{
885 x /= sqrt(x.sumSquare());
886
887 return x;
888}
889
901{
902
903 double sum_square = sumSquare();
904
905 // if (sum != 0.0)
906 if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon())
907 *this /= sqrt(sum_square);
908
909 // If sum = 0, we have a nul vector. So we return just.
910 return *this;
911}
912
942{
943 if (v.data == NULL) {
944 throw(vpException(vpException::fatalError, "Cannot sort content of column vector: vector empty"));
945 }
946 vpColVector tab;
947 tab = v;
948 unsigned int nb_permutation = 1;
949 unsigned int i = 0;
950 while (nb_permutation != 0) {
951 nb_permutation = 0;
952 for (unsigned int j = v.getRows() - 1; j >= i + 1; j--) {
953 if ((tab[j] > tab[j - 1])) {
954 double tmp = tab[j];
955 tab[j] = tab[j - 1];
956 tab[j - 1] = tmp;
957 nb_permutation++;
958 }
959 }
960 i++;
961 }
962
963 return tab;
964}
965
994{
995 if (v.data == NULL) {
996 throw(vpException(vpException::fatalError, "Cannot sort content of column vector: vector empty"));
997 }
998 vpColVector tab;
999 tab = v;
1000 unsigned int nb_permutation = 1;
1001 unsigned int i = 0;
1002 while (nb_permutation != 0) {
1003 nb_permutation = 0;
1004 for (unsigned int j = v.getRows() - 1; j >= i + 1; j--) {
1005 if ((tab[j] < tab[j - 1])) {
1006 double tmp = tab[j];
1007 tab[j] = tab[j - 1];
1008 tab[j - 1] = tmp;
1009 nb_permutation++;
1010 }
1011 }
1012 i++;
1013 }
1014
1015 return tab;
1016}
1017
1035{
1036 this->resize(rowNum + 1, false);
1037 (*this)[rowNum - 1] = d;
1038}
1039
1059void vpColVector::stack(const vpColVector &v) { *this = vpColVector::stack(*this, v); }
1060
1080{
1081 vpColVector C;
1082 vpColVector::stack(A, B, C);
1083 return C;
1084}
1085
1105{
1106 unsigned int nrA = A.getRows();
1107 unsigned int nrB = B.getRows();
1108
1109 if (nrA == 0 && nrB == 0) {
1110 C.resize(0);
1111 return;
1112 }
1113
1114 if (nrB == 0) {
1115 C = A;
1116 return;
1117 }
1118
1119 if (nrA == 0) {
1120 C = B;
1121 return;
1122 }
1123
1124 // General case
1125 C.resize(nrA + nrB, false);
1126
1127 for (unsigned int i = 0; i < nrA; i++)
1128 C[i] = A[i];
1129
1130 for (unsigned int i = 0; i < nrB; i++)
1131 C[nrA + i] = B[i];
1132}
1133
1138{
1139 if (v.data == NULL || v.size() == 0) {
1140 throw(vpException(vpException::dimensionError, "Cannot compute column vector mean: vector empty"));
1141 }
1142
1143 // Use directly sum() function
1144 double mean = v.sum();
1145
1146 // Old code used
1147 // double *vd = v.data;
1148 // for (unsigned int i=0 ; i < v.getRows() ; i++)
1149 // mean += *(vd++);
1150
1151 return mean / v.getRows();
1152}
1153
1158{
1159 if (v.data == NULL || v.size() == 0) {
1160 throw(vpException(vpException::dimensionError, "Cannot compute column vector median: vector empty"));
1161 }
1162
1163 std::vector<double> vectorOfDoubles(v.data, v.data + v.rowNum);
1164
1165 return vpMath::getMedian(vectorOfDoubles);
1166}
1167
1171double vpColVector::stdev(const vpColVector &v, bool useBesselCorrection)
1172{
1173 if (v.data == NULL || v.size() == 0) {
1174 throw(vpException(vpException::dimensionError, "Cannot compute column vector stdev: vector empty"));
1175 }
1176
1177 return SimdVectorStdev(v.data, v.rowNum, useBesselCorrection);
1178}
1179
1195{
1196 vpMatrix M;
1197 if (v.getRows() != 3) {
1198 throw(vpException(vpException::dimensionError, "Cannot compute skew vector of a non 3-dimention vector (%d)",
1199 v.getRows()));
1200 }
1201
1202 M.resize(3, 3, false, false);
1203 M[0][0] = 0;
1204 M[0][1] = -v[2];
1205 M[0][2] = v[1];
1206 M[1][0] = v[2];
1207 M[1][1] = 0;
1208 M[1][2] = -v[0];
1209 M[2][0] = -v[1];
1210 M[2][1] = v[0];
1211 M[2][2] = 0;
1212
1213 return M;
1214}
1215
1226{
1227 if (a.getRows() != 3 || b.getRows() != 3) {
1229 "Cannot compute the cross product between column "
1230 "vector with dimension %d and %d",
1231 a.getRows(), b.getRows()));
1232 }
1233
1234 return vpColVector::skew(a) * b;
1235}
1236
1245vpMatrix vpColVector::reshape(unsigned int nrows, unsigned int ncols)
1246{
1247 vpMatrix M(nrows, ncols);
1248 reshape(M, nrows, ncols);
1249 return M;
1250}
1251
1307void vpColVector::reshape(vpMatrix &M, const unsigned int &nrows, const unsigned int &ncols)
1308{
1309 if (dsize != nrows * ncols) {
1310 throw(vpException(vpException::dimensionError, "Cannot reshape (%dx1) column vector in (%dx%d) matrix", rowNum,
1311 M.getRows(), M.getCols()));
1312 }
1313 if ((M.getRows() != nrows) || (M.getCols() != ncols))
1314 M.resize(nrows, ncols, false, false);
1315
1316 for (unsigned int j = 0; j < ncols; j++)
1317 for (unsigned int i = 0; i < nrows; i++)
1318 M[i][j] = data[j * nrows + i];
1319}
1320
1353void vpColVector::insert(unsigned int i, const vpColVector &v)
1354{
1355 if (i + v.size() > this->size())
1356 throw(vpException(vpException::dimensionError, "Unable to insert a column vector"));
1357
1358 if (data != NULL && v.data != NULL && v.rowNum > 0) {
1359 memcpy(data + i, v.data, sizeof(double) * v.rowNum);
1360 }
1361}
1362void vpColVector::insert(const vpColVector &v, unsigned int i)
1363{
1364 if (i + v.size() > this->size())
1365 throw(vpException(vpException::dimensionError, "Unable to insert a column vector"));
1366
1367 if (data != NULL && v.data != NULL && v.rowNum > 0) {
1368 memcpy(data + i, v.data, sizeof(double) * v.rowNum);
1369 }
1370}
1371
1391int vpColVector::print(std::ostream &s, unsigned int length, char const *intro) const
1392{
1393 typedef std::string::size_type size_type;
1394
1395 unsigned int m = getRows();
1396 unsigned int n = 1;
1397
1398 std::vector<std::string> values(m * n);
1399 std::ostringstream oss;
1400 std::ostringstream ossFixed;
1401 std::ios_base::fmtflags original_flags = oss.flags();
1402
1403 // ossFixed <<std::fixed;
1404 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
1405
1406 size_type maxBefore = 0; // the length of the integral part
1407 size_type maxAfter = 0; // number of decimals plus
1408 // one place for the decimal point
1409 for (unsigned int i = 0; i < m; ++i) {
1410 oss.str("");
1411 oss << (*this)[i];
1412 if (oss.str().find("e") != std::string::npos) {
1413 ossFixed.str("");
1414 ossFixed << (*this)[i];
1415 oss.str(ossFixed.str());
1416 }
1417
1418 values[i] = oss.str();
1419 size_type thislen = values[i].size();
1420 size_type p = values[i].find('.');
1421
1422 if (p == std::string::npos) {
1423 maxBefore = vpMath::maximum(maxBefore, thislen);
1424 // maxAfter remains the same
1425 }
1426 else {
1427 maxBefore = vpMath::maximum(maxBefore, p);
1428 maxAfter = vpMath::maximum(maxAfter, thislen - p - 1);
1429 }
1430 }
1431
1432 size_type totalLength = length;
1433 // increase totalLength according to maxBefore
1434 totalLength = vpMath::maximum(totalLength, maxBefore);
1435 // decrease maxAfter according to totalLength
1436 maxAfter = (std::min)(maxAfter, totalLength - maxBefore);
1437 if (maxAfter == 1)
1438 maxAfter = 0;
1439
1440 // the following line is useful for debugging
1441 // std::cerr <<totalLength <<" " <<maxBefore <<" " <<maxAfter <<"\n";
1442
1443 if (intro)
1444 s << intro;
1445 s << "[" << m << "," << n << "]=\n";
1446
1447 for (unsigned int i = 0; i < m; i++) {
1448 s << " ";
1449 size_type p = values[i].find('.');
1450 s.setf(std::ios::right, std::ios::adjustfield);
1451 s.width((std::streamsize)maxBefore);
1452 s << values[i].substr(0, p).c_str();
1453
1454 if (maxAfter > 0) {
1455 s.setf(std::ios::left, std::ios::adjustfield);
1456 if (p != std::string::npos) {
1457 s.width((std::streamsize)maxAfter);
1458 s << values[i].substr(p, maxAfter).c_str();
1459 }
1460 else {
1461 assert(maxAfter > 1);
1462 s.width((std::streamsize)maxAfter);
1463 s << ".0";
1464 }
1465 }
1466
1467 s << ' ';
1468
1469 s << std::endl;
1470 }
1471
1472 s.flags(original_flags); // restore s to standard state
1473
1474 return (int)(maxBefore + maxAfter);
1475}
1476
1482double vpColVector::sum() const { return SimdVectorSum(data, rowNum); }
1483
1490double vpColVector::sumSquare() const { return SimdVectorSumSquare(data, rowNum); }
1491
1492
1493
1503{
1504 double norm = sumSquare();
1505
1506 return sqrt(norm);
1507}
1508
1516{
1517 if (v.getRows() != rowNum || v.getCols() != colNum) {
1518 throw(vpException(vpException::dimensionError, "Hadamard product: bad dimensions!"));
1519 }
1520
1521 vpColVector out;
1522 out.resize(rowNum, false);
1523
1524 SimdVectorHadamard(data, v.data, rowNum, out.data);
1525
1526 return out;
1527}
1528
1541{
1542 double norm = 0.0;
1543 for (unsigned int i = 0; i < rowNum; i++) {
1544 double x = fabs((*this)[i]);
1545 if (x > norm) {
1546 norm = x;
1547 }
1548 }
1549 return norm;
1550}
1551
1580std::ostream &vpColVector::cppPrint(std::ostream &os, const std::string &matrixName, bool octet) const
1581{
1582 os << "vpColVector " << matrixName << " (" << this->getRows() << "); " << std::endl;
1583
1584 for (unsigned int i = 0; i < this->getRows(); ++i) {
1585
1586 if (!octet) {
1587 os << matrixName << "[" << i << "] = " << (*this)[i] << "; " << std::endl;
1588 }
1589 else {
1590 for (unsigned int k = 0; k < sizeof(double); ++k) {
1591 os << "((unsigned char*)&(" << matrixName << "[" << i << "]) )[" << k << "] = 0x" << std::hex
1592 << (unsigned int)((unsigned char *)&((*this)[i]))[k] << "; " << std::endl;
1593 }
1594 }
1595 }
1596 std::cout << std::endl;
1597 return os;
1598};
1599
1626std::ostream &vpColVector::csvPrint(std::ostream &os) const
1627{
1628 for (unsigned int i = 0; i < this->getRows(); ++i) {
1629 os << (*this)[i];
1630
1631 os << std::endl;
1632 }
1633 return os;
1634};
1635
1661std::ostream &vpColVector::maplePrint(std::ostream &os) const
1662{
1663 os << "([ " << std::endl;
1664 for (unsigned int i = 0; i < this->getRows(); ++i) {
1665 os << "[";
1666 os << (*this)[i] << ", ";
1667 os << "]," << std::endl;
1668 }
1669 os << "])" << std::endl;
1670 return os;
1671};
1672
1709std::ostream &vpColVector::matlabPrint(std::ostream &os) const
1710{
1711 os << "[ ";
1712 for (unsigned int i = 0; i < this->getRows(); ++i) {
1713 os << (*this)[i] << ", ";
1714 if (this->getRows() != i + 1) {
1715 os << ";" << std::endl;
1716 }
1717 else {
1718 os << "]" << std::endl;
1719 }
1720 }
1721 return os;
1722};
1723
1724#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
1725
1740void vpColVector::insert(const vpColVector &v, unsigned int r, unsigned int c)
1741{
1742 (void)c;
1743 insert(r, v);
1744}
1745
1756double vpColVector::euclideanNorm() const { return frobeniusNorm(); }
1757#endif // defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
Implementation of a generic 2D array used as base class for matrices and vectors.
Definition vpArray2D.h:131
unsigned int getCols() const
Definition vpArray2D.h:280
double * data
Address of the first element of the data array.
Definition vpArray2D.h:144
double ** rowPtrs
Address of the first element of each rows.
Definition vpArray2D.h:138
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Definition vpArray2D.h:305
unsigned int rowNum
Number of rows in the array.
Definition vpArray2D.h:134
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< double > &A)
Definition vpArray2D.h:529
unsigned int dsize
Current array size (rowNum * colNum)
Definition vpArray2D.h:140
unsigned int size() const
Return the number of elements of the 2D array.
Definition vpArray2D.h:292
unsigned int getRows() const
Definition vpArray2D.h:290
unsigned int colNum
Number of columns in the array.
Definition vpArray2D.h:136
Implementation of column vector and the associated operations.
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()
double operator*(const vpColVector &x) const
vpColVector()
Basic constructor that creates an empty 0-size column vector.
vpColVector operator+(const vpColVector &v) const
Operator that allows to add two column vectors.
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
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)
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:172
static bool equal(double x, double y, double threshold=0.001)
Definition vpMath.h:369
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:152
Implementation of a pose vector and operations on poses.
Implementation of a generic rotation vector.
Implementation of row vector and the associated operations.
Class that consider the case of a translation vector.