Visual Servoing Platform  version 3.6.1 under development (2024-06-12)
vpMatrix.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2023 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 _vpMatrix_H_
42 #define _vpMatrix_H_
43 
44 #include <visp3/core/vpConfig.h>
46 
47 class vpRowVector;
48 class vpColVector;
52 class vpForceTwistMatrix;
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 
67 
150 class VISP_EXPORT vpMatrix : public vpArray2D<double>
151 {
152 public:
157  typedef enum
158  {
159  LU_DECOMPOSITION
160  } vpDetMethod;
161 
162 public:
167  vpMatrix() : vpArray2D<double>(0, 0) { }
168 
175  vpMatrix(unsigned int r, unsigned int c) : vpArray2D<double>(r, c) { }
176 
184  vpMatrix(unsigned int r, unsigned int c, double val) : vpArray2D<double>(r, c, val) { }
185  vpMatrix(const vpMatrix &M, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols);
186 
199  vpMatrix(const vpArray2D<double> &A) : vpArray2D<double>(A) { }
200 
201  vpMatrix(const vpMatrix &A) : vpArray2D<double>(A) { }
202 
203 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
204  vpMatrix(vpMatrix &&A);
205  explicit vpMatrix(const std::initializer_list<double> &list);
206  explicit vpMatrix(unsigned int nrows, unsigned int ncols, const std::initializer_list<double> &list);
207  explicit vpMatrix(const std::initializer_list<std::initializer_list<double> > &lists);
208 #endif
209 
214  void clear()
215  {
216  if (data != nullptr) {
217  free(data);
218  data = nullptr;
219  }
220 
221  if (rowPtrs != nullptr) {
222  free(rowPtrs);
223  rowPtrs = nullptr;
224  }
225  rowNum = 0;
226  colNum = 0;
227  dsize = 0;
228  }
229 
230  //-------------------------------------------------
231  // Setting a diagonal matrix
232  //-------------------------------------------------
243  static unsigned int getLapackMatrixMinSize() { return m_lapack_min_size; }
244 
257  static void setLapackMatrixMinSize(unsigned int min_size) { m_lapack_min_size = min_size; }
259 
260  //-------------------------------------------------
261  // Setting a diagonal matrix
262  //-------------------------------------------------
265  void diag(const double &val = 1.0);
266  void diag(const vpColVector &A);
267  // Initialize an identity matrix n-by-n
268  void eye();
269  void eye(unsigned int n);
270  // Initialize an identity matrix m-by-n
271  void eye(unsigned int m, unsigned int n);
273 
274  //---------------------------------
275  // Assignment
276  //---------------------------------
279  vpMatrix &operator<<(double *p);
280  vpMatrix &operator<<(double val);
281  vpMatrix &operator,(double val);
283  vpMatrix &operator=(const vpMatrix &A);
284 
285 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
287 
288  vpMatrix &operator=(const std::initializer_list<double> &list);
289  vpMatrix &operator=(const std::initializer_list<std::initializer_list<double> > &lists);
290 #endif
291  vpMatrix &operator=(double x);
293 
294  //-------------------------------------------------
295  // Stacking
296  //-------------------------------------------------
299  // Stack the matrix A below the current one, copy if not initialized this =
300  // [ this A ]^T
301  void stack(const vpMatrix &A);
302  void stack(const vpRowVector &r);
303  void stack(const vpColVector &c);
304  // Stacks columns of a matrix in a vector
305  void stackColumns(vpColVector &out);
306 
307  // Stacks columns of a matrix in a vector
308  vpColVector stackColumns();
309 
310  // Stacks columns of a matrix in a vector
311  void stackRows(vpRowVector &out);
312 
313  // Stacks columns of a matrix in a vector
314  vpRowVector stackRows();
316 
317  //---------------------------------
318  // Matrix insertion
319  //---------------------------------
322  // Insert matrix A in the current matrix at the given position (r, c).
323  void insert(const vpMatrix &A, unsigned int r, unsigned int c);
325 
326  //-------------------------------------------------
327  // Columns, Rows, Diag extraction, SubMatrix
328  //-------------------------------------------------
331  vpMatrix extract(unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols) const;
332  vpColVector getCol(unsigned int j) const;
333  vpColVector getCol(unsigned int j, unsigned int i_begin, unsigned int size) const;
334  vpRowVector getRow(unsigned int i) const;
335  vpRowVector getRow(unsigned int i, unsigned int j_begin, unsigned int size) const;
336  vpColVector getDiag() const;
337  void init(const vpMatrix &M, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols);
339 
340  //---------------------------------
341  // Matrix operations.
342  //---------------------------------
345  // return the determinant of the matrix.
346  double det(vpDetMethod method = LU_DECOMPOSITION) const;
347  double detByLU() const;
348 #if defined(VISP_HAVE_EIGEN3)
349  double detByLUEigen3() const;
350 #endif
351 #if defined(VISP_HAVE_LAPACK)
352  double detByLULapack() const;
353 #endif
354 #if defined(VISP_HAVE_OPENCV)
355  double detByLUOpenCV() const;
356 #endif
357  vpMatrix cholesky() const;
358 #if defined(VISP_HAVE_EIGEN3)
359  vpMatrix choleskyByEigen3() const;
360 #endif
361 #if defined(VISP_HAVE_LAPACK)
362  vpMatrix choleskyByLapack() const;
363 #endif
364 #if defined(VISP_HAVE_OPENCV)
365  vpMatrix choleskyByOpenCV() const;
366 #endif
367 
368  // Compute the exponential matrix of a square matrix
369  vpMatrix expm() const;
370 
371  // operation A = A + B
372  vpMatrix &operator+=(const vpMatrix &B);
373  // operation A = A - B
374  vpMatrix &operator-=(const vpMatrix &B);
375  vpMatrix operator*(const vpMatrix &B) const;
376  vpMatrix operator*(const vpRotationMatrix &R) const;
377  vpMatrix operator*(const vpHomogeneousMatrix &R) const;
378  vpMatrix operator*(const vpVelocityTwistMatrix &V) const;
379  vpMatrix operator*(const vpForceTwistMatrix &V) const;
380  // operation t_out = A * t (A is unchanged, t and t_out are translation
381  // vectors)
383  vpColVector operator*(const vpColVector &v) const;
384  vpMatrix operator+(const vpMatrix &B) const;
385  vpMatrix operator-(const vpMatrix &B) const;
386  vpMatrix operator-() const;
387 
389  vpMatrix &operator+=(double x);
391  vpMatrix &operator-=(double x);
393  vpMatrix &operator*=(double x);
395  vpMatrix &operator/=(double x);
396 
397  // Cij = Aij * x (A is unchanged)
398  vpMatrix operator*(double x) const;
399  // Cij = Aij / x (A is unchanged)
400  vpMatrix operator/(double x) const;
401 
407  double sum() const;
408  double sumSquare() const;
409 
410  //-------------------------------------------------
411  // Hadamard product
412  //-------------------------------------------------
414  vpMatrix hadamard(const vpMatrix &m) const;
415 
416  //-------------------------------------------------
417  // Kronecker product
418  //-------------------------------------------------
421  // Compute Kronecker product matrix
422  void kron(const vpMatrix &m1, vpMatrix &out) const;
423 
424  // Compute Kronecker product matrix
425  vpMatrix kron(const vpMatrix &m1) const;
427 
428  //-------------------------------------------------
429  // Transpose
430  //-------------------------------------------------
433  // Compute the transpose C = A^T
434  vpMatrix t() const;
435 
436  // Compute the transpose C = A^T
437  vpMatrix transpose() const;
438  void transpose(vpMatrix &At) const;
439 
440  vpMatrix AAt() const;
441  void AAt(vpMatrix &B) const;
442 
443  vpMatrix AtA() const;
444  void AtA(vpMatrix &B) const;
446 
447  //-------------------------------------------------
448  // Matrix inversion
449  //-------------------------------------------------
452  // inverse matrix A using the LU decomposition
453  vpMatrix inverseByLU() const;
454 
455 #if defined(VISP_HAVE_EIGEN3)
456  vpMatrix inverseByLUEigen3() const;
457 #endif
458 #if defined(VISP_HAVE_LAPACK)
459  vpMatrix inverseByLULapack() const;
460 #endif
461 #if defined(VISP_HAVE_OPENCV)
462  vpMatrix inverseByLUOpenCV() const;
463 #endif
464 
465  // inverse matrix A using the Cholesky decomposition (only for real
466  // symmetric matrices)
467  vpMatrix inverseByCholesky() const;
468 
469 #if defined(VISP_HAVE_LAPACK)
470  vpMatrix inverseByCholeskyLapack() const;
471 #endif
472 #if defined(VISP_HAVE_OPENCV)
473  vpMatrix inverseByCholeskyOpenCV() const;
474 #endif
475 
476  // inverse matrix A using the QR decomposition
477  vpMatrix inverseByQR() const;
478 #if defined(VISP_HAVE_LAPACK)
479  vpMatrix inverseByQRLapack() const;
480 #endif
481 
482  // inverse triangular matrix
483  vpMatrix inverseTriangular(bool upper = true) const;
484 
485  vpMatrix pseudoInverse(double svThreshold = 1e-6) const;
486  unsigned int pseudoInverse(vpMatrix &Ap, double svThreshold = 1e-6) const;
487  unsigned int pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
488  unsigned int pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt) const;
489  unsigned int pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
490  vpMatrix pseudoInverse(int rank_in) const;
491  int pseudoInverse(vpMatrix &Ap, int rank_in) const;
492  int pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
493  int pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt) const;
494  int pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
495 
496 #if defined(VISP_HAVE_LAPACK)
497  vpMatrix pseudoInverseLapack(double svThreshold = 1e-6) const;
498  unsigned int pseudoInverseLapack(vpMatrix &Ap, double svThreshold = 1e-6) const;
499  unsigned int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
500  unsigned int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
501  vpMatrix pseudoInverseLapack(int rank_in) const;
502  int pseudoInverseLapack(vpMatrix &Ap, int rank_in) const;
503  int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
504  int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
505 #endif
506 #if defined(VISP_HAVE_EIGEN3)
507  vpMatrix pseudoInverseEigen3(double svThreshold = 1e-6) const;
508  unsigned int pseudoInverseEigen3(vpMatrix &Ap, double svThreshold = 1e-6) const;
509  unsigned int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
510  unsigned int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
511  vpMatrix pseudoInverseEigen3(int rank_in) const;
512  int pseudoInverseEigen3(vpMatrix &Ap, int rank_in) const;
513  int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
514  int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
515 #endif
516 #if defined(VISP_HAVE_OPENCV)
517  vpMatrix pseudoInverseOpenCV(double svThreshold = 1e-6) const;
518  unsigned int pseudoInverseOpenCV(vpMatrix &Ap, double svThreshold = 1e-6) const;
519  unsigned int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
520  unsigned int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
521  vpMatrix pseudoInverseOpenCV(int rank_in) const;
522  int pseudoInverseOpenCV(vpMatrix &Ap, int rank_in) const;
523  int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
524  int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
525 #endif
527 
528  //-------------------------------------------------
529  // SVD decomposition
530  //-------------------------------------------------
531 
534  double cond(double svThreshold = 1e-6) const;
535  unsigned int kernel(vpMatrix &kerAt, double svThreshold = 1e-6) const;
536  unsigned int nullSpace(vpMatrix &kerA, double svThreshold = 1e-6) const;
537  unsigned int nullSpace(vpMatrix &kerA, int dim) const;
538 
539  // solve Ax=B using the SVD decomposition (usage A = solveBySVD(B,x) )
540  void solveBySVD(const vpColVector &B, vpColVector &x) const;
541  // solve Ax=B using the SVD decomposition (usage x=A.solveBySVD(B))
542  vpColVector solveBySVD(const vpColVector &B) const;
543 
544  // singular value decomposition SVD
545  void svd(vpColVector &w, vpMatrix &V);
546 #ifdef VISP_HAVE_EIGEN3
547  void svdEigen3(vpColVector &w, vpMatrix &V);
548 #endif
549 #if defined(VISP_HAVE_LAPACK)
550  void svdLapack(vpColVector &w, vpMatrix &V);
551 #endif
552 #if defined(VISP_HAVE_OPENCV) // Require opencv >= 2.1.1
553  void svdOpenCV(vpColVector &w, vpMatrix &V);
554 #endif
556 
557  //-------------------------------------------------
558  // QR decomposition
559  //-------------------------------------------------
560 
563  unsigned int qr(vpMatrix &Q, vpMatrix &R, bool full = false, bool squareR = false, double tol = 1e-6) const;
564  unsigned int qrPivot(vpMatrix &Q, vpMatrix &R, vpMatrix &P, bool full = false, bool squareR = false,
565  double tol = 1e-6) const;
566  void solveByQR(const vpColVector &b, vpColVector &x) const;
567  vpColVector solveByQR(const vpColVector &b) const;
569 
570  //-------------------------------------------------
571  // Eigen values and vectors
572  //-------------------------------------------------
576  // Compute the eigen values using Lapack.
577  vpColVector eigenValues() const;
578  void eigenValues(vpColVector &evalue, vpMatrix &evector) const;
580 
581  //-------------------------------------------------
582  // Norms
583  //-------------------------------------------------
586  double frobeniusNorm() const;
587  double inducedL2Norm() const;
588  double infinityNorm() const;
590 
591  //---------------------------------
592  // Printing
593  //---------------------------------
596  std::ostream &cppPrint(std::ostream &os, const std::string &matrixName = "A", bool octet = false) const;
597  std::ostream &csvPrint(std::ostream &os) const;
598  std::ostream &maplePrint(std::ostream &os) const;
599  std::ostream &matlabPrint(std::ostream &os) const;
600  int print(std::ostream &s, unsigned int length, const std::string &intro = "") const;
601  void printSize() const { std::cout << getRows() << " x " << getCols() << " "; }
603 
604  //------------------------------------------------------------------
605  // Static functionalities
606  //------------------------------------------------------------------
607 
608  //---------------------------------
609  // Setting a diagonal matrix with Static Public Member Functions
610  //---------------------------------
613  // Create a diagonal matrix with the element of a vector DAii = Ai
614  static void createDiagonalMatrix(const vpColVector &A, vpMatrix &DA);
616 
617  //---------------------------------
618  // Matrix insertion with Static Public Member Functions
619  //---------------------------------
622  // Insert matrix B in matrix A at the given position (r, c).
623  static vpMatrix insert(const vpMatrix &A, const vpMatrix &B, unsigned int r, unsigned int c);
624  // Insert matrix B in matrix A (not modified) at the given position (r, c),
625  // the result is given in matrix C.
626  static void insert(const vpMatrix &A, const vpMatrix &B, vpMatrix &C, unsigned int r, unsigned int c);
627 
628  //---------------------------------
629  // Stacking with Static Public Member Functions
630  //---------------------------------
633  // Juxtapose to matrices C = [ A B ]
634  static vpMatrix juxtaposeMatrices(const vpMatrix &A, const vpMatrix &B);
635  // Juxtapose to matrices C = [ A B ]
636  static void juxtaposeMatrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
637  // Stack two matrices C = [ A B ]^T
638  static vpMatrix stack(const vpMatrix &A, const vpMatrix &B);
639  static vpMatrix stack(const vpMatrix &A, const vpRowVector &r);
640  static vpMatrix stack(const vpMatrix &A, const vpColVector &c);
641 
642  // Stack two matrices C = [ A B ]^T
643  static void stack(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
644  static void stack(const vpMatrix &A, const vpRowVector &r, vpMatrix &C);
645  static void stack(const vpMatrix &A, const vpColVector &c, vpMatrix &C);
647 
648  //---------------------------------
649  // Matrix operations Static Public Member Functions
650  //---------------------------------
653  static void add2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
654  static void add2Matrices(const vpColVector &A, const vpColVector &B, vpColVector &C);
655  static void add2WeightedMatrices(const vpMatrix &A, const double &wA, const vpMatrix &B, const double &wB,
656  vpMatrix &C);
657  static void computeHLM(const vpMatrix &H, const double &alpha, vpMatrix &HLM);
658  static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
659  static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpRotationMatrix &C);
660  static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpHomogeneousMatrix &C);
661  static void mult2Matrices(const vpMatrix &A, const vpColVector &B, vpColVector &C);
662  static void multMatrixVector(const vpMatrix &A, const vpColVector &v, vpColVector &w);
663  static void negateMatrix(const vpMatrix &A, vpMatrix &C);
664  static void sub2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
665  static void sub2Matrices(const vpColVector &A, const vpColVector &B, vpColVector &C);
667 
668  //---------------------------------
669  // Kronecker product Static Public Member Functions
670  //---------------------------------
673  // Compute Kronecker product matrix
674  static void kron(const vpMatrix &m1, const vpMatrix &m2, vpMatrix &out);
675 
676  // Compute Kronecker product matrix
677  static vpMatrix kron(const vpMatrix &m1, const vpMatrix &m2);
679 
680  //---------------------------------
681  // Covariance computation Static Public Member Functions
682  //---------------------------------
685  static vpMatrix computeCovarianceMatrix(const vpMatrix &A, const vpColVector &x, const vpColVector &b);
686  static vpMatrix computeCovarianceMatrix(const vpMatrix &A, const vpColVector &x, const vpColVector &b,
687  const vpMatrix &w);
688  static vpMatrix computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS,
689  const vpMatrix &Ls, const vpMatrix &W);
690  static vpMatrix computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS,
691  const vpMatrix &Ls);
693 
694  //---------------------------------
695  // Matrix I/O Static Public Member Functions
696  //---------------------------------
765  static inline bool loadMatrix(const std::string &filename, vpArray2D<double> &M, bool binary = false,
766  char *header = nullptr)
767  {
768  return vpArray2D<double>::load(filename, M, binary, header);
769  }
770 
840  static inline bool loadMatrixYAML(const std::string &filename, vpArray2D<double> &M, char *header = nullptr)
841  {
842  return vpArray2D<double>::loadYAML(filename, M, header);
843  }
844 
913  static inline bool saveMatrix(const std::string &filename, const vpArray2D<double> &M, bool binary = false,
914  const char *header = "")
915  {
916  return vpArray2D<double>::save(filename, M, binary, header);
917  }
918 
989  static inline bool saveMatrixYAML(const std::string &filename, const vpArray2D<double> &M, const char *header = "")
990  {
991  return vpArray2D<double>::saveYAML(filename, M, header);
992  }
994 
995 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
996  vp_deprecated double euclideanNorm() const;
997 
1006  vp_deprecated void init() { }
1007 
1011  vp_deprecated void stackMatrices(const vpMatrix &A) { stack(A); }
1016  vp_deprecated static vpMatrix stackMatrices(const vpMatrix &A, const vpMatrix &B) { return stack(A, B); }
1021  vp_deprecated static void stackMatrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C) { stack(A, B, C); }
1026  vp_deprecated static vpMatrix stackMatrices(const vpMatrix &A, const vpRowVector &B);
1031  vp_deprecated static void stackMatrices(const vpMatrix &A, const vpRowVector &B, vpMatrix &C);
1036  vp_deprecated static vpMatrix stackMatrices(const vpColVector &A, const vpColVector &B);
1041  vp_deprecated static void stackMatrices(const vpColVector &A, const vpColVector &B, vpColVector &C);
1042 
1046  vp_deprecated void setIdentity(const double &val = 1.0);
1047 
1048  vp_deprecated vpRowVector row(unsigned int i);
1049  vp_deprecated vpColVector column(unsigned int j);
1050 
1051  // Deprecated functions using GSL
1052 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1056  vp_deprecated double detByLUGsl() const
1057  {
1058 #if defined(VISP_HAVE_LAPACK)
1059  return detByLULapack();
1060 #else
1061  throw(vpException(vpException::fatalError, "Undefined detByLULapack(). Install Lapack 3rd party"));
1062 #endif
1063  }
1064 
1068  vp_deprecated vpMatrix inverseByLUGsl() const
1069  {
1070 #if defined(VISP_HAVE_LAPACK)
1071  return inverseByLULapack();
1072 #else
1073  throw(vpException(vpException::fatalError, "Undefined inverseByLULapack(). Install Lapack 3rd party"));
1074 #endif
1075  }
1076 
1080  vp_deprecated vpMatrix inverseByCholeskyGsl() const
1081  {
1082 #if defined(VISP_HAVE_LAPACK)
1083  return inverseByCholeskyLapack();
1084 #else
1085  throw(vpException(vpException::fatalError, "Undefined inverseByCholeskyLapack(). Install Lapack 3rd party"));
1086 #endif
1087  }
1088 
1092  vp_deprecated vpMatrix inverseByQRGsl() const
1093  {
1094 #if defined(VISP_HAVE_LAPACK)
1095  return inverseByQRLapack();
1096 #else
1097  throw(vpException(vpException::fatalError, "Undefined inverseByQRLapack(). Install Lapack 3rd party"));
1098 #endif
1099  }
1100 
1104  vp_deprecated vpMatrix pseudoInverseGsl(double svThreshold = 1e-6) const
1105  {
1106 #if defined(VISP_HAVE_LAPACK)
1107  return pseudoInverseLapack(svThreshold);
1108 #else
1109  (void)svThreshold;
1110  throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
1111 #endif
1112  }
1113 
1117  vp_deprecated unsigned int pseudoInverseGsl(vpMatrix &Ap, double svThreshold = 1e-6) const
1118  {
1119 #if defined(VISP_HAVE_LAPACK)
1120  return pseudoInverseLapack(Ap, svThreshold);
1121 #else
1122  (void)Ap;
1123  (void)svThreshold;
1124  throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
1125 #endif
1126  }
1127 
1131  vp_deprecated unsigned int pseudoInverseGsl(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const
1132  {
1133 #if defined(VISP_HAVE_LAPACK)
1134  return pseudoInverseLapack(Ap, sv, svThreshold);
1135 #else
1136  (void)Ap;
1137  (void)sv;
1138  (void)svThreshold;
1139  throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
1140 #endif
1141  }
1142 
1146  vp_deprecated unsigned int pseudoInverseGsl(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt,
1147  vpMatrix &kerAt) const
1148  {
1149 #if defined(VISP_HAVE_LAPACK)
1150  return pseudoInverseLapack(Ap, sv, svThreshold, imA, imAt, kerAt);
1151 #else
1152  (void)Ap;
1153  (void)sv;
1154  (void)svThreshold;
1155  (void)imA;
1156  (void)imAt;
1157  (void)kerAt;
1158  throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
1159 #endif
1160  }
1161 
1165  vp_deprecated void svdGsl(vpColVector &w, vpMatrix &V)
1166  {
1167 #if defined(VISP_HAVE_LAPACK)
1168  svdLapack(w, V);
1169 #else
1170  (void)w;
1171  (void)V;
1172  throw(vpException(vpException::fatalError, "Undefined svdLapack(). Install Lapack 3rd party"));
1173 #endif
1174  }
1175 
1176 #endif // ifndef DOXYGEN_SHOULD_SKIP_THIS
1178 #endif
1179 
1180 private:
1181  static unsigned int m_lapack_min_size;
1182  static const unsigned int m_lapack_min_size_default;
1183 
1184 #if defined(VISP_HAVE_LAPACK)
1185  static void blas_dgemm(char trans_a, char trans_b, unsigned int M_, unsigned int N_, unsigned int K_, double alpha,
1186  double *a_data, unsigned int lda_, double *b_data, unsigned int ldb_, double beta,
1187  double *c_data, unsigned int ldc_);
1188  static void blas_dgemv(char trans, unsigned int M_, unsigned int N_, double alpha, double *a_data, unsigned int lda_,
1189  double *x_data, int incx_, double beta, double *y_data, int incy_);
1190  static void blas_dsyev(char jobz, char uplo, unsigned int n_, double *a_data, unsigned int lda_, double *w_data,
1191  double *work_data, int lwork_, int &info_);
1192 #endif
1193 
1194  static void computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS, const vpMatrix &Ls,
1195  vpMatrix &Js, vpColVector &deltaP);
1196 };
1197 
1199 #if defined(VISP_USE_MSVC) && defined(visp_EXPORTS)
1200 const __declspec(selectany) unsigned int vpMatrix::m_lapack_min_size_default = 0;
1201 __declspec(selectany) unsigned int vpMatrix::m_lapack_min_size = vpMatrix::m_lapack_min_size_default;
1202 #endif
1203 
1204 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1205 VISP_EXPORT
1206 #endif
1207 vpMatrix operator*(const double &x, const vpMatrix &A);
1208 
1210 #endif
Implementation of a generic 2D array used as base class for matrices and vectors.
Definition: vpArray2D.h:127
unsigned int getCols() const
Definition: vpArray2D.h:330
static bool loadYAML(const std::string &filename, vpArray2D< Type > &A, char *header=nullptr)
Definition: vpArray2D.h:773
void insert(const vpArray2D< Type > &A, unsigned int r, unsigned int c)
Definition: vpArray2D.h:487
static bool saveYAML(const std::string &filename, const vpArray2D< Type > &A, const char *header="")
Definition: vpArray2D.h:959
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:604
static bool load(const std::string &filename, vpArray2D< Type > &A, bool binary=false, char *header=nullptr)
Definition: vpArray2D.h:659
vpArray2D< Type > t() const
Compute the transpose of the array.
Definition: vpArray2D.h:1143
unsigned int getRows() const
Definition: vpArray2D.h:340
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition: vpArray2D.h:516
vpArray2D< Type > hadamard(const vpArray2D< Type > &m) const
Definition: vpArray2D.h:1127
static bool save(const std::string &filename, const vpArray2D< Type > &A, bool binary=false, const char *header="")
Definition: vpArray2D.h:861
Implementation of column vector and the associated operations.
Definition: vpColVector.h:171
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:151
static void setLapackMatrixMinSize(unsigned int min_size)
Definition: vpMatrix.h:257
int pseudoInverseOpenCV(vpMatrix &Ap, int rank_in) const
vpMatrix(unsigned int r, unsigned int c)
Definition: vpMatrix.h:175
vpMatrix(unsigned int r, unsigned int c, double val)
Definition: vpMatrix.h:184
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:243
vpMatrix pseudoInverseEigen3(double svThreshold=1e-6) const
unsigned int pseudoInverseOpenCV(vpMatrix &Ap, double svThreshold=1e-6) const
void printSize() const
Definition: vpMatrix.h:601
unsigned int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const
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:765
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
vp_deprecated void stackMatrices(const vpMatrix &A)
Definition: vpMatrix.h:1011
unsigned int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold=1e-6) const
int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, int rank_in) const
vpMatrix(const vpArray2D< double > &A)
Definition: vpMatrix.h:199
unsigned int pseudoInverseEigen3(vpMatrix &Ap, double svThreshold=1e-6) const
static vp_deprecated vpMatrix stackMatrices(const vpMatrix &A, const vpMatrix &B)
Definition: vpMatrix.h:1016
vpMatrix()
Definition: vpMatrix.h:167
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:201
vp_deprecated void init()
Definition: vpMatrix.h:1006
void clear()
Definition: vpMatrix.h:214
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:989
static vp_deprecated void stackMatrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
Definition: vpMatrix.h:1021
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:840
static bool saveMatrix(const std::string &filename, const vpArray2D< double > &M, bool binary=false, const char *header="")
Definition: vpMatrix.h:913
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:110
Class that consider the case of a translation vector.
vpMatrix operator*(const double &x, const vpMatrix &A)