Visual Servoing Platform  version 3.6.1 under development (2025-02-18)
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  static vpMatrix view(double *data, unsigned int rows, unsigned int cols);
228 
229 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
230  vpMatrix(vpMatrix &&A);
231  VP_EXPLICIT vpMatrix(const std::initializer_list<double> &list);
232  VP_EXPLICIT vpMatrix(unsigned int nrows, unsigned int ncols, const std::initializer_list<double> &list);
233  VP_EXPLICIT vpMatrix(const std::initializer_list<std::initializer_list<double> > &lists);
234 #endif
235 
240  void clear()
241  {
242  if (data != nullptr) {
243  free(data);
244  data = nullptr;
245  }
246 
247  if (rowPtrs != nullptr) {
248  free(rowPtrs);
249  rowPtrs = nullptr;
250  }
251  rowNum = 0;
252  colNum = 0;
253  dsize = 0;
254  }
255 
256  //-------------------------------------------------
257  // Setting a diagonal matrix
258  //-------------------------------------------------
269  static unsigned int getLapackMatrixMinSize() { return m_lapack_min_size; }
270 
283  static void setLapackMatrixMinSize(unsigned int min_size) { m_lapack_min_size = min_size; }
285 
286  //-------------------------------------------------
287  // Setting a diagonal matrix
288  //-------------------------------------------------
291  void diag(const double &val = 1.0);
292  void diag(const vpColVector &A);
293  // Initialize an identity matrix n-by-n
294  void eye();
295  void eye(unsigned int n);
296  // Initialize an identity matrix m-by-n
297  void eye(unsigned int m, unsigned int n);
299 
300  //---------------------------------
301  // Assignment
302  //---------------------------------
305  vpMatrix &operator<<(double *p);
306  vpMatrix &operator<<(double val);
307  vpMatrix &operator,(double val);
309  vpMatrix &operator=(const vpMatrix &A);
314  vpMatrix &operator=(const vpColVector &v);
315  vpMatrix &operator=(const vpRowVector &v);
317 
318 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
320 
321  vpMatrix &operator=(const std::initializer_list<double> &list);
322  vpMatrix &operator=(const std::initializer_list<std::initializer_list<double> > &lists);
323 #endif
324  vpMatrix &operator=(double x);
326 
327  //-------------------------------------------------
328  // Stacking
329  //-------------------------------------------------
332  // Stack the matrix A below the current one, copy if not initialized this =
333  // [ this A ]^T
334  void stack(const vpMatrix &A);
335  void stack(const vpRowVector &r);
336  void stack(const vpColVector &c);
337  // Stacks columns of a matrix in a vector
338  void stackColumns(vpColVector &out);
339 
340  // Stacks columns of a matrix in a vector
341  vpColVector stackColumns();
342 
343  // Stacks columns of a matrix in a vector
344  void stackRows(vpRowVector &out);
345 
346  // Stacks columns of a matrix in a vector
347  vpRowVector stackRows();
349 
350  //---------------------------------
351  // Matrix insertion
352  //---------------------------------
355  // Insert matrix A in the current matrix at the given position (r, c).
356  void insert(const vpMatrix &A, unsigned int r, unsigned int c);
358 
359  //-------------------------------------------------
360  // Columns, Rows, Diag extraction, SubMatrix
361  //-------------------------------------------------
364  vpMatrix extract(unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols) const;
365  vpColVector getCol(unsigned int j) const;
366  vpColVector getCol(unsigned int j, unsigned int i_begin, unsigned int size) const;
367  vpRowVector getRow(unsigned int i) const;
368  vpRowVector getRow(unsigned int i, unsigned int j_begin, unsigned int size) const;
369  vpColVector getDiag() const;
370  void init(const vpMatrix &M, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols);
372 
373  //---------------------------------
374  // Matrix operations.
375  //---------------------------------
389  static vpMatrix conv2(const vpMatrix &M, const vpMatrix &kernel, const std::string &mode);
390 
403  static void conv2(const vpMatrix &M, const vpMatrix &kernel, vpMatrix &res, const std::string &mode);
404 
405  // return the determinant of the matrix.
406  double det(vpDetMethod method = LU_DECOMPOSITION) const;
407  double detByLU() const;
408 #if defined(VISP_HAVE_EIGEN3)
409  double detByLUEigen3() const;
410 #endif
411 #if defined(VISP_HAVE_LAPACK)
412  double detByLULapack() const;
413 #endif
414 #if defined(VISP_HAVE_OPENCV)
415  double detByLUOpenCV() const;
416 #endif
417  vpMatrix cholesky() const;
418 #if defined(VISP_HAVE_EIGEN3)
419  vpMatrix choleskyByEigen3() const;
420 #endif
421 #if defined(VISP_HAVE_LAPACK)
422  vpMatrix choleskyByLapack() const;
423 #endif
424 #if defined(VISP_HAVE_OPENCV)
425  vpMatrix choleskyByOpenCV() const;
426 #endif
427 
428  // Compute the exponential matrix of a square matrix
429  vpMatrix expm() const;
430 
431  // operation A = A + B
432  vpMatrix &operator+=(const vpMatrix &B);
433  // operation A = A - B
434  vpMatrix &operator-=(const vpMatrix &B);
435  vpMatrix operator*(const vpMatrix &B) const;
436  vpMatrix operator*(const vpRotationMatrix &R) const;
437  vpMatrix operator*(const vpHomogeneousMatrix &R) const;
438  vpMatrix operator*(const vpVelocityTwistMatrix &V) const;
439  vpMatrix operator*(const vpForceTwistMatrix &V) const;
440  // operation t_out = A * t (A is unchanged, t and t_out are translation
441  // vectors)
443  vpColVector operator*(const vpColVector &v) const;
444  vpMatrix operator+(const vpMatrix &B) const;
445  vpMatrix operator-(const vpMatrix &B) const;
446  vpMatrix operator-() const;
447 
449  vpMatrix &operator+=(double x);
451  vpMatrix &operator-=(double x);
453  vpMatrix &operator*=(double x);
455  vpMatrix &operator/=(double x);
456 
457  // Cij = Aij * x (A is unchanged)
458  vpMatrix operator*(double x) const;
459  // Cij = Aij / x (A is unchanged)
460  vpMatrix operator/(double x) const;
461 
467  double sum() const;
468  double sumSquare() const;
469 
470  //-------------------------------------------------
471  // Hadamard product
472  //-------------------------------------------------
474  vpMatrix hadamard(const vpMatrix &m) const;
475 
476  //-------------------------------------------------
477  // Kronecker product
478  //-------------------------------------------------
481  // Compute Kronecker product matrix
482  void kron(const vpMatrix &m1, vpMatrix &out) const;
483 
484  // Compute Kronecker product matrix
485  vpMatrix kron(const vpMatrix &m1) const;
487 
488  //-------------------------------------------------
489  // Transpose
490  //-------------------------------------------------
493  // Compute the transpose C = A^T
494  vpMatrix t() const;
495 
496  // Compute the transpose C = A^T
497  vpMatrix transpose() const;
498  void transpose(vpMatrix &At) const;
499 
500  vpMatrix AAt() const;
501  void AAt(vpMatrix &B) const;
502 
503  vpMatrix AtA() const;
504  void AtA(vpMatrix &B) const;
506 
507  //-------------------------------------------------
508  // Matrix inversion
509  //-------------------------------------------------
512  // inverse matrix A using the LU decomposition
513  vpMatrix inverseByLU() const;
514 
515 #if defined(VISP_HAVE_EIGEN3)
516  vpMatrix inverseByLUEigen3() const;
517 #endif
518 #if defined(VISP_HAVE_LAPACK)
519  vpMatrix inverseByLULapack() const;
520 #endif
521 #if defined(VISP_HAVE_OPENCV)
522  vpMatrix inverseByLUOpenCV() const;
523 #endif
524 
525  // inverse matrix A using the Cholesky decomposition (only for real
526  // symmetric matrices)
527  vpMatrix inverseByCholesky() const;
528 
529 #if defined(VISP_HAVE_LAPACK)
530  vpMatrix inverseByCholeskyLapack() const;
531 #endif
532 #if defined(VISP_HAVE_OPENCV)
533  vpMatrix inverseByCholeskyOpenCV() const;
534 #endif
535 
536  // inverse matrix A using the QR decomposition
537  vpMatrix inverseByQR() const;
538 #if defined(VISP_HAVE_LAPACK)
539  vpMatrix inverseByQRLapack() const;
540 #endif
541 
542  // inverse triangular matrix
543  vpMatrix inverseTriangular(bool upper = true) const;
544 
545  vpMatrix pseudoInverse(double svThreshold = 1e-6) const;
546  unsigned int pseudoInverse(vpMatrix &Ap, double svThreshold = 1e-6) const;
547  unsigned int pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
548  unsigned int pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt) const;
549  unsigned int pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
550  vpMatrix pseudoInverse(int rank_in) const;
551  int pseudoInverse(vpMatrix &Ap, int rank_in) const;
552  int pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
553  int pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt) const;
554  int pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
555 
556 #if defined(VISP_HAVE_LAPACK)
557  vpMatrix pseudoInverseLapack(double svThreshold = 1e-6) const;
558  unsigned int pseudoInverseLapack(vpMatrix &Ap, double svThreshold = 1e-6) const;
559  unsigned int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
560  unsigned int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
561  vpMatrix pseudoInverseLapack(int rank_in) const;
562  int pseudoInverseLapack(vpMatrix &Ap, int rank_in) const;
563  int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
564  int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
565 #endif
566 #if defined(VISP_HAVE_EIGEN3)
567  vpMatrix pseudoInverseEigen3(double svThreshold = 1e-6) const;
568  unsigned int pseudoInverseEigen3(vpMatrix &Ap, double svThreshold = 1e-6) const;
569  unsigned int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
570  unsigned int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
571  vpMatrix pseudoInverseEigen3(int rank_in) const;
572  int pseudoInverseEigen3(vpMatrix &Ap, int rank_in) const;
573  int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
574  int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
575 #endif
576 #if defined(VISP_HAVE_OPENCV)
577  vpMatrix pseudoInverseOpenCV(double svThreshold = 1e-6) const;
578  unsigned int pseudoInverseOpenCV(vpMatrix &Ap, double svThreshold = 1e-6) const;
579  unsigned int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
580  unsigned int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
581  vpMatrix pseudoInverseOpenCV(int rank_in) const;
582  int pseudoInverseOpenCV(vpMatrix &Ap, int rank_in) const;
583  int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
584  int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
585 #endif
586 
587  vpMatrix dampedInverse(const double &ratioOfMaxSvd = 1e-4) const;
589 
590  //-------------------------------------------------
591  // SVD decomposition
592  //-------------------------------------------------
593 
596  double cond(double svThreshold = 1e-6) const;
597  unsigned int kernel(vpMatrix &kerAt, double svThreshold = 1e-6) const;
598  unsigned int nullSpace(vpMatrix &kerA, double svThreshold = 1e-6) const;
599  unsigned int nullSpace(vpMatrix &kerA, int dim) const;
600 
601  // solve Ax=B using the SVD decomposition (usage A = solveBySVD(B,x) )
602  void solveBySVD(const vpColVector &B, vpColVector &x) const;
603  // solve Ax=B using the SVD decomposition (usage x=A.solveBySVD(B))
604  vpColVector solveBySVD(const vpColVector &B) const;
605 
606  // singular value decomposition SVD
607  void svd(vpColVector &w, vpMatrix &V);
608 #ifdef VISP_HAVE_EIGEN3
609  void svdEigen3(vpColVector &w, vpMatrix &V);
610 #endif
611 #if defined(VISP_HAVE_LAPACK)
612  void svdLapack(vpColVector &w, vpMatrix &V);
613 #endif
614 #if defined(VISP_HAVE_OPENCV) // Require opencv >= 2.1.1
615  void svdOpenCV(vpColVector &w, vpMatrix &V);
616 #endif
618 
619  //-------------------------------------------------
620  // QR decomposition
621  //-------------------------------------------------
622 
625  unsigned int qr(vpMatrix &Q, vpMatrix &R, bool full = false, bool squareR = false, double tol = 1e-6) const;
626  unsigned int qrPivot(vpMatrix &Q, vpMatrix &R, vpMatrix &P, bool full = false, bool squareR = false,
627  double tol = 1e-6) const;
628  void solveByQR(const vpColVector &b, vpColVector &x) const;
629  vpColVector solveByQR(const vpColVector &b) const;
631 
632  //-------------------------------------------------
633  // Eigen values and vectors
634  //-------------------------------------------------
638  // Compute the eigen values using Lapack.
639  vpColVector eigenValues() const;
640  void eigenValues(vpColVector &evalue, vpMatrix &evector) const;
642 
643  //-------------------------------------------------
644  // Norms
645  //-------------------------------------------------
648  double frobeniusNorm() const;
649  double inducedL2Norm() const;
650  double infinityNorm() const;
652 
653  //---------------------------------
654  // Printing
655  //---------------------------------
658  std::ostream &cppPrint(std::ostream &os, const std::string &matrixName = "A", bool octet = false) const;
659  std::ostream &csvPrint(std::ostream &os) const;
660  std::ostream &maplePrint(std::ostream &os) const;
661  std::ostream &matlabPrint(std::ostream &os) const;
662  int print(std::ostream &s, unsigned int length, const std::string &intro = "") const;
663  void printSize() const { std::cout << getRows() << " x " << getCols() << " "; }
665 
666  //------------------------------------------------------------------
667  // Static functionalities
668  //------------------------------------------------------------------
669 
670  //---------------------------------
671  // Setting a diagonal matrix with Static Public Member Functions
672  //---------------------------------
675  // Create a diagonal matrix with the element of a vector DAii = Ai
676  static void createDiagonalMatrix(const vpColVector &A, vpMatrix &DA);
678 
679  //---------------------------------
680  // Matrix insertion with Static Public Member Functions
681  //---------------------------------
684  // Insert matrix B in matrix A at the given position (r, c).
685  static vpMatrix insert(const vpMatrix &A, const vpMatrix &B, unsigned int r, unsigned int c);
686  // Insert matrix B in matrix A (not modified) at the given position (r, c),
687  // the result is given in matrix C.
688  static void insert(const vpMatrix &A, const vpMatrix &B, vpMatrix &C, unsigned int r, unsigned int c);
689 
690  //---------------------------------
691  // Stacking with Static Public Member Functions
692  //---------------------------------
695  // Juxtapose to matrices C = [ A B ]
696  static vpMatrix juxtaposeMatrices(const vpMatrix &A, const vpMatrix &B);
697  // Juxtapose to matrices C = [ A B ]
698  static void juxtaposeMatrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
699  // Stack two matrices C = [ A B ]^T
700  static vpMatrix stack(const vpMatrix &A, const vpMatrix &B);
701  static vpMatrix stack(const vpMatrix &A, const vpRowVector &r);
702  static vpMatrix stack(const vpMatrix &A, const vpColVector &c);
703 
704  // Stack two matrices C = [ A B ]^T
705  static void stack(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
706  static void stack(const vpMatrix &A, const vpRowVector &r, vpMatrix &C);
707  static void stack(const vpMatrix &A, const vpColVector &c, vpMatrix &C);
709 
710  //---------------------------------
711  // Matrix operations Static Public Member Functions
712  //---------------------------------
715  static void add2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
716  static void add2Matrices(const vpColVector &A, const vpColVector &B, vpColVector &C);
717  static void add2WeightedMatrices(const vpMatrix &A, const double &wA, const vpMatrix &B, const double &wB,
718  vpMatrix &C);
719  static void computeHLM(const vpMatrix &H, const double &alpha, vpMatrix &HLM);
720  static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
721  static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpRotationMatrix &C);
722  static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpHomogeneousMatrix &C);
723  static void mult2Matrices(const vpMatrix &A, const vpColVector &B, vpColVector &C);
724  static void multMatrixVector(const vpMatrix &A, const vpColVector &v, vpColVector &w);
725  static void negateMatrix(const vpMatrix &A, vpMatrix &C);
726  static void sub2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
727  static void sub2Matrices(const vpColVector &A, const vpColVector &B, vpColVector &C);
729 
730  //---------------------------------
731  // Kronecker product Static Public Member Functions
732  //---------------------------------
735  // Compute Kronecker product matrix
736  static void kron(const vpMatrix &m1, const vpMatrix &m2, vpMatrix &out);
737 
738  // Compute Kronecker product matrix
739  static vpMatrix kron(const vpMatrix &m1, const vpMatrix &m2);
741 
742  //---------------------------------
743  // Covariance computation Static Public Member Functions
744  //---------------------------------
747  static vpMatrix computeCovarianceMatrix(const vpMatrix &A, const vpColVector &x, const vpColVector &b);
748  static vpMatrix computeCovarianceMatrix(const vpMatrix &A, const vpColVector &x, const vpColVector &b,
749  const vpMatrix &w);
750  static vpMatrix computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS,
751  const vpMatrix &Ls, const vpMatrix &W);
752  static vpMatrix computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS,
753  const vpMatrix &Ls);
755 
756  //---------------------------------
757  // Matrix I/O Static Public Member Functions
758  //---------------------------------
831  static inline bool loadMatrix(const std::string &filename, vpArray2D<double> &M, bool binary = false,
832  char *header = nullptr)
833  {
834  return vpArray2D<double>::load(filename, M, binary, header);
835  }
836 
910  static inline bool loadMatrixYAML(const std::string &filename, vpArray2D<double> &M, char *header = nullptr)
911  {
912  return vpArray2D<double>::loadYAML(filename, M, header);
913  }
914 
987  static inline bool saveMatrix(const std::string &filename, const vpArray2D<double> &M, bool binary = false,
988  const char *header = "")
989  {
990  return vpArray2D<double>::save(filename, M, binary, header);
991  }
992 
1067  static inline bool saveMatrixYAML(const std::string &filename, const vpArray2D<double> &M, const char *header = "")
1068  {
1069  return vpArray2D<double>::saveYAML(filename, M, header);
1070  }
1072 
1073 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
1074  VP_DEPRECATED double euclideanNorm() const;
1075 
1084  VP_DEPRECATED void init() { }
1085 
1089  VP_DEPRECATED void stackMatrices(const vpMatrix &A) { stack(A); }
1094  VP_DEPRECATED static vpMatrix stackMatrices(const vpMatrix &A, const vpMatrix &B) { return stack(A, B); }
1099  VP_DEPRECATED static void stackMatrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C) { stack(A, B, C); }
1104  VP_DEPRECATED static vpMatrix stackMatrices(const vpMatrix &A, const vpRowVector &B);
1109  VP_DEPRECATED static void stackMatrices(const vpMatrix &A, const vpRowVector &B, vpMatrix &C);
1114  VP_DEPRECATED static vpMatrix stackMatrices(const vpColVector &A, const vpColVector &B);
1119  VP_DEPRECATED static void stackMatrices(const vpColVector &A, const vpColVector &B, vpColVector &C);
1120 
1124  VP_DEPRECATED void setIdentity(const double &val = 1.0);
1125 
1126  VP_DEPRECATED vpRowVector row(unsigned int i);
1127  VP_DEPRECATED vpColVector column(unsigned int j);
1128 
1129  // Deprecated functions using GSL
1130 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1134  VP_DEPRECATED double detByLUGsl() const
1135  {
1136 #if defined(VISP_HAVE_LAPACK)
1137  return detByLULapack();
1138 #else
1139  throw(vpException(vpException::fatalError, "Undefined detByLULapack(). Install Lapack 3rd party"));
1140 #endif
1141  }
1142 
1146  VP_DEPRECATED vpMatrix inverseByLUGsl() const
1147  {
1148 #if defined(VISP_HAVE_LAPACK)
1149  return inverseByLULapack();
1150 #else
1151  throw(vpException(vpException::fatalError, "Undefined inverseByLULapack(). Install Lapack 3rd party"));
1152 #endif
1153  }
1154 
1158  VP_DEPRECATED vpMatrix inverseByCholeskyGsl() const
1159  {
1160 #if defined(VISP_HAVE_LAPACK)
1161  return inverseByCholeskyLapack();
1162 #else
1163  throw(vpException(vpException::fatalError, "Undefined inverseByCholeskyLapack(). Install Lapack 3rd party"));
1164 #endif
1165  }
1166 
1170  VP_DEPRECATED vpMatrix inverseByQRGsl() const
1171  {
1172 #if defined(VISP_HAVE_LAPACK)
1173  return inverseByQRLapack();
1174 #else
1175  throw(vpException(vpException::fatalError, "Undefined inverseByQRLapack(). Install Lapack 3rd party"));
1176 #endif
1177  }
1178 
1182  VP_DEPRECATED vpMatrix pseudoInverseGsl(double svThreshold = 1e-6) const
1183  {
1184 #if defined(VISP_HAVE_LAPACK)
1185  return pseudoInverseLapack(svThreshold);
1186 #else
1187  (void)svThreshold;
1188  throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
1189 #endif
1190  }
1191 
1195  VP_DEPRECATED unsigned int pseudoInverseGsl(vpMatrix &Ap, double svThreshold = 1e-6) const
1196  {
1197 #if defined(VISP_HAVE_LAPACK)
1198  return pseudoInverseLapack(Ap, svThreshold);
1199 #else
1200  (void)Ap;
1201  (void)svThreshold;
1202  throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
1203 #endif
1204  }
1205 
1209  VP_DEPRECATED unsigned int pseudoInverseGsl(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const
1210  {
1211 #if defined(VISP_HAVE_LAPACK)
1212  return pseudoInverseLapack(Ap, sv, svThreshold);
1213 #else
1214  (void)Ap;
1215  (void)sv;
1216  (void)svThreshold;
1217  throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
1218 #endif
1219  }
1220 
1224  VP_DEPRECATED unsigned int pseudoInverseGsl(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt,
1225  vpMatrix &kerAt) const
1226  {
1227 #if defined(VISP_HAVE_LAPACK)
1228  return pseudoInverseLapack(Ap, sv, svThreshold, imA, imAt, kerAt);
1229 #else
1230  (void)Ap;
1231  (void)sv;
1232  (void)svThreshold;
1233  (void)imA;
1234  (void)imAt;
1235  (void)kerAt;
1236  throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
1237 #endif
1238  }
1239 
1243  VP_DEPRECATED void svdGsl(vpColVector &w, vpMatrix &V)
1244  {
1245 #if defined(VISP_HAVE_LAPACK)
1246  svdLapack(w, V);
1247 #else
1248  (void)w;
1249  (void)V;
1250  throw(vpException(vpException::fatalError, "Undefined svdLapack(). Install Lapack 3rd party"));
1251 #endif
1252  }
1253 
1254 #endif // ifndef DOXYGEN_SHOULD_SKIP_THIS
1256 #endif
1257 
1258 private:
1259  static unsigned int m_lapack_min_size;
1260  static const unsigned int m_lapack_min_size_default;
1261 
1262 #if defined(VISP_HAVE_LAPACK)
1263  static void blas_dgemm(char trans_a, char trans_b, unsigned int M_, unsigned int N_, unsigned int K_, double alpha,
1264  double *a_data, unsigned int lda_, double *b_data, unsigned int ldb_, double beta,
1265  double *c_data, unsigned int ldc_);
1266  static void blas_dgemv(char trans, unsigned int M_, unsigned int N_, double alpha, double *a_data, unsigned int lda_,
1267  double *x_data, int incx_, double beta, double *y_data, int incy_);
1268  static void blas_dsyev(char jobz, char uplo, unsigned int n_, double *a_data, unsigned int lda_, double *w_data,
1269  double *work_data, int lwork_, int &info_);
1270 
1271  unsigned int qrPivotLapack(vpMatrix &Q, vpMatrix &R, vpMatrix &P, bool full, bool squareR,
1272  double tol) const;
1273 
1274 #ifdef VISP_HAVE_GSL
1275  unsigned int qrPivotLapackGSL(vpMatrix &Q, vpMatrix &R, vpMatrix &P, bool full, bool squareR,
1276  double tol) const;
1277 #endif
1278 #endif
1279 
1280  static void computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS, const vpMatrix &Ls,
1281  vpMatrix &Js, vpColVector &deltaP);
1282 };
1283 
1285 #if defined(VISP_USE_MSVC) && defined(visp_EXPORTS)
1286 const __declspec(selectany) unsigned int vpMatrix::m_lapack_min_size_default = 0;
1287 __declspec(selectany) unsigned int vpMatrix::m_lapack_min_size = vpMatrix::m_lapack_min_size_default;
1288 #endif
1289 
1290 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1291 VISP_EXPORT
1292 #endif
1293 vpMatrix operator*(const double &x, const vpMatrix &A);
1294 
1295 END_VISP_NAMESPACE
1296 #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:417
static bool loadYAML(const std::string &filename, vpArray2D< Type > &A, char *header=nullptr)
Definition: vpArray2D.h:868
void insert(const vpArray2D< Type > &A, unsigned int r, unsigned int c)
Definition: vpArray2D.h:580
static bool saveYAML(const std::string &filename, const vpArray2D< Type > &A, const char *header="")
Definition: vpArray2D.h:1057
static vpArray2D< Type > view(const vpArray2D< Type > &A)
Creates a view of the Matrix A. A view shares the same underlying memory as the original array....
Definition: vpArray2D.h:323
static vpArray2D< Type > conv2(const vpArray2D< Type > &M, const vpArray2D< Type > &kernel, const std::string &mode)
Definition: vpArray2D.h:1267
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:699
static bool load(const std::string &filename, vpArray2D< Type > &A, bool binary=false, char *header=nullptr)
Definition: vpArray2D.h:754
vpArray2D< Type > t() const
Compute the transpose of the array.
Definition: vpArray2D.h:1256
unsigned int getRows() const
Definition: vpArray2D.h:427
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition: vpArray2D.h:609
vpArray2D< Type > hadamard(const vpArray2D< Type > &m) const
Definition: vpArray2D.h:1240
static bool save(const std::string &filename, const vpArray2D< Type > &A, bool binary=false, const char *header="")
Definition: vpArray2D.h:959
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:283
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:269
vpMatrix pseudoInverseEigen3(double svThreshold=1e-6) const
unsigned int pseudoInverseOpenCV(vpMatrix &Ap, double svThreshold=1e-6) const
void printSize() const
Definition: vpMatrix.h:663
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:831
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:240
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:1067
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:910
static bool saveMatrix(const std::string &filename, const vpArray2D< double > &M, bool binary=false, const char *header="")
Definition: vpMatrix.h:987
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)