Visual Servoing Platform  version 3.6.1 under development (2024-07-27)
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 
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  }
297  return v;
298 }
299 
318 {
319  for (unsigned int i = 0; i < colNum; ++i) {
320  (*this)[i] *= x;
321  }
322  return (*this);
323 }
324 
345 {
346  vpRowVector v(colNum);
347 
348  double *vd = v.data;
349  double *d = data;
350 
351  for (unsigned int i = 0; i < colNum; ++i) {
352  *(vd++) = (*d++) / x;
353  }
354  return v;
355 }
356 
376 {
377  for (unsigned int i = 0; i < colNum; ++i) {
378  (*this)[i] /= x;
379  }
380  return (*this);
381 }
382 
394 {
395  vpRowVector A(colNum);
396 
397  double *vd = A.data;
398  double *d = data;
399 
400  for (unsigned int i = 0; i < colNum; ++i) {
401  *(vd++) = -(*d++);
402  }
403 
404  return A;
405 }
406 
412 {
413  if (getCols() != m.getCols()) {
414  throw(vpException(vpException::dimensionError, "Cannot subtract (1x%d) row vector to (1x%d) row vector", getCols(),
415  m.getCols()));
416  }
417 
418  vpRowVector v(colNum);
419 
420  for (unsigned int i = 0; i < colNum; ++i) {
421  v[i] = (*this)[i] - m[i];
422  }
423  return v;
424 }
425 
431 {
432  if (getCols() != v.getCols()) {
433  throw(vpException(vpException::dimensionError, "Cannot add (1x%d) row vector to (1x%d) row vector", getCols(),
434  v.getCols()));
435  }
436 
437  vpRowVector r(colNum);
438 
439  for (unsigned int i = 0; i < colNum; ++i) {
440  r[i] = (*this)[i] + v[i];
441  }
442  return r;
443 }
444 
451 {
452  if (getCols() != v.getCols()) {
453  throw(vpException(vpException::dimensionError, "Cannot add (1x%d) row vector to (1x%d) row vector", getCols(),
454  v.getCols()));
455  }
456 
457  for (unsigned int i = 0; i < colNum; ++i) {
458  (*this)[i] += v[i];
459  }
460  return (*this);
461 }
462 
469 {
470  if (getCols() != v.getCols()) {
471  throw(vpException(vpException::dimensionError, "Cannot subtract (1x%d) row vector to (1x%d) row vector", getCols(),
472  v.getCols()));
473  }
474 
475  for (unsigned int i = 0; i < colNum; ++i) {
476  (*this)[i] -= v[i];
477  }
478  return (*this);
479 }
480 
507 {
508  *this = v;
509  return *this;
510 }
511 
513 {
514  resize(1, false);
515  data[0] = val;
516  return *this;
517 }
518 
520 {
521  resize(colNum + 1, false);
522  data[colNum - 1] = val;
523  return *this;
524 }
525 
530 {
531  vpColVector v(colNum);
532  memcpy(v.data, data, colNum * sizeof(double));
533  return v;
534 }
535 
540 vpColVector vpRowVector::transpose() const { return t(); }
545 void vpRowVector::transpose(vpColVector &v) const { v = t(); }
546 
551 vpRowVector::vpRowVector(const vpMatrix &M, unsigned int i) : vpArray2D<double>(1, M.getCols())
552 {
553  unsigned int m_cols = M.getCols();
554  for (unsigned int j = 0; j < m_cols; ++j) {
555  (*this)[j] = M[i][j];
556  }
557 }
558 
565 vpRowVector::vpRowVector(const vpMatrix &M) : vpArray2D<double>(1, M.getCols())
566 {
567  if (M.getRows() != 1) {
568  throw(vpException(vpException::dimensionError, "Cannot construct a (1x%d) row vector from a (%dx%d) matrix",
569  M.getCols(), M.getRows(), M.getCols()));
570  }
571  unsigned int m_cols = M.getCols();
572  for (unsigned int j = 0; j < m_cols; ++j) {
573  (*this)[j] = M[0][j];
574  }
575 }
576 
580 vpRowVector::vpRowVector(const std::vector<double> &v) : vpArray2D<double>(1, static_cast<unsigned int>(v.size()))
581 {
582  unsigned int v_size = static_cast<unsigned int>(v.size());
583  for (unsigned int j = 0; j < v_size; ++j) {
584  (*this)[j] = v[j];
585  }
586 }
587 
591 vpRowVector::vpRowVector(const std::vector<float> &v) : vpArray2D<double>(1, static_cast<unsigned int>(v.size()))
592 {
593  unsigned int v_size = static_cast<unsigned int>(v.size());
594  for (unsigned int j = 0; j < v_size; ++j) {
595  (*this)[j] = static_cast<double>(v[j]);
596  }
597 }
598 
612 vpRowVector::vpRowVector(const vpRowVector &v, unsigned int c, unsigned int ncols) : vpArray2D<double>(1, ncols)
613 {
614  init(v, c, ncols);
615 }
616 
617 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
619 {
620  rowNum = v.rowNum;
621  colNum = v.colNum;
622  rowPtrs = v.rowPtrs;
623  dsize = v.dsize;
624  data = v.data;
625 
626  v.rowNum = 0;
627  v.colNum = 0;
628  v.rowPtrs = nullptr;
629  v.dsize = 0;
630  v.data = nullptr;
631 }
632 #endif
633 
644 {
645  x = x / sqrt(x.sumSquare());
646 
647  return x;
648 }
649 
659 {
660  double sum_square = sumSquare();
661  if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon()) {
662  *this /= sqrt(sum_square);
663  }
664 
665  // If sum = 0, we have a nul vector. So we return just.
666  return *this;
667 }
668 
680 vpMatrix vpRowVector::reshape(unsigned int nrows, unsigned int ncols)
681 {
682  vpMatrix M(nrows, ncols);
683  reshape(M, nrows, ncols);
684  return M;
685 }
686 
734 void vpRowVector::reshape(vpMatrix &M, const unsigned int &nrows, const unsigned int &ncols)
735 {
736  if (dsize != (nrows * ncols)) {
737  throw(vpException(vpException::dimensionError, "Cannot reshape (1x%d) row vector in (%dx%d) matrix", colNum,
738  M.getRows(), M.getCols()));
739  }
740  try {
741  if ((M.getRows() != nrows) || (M.getCols() != ncols)) {
742  M.resize(nrows, ncols);
743  }
744  }
745  catch (...) {
746  throw;
747  }
748  for (unsigned int i = 0; i < nrows; ++i) {
749  for (unsigned int j = 0; j < ncols; ++j) {
750  M[i][j] = data[(i * ncols) + j];
751  }
752  }
753 }
754 
791 void vpRowVector::insert(unsigned int i, const vpRowVector &v)
792 {
793  if ((i + v.size()) > this->size()) {
795  "Unable to insert (1x%d) row vector in (1x%d) row "
796  "vector at position (%d)",
797  v.getCols(), colNum, i));
798  }
799  unsigned int v_size = v.size();
800  for (unsigned int j = 0; j < v_size; ++j) {
801  (*this)[i + j] = v[j];
802  }
803 }
804 
809 std::vector<double> vpRowVector::toStdVector() const
810 {
811  std::vector<double> v(this->size());
812 
813  unsigned int this_size = this->size();
814  for (unsigned int i = 0; i < this_size; ++i) {
815  v[i] = data[i];
816  }
817  return v;
818 }
819 
836 void vpRowVector::stack(double d)
837 {
838  this->resize(colNum + 1, false);
839  (*this)[colNum - 1] = d;
840 }
841 
861 void vpRowVector::stack(const vpRowVector &v) { *this = vpRowVector::stack(*this, v); }
862 
884 {
885  vpRowVector C;
886  vpRowVector::stack(A, B, C);
887  return C;
888 }
889 
911 {
912  unsigned int nrA = A.getCols();
913  unsigned int nrB = B.getCols();
914 
915  if ((nrA == 0) && (nrB == 0)) {
916  C.resize(0);
917  return;
918  }
919 
920  if (nrB == 0) {
921  C = A;
922  return;
923  }
924 
925  if (nrA == 0) {
926  C = B;
927  return;
928  }
929 
930  // General case
931  C.resize(nrA + nrB);
932 
933  for (unsigned int i = 0; i < nrA; ++i) {
934  C[i] = A[i];
935  }
936 
937  for (unsigned int i = 0; i < nrB; ++i) {
938  C[nrA + i] = B[i];
939  }
940 }
941 
946 {
947  if ((v.data == nullptr) || (v.size() == 0)) {
948  throw(vpException(vpException::dimensionError, "Cannot compute mean value of an empty row vector"));
949  }
950 
951  double mean = 0;
952  double *vd = v.data;
953  unsigned int v_col = v.getCols();
954  for (unsigned int i = 0; i < v_col; ++i) {
955  mean += *(vd++);
956  }
957 
958  return mean / v.getCols();
959 }
960 
965 {
966  if ((v.data == nullptr) || (v.size() == 0)) {
967  throw(vpException(vpException::dimensionError, "Cannot compute mean value of an empty row vector"));
968  }
969 
970  std::vector<double> vectorOfDoubles(v.data, v.data + v.colNum);
971 
972  return vpMath::getMedian(vectorOfDoubles);
973 }
974 
978 double vpRowVector::stdev(const vpRowVector &v, bool useBesselCorrection)
979 {
980  if ((v.data == nullptr) || (v.size() == 0)) {
981  throw(vpException(vpException::dimensionError, "Cannot compute mean value of an empty row vector"));
982  }
983 
984  double mean_value = mean(v);
985  double sum_squared_diff = 0.0;
986  unsigned int v_size = v.size();
987  for (unsigned int i = 0; i < v_size; ++i) {
988  sum_squared_diff += (v[i] - mean_value) * (v[i] - mean_value);
989  }
990 
991  double divisor = static_cast<double>(v.size());
992  if (useBesselCorrection && (v.size() > 1)) {
993  divisor = divisor - 1;
994  }
995 
996  return std::sqrt(sum_squared_diff / divisor);
997 }
998 
1018 int vpRowVector::print(std::ostream &s, unsigned int length, char const *intro) const
1019 {
1020  typedef std::string::size_type size_type;
1021 
1022  unsigned int m = 1;
1023  unsigned int n = getCols();
1024 
1025  std::vector<std::string> values(m * n);
1026  std::ostringstream oss;
1027  std::ostringstream ossFixed;
1028  std::ios_base::fmtflags original_flags = oss.flags();
1029 
1030  // ossFixed <<std::fixed
1031  ossFixed.setf(std::ios::fixed, std::ios::floatfield);
1032 
1033  size_type maxBefore = 0; // the length of the integral part
1034  size_type maxAfter = 0; // number of decimals plus
1035  // one place for the decimal point
1036  for (unsigned int j = 0; j < n; ++j) {
1037  oss.str("");
1038  oss << (*this)[j];
1039  if (oss.str().find("e") != std::string::npos) {
1040  ossFixed.str("");
1041  ossFixed << (*this)[j];
1042  oss.str(ossFixed.str());
1043  }
1044 
1045  values[j] = oss.str();
1046  size_type thislen = values[j].size();
1047  size_type p = values[j].find('.');
1048 
1049  if (p == std::string::npos) {
1050  maxBefore = vpMath::maximum(maxBefore, thislen);
1051  // maxAfter remains the same
1052  }
1053  else {
1054  maxBefore = vpMath::maximum(maxBefore, p);
1055  maxAfter = vpMath::maximum(maxAfter, thislen - p - 1);
1056  }
1057  }
1058 
1059  size_type totalLength = length;
1060  // increase totalLength according to maxBefore
1061  totalLength = vpMath::maximum(totalLength, maxBefore);
1062  // decrease maxAfter according to totalLength
1063  maxAfter = std::min<size_type>(maxAfter, totalLength - maxBefore);
1064  if (maxAfter == 1) {
1065  maxAfter = 0;
1066  }
1067 
1068  // the following line is useful for debugging
1069  // std::cerr <<totalLength <<" " <<maxBefore <<" " <<maxAfter <<"\n";
1070 
1071  if (intro) {
1072  s << intro;
1073  }
1074  s << "[" << m << "," << n << "]=\n";
1075 
1076  s << " ";
1077  for (unsigned int j = 0; j < n; ++j) {
1078  size_type p = values[j].find('.');
1079  s.setf(std::ios::right, std::ios::adjustfield);
1080  s.width(static_cast<std::streamsize>(maxBefore));
1081  s << values[j].substr(0, p).c_str();
1082 
1083  if (maxAfter > 0) {
1084  s.setf(std::ios::left, std::ios::adjustfield);
1085  if (p != std::string::npos) {
1086  s.width(static_cast<std::streamsize>(maxAfter));
1087  s << values[j].substr(p, maxAfter).c_str();
1088  }
1089  else {
1090  assert(maxAfter > 1);
1091  s.width(static_cast<std::streamsize> (maxAfter));
1092  s << ".0";
1093  }
1094  }
1095 
1096  s << ' ';
1097  }
1098  s << std::endl;
1099 
1100  s.flags(original_flags); // restore s to standard state
1101 
1102  return static_cast<int>(maxBefore + maxAfter);
1103 }
1104 
1110 double vpRowVector::sum() const
1111 {
1112  double sum = 0.0;
1113 
1114  for (unsigned int j = 0; j < colNum; ++j) {
1115  sum += rowPtrs[0][j];
1116  }
1117 
1118  return sum;
1119 }
1120 
1128 {
1129  double sum_square = 0.0;
1130 
1131  for (unsigned int j = 0; j < colNum; ++j) {
1132  double x = rowPtrs[0][j];
1133  sum_square += x * x;
1134  }
1135 
1136  return sum_square;
1137 }
1138 
1145 {
1146  double norm = sumSquare();
1147 
1148  return sqrt(norm);
1149 }
1150 
1151 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
1161 double vpRowVector::euclideanNorm() const { return frobeniusNorm(); }
1162 #endif
1163 
1203 void vpRowVector::init(const vpRowVector &v, unsigned int c, unsigned int ncols)
1204 {
1205  unsigned int cncols = c + ncols;
1206 
1207  if (cncols > v.getCols()) {
1208  throw(vpException(vpException::dimensionError, "Bad column dimension (%d > %d) used to initialize vpRowVector",
1209  cncols, v.getCols()));
1210  }
1211  resize(ncols);
1212  if (this->rowPtrs == nullptr) { // Fix coverity scan: explicit null dereferenced
1213  return; // Noting to do
1214  }
1215  for (unsigned int i = 0; i < ncols; ++i) {
1216  (*this)[i] = v[i + c];
1217  }
1218 }
1219 
1253 std::ostream &vpRowVector::cppPrint(std::ostream &os, const std::string &matrixName, bool octet) const
1254 {
1255  os << "vpRowVector " << matrixName << " (" << this->getCols() << "); " << std::endl;
1256 
1257  unsigned int this_cols = this->getCols();
1258  for (unsigned int j = 0; j < this_cols; ++j) {
1259  if (!octet) {
1260  os << matrixName << "[" << j << "] = " << (*this)[j] << "; " << std::endl;
1261  }
1262  else {
1263  for (unsigned int k = 0; k < sizeof(double); ++k) {
1264  os << "((unsigned char*)&(" << matrixName << "[" << j << "]) )[" << k << "] = 0x" << std::hex
1265  << static_cast<unsigned int>(((unsigned char *)&((*this)[j]))[k]) << "; " << std::endl;
1266  }
1267  }
1268  }
1269  std::cout << std::endl;
1270  return os;
1271 }
1272 
1301 std::ostream &vpRowVector::csvPrint(std::ostream &os) const
1302 {
1303  unsigned int this_cols = this->getCols();
1304  for (unsigned int j = 0; j < this_cols; ++j) {
1305  os << (*this)[j];
1306  if (!(j == (this->getCols() - 1))) {
1307  os << ", ";
1308  }
1309  }
1310  os << std::endl;
1311  return os;
1312 }
1313 
1341 std::ostream &vpRowVector::maplePrint(std::ostream &os) const
1342 {
1343  os << "([ " << std::endl;
1344  os << "[";
1345  unsigned int this_cols = this->getCols();
1346  for (unsigned int j = 0; j < this_cols; ++j) {
1347  os << (*this)[j] << ", ";
1348  }
1349  os << "]," << std::endl;
1350  os << "])" << std::endl;
1351  return os;
1352 }
1353 
1388 std::ostream &vpRowVector::matlabPrint(std::ostream &os) const
1389 {
1390  os << "[ ";
1391 
1392  unsigned int this_cols = this->getCols();
1393  for (unsigned int j = 0; j < this_cols; ++j) {
1394  os << (*this)[j] << ", ";
1395  }
1396  os << "]" << std::endl;
1397  return os;
1398 }
1399 
1403 vpRowVector operator*(const double &x, const vpRowVector &v)
1404 {
1405  vpRowVector vout;
1406  vout = v * x;
1407  return vout;
1408 }
1409 
1411 {
1412  if ((v.getRows() != rowNum) || (v.getCols() != colNum)) {
1413  throw(vpException(vpException::dimensionError, "Hadamard product: bad dimensions!"));
1414  }
1415 
1416  vpRowVector out;
1417  out.resize(colNum, false);
1418 #if defined(VISP_HAVE_SIMDLIB)
1419  SimdVectorHadamard(data, v.data, colNum, out.data);
1420 #else
1421  for (unsigned int i = 0; i < dsize; ++i) {
1422  out.data[i] = data[i] * v.data[i];
1423  }
1424 #endif
1425  return out;
1426 }
1427 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:1102
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:1098
unsigned int dsize
Current array size (rowNum * colNum)
Definition: vpArray2D.h:1104
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:1100
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:458
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
VP_DEPRECATED double euclideanNorm() 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)
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)
VP_DEPRECATED void init()
Definition: vpRowVector.h:335
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