Visual Servoing Platform  version 3.6.1 under development (2024-12-17)
vpRowVector.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 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  * Operation on row vectors.
32  */
33 
39 #include <assert.h>
40 #include <cmath>
41 #include <sstream>
42 #include <stdlib.h>
43 #include <string.h>
44 
45 #include <visp3/core/vpArray2D.h>
46 #include <visp3/core/vpColVector.h>
47 #include <visp3/core/vpException.h>
48 #include <visp3/core/vpMatrix.h>
49 #include <visp3/core/vpRowVector.h>
50 
51 #if defined(VISP_HAVE_SIMDLIB)
52 #include <Simd/SimdLib.h>
53 #endif
54 
55 BEGIN_VISP_NAMESPACE
58 {
59  unsigned int k = v.colNum;
60  if (colNum != k) {
61  try {
62  resize(k);
63  }
64  catch (...) {
65  throw;
66  }
67  }
68 
69  memcpy(data, v.data, colNum * sizeof(double));
70 
71  return *this;
72 }
73 
82 {
83  if (M.getRows() != 1) {
84  throw(vpException(vpException::dimensionError, "Cannot initialize a (1x%d) row vector from a (%dx%d) matrix",
85  M.getCols(), M.getRows(), M.getCols()));
86  }
87 
88  if (M.getCols() != colNum) {
89  resize(M.getCols());
90  }
91 
92  memcpy(data, M.data, colNum * sizeof(double));
93  return *this;
94 }
95 
99 vpRowVector &vpRowVector::operator=(const std::vector<double> &v)
100 {
101  unsigned int v_size = static_cast<unsigned int>(v.size());
102  resize(v_size);
103  for (unsigned int i = 0; i < v_size; ++i) {
104  (*this)[i] = v[i];
105  }
106  return *this;
107 }
111 vpRowVector &vpRowVector::operator=(const std::vector<float> &v)
112 {
113  unsigned int v_size = static_cast<unsigned int>(v.size());
114  resize(v_size);
115  for (unsigned int i = 0; i < v_size; ++i) {
116  (*this)[i] = static_cast<float>(v[i]);
117  }
118  return *this;
119 }
120 
123 {
124  for (unsigned int i = 0; i < rowNum; ++i) {
125  for (unsigned int j = 0; j < colNum; ++j) {
126  rowPtrs[i][j] = x;
127  }
128  }
129  return *this;
130 }
131 
132 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
134 {
135  if (this != &other) {
136  free(data);
137  free(rowPtrs);
138 
139  rowNum = other.rowNum;
140  colNum = other.colNum;
141  rowPtrs = other.rowPtrs;
142  dsize = other.dsize;
143  data = other.data;
144 
145  other.rowNum = 0;
146  other.colNum = 0;
147  other.rowPtrs = nullptr;
148  other.dsize = 0;
149  other.data = nullptr;
150  }
151 
152  return *this;
153 }
154 
177 vpRowVector &vpRowVector::operator=(const std::initializer_list<double> &list)
178 {
179  resize(1, static_cast<unsigned int>(list.size()), false);
180  std::copy(list.begin(), list.end(), data);
181  return *this;
182 }
183 #endif
184 
186 {
187  if ((colNum != v.colNum) || (rowNum != v.rowNum) /* should not happen */) {
188  return false;
189  }
190 
191  for (unsigned int i = 0; i < colNum; ++i) {
192  if (!vpMath::equal(data[i], v.data[i], std::numeric_limits<double>::epsilon())) {
193  return false;
194  }
195  }
196 
197  return true;
198 }
199 
200 bool vpRowVector::operator!=(const vpRowVector &v) const { return !(*this == v); }
201 
216 double vpRowVector::operator*(const vpColVector &x) const
217 {
218  unsigned int nelements = x.getRows();
219  if (getCols() != nelements) {
220  throw(vpException(vpException::dimensionError, "Cannot multiply (1x%d) row vector by (%dx1) column vector", colNum,
221  x.getRows()));
222  }
223 
224  double scalar = 0.0;
225 
226  for (unsigned int i = 0; i < nelements; ++i) {
227  scalar += (*this)[i] * x[i];
228  }
229  return scalar;
230 }
247 {
248  vpRowVector c(M.getCols());
249 
250  if (colNum != M.getRows()) {
251  throw(vpException(vpException::dimensionError, "Cannot multiply (1x%d) row vector by (%dx%d) matrix", colNum,
252  M.getRows(), M.getCols()));
253  }
254 
255  c = 0.0;
256 
257  for (unsigned int i = 0; i < colNum; ++i) {
258  double bi = data[i]; // optimization em 5/12/2006
259  unsigned int m_cols = M.getCols();
260  for (unsigned int j = 0; j < m_cols; ++j) {
261  c[j] += bi * M[i][j];
262  }
263  }
264 
265  return c;
266 }
267 
288 {
289  vpRowVector v(colNum);
290 
291  double *vd = v.data;
292  double *d = data;
293 
294  for (unsigned int i = 0; i < colNum; ++i) {
295  *(vd++) = (*d) * x;
296  ++d;
297  }
298  return v;
299 }
300 
319 {
320  for (unsigned int i = 0; i < colNum; ++i) {
321  (*this)[i] *= x;
322  }
323  return (*this);
324 }
325 
346 {
347  vpRowVector v(colNum);
348 
349  double *vd = v.data;
350  double *d = data;
351 
352  for (unsigned int i = 0; i < colNum; ++i) {
353  *(vd++) = (*d) / x;
354  ++d;
355  }
356  return v;
357 }
358 
378 {
379  for (unsigned int i = 0; i < colNum; ++i) {
380  (*this)[i] /= x;
381  }
382  return (*this);
383 }
384 
396 {
397  vpRowVector A(colNum);
398 
399  double *vd = A.data;
400  double *d = data;
401 
402  for (unsigned int i = 0; i < colNum; ++i) {
403  *(vd++) = -(*d);
404  ++d;
405  }
406 
407  return A;
408 }
409 
415 {
416  if (getCols() != m.getCols()) {
417  throw(vpException(vpException::dimensionError, "Cannot subtract (1x%d) row vector to (1x%d) row vector", getCols(),
418  m.getCols()));
419  }
420 
421  vpRowVector v(colNum);
422 
423  for (unsigned int i = 0; i < colNum; ++i) {
424  v[i] = (*this)[i] - m[i];
425  }
426  return v;
427 }
428 
434 {
435  if (getCols() != v.getCols()) {
436  throw(vpException(vpException::dimensionError, "Cannot add (1x%d) row vector to (1x%d) row vector", getCols(),
437  v.getCols()));
438  }
439 
440  vpRowVector r(colNum);
441 
442  for (unsigned int i = 0; i < colNum; ++i) {
443  r[i] = (*this)[i] + v[i];
444  }
445  return r;
446 }
447 
454 {
455  if (getCols() != v.getCols()) {
456  throw(vpException(vpException::dimensionError, "Cannot add (1x%d) row vector to (1x%d) row vector", getCols(),
457  v.getCols()));
458  }
459 
460  for (unsigned int i = 0; i < colNum; ++i) {
461  (*this)[i] += v[i];
462  }
463  return (*this);
464 }
465 
472 {
473  if (getCols() != v.getCols()) {
474  throw(vpException(vpException::dimensionError, "Cannot subtract (1x%d) row vector to (1x%d) row vector", getCols(),
475  v.getCols()));
476  }
477 
478  for (unsigned int i = 0; i < colNum; ++i) {
479  (*this)[i] -= v[i];
480  }
481  return (*this);
482 }
483 
510 {
511  *this = v;
512  return *this;
513 }
514 
516 {
517  resize(1, false);
518  data[0] = val;
519  return *this;
520 }
521 
523 {
524  resize(colNum + 1, false);
525  data[colNum - 1] = val;
526  return *this;
527 }
528 
533 {
534  vpColVector v(colNum);
535  memcpy(v.data, data, colNum * sizeof(double));
536  return v;
537 }
538 
543 vpColVector vpRowVector::transpose() const { return t(); }
548 void vpRowVector::transpose(vpColVector &v) const { v = t(); }
549 
554 vpRowVector::vpRowVector(const vpMatrix &M, unsigned int i) : vpArray2D<double>(1, M.getCols())
555 {
556  unsigned int m_cols = M.getCols();
557  for (unsigned int j = 0; j < m_cols; ++j) {
558  (*this)[j] = M[i][j];
559  }
560 }
561 
568 vpRowVector::vpRowVector(const vpMatrix &M) : vpArray2D<double>(1, M.getCols())
569 {
570  if (M.getRows() != 1) {
571  throw(vpException(vpException::dimensionError, "Cannot construct a (1x%d) row vector from a (%dx%d) matrix",
572  M.getCols(), M.getRows(), M.getCols()));
573  }
574  unsigned int m_cols = M.getCols();
575  for (unsigned int j = 0; j < m_cols; ++j) {
576  (*this)[j] = M[0][j];
577  }
578 }
579 
583 vpRowVector::vpRowVector(const std::vector<double> &v) : vpArray2D<double>(1, static_cast<unsigned int>(v.size()))
584 {
585  unsigned int v_size = static_cast<unsigned int>(v.size());
586  for (unsigned int j = 0; j < v_size; ++j) {
587  (*this)[j] = v[j];
588  }
589 }
590 
594 vpRowVector::vpRowVector(const std::vector<float> &v) : vpArray2D<double>(1, static_cast<unsigned int>(v.size()))
595 {
596  unsigned int v_size = static_cast<unsigned int>(v.size());
597  for (unsigned int j = 0; j < v_size; ++j) {
598  (*this)[j] = static_cast<double>(v[j]);
599  }
600 }
601 
615 vpRowVector::vpRowVector(const vpRowVector &v, unsigned int c, unsigned int ncols) : vpArray2D<double>(1, ncols)
616 {
617  init(v, c, ncols);
618 }
619 
620 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
622 {
623  rowNum = v.rowNum;
624  colNum = v.colNum;
625  rowPtrs = v.rowPtrs;
626  dsize = v.dsize;
627  data = v.data;
628 
629  v.rowNum = 0;
630  v.colNum = 0;
631  v.rowPtrs = nullptr;
632  v.dsize = 0;
633  v.data = nullptr;
634 }
635 #endif
636 
647 {
648  x = x / sqrt(x.sumSquare());
649 
650  return x;
651 }
652 
662 {
663  double sum_square = sumSquare();
664  if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon()) {
665  *this /= sqrt(sum_square);
666  }
667 
668  // If sum = 0, we have a nul vector. So we return just.
669  return *this;
670 }
671 
683 vpMatrix vpRowVector::reshape(unsigned int nrows, unsigned int ncols)
684 {
685  vpMatrix M(nrows, ncols);
686  reshape(M, nrows, ncols);
687  return M;
688 }
689 
737 void vpRowVector::reshape(vpMatrix &M, const unsigned int &nrows, const unsigned int &ncols)
738 {
739  if (dsize != (nrows * ncols)) {
740  throw(vpException(vpException::dimensionError, "Cannot reshape (1x%d) row vector in (%dx%d) matrix", colNum,
741  M.getRows(), M.getCols()));
742  }
743  try {
744  if ((M.getRows() != nrows) || (M.getCols() != ncols)) {
745  M.resize(nrows, ncols);
746  }
747  }
748  catch (...) {
749  throw;
750  }
751  for (unsigned int i = 0; i < nrows; ++i) {
752  for (unsigned int j = 0; j < ncols; ++j) {
753  M[i][j] = data[(i * ncols) + j];
754  }
755  }
756 }
757 
794 void vpRowVector::insert(unsigned int i, const vpRowVector &v)
795 {
796  if ((i + v.size()) > this->size()) {
798  "Unable to insert (1x%d) row vector in (1x%d) row "
799  "vector at position (%d)",
800  v.getCols(), colNum, i));
801  }
802  unsigned int v_size = v.size();
803  for (unsigned int j = 0; j < v_size; ++j) {
804  (*this)[i + j] = v[j];
805  }
806 }
807 
812 std::vector<double> vpRowVector::toStdVector() const
813 {
814  std::vector<double> v(this->size());
815 
816  unsigned int this_size = this->size();
817  for (unsigned int i = 0; i < this_size; ++i) {
818  v[i] = data[i];
819  }
820  return v;
821 }
822 
839 void vpRowVector::stack(double d)
840 {
841  this->resize(colNum + 1, false);
842  (*this)[colNum - 1] = d;
843 }
844 
864 void vpRowVector::stack(const vpRowVector &v) { *this = vpRowVector::stack(*this, v); }
865 
887 {
888  vpRowVector C;
889  vpRowVector::stack(A, B, C);
890  return C;
891 }
892 
914 {
915  unsigned int nrA = A.getCols();
916  unsigned int nrB = B.getCols();
917 
918  if ((nrA == 0) && (nrB == 0)) {
919  C.resize(0);
920  return;
921  }
922 
923  if (nrB == 0) {
924  C = A;
925  return;
926  }
927 
928  if (nrA == 0) {
929  C = B;
930  return;
931  }
932 
933  // General case
934  C.resize(nrA + nrB);
935 
936  for (unsigned int i = 0; i < nrA; ++i) {
937  C[i] = A[i];
938  }
939 
940  for (unsigned int i = 0; i < nrB; ++i) {
941  C[nrA + i] = B[i];
942  }
943 }
944 
949 {
950  if ((v.data == nullptr) || (v.size() == 0)) {
951  throw(vpException(vpException::dimensionError, "Cannot compute mean value of an empty row vector"));
952  }
953 
954  double mean = 0;
955  double *vd = v.data;
956  unsigned int v_col = v.getCols();
957  for (unsigned int i = 0; i < v_col; ++i) {
958  mean += *(vd++);
959  }
960 
961  return mean / v.getCols();
962 }
963 
968 {
969  if ((v.data == nullptr) || (v.size() == 0)) {
970  throw(vpException(vpException::dimensionError, "Cannot compute mean value of an empty row vector"));
971  }
972 
973  std::vector<double> vectorOfDoubles(v.data, v.data + v.colNum);
974 
975  return vpMath::getMedian(vectorOfDoubles);
976 }
977 
981 double vpRowVector::stdev(const vpRowVector &v, bool useBesselCorrection)
982 {
983  if ((v.data == nullptr) || (v.size() == 0)) {
984  throw(vpException(vpException::dimensionError, "Cannot compute mean value of an empty row vector"));
985  }
986 
987  double mean_value = mean(v);
988  double sum_squared_diff = 0.0;
989  unsigned int v_size = v.size();
990  for (unsigned int i = 0; i < v_size; ++i) {
991  sum_squared_diff += (v[i] - mean_value) * (v[i] - mean_value);
992  }
993 
994  double divisor = static_cast<double>(v.size());
995  if (useBesselCorrection && (v.size() > 1)) {
996  divisor = divisor - 1;
997  }
998 
999  return std::sqrt(sum_squared_diff / divisor);
1000 }
1001 
1021 int vpRowVector::print(std::ostream &s, unsigned int length, char const *intro) const
1022 {
1023  typedef std::string::size_type size_type;
1024 
1025  unsigned int m = 1;
1026  unsigned int n = getCols();
1027 
1028  std::vector<std::string> values(m * n);
1029  std::ostringstream oss;
1030  std::ostringstream ossFixed;
1031  std::ios_base::fmtflags original_flags = oss.flags();
1032 
1033  // ossFixed <<std::fixed
1034  ossFixed.setf(std::ios::fixed, std::ios::floatfield);
1035 
1036  size_type maxBefore = 0; // the length of the integral part
1037  size_type maxAfter = 0; // number of decimals plus
1038  // one place for the decimal point
1039  for (unsigned int j = 0; j < n; ++j) {
1040  oss.str("");
1041  oss << (*this)[j];
1042  if (oss.str().find("e") != std::string::npos) {
1043  ossFixed.str("");
1044  ossFixed << (*this)[j];
1045  oss.str(ossFixed.str());
1046  }
1047 
1048  values[j] = oss.str();
1049  size_type thislen = values[j].size();
1050  size_type p = values[j].find('.');
1051 
1052  if (p == std::string::npos) {
1053  maxBefore = vpMath::maximum(maxBefore, thislen);
1054  // maxAfter remains the same
1055  }
1056  else {
1057  maxBefore = vpMath::maximum(maxBefore, p);
1058  maxAfter = vpMath::maximum(maxAfter, thislen - p - 1);
1059  }
1060  }
1061 
1062  size_type totalLength = length;
1063  // increase totalLength according to maxBefore
1064  totalLength = vpMath::maximum(totalLength, maxBefore);
1065  // decrease maxAfter according to totalLength
1066  maxAfter = std::min<size_type>(maxAfter, totalLength - maxBefore);
1067  if (maxAfter == 1) {
1068  maxAfter = 0;
1069  }
1070 
1071  // the following line is useful for debugging
1072  // std::cerr <<totalLength <<" " <<maxBefore <<" " <<maxAfter <<"\n";
1073 
1074  if (intro) {
1075  s << intro;
1076  }
1077  s << "[" << m << "," << n << "]=\n";
1078 
1079  s << " ";
1080  for (unsigned int j = 0; j < n; ++j) {
1081  size_type p = values[j].find('.');
1082  s.setf(std::ios::right, std::ios::adjustfield);
1083  s.width(static_cast<std::streamsize>(maxBefore));
1084  s << values[j].substr(0, p).c_str();
1085 
1086  if (maxAfter > 0) {
1087  s.setf(std::ios::left, std::ios::adjustfield);
1088  if (p != std::string::npos) {
1089  s.width(static_cast<std::streamsize>(maxAfter));
1090  s << values[j].substr(p, maxAfter).c_str();
1091  }
1092  else {
1093  assert(maxAfter > 1);
1094  s.width(static_cast<std::streamsize> (maxAfter));
1095  s << ".0";
1096  }
1097  }
1098 
1099  s << ' ';
1100  }
1101  s << std::endl;
1102 
1103  s.flags(original_flags); // restore s to standard state
1104 
1105  return static_cast<int>(maxBefore + maxAfter);
1106 }
1107 
1113 double vpRowVector::sum() const
1114 {
1115  double sum = 0.0;
1116 
1117  for (unsigned int j = 0; j < colNum; ++j) {
1118  sum += rowPtrs[0][j];
1119  }
1120 
1121  return sum;
1122 }
1123 
1131 {
1132  double sum_square = 0.0;
1133 
1134  for (unsigned int j = 0; j < colNum; ++j) {
1135  double x = rowPtrs[0][j];
1136  sum_square += x * x;
1137  }
1138 
1139  return sum_square;
1140 }
1141 
1148 {
1149  double norm = sumSquare();
1150 
1151  return sqrt(norm);
1152 }
1153 
1154 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
1164 double vpRowVector::euclideanNorm() const { return frobeniusNorm(); }
1165 #endif
1166 
1206 void vpRowVector::init(const vpRowVector &v, unsigned int c, unsigned int ncols)
1207 {
1208  unsigned int cncols = c + ncols;
1209 
1210  if (cncols > v.getCols()) {
1211  throw(vpException(vpException::dimensionError, "Bad column dimension (%d > %d) used to initialize vpRowVector",
1212  cncols, v.getCols()));
1213  }
1214  resize(ncols);
1215  if (this->rowPtrs == nullptr) { // Fix coverity scan: explicit null dereferenced
1216  return; // Noting to do
1217  }
1218  for (unsigned int i = 0; i < ncols; ++i) {
1219  (*this)[i] = v[i + c];
1220  }
1221 }
1222 
1256 std::ostream &vpRowVector::cppPrint(std::ostream &os, const std::string &matrixName, bool octet) const
1257 {
1258  os << "vpRowVector " << matrixName << " (" << this->getCols() << "); " << std::endl;
1259 
1260  unsigned int this_cols = this->getCols();
1261  for (unsigned int j = 0; j < this_cols; ++j) {
1262  if (!octet) {
1263  os << matrixName << "[" << j << "] = " << (*this)[j] << "; " << std::endl;
1264  }
1265  else {
1266  for (unsigned int k = 0; k < sizeof(double); ++k) {
1267  os << "((unsigned char*)&(" << matrixName << "[" << j << "]) )[" << k << "] = 0x" << std::hex
1268  << static_cast<unsigned int>(((unsigned char *)&((*this)[j]))[k]) << "; " << std::endl;
1269  }
1270  }
1271  }
1272  std::cout << std::endl;
1273  return os;
1274 }
1275 
1304 std::ostream &vpRowVector::csvPrint(std::ostream &os) const
1305 {
1306  unsigned int this_cols = this->getCols();
1307  for (unsigned int j = 0; j < this_cols; ++j) {
1308  os << (*this)[j];
1309  if (!(j == (this->getCols() - 1))) {
1310  os << ", ";
1311  }
1312  }
1313  os << std::endl;
1314  return os;
1315 }
1316 
1344 std::ostream &vpRowVector::maplePrint(std::ostream &os) const
1345 {
1346  os << "([ " << std::endl;
1347  os << "[";
1348  unsigned int this_cols = this->getCols();
1349  for (unsigned int j = 0; j < this_cols; ++j) {
1350  os << (*this)[j] << ", ";
1351  }
1352  os << "]," << std::endl;
1353  os << "])" << std::endl;
1354  return os;
1355 }
1356 
1391 std::ostream &vpRowVector::matlabPrint(std::ostream &os) const
1392 {
1393  os << "[ ";
1394 
1395  unsigned int this_cols = this->getCols();
1396  for (unsigned int j = 0; j < this_cols; ++j) {
1397  os << (*this)[j] << ", ";
1398  }
1399  os << "]" << std::endl;
1400  return os;
1401 }
1402 
1406 vpRowVector operator*(const double &x, const vpRowVector &v)
1407 {
1408  vpRowVector vout;
1409  vout = v * x;
1410  return vout;
1411 }
1412 
1414 {
1415  if ((v.getRows() != rowNum) || (v.getCols() != colNum)) {
1416  throw(vpException(vpException::dimensionError, "Hadamard product: bad dimensions!"));
1417  }
1418 
1419  vpRowVector out;
1420  out.resize(colNum, false);
1421 #if defined(VISP_HAVE_SIMDLIB)
1422  SimdVectorHadamard(data, v.data, colNum, out.data);
1423 #else
1424  for (unsigned int i = 0; i < dsize; ++i) {
1425  out.data[i] = data[i] * v.data[i];
1426  }
1427 #endif
1428  return out;
1429 }
1430 END_VISP_NAMESPACE
Implementation of a generic 2D array used as base class for matrices and vectors.
Definition: vpArray2D.h:145
unsigned int getCols() const
Definition: vpArray2D.h:337
double * data
Address of the first element of the data array.
Definition: vpArray2D.h:148
double ** rowPtrs
Address of the first element of each rows.
Definition: vpArray2D.h:1105
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Definition: vpArray2D.h:362
unsigned int rowNum
Number of rows in the array.
Definition: vpArray2D.h:1101
unsigned int dsize
Current array size (rowNum * colNum)
Definition: vpArray2D.h:1107
unsigned int size() const
Return the number of elements of the 2D array.
Definition: vpArray2D.h:349
unsigned int getRows() const
Definition: vpArray2D.h:347
unsigned int colNum
Number of columns in the array.
Definition: vpArray2D.h:1103
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
vpColVector operator*(const double &x, const vpColVector &v)
error that can be emitted by ViSP classes.
Definition: vpException.h:60
@ dimensionError
Bad dimension.
Definition: vpException.h:71
static double getMedian(const std::vector< double > &v)
Definition: vpMath.cpp:322
static Type maximum(const Type &a, const Type &b)
Definition: vpMath.h:254
static bool equal(double x, double y, double threshold=0.001)
Definition: vpMath.h:459
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:169
Implementation of row vector and the associated operations.
Definition: vpRowVector.h:124
bool operator==(const vpRowVector &v) const
Comparison operator.
vpRowVector & operator=(const vpRowVector &v)
Copy operator. Allow operation such as A = v.
Definition: vpRowVector.cpp:57
vpRowVector & operator/=(double x)
double frobeniusNorm() const
vpColVector t() const
void resize(unsigned int i, bool flagNullify=true)
Definition: vpRowVector.h:287
vpRowVector & operator+=(vpRowVector v)
bool operator!=(const vpRowVector &v) const
vpRowVector operator-() const
static double mean(const vpRowVector &v)
void insert(unsigned int i, const vpRowVector &v)
vpRowVector & operator,(double val)
vpRowVector()
Basic constructor that creates an empty 0-size row vector.
Definition: vpRowVector.h:127
vpColVector transpose() const
void stack(double d)
void init(const vpRowVector &v, unsigned int c, unsigned int ncols)
vpRowVector operator+(const vpRowVector &v) const
std::ostream & maplePrint(std::ostream &os) const
double sum() const
double operator*(const vpColVector &x) const
std::ostream & cppPrint(std::ostream &os, const std::string &matrixName="A", bool octet=false) const
vpRowVector & operator*=(double x)
double sumSquare() const
vpRowVector & normalize()
std::ostream & csvPrint(std::ostream &os) const
vpRowVector operator/(double x) const
void reshape(vpMatrix &M, const unsigned int &nrows, const unsigned int &ncols)
static double median(const vpRowVector &v)
std::vector< double > toStdVector() const
vpRowVector & operator<<(const vpRowVector &v)
static double stdev(const vpRowVector &v, bool useBesselCorrection=false)
vpRowVector & operator-=(vpRowVector v)
int print(std::ostream &s, unsigned int length, char const *intro=0) const
std::ostream & matlabPrint(std::ostream &os) const
vpRowVector hadamard(const vpRowVector &v) const