Visual Servoing Platform  version 3.6.1 under development (2024-11-21)
vpMatrix.h
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  * Matrix manipulation.
32  */
33 
41 #ifndef VP_MATRIX_H
42 #define VP_MATRIX_H
43 
44 #include <visp3/core/vpConfig.h>
45 
46 BEGIN_VISP_NAMESPACE
47 class vpRowVector;
48 class vpColVector;
52 class vpForceTwistMatrix;
53 END_VISP_NAMESPACE
54 
55 #include <visp3/core/vpArray2D.h>
56 #include <visp3/core/vpException.h>
57 #include <visp3/core/vpForceTwistMatrix.h>
58 #include <visp3/core/vpHomogeneousMatrix.h>
59 #include <visp3/core/vpRotationMatrix.h>
60 #include <visp3/core/vpTime.h>
61 #include <visp3/core/vpVelocityTwistMatrix.h>
62 
63 #include <iostream>
64 #include <math.h>
65 
66 BEGIN_VISP_NAMESPACE
67 
168 class VISP_EXPORT vpMatrix : public vpArray2D<double>
169 {
170 public:
175  typedef enum
176  {
177  LU_DECOMPOSITION
178  } vpDetMethod;
179 
180 public:
185  vpMatrix() : vpArray2D<double>(0, 0) { }
186 
193  vpMatrix(unsigned int r, unsigned int c) : vpArray2D<double>(r, c) { }
194 
202  vpMatrix(unsigned int r, unsigned int c, double val) : vpArray2D<double>(r, c, val) { }
203  vpMatrix(const vpMatrix &M, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols);
204 
217  VP_EXPLICIT vpMatrix(const vpArray2D<double> &A) : vpArray2D<double>(A) { }
218  vpMatrix(const vpMatrix &A) : vpArray2D<double>(A) { }
219  VP_EXPLICIT vpMatrix(const vpHomogeneousMatrix &R);
220  VP_EXPLICIT vpMatrix(const vpRotationMatrix &R);
221  VP_EXPLICIT vpMatrix(const vpVelocityTwistMatrix &V);
222  VP_EXPLICIT vpMatrix(const vpForceTwistMatrix &F);
223  VP_EXPLICIT vpMatrix(const vpColVector &v);
224  VP_EXPLICIT vpMatrix(const vpRowVector &v);
225  VP_EXPLICIT vpMatrix(const vpTranslationVector &t);
226 
227 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
228  vpMatrix(vpMatrix &&A);
229  VP_EXPLICIT vpMatrix(const std::initializer_list<double> &list);
230  VP_EXPLICIT vpMatrix(unsigned int nrows, unsigned int ncols, const std::initializer_list<double> &list);
231  VP_EXPLICIT vpMatrix(const std::initializer_list<std::initializer_list<double> > &lists);
232 #endif
233 
238  void clear()
239  {
240  if (data != nullptr) {
241  free(data);
242  data = nullptr;
243  }
244 
245  if (rowPtrs != nullptr) {
246  free(rowPtrs);
247  rowPtrs = nullptr;
248  }
249  rowNum = 0;
250  colNum = 0;
251  dsize = 0;
252  }
253 
254  //-------------------------------------------------
255  // Setting a diagonal matrix
256  //-------------------------------------------------
267  static unsigned int getLapackMatrixMinSize() { return m_lapack_min_size; }
268 
281  static void setLapackMatrixMinSize(unsigned int min_size) { m_lapack_min_size = min_size; }
283 
284  //-------------------------------------------------
285  // Setting a diagonal matrix
286  //-------------------------------------------------
289  void diag(const double &val = 1.0);
290  void diag(const vpColVector &A);
291  // Initialize an identity matrix n-by-n
292  void eye();
293  void eye(unsigned int n);
294  // Initialize an identity matrix m-by-n
295  void eye(unsigned int m, unsigned int n);
297 
298  //---------------------------------
299  // Assignment
300  //---------------------------------
303  vpMatrix &operator<<(double *p);
304  vpMatrix &operator<<(double val);
305  vpMatrix &operator,(double val);
307  vpMatrix &operator=(const vpMatrix &A);
312  vpMatrix &operator=(const vpColVector &v);
313  vpMatrix &operator=(const vpRowVector &v);
315 
316 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
318 
319  vpMatrix &operator=(const std::initializer_list<double> &list);
320  vpMatrix &operator=(const std::initializer_list<std::initializer_list<double> > &lists);
321 #endif
322  vpMatrix &operator=(double x);
324 
325  //-------------------------------------------------
326  // Stacking
327  //-------------------------------------------------
330  // Stack the matrix A below the current one, copy if not initialized this =
331  // [ this A ]^T
332  void stack(const vpMatrix &A);
333  void stack(const vpRowVector &r);
334  void stack(const vpColVector &c);
335  // Stacks columns of a matrix in a vector
336  void stackColumns(vpColVector &out);
337 
338  // Stacks columns of a matrix in a vector
339  vpColVector stackColumns();
340 
341  // Stacks columns of a matrix in a vector
342  void stackRows(vpRowVector &out);
343 
344  // Stacks columns of a matrix in a vector
345  vpRowVector stackRows();
347 
348  //---------------------------------
349  // Matrix insertion
350  //---------------------------------
353  // Insert matrix A in the current matrix at the given position (r, c).
354  void insert(const vpMatrix &A, unsigned int r, unsigned int c);
356 
357  //-------------------------------------------------
358  // Columns, Rows, Diag extraction, SubMatrix
359  //-------------------------------------------------
362  vpMatrix extract(unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols) const;
363  vpColVector getCol(unsigned int j) const;
364  vpColVector getCol(unsigned int j, unsigned int i_begin, unsigned int size) const;
365  vpRowVector getRow(unsigned int i) const;
366  vpRowVector getRow(unsigned int i, unsigned int j_begin, unsigned int size) const;
367  vpColVector getDiag() const;
368  void init(const vpMatrix &M, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols);
370 
371  //---------------------------------
372  // Matrix operations.
373  //---------------------------------
387  static vpMatrix conv2(const vpMatrix &M, const vpMatrix &kernel, const std::string &mode);
388 
401  static void conv2(const vpMatrix &M, const vpMatrix &kernel, vpMatrix &res, const std::string &mode);
402 
403  // return the determinant of the matrix.
404  double det(vpDetMethod method = LU_DECOMPOSITION) const;
405  double detByLU() const;
406 #if defined(VISP_HAVE_EIGEN3)
407  double detByLUEigen3() const;
408 #endif
409 #if defined(VISP_HAVE_LAPACK)
410  double detByLULapack() const;
411 #endif
412 #if defined(VISP_HAVE_OPENCV)
413  double detByLUOpenCV() const;
414 #endif
415  vpMatrix cholesky() const;
416 #if defined(VISP_HAVE_EIGEN3)
417  vpMatrix choleskyByEigen3() const;
418 #endif
419 #if defined(VISP_HAVE_LAPACK)
420  vpMatrix choleskyByLapack() const;
421 #endif
422 #if defined(VISP_HAVE_OPENCV)
423  vpMatrix choleskyByOpenCV() const;
424 #endif
425 
426  // Compute the exponential matrix of a square matrix
427  vpMatrix expm() const;
428 
429  // operation A = A + B
430  vpMatrix &operator+=(const vpMatrix &B);
431  // operation A = A - B
432  vpMatrix &operator-=(const vpMatrix &B);
433  vpMatrix operator*(const vpMatrix &B) const;
434  vpMatrix operator*(const vpRotationMatrix &R) const;
435  vpMatrix operator*(const vpHomogeneousMatrix &R) const;
436  vpMatrix operator*(const vpVelocityTwistMatrix &V) const;
437  vpMatrix operator*(const vpForceTwistMatrix &V) const;
438  // operation t_out = A * t (A is unchanged, t and t_out are translation
439  // vectors)
441  vpColVector operator*(const vpColVector &v) const;
442  vpMatrix operator+(const vpMatrix &B) const;
443  vpMatrix operator-(const vpMatrix &B) const;
444  vpMatrix operator-() const;
445 
447  vpMatrix &operator+=(double x);
449  vpMatrix &operator-=(double x);
451  vpMatrix &operator*=(double x);
453  vpMatrix &operator/=(double x);
454 
455  // Cij = Aij * x (A is unchanged)
456  vpMatrix operator*(double x) const;
457  // Cij = Aij / x (A is unchanged)
458  vpMatrix operator/(double x) const;
459 
465  double sum() const;
466  double sumSquare() const;
467 
468  //-------------------------------------------------
469  // Hadamard product
470  //-------------------------------------------------
472  vpMatrix hadamard(const vpMatrix &m) const;
473 
474  //-------------------------------------------------
475  // Kronecker product
476  //-------------------------------------------------
479  // Compute Kronecker product matrix
480  void kron(const vpMatrix &m1, vpMatrix &out) const;
481 
482  // Compute Kronecker product matrix
483  vpMatrix kron(const vpMatrix &m1) const;
485 
486  //-------------------------------------------------
487  // Transpose
488  //-------------------------------------------------
491  // Compute the transpose C = A^T
492  vpMatrix t() const;
493 
494  // Compute the transpose C = A^T
495  vpMatrix transpose() const;
496  void transpose(vpMatrix &At) const;
497 
498  vpMatrix AAt() const;
499  void AAt(vpMatrix &B) const;
500 
501  vpMatrix AtA() const;
502  void AtA(vpMatrix &B) const;
504 
505  //-------------------------------------------------
506  // Matrix inversion
507  //-------------------------------------------------
510  // inverse matrix A using the LU decomposition
511  vpMatrix inverseByLU() const;
512 
513 #if defined(VISP_HAVE_EIGEN3)
514  vpMatrix inverseByLUEigen3() const;
515 #endif
516 #if defined(VISP_HAVE_LAPACK)
517  vpMatrix inverseByLULapack() const;
518 #endif
519 #if defined(VISP_HAVE_OPENCV)
520  vpMatrix inverseByLUOpenCV() const;
521 #endif
522 
523  // inverse matrix A using the Cholesky decomposition (only for real
524  // symmetric matrices)
525  vpMatrix inverseByCholesky() const;
526 
527 #if defined(VISP_HAVE_LAPACK)
528  vpMatrix inverseByCholeskyLapack() const;
529 #endif
530 #if defined(VISP_HAVE_OPENCV)
531  vpMatrix inverseByCholeskyOpenCV() const;
532 #endif
533 
534  // inverse matrix A using the QR decomposition
535  vpMatrix inverseByQR() const;
536 #if defined(VISP_HAVE_LAPACK)
537  vpMatrix inverseByQRLapack() const;
538 #endif
539 
540  // inverse triangular matrix
541  vpMatrix inverseTriangular(bool upper = true) const;
542 
543  vpMatrix pseudoInverse(double svThreshold = 1e-6) const;
544  unsigned int pseudoInverse(vpMatrix &Ap, double svThreshold = 1e-6) const;
545  unsigned int pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
546  unsigned int pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt) const;
547  unsigned int pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
548  vpMatrix pseudoInverse(int rank_in) const;
549  int pseudoInverse(vpMatrix &Ap, int rank_in) const;
550  int pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
551  int pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt) const;
552  int pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
553 
554 #if defined(VISP_HAVE_LAPACK)
555  vpMatrix pseudoInverseLapack(double svThreshold = 1e-6) const;
556  unsigned int pseudoInverseLapack(vpMatrix &Ap, double svThreshold = 1e-6) const;
557  unsigned int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
558  unsigned int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
559  vpMatrix pseudoInverseLapack(int rank_in) const;
560  int pseudoInverseLapack(vpMatrix &Ap, int rank_in) const;
561  int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
562  int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
563 #endif
564 #if defined(VISP_HAVE_EIGEN3)
565  vpMatrix pseudoInverseEigen3(double svThreshold = 1e-6) const;
566  unsigned int pseudoInverseEigen3(vpMatrix &Ap, double svThreshold = 1e-6) const;
567  unsigned int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
568  unsigned int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
569  vpMatrix pseudoInverseEigen3(int rank_in) const;
570  int pseudoInverseEigen3(vpMatrix &Ap, int rank_in) const;
571  int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
572  int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
573 #endif
574 #if defined(VISP_HAVE_OPENCV)
575  vpMatrix pseudoInverseOpenCV(double svThreshold = 1e-6) const;
576  unsigned int pseudoInverseOpenCV(vpMatrix &Ap, double svThreshold = 1e-6) const;
577  unsigned int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
578  unsigned int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
579  vpMatrix pseudoInverseOpenCV(int rank_in) const;
580  int pseudoInverseOpenCV(vpMatrix &Ap, int rank_in) const;
581  int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
582  int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
583 #endif
584 
585  vpMatrix dampedInverse(const double &ratioOfMaxSvd = 1e-4) const;
587 
588  //-------------------------------------------------
589  // SVD decomposition
590  //-------------------------------------------------
591 
594  double cond(double svThreshold = 1e-6) const;
595  unsigned int kernel(vpMatrix &kerAt, double svThreshold = 1e-6) const;
596  unsigned int nullSpace(vpMatrix &kerA, double svThreshold = 1e-6) const;
597  unsigned int nullSpace(vpMatrix &kerA, int dim) const;
598 
599  // solve Ax=B using the SVD decomposition (usage A = solveBySVD(B,x) )
600  void solveBySVD(const vpColVector &B, vpColVector &x) const;
601  // solve Ax=B using the SVD decomposition (usage x=A.solveBySVD(B))
602  vpColVector solveBySVD(const vpColVector &B) const;
603 
604  // singular value decomposition SVD
605  void svd(vpColVector &w, vpMatrix &V);
606 #ifdef VISP_HAVE_EIGEN3
607  void svdEigen3(vpColVector &w, vpMatrix &V);
608 #endif
609 #if defined(VISP_HAVE_LAPACK)
610  void svdLapack(vpColVector &w, vpMatrix &V);
611 #endif
612 #if defined(VISP_HAVE_OPENCV) // Require opencv >= 2.1.1
613  void svdOpenCV(vpColVector &w, vpMatrix &V);
614 #endif
616 
617  //-------------------------------------------------
618  // QR decomposition
619  //-------------------------------------------------
620 
623  unsigned int qr(vpMatrix &Q, vpMatrix &R, bool full = false, bool squareR = false, double tol = 1e-6) const;
624  unsigned int qrPivot(vpMatrix &Q, vpMatrix &R, vpMatrix &P, bool full = false, bool squareR = false,
625  double tol = 1e-6) const;
626  void solveByQR(const vpColVector &b, vpColVector &x) const;
627  vpColVector solveByQR(const vpColVector &b) const;
629 
630  //-------------------------------------------------
631  // Eigen values and vectors
632  //-------------------------------------------------
636  // Compute the eigen values using Lapack.
637  vpColVector eigenValues() const;
638  void eigenValues(vpColVector &evalue, vpMatrix &evector) const;
640 
641  //-------------------------------------------------
642  // Norms
643  //-------------------------------------------------
646  double frobeniusNorm() const;
647  double inducedL2Norm() const;
648  double infinityNorm() const;
650 
651  //---------------------------------
652  // Printing
653  //---------------------------------
656  std::ostream &cppPrint(std::ostream &os, const std::string &matrixName = "A", bool octet = false) const;
657  std::ostream &csvPrint(std::ostream &os) const;
658  std::ostream &maplePrint(std::ostream &os) const;
659  std::ostream &matlabPrint(std::ostream &os) const;
660  int print(std::ostream &s, unsigned int length, const std::string &intro = "") const;
661  void printSize() const { std::cout << getRows() << " x " << getCols() << " "; }
663 
664  //------------------------------------------------------------------
665  // Static functionalities
666  //------------------------------------------------------------------
667 
668  //---------------------------------
669  // Setting a diagonal matrix with Static Public Member Functions
670  //---------------------------------
673  // Create a diagonal matrix with the element of a vector DAii = Ai
674  static void createDiagonalMatrix(const vpColVector &A, vpMatrix &DA);
676 
677  //---------------------------------
678  // Matrix insertion with Static Public Member Functions
679  //---------------------------------
682  // Insert matrix B in matrix A at the given position (r, c).
683  static vpMatrix insert(const vpMatrix &A, const vpMatrix &B, unsigned int r, unsigned int c);
684  // Insert matrix B in matrix A (not modified) at the given position (r, c),
685  // the result is given in matrix C.
686  static void insert(const vpMatrix &A, const vpMatrix &B, vpMatrix &C, unsigned int r, unsigned int c);
687 
688  //---------------------------------
689  // Stacking with Static Public Member Functions
690  //---------------------------------
693  // Juxtapose to matrices C = [ A B ]
694  static vpMatrix juxtaposeMatrices(const vpMatrix &A, const vpMatrix &B);
695  // Juxtapose to matrices C = [ A B ]
696  static void juxtaposeMatrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
697  // Stack two matrices C = [ A B ]^T
698  static vpMatrix stack(const vpMatrix &A, const vpMatrix &B);
699  static vpMatrix stack(const vpMatrix &A, const vpRowVector &r);
700  static vpMatrix stack(const vpMatrix &A, const vpColVector &c);
701 
702  // Stack two matrices C = [ A B ]^T
703  static void stack(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
704  static void stack(const vpMatrix &A, const vpRowVector &r, vpMatrix &C);
705  static void stack(const vpMatrix &A, const vpColVector &c, vpMatrix &C);
707 
708  //---------------------------------
709  // Matrix operations Static Public Member Functions
710  //---------------------------------
713  static void add2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
714  static void add2Matrices(const vpColVector &A, const vpColVector &B, vpColVector &C);
715  static void add2WeightedMatrices(const vpMatrix &A, const double &wA, const vpMatrix &B, const double &wB,
716  vpMatrix &C);
717  static void computeHLM(const vpMatrix &H, const double &alpha, vpMatrix &HLM);
718  static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
719  static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpRotationMatrix &C);
720  static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpHomogeneousMatrix &C);
721  static void mult2Matrices(const vpMatrix &A, const vpColVector &B, vpColVector &C);
722  static void multMatrixVector(const vpMatrix &A, const vpColVector &v, vpColVector &w);
723  static void negateMatrix(const vpMatrix &A, vpMatrix &C);
724  static void sub2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
725  static void sub2Matrices(const vpColVector &A, const vpColVector &B, vpColVector &C);
727 
728  //---------------------------------
729  // Kronecker product Static Public Member Functions
730  //---------------------------------
733  // Compute Kronecker product matrix
734  static void kron(const vpMatrix &m1, const vpMatrix &m2, vpMatrix &out);
735 
736  // Compute Kronecker product matrix
737  static vpMatrix kron(const vpMatrix &m1, const vpMatrix &m2);
739 
740  //---------------------------------
741  // Covariance computation Static Public Member Functions
742  //---------------------------------
745  static vpMatrix computeCovarianceMatrix(const vpMatrix &A, const vpColVector &x, const vpColVector &b);
746  static vpMatrix computeCovarianceMatrix(const vpMatrix &A, const vpColVector &x, const vpColVector &b,
747  const vpMatrix &w);
748  static vpMatrix computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS,
749  const vpMatrix &Ls, const vpMatrix &W);
750  static vpMatrix computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS,
751  const vpMatrix &Ls);
753 
754  //---------------------------------
755  // Matrix I/O Static Public Member Functions
756  //---------------------------------
829  static inline bool loadMatrix(const std::string &filename, vpArray2D<double> &M, bool binary = false,
830  char *header = nullptr)
831  {
832  return vpArray2D<double>::load(filename, M, binary, header);
833  }
834 
908  static inline bool loadMatrixYAML(const std::string &filename, vpArray2D<double> &M, char *header = nullptr)
909  {
910  return vpArray2D<double>::loadYAML(filename, M, header);
911  }
912 
985  static inline bool saveMatrix(const std::string &filename, const vpArray2D<double> &M, bool binary = false,
986  const char *header = "")
987  {
988  return vpArray2D<double>::save(filename, M, binary, header);
989  }
990 
1065  static inline bool saveMatrixYAML(const std::string &filename, const vpArray2D<double> &M, const char *header = "")
1066  {
1067  return vpArray2D<double>::saveYAML(filename, M, header);
1068  }
1070 
1071 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
1072  VP_DEPRECATED double euclideanNorm() const;
1073 
1082  VP_DEPRECATED void init() { }
1083 
1087  VP_DEPRECATED void stackMatrices(const vpMatrix &A) { stack(A); }
1092  VP_DEPRECATED static vpMatrix stackMatrices(const vpMatrix &A, const vpMatrix &B) { return stack(A, B); }
1097  VP_DEPRECATED static void stackMatrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C) { stack(A, B, C); }
1102  VP_DEPRECATED static vpMatrix stackMatrices(const vpMatrix &A, const vpRowVector &B);
1107  VP_DEPRECATED static void stackMatrices(const vpMatrix &A, const vpRowVector &B, vpMatrix &C);
1112  VP_DEPRECATED static vpMatrix stackMatrices(const vpColVector &A, const vpColVector &B);
1117  VP_DEPRECATED static void stackMatrices(const vpColVector &A, const vpColVector &B, vpColVector &C);
1118 
1122  VP_DEPRECATED void setIdentity(const double &val = 1.0);
1123 
1124  VP_DEPRECATED vpRowVector row(unsigned int i);
1125  VP_DEPRECATED vpColVector column(unsigned int j);
1126 
1127  // Deprecated functions using GSL
1128 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1132  VP_DEPRECATED double detByLUGsl() const
1133  {
1134 #if defined(VISP_HAVE_LAPACK)
1135  return detByLULapack();
1136 #else
1137  throw(vpException(vpException::fatalError, "Undefined detByLULapack(). Install Lapack 3rd party"));
1138 #endif
1139  }
1140 
1144  VP_DEPRECATED vpMatrix inverseByLUGsl() const
1145  {
1146 #if defined(VISP_HAVE_LAPACK)
1147  return inverseByLULapack();
1148 #else
1149  throw(vpException(vpException::fatalError, "Undefined inverseByLULapack(). Install Lapack 3rd party"));
1150 #endif
1151  }
1152 
1156  VP_DEPRECATED vpMatrix inverseByCholeskyGsl() const
1157  {
1158 #if defined(VISP_HAVE_LAPACK)
1159  return inverseByCholeskyLapack();
1160 #else
1161  throw(vpException(vpException::fatalError, "Undefined inverseByCholeskyLapack(). Install Lapack 3rd party"));
1162 #endif
1163  }
1164 
1168  VP_DEPRECATED vpMatrix inverseByQRGsl() const
1169  {
1170 #if defined(VISP_HAVE_LAPACK)
1171  return inverseByQRLapack();
1172 #else
1173  throw(vpException(vpException::fatalError, "Undefined inverseByQRLapack(). Install Lapack 3rd party"));
1174 #endif
1175  }
1176 
1180  VP_DEPRECATED vpMatrix pseudoInverseGsl(double svThreshold = 1e-6) const
1181  {
1182 #if defined(VISP_HAVE_LAPACK)
1183  return pseudoInverseLapack(svThreshold);
1184 #else
1185  (void)svThreshold;
1186  throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
1187 #endif
1188  }
1189 
1193  VP_DEPRECATED unsigned int pseudoInverseGsl(vpMatrix &Ap, double svThreshold = 1e-6) const
1194  {
1195 #if defined(VISP_HAVE_LAPACK)
1196  return pseudoInverseLapack(Ap, svThreshold);
1197 #else
1198  (void)Ap;
1199  (void)svThreshold;
1200  throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
1201 #endif
1202  }
1203 
1207  VP_DEPRECATED unsigned int pseudoInverseGsl(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const
1208  {
1209 #if defined(VISP_HAVE_LAPACK)
1210  return pseudoInverseLapack(Ap, sv, svThreshold);
1211 #else
1212  (void)Ap;
1213  (void)sv;
1214  (void)svThreshold;
1215  throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
1216 #endif
1217  }
1218 
1222  VP_DEPRECATED unsigned int pseudoInverseGsl(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt,
1223  vpMatrix &kerAt) const
1224  {
1225 #if defined(VISP_HAVE_LAPACK)
1226  return pseudoInverseLapack(Ap, sv, svThreshold, imA, imAt, kerAt);
1227 #else
1228  (void)Ap;
1229  (void)sv;
1230  (void)svThreshold;
1231  (void)imA;
1232  (void)imAt;
1233  (void)kerAt;
1234  throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
1235 #endif
1236  }
1237 
1241  VP_DEPRECATED void svdGsl(vpColVector &w, vpMatrix &V)
1242  {
1243 #if defined(VISP_HAVE_LAPACK)
1244  svdLapack(w, V);
1245 #else
1246  (void)w;
1247  (void)V;
1248  throw(vpException(vpException::fatalError, "Undefined svdLapack(). Install Lapack 3rd party"));
1249 #endif
1250  }
1251 
1252 #endif // ifndef DOXYGEN_SHOULD_SKIP_THIS
1254 #endif
1255 
1256 private:
1257  static unsigned int m_lapack_min_size;
1258  static const unsigned int m_lapack_min_size_default;
1259 
1260 #if defined(VISP_HAVE_LAPACK)
1261  static void blas_dgemm(char trans_a, char trans_b, unsigned int M_, unsigned int N_, unsigned int K_, double alpha,
1262  double *a_data, unsigned int lda_, double *b_data, unsigned int ldb_, double beta,
1263  double *c_data, unsigned int ldc_);
1264  static void blas_dgemv(char trans, unsigned int M_, unsigned int N_, double alpha, double *a_data, unsigned int lda_,
1265  double *x_data, int incx_, double beta, double *y_data, int incy_);
1266  static void blas_dsyev(char jobz, char uplo, unsigned int n_, double *a_data, unsigned int lda_, double *w_data,
1267  double *work_data, int lwork_, int &info_);
1268 
1269  unsigned int qrPivotLapack(vpMatrix &Q, vpMatrix &R, vpMatrix &P, bool full, bool squareR,
1270  double tol) const;
1271 
1272 #ifdef VISP_HAVE_GSL
1273  unsigned int qrPivotLapackGSL(vpMatrix &Q, vpMatrix &R, vpMatrix &P, bool full, bool squareR,
1274  double tol) const;
1275 #endif
1276 #endif
1277 
1278  static void computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS, const vpMatrix &Ls,
1279  vpMatrix &Js, vpColVector &deltaP);
1280 };
1281 
1283 #if defined(VISP_USE_MSVC) && defined(visp_EXPORTS)
1284 const __declspec(selectany) unsigned int vpMatrix::m_lapack_min_size_default = 0;
1285 __declspec(selectany) unsigned int vpMatrix::m_lapack_min_size = vpMatrix::m_lapack_min_size_default;
1286 #endif
1287 
1288 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1289 VISP_EXPORT
1290 #endif
1291 vpMatrix operator*(const double &x, const vpMatrix &A);
1292 
1293 END_VISP_NAMESPACE
1294 #endif
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
static bool loadYAML(const std::string &filename, vpArray2D< Type > &A, char *header=nullptr)
Definition: vpArray2D.h:783
void insert(const vpArray2D< Type > &A, unsigned int r, unsigned int c)
Definition: vpArray2D.h:497
static bool saveYAML(const std::string &filename, const vpArray2D< Type > &A, const char *header="")
Definition: vpArray2D.h:972
static vpArray2D< Type > conv2(const vpArray2D< Type > &M, const vpArray2D< Type > &kernel, const std::string &mode)
Definition: vpArray2D.h:1177
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:614
static bool load(const std::string &filename, vpArray2D< Type > &A, bool binary=false, char *header=nullptr)
Definition: vpArray2D.h:669
vpArray2D< Type > t() const
Compute the transpose of the array.
Definition: vpArray2D.h:1166
unsigned int getRows() const
Definition: vpArray2D.h:347
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition: vpArray2D.h:526
vpArray2D< Type > hadamard(const vpArray2D< Type > &m) const
Definition: vpArray2D.h:1150
static bool save(const std::string &filename, const vpArray2D< Type > &A, bool binary=false, const char *header="")
Definition: vpArray2D.h:874
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
@ fatalError
Fatal error.
Definition: vpException.h:72
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:169
static void setLapackMatrixMinSize(unsigned int min_size)
Definition: vpMatrix.h:281
int pseudoInverseOpenCV(vpMatrix &Ap, int rank_in) const
vpMatrix(unsigned int r, unsigned int c)
Definition: vpMatrix.h:193
vpMatrix(unsigned int r, unsigned int c, double val)
Definition: vpMatrix.h:202
vpMatrix pseudoInverseOpenCV(double svThreshold=1e-6) const
int pseudoInverseLapack(vpMatrix &Ap, int rank_in) const
unsigned int pseudoInverseLapack(vpMatrix &Ap, double svThreshold=1e-6) const
static unsigned int getLapackMatrixMinSize()
Definition: vpMatrix.h:267
vpMatrix pseudoInverseEigen3(double svThreshold=1e-6) const
unsigned int pseudoInverseOpenCV(vpMatrix &Ap, double svThreshold=1e-6) const
void printSize() const
Definition: vpMatrix.h:661
unsigned int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const
VP_EXPLICIT vpMatrix(const vpArray2D< double > &A)
Definition: vpMatrix.h:217
int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, int rank_in) const
static bool loadMatrix(const std::string &filename, vpArray2D< double > &M, bool binary=false, char *header=nullptr)
Definition: vpMatrix.h:829
int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const
int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const
vpMatrix pseudoInverseOpenCV(int rank_in) const
unsigned int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold=1e-6) const
int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, int rank_in) const
unsigned int pseudoInverseEigen3(vpMatrix &Ap, double svThreshold=1e-6) const
vpMatrix()
Definition: vpMatrix.h:185
unsigned int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold=1e-6) const
vpMatrix pseudoInverseLapack(int rank_in) const
unsigned int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const
vpMatrix pseudoInverseEigen3(int rank_in) const
int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const
int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, int rank_in) const
vpMatrix pseudoInverseLapack(double svThreshold=1e-6) const
vpMatrix(const vpMatrix &A)
Definition: vpMatrix.h:218
void clear()
Definition: vpMatrix.h:238
int pseudoInverseEigen3(vpMatrix &Ap, int rank_in) const
static bool saveMatrixYAML(const std::string &filename, const vpArray2D< double > &M, const char *header="")
Definition: vpMatrix.h:1065
unsigned int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold=1e-6) const
static bool loadMatrixYAML(const std::string &filename, vpArray2D< double > &M, char *header=nullptr)
Definition: vpMatrix.h:908
static bool saveMatrix(const std::string &filename, const vpArray2D< double > &M, bool binary=false, const char *header="")
Definition: vpMatrix.h:985
unsigned int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const
Implementation of a rotation matrix and operations on such kind of matrices.
Implementation of row vector and the associated operations.
Definition: vpRowVector.h:124
Class that consider the case of a translation vector.
vpMatrix operator*(const double &x, const vpMatrix &A)