Visual Servoing Platform  version 3.5.1 under development (2023-06-02)
vpMatrix.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2022 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Matrix manipulation.
33  *
34  *****************************************************************************/
35 
36 #ifndef vpMatrix_H
37 #define vpMatrix_H
38 
39 #include <visp3/core/vpArray2D.h>
40 #include <visp3/core/vpConfig.h>
41 #include <visp3/core/vpException.h>
42 #include <visp3/core/vpForceTwistMatrix.h>
43 #include <visp3/core/vpHomogeneousMatrix.h>
44 #include <visp3/core/vpRotationMatrix.h>
45 #include <visp3/core/vpTime.h>
46 #include <visp3/core/vpVelocityTwistMatrix.h>
47 
48 #include <iostream>
49 #include <math.h>
50 
51 class vpRowVector;
52 class vpColVector;
56 class vpForceTwistMatrix;
57 
153 class VISP_EXPORT vpMatrix : public vpArray2D<double>
154 {
155 public:
160  typedef enum {
161  LU_DECOMPOSITION
162  } vpDetMethod;
163 
164 public:
169  vpMatrix() : vpArray2D<double>(0, 0) {}
170 
177  vpMatrix(unsigned int r, unsigned int c) : vpArray2D<double>(r, c) {}
178 
186  vpMatrix(unsigned int r, unsigned int c, double val) : vpArray2D<double>(r, c, val) {}
187  vpMatrix(const vpMatrix &M, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols);
188 
201  vpMatrix(const vpArray2D<double> &A) : vpArray2D<double>(A) {}
202 
203  vpMatrix(const vpMatrix &A) : vpArray2D<double>(A) {}
204 
205 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
206  vpMatrix(vpMatrix &&A);
207  explicit vpMatrix(const std::initializer_list<double> &list);
208  explicit vpMatrix(unsigned int nrows, unsigned int ncols, const std::initializer_list<double> &list);
209  explicit vpMatrix(const std::initializer_list<std::initializer_list<double> > &lists);
210 #endif
211 
213  virtual ~vpMatrix() {}
214 
219  void clear()
220  {
221  if (data != NULL) {
222  free(data);
223  data = NULL;
224  }
225 
226  if (rowPtrs != NULL) {
227  free(rowPtrs);
228  rowPtrs = NULL;
229  }
230  rowNum = colNum = dsize = 0;
231  }
232 
233  //-------------------------------------------------
234  // Setting a diagonal matrix
235  //-------------------------------------------------
246  static unsigned int getLapackMatrixMinSize() { return m_lapack_min_size; }
247 
260  static void setLapackMatrixMinSize(unsigned int min_size) { m_lapack_min_size = min_size; }
262 
263  //-------------------------------------------------
264  // Setting a diagonal matrix
265  //-------------------------------------------------
268  void diag(const double &val = 1.0);
269  void diag(const vpColVector &A);
270  // Initialize an identity matrix n-by-n
271  void eye();
272  void eye(unsigned int n);
273  // Initialize an identity matrix m-by-n
274  void eye(unsigned int m, unsigned int n);
276 
277  //---------------------------------
278  // Assignment
279  //---------------------------------
282  vpMatrix &operator<<(double *);
283  vpMatrix &operator<<(double val);
284  vpMatrix &operator,(double val);
286 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
287  vpMatrix &operator=(const vpMatrix &A);
289 
290  vpMatrix &operator=(const std::initializer_list<double> &list);
291  vpMatrix &operator=(const std::initializer_list<std::initializer_list<double> > &lists);
292 #endif
293  vpMatrix &operator=(double x);
295 
296  //-------------------------------------------------
297  // Stacking
298  //-------------------------------------------------
301  // Stack the matrix A below the current one, copy if not initialized this =
302  // [ this A ]^T
303  void stack(const vpMatrix &A);
304  void stack(const vpRowVector &r);
305  void stack(const vpColVector &c);
306  // Stacks columns of a matrix in a vector
307  void stackColumns(vpColVector &out);
308 
309  // Stacks columns of a matrix in a vector
310  vpColVector stackColumns();
311 
312  // Stacks columns of a matrix in a vector
313  void stackRows(vpRowVector &out);
314 
315  // Stacks columns of a matrix in a vector
316  vpRowVector stackRows();
318 
319  //---------------------------------
320  // Matrix insertion
321  //---------------------------------
324  // Insert matrix A in the current matrix at the given position (r, c).
325  void insert(const vpMatrix &A, unsigned int r, unsigned int c);
327 
328  //-------------------------------------------------
329  // Columns, Rows, Diag extraction, SubMatrix
330  //-------------------------------------------------
333  vpMatrix extract(unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols) const;
334  vpColVector getCol(unsigned int j) const;
335  vpColVector getCol(unsigned int j, unsigned int i_begin, unsigned int size) const;
336  vpRowVector getRow(unsigned int i) const;
337  vpRowVector getRow(unsigned int i, unsigned int j_begin, unsigned int size) const;
338  vpColVector getDiag() const;
339  void init(const vpMatrix &M, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols);
341 
342  //---------------------------------
343  // Matrix operations.
344  //---------------------------------
347  // return the determinant of the matrix.
348  double det(vpDetMethod method = LU_DECOMPOSITION) const;
349  double detByLU() const;
350 #ifdef VISP_HAVE_EIGEN3
351  double detByLUEigen3() const;
352 #endif
353 #if defined(VISP_HAVE_LAPACK)
354  double detByLULapack() const;
355 #endif
356 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
357  double detByLUOpenCV() const;
358 #endif
359 
360  // Compute the exponential matrix of a square matrix
361  vpMatrix expm() const;
362 
363  // operation A = A + B
364  vpMatrix &operator+=(const vpMatrix &B);
365  // operation A = A - B
366  vpMatrix &operator-=(const vpMatrix &B);
367  vpMatrix operator*(const vpMatrix &B) const;
368  vpMatrix operator*(const vpRotationMatrix &R) const;
369  vpMatrix operator*(const vpHomogeneousMatrix &R) const;
370  vpMatrix operator*(const vpVelocityTwistMatrix &V) const;
371  vpMatrix operator*(const vpForceTwistMatrix &V) const;
372  // operation t_out = A * t (A is unchanged, t and t_out are translation
373  // vectors)
375  vpColVector operator*(const vpColVector &v) const;
376  vpMatrix operator+(const vpMatrix &B) const;
377  vpMatrix operator-(const vpMatrix &B) const;
378  vpMatrix operator-() const;
379 
381  vpMatrix &operator+=(double x);
383  vpMatrix &operator-=(double x);
385  vpMatrix &operator*=(double x);
387  vpMatrix &operator/=(double x);
388 
389  // Cij = Aij * x (A is unchanged)
390  vpMatrix operator*(double x) const;
391  // Cij = Aij / x (A is unchanged)
392  vpMatrix operator/(double x) const;
393 
399  double sum() const;
400  double sumSquare() const;
401 
402  //-------------------------------------------------
403  // Hadamard product
404  //-------------------------------------------------
406  vpMatrix hadamard(const vpMatrix &m) const;
407 
408  //-------------------------------------------------
409  // Kronecker product
410  //-------------------------------------------------
413  // Compute Kronecker product matrix
414  void kron(const vpMatrix &m1, vpMatrix &out) const;
415 
416  // Compute Kronecker product matrix
417  vpMatrix kron(const vpMatrix &m1) const;
419 
420  //-------------------------------------------------
421  // Transpose
422  //-------------------------------------------------
425  // Compute the transpose C = A^T
426  vpMatrix t() const;
427 
428  // Compute the transpose C = A^T
429  vpMatrix transpose() const;
430  void transpose(vpMatrix &At) const;
431 
432  vpMatrix AAt() const;
433  void AAt(vpMatrix &B) const;
434 
435  vpMatrix AtA() const;
436  void AtA(vpMatrix &B) const;
438 
439  //-------------------------------------------------
440  // Matrix inversion
441  //-------------------------------------------------
444  // inverse matrix A using the LU decomposition
445  vpMatrix inverseByLU() const;
446 
447 #if defined(VISP_HAVE_EIGEN3)
448  vpMatrix inverseByLUEigen3() const;
449 #endif
450 #if defined(VISP_HAVE_LAPACK)
451  vpMatrix inverseByLULapack() const;
452 #endif
453 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
454  vpMatrix inverseByLUOpenCV() const;
455 #endif
456 
457  // inverse matrix A using the Cholesky decomposition (only for real
458  // symmetric matrices)
459  vpMatrix inverseByCholesky() const;
460 
461 #if defined(VISP_HAVE_LAPACK)
462  vpMatrix inverseByCholeskyLapack() const;
463 #endif
464 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
465  vpMatrix inverseByCholeskyOpenCV() const;
466 #endif
467 
468  // inverse matrix A using the QR decomposition
469  vpMatrix inverseByQR() const;
470 #if defined(VISP_HAVE_LAPACK)
471  vpMatrix inverseByQRLapack() const;
472 #endif
473 
474  // inverse triangular matrix
475  vpMatrix inverseTriangular(bool upper = true) const;
476 
477  vpMatrix pseudoInverse(double svThreshold = 1e-6) const;
478  unsigned int pseudoInverse(vpMatrix &Ap, double svThreshold = 1e-6) const;
479  unsigned int pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
480  unsigned int pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt) const;
481  unsigned int pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt,
482  vpMatrix &kerAt) const;
483  vpMatrix pseudoInverse(int rank_in) const;
484  int pseudoInverse(vpMatrix &Ap, int rank_in) const;
485  int pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
486  int pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt) const;
487  int pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
488 
489 #if defined(VISP_HAVE_LAPACK)
490  vpMatrix pseudoInverseLapack(double svThreshold = 1e-6) const;
491  unsigned int pseudoInverseLapack(vpMatrix &Ap, double svThreshold = 1e-6) const;
492  unsigned int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
493  unsigned int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt,
494  vpMatrix &kerAt) const;
495  vpMatrix pseudoInverseLapack(int rank_in) const;
496  int pseudoInverseLapack(vpMatrix &Ap, int rank_in) const;
497  int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
498  int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt,
499  vpMatrix &kerAt) const;
500 #endif
501 #if defined(VISP_HAVE_EIGEN3)
502  vpMatrix pseudoInverseEigen3(double svThreshold = 1e-6) const;
503  unsigned int pseudoInverseEigen3(vpMatrix &Ap, double svThreshold = 1e-6) const;
504  unsigned int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
505  unsigned int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt,
506  vpMatrix &kerAt) const;
507  vpMatrix pseudoInverseEigen3(int rank_in) const;
508  int pseudoInverseEigen3(vpMatrix &Ap, int rank_in) const;
509  int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
510  int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt,
511  vpMatrix &kerAt) const;
512 #endif
513 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
514  vpMatrix pseudoInverseOpenCV(double svThreshold = 1e-6) const;
515  unsigned int pseudoInverseOpenCV(vpMatrix &Ap, double svThreshold = 1e-6) const;
516  unsigned int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
517  unsigned int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt,
518  vpMatrix &kerAt) const;
519  vpMatrix pseudoInverseOpenCV(int rank_in) const;
520  int pseudoInverseOpenCV(vpMatrix &Ap, int rank_in) const;
521  int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
522  int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt,
523  vpMatrix &kerAt) const;
524 #endif
526 
527  //-------------------------------------------------
528  // SVD decomposition
529  //-------------------------------------------------
530 
533  double cond(double svThreshold = 1e-6) const;
534  unsigned int kernel(vpMatrix &kerAt, double svThreshold = 1e-6) const;
535  unsigned int nullSpace(vpMatrix &kerA, double svThreshold = 1e-6) const;
536  unsigned int nullSpace(vpMatrix &kerA, int dim) const;
537 
538  // solve Ax=B using the SVD decomposition (usage A = solveBySVD(B,x) )
539  void solveBySVD(const vpColVector &B, vpColVector &x) const;
540  // solve Ax=B using the SVD decomposition (usage x=A.solveBySVD(B))
541  vpColVector solveBySVD(const vpColVector &B) const;
542 
543  // singular value decomposition SVD
544  void svd(vpColVector &w, vpMatrix &V);
545 #ifdef VISP_HAVE_EIGEN3
546  void svdEigen3(vpColVector &w, vpMatrix &V);
547 #endif
548 #if defined(VISP_HAVE_LAPACK)
549  void svdLapack(vpColVector &w, vpMatrix &V);
550 #endif
551 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1
552  void svdOpenCV(vpColVector &w, vpMatrix &V);
553 #endif
555 
556  //-------------------------------------------------
557  // QR decomposition
558  //-------------------------------------------------
559 
562  unsigned int qr(vpMatrix &Q, vpMatrix &R, bool full = false, bool squareR = false, double tol = 1e-6) const;
563  unsigned int qrPivot(vpMatrix &Q, vpMatrix &R, vpMatrix &P, bool full = false, bool squareR = false,
564  double tol = 1e-6) const;
565  void solveByQR(const vpColVector &b, vpColVector &x) const;
566  vpColVector solveByQR(const vpColVector &b) const;
568 
569  //-------------------------------------------------
570  // Eigen values and vectors
571  //-------------------------------------------------
575  // compute the eigen values using Lapack
576  vpColVector eigenValues() const;
577  void eigenValues(vpColVector &evalue, vpMatrix &evector) const;
579 
580  //-------------------------------------------------
581  // Norms
582  //-------------------------------------------------
585  double euclideanNorm() const;
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  // 2D Convolution Static Public Member Functions
682  //-------------------------------------------------
684  static vpMatrix conv2(const vpMatrix &M, const vpMatrix &kernel, const std::string &mode = "full");
685  static void conv2(const vpMatrix &M, const vpMatrix &kernel, vpMatrix &res, const std::string &mode = "full");
686 
687  //---------------------------------
688  // Covariance computation Static Public Member Functions
689  //---------------------------------
692  static vpMatrix computeCovarianceMatrix(const vpMatrix &A, const vpColVector &x, const vpColVector &b);
693  static vpMatrix computeCovarianceMatrix(const vpMatrix &A, const vpColVector &x, const vpColVector &b,
694  const vpMatrix &w);
695  static vpMatrix computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS,
696  const vpMatrix &Ls, const vpMatrix &W);
697  static vpMatrix computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS,
698  const vpMatrix &Ls);
700 
701  //---------------------------------
702  // Matrix I/O Static Public Member Functions
703  //---------------------------------
772  static inline bool loadMatrix(const std::string &filename, vpArray2D<double> &M, bool binary = false,
773  char *header = NULL)
774  {
775  return vpArray2D<double>::load(filename, M, binary, header);
776  }
777 
847  static inline bool loadMatrixYAML(const std::string &filename, vpArray2D<double> &M, char *header = NULL)
848  {
849  return vpArray2D<double>::loadYAML(filename, M, header);
850  }
851 
920  static inline bool saveMatrix(const std::string &filename, const vpArray2D<double> &M, bool binary = false,
921  const char *header = "")
922  {
923  return vpArray2D<double>::save(filename, M, binary, header);
924  }
925 
996  static inline bool saveMatrixYAML(const std::string &filename, const vpArray2D<double> &M, const char *header = "")
997  {
998  return vpArray2D<double>::saveYAML(filename, M, header);
999  }
1001 
1002 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
1011  vp_deprecated void init() {}
1012 
1016  vp_deprecated void stackMatrices(const vpMatrix &A) { stack(A); }
1021  vp_deprecated static vpMatrix stackMatrices(const vpMatrix &A, const vpMatrix &B) { return stack(A, B); }
1026  vp_deprecated static void stackMatrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C) { stack(A, B, C); }
1031  vp_deprecated static vpMatrix stackMatrices(const vpMatrix &A, const vpRowVector &B);
1036  vp_deprecated static void stackMatrices(const vpMatrix &A, const vpRowVector &B, vpMatrix &C);
1041  vp_deprecated static vpMatrix stackMatrices(const vpColVector &A, const vpColVector &B);
1046  vp_deprecated static void stackMatrices(const vpColVector &A, const vpColVector &B, vpColVector &C);
1047 
1051  vp_deprecated void setIdentity(const double &val = 1.0);
1052 
1053  vp_deprecated vpRowVector row(unsigned int i);
1054  vp_deprecated vpColVector column(unsigned int j);
1055 
1056  // Deprecated functions using GSL
1057 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1061  vp_deprecated double detByLUGsl() const
1062  {
1063 #if defined(VISP_HAVE_LAPACK)
1064  return detByLULapack();
1065 #else
1066  throw(vpException(vpException::fatalError, "Undefined detByLULapack(). Install Lapack 3rd party"));
1067 #endif
1068  }
1069 
1073  vp_deprecated vpMatrix inverseByLUGsl() const
1074  {
1075 #if defined(VISP_HAVE_LAPACK)
1076  return inverseByLULapack();
1077 #else
1078  throw(vpException(vpException::fatalError, "Undefined inverseByLULapack(). Install Lapack 3rd party"));
1079 #endif
1080  }
1081 
1085  vpMatrix inverseByCholeskyGsl() const
1086  {
1087 #if defined(VISP_HAVE_LAPACK)
1088  return inverseByCholeskyLapack();
1089 #else
1090  throw(vpException(vpException::fatalError, "Undefined inverseByCholeskyLapack(). Install Lapack 3rd party"));
1091 #endif
1092  }
1093 
1097  vpMatrix inverseByQRGsl() const
1098  {
1099 #if defined(VISP_HAVE_LAPACK)
1100  return inverseByQRLapack();
1101 #else
1102  throw(vpException(vpException::fatalError, "Undefined inverseByQRLapack(). Install Lapack 3rd party"));
1103 #endif
1104  }
1105 
1109  vpMatrix pseudoInverseGsl(double svThreshold = 1e-6) const
1110  {
1111 #if defined(VISP_HAVE_LAPACK)
1112  return pseudoInverseLapack(svThreshold);
1113 #else
1114  (void)svThreshold;
1115  throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
1116 #endif
1117  }
1118 
1122  unsigned int pseudoInverseGsl(vpMatrix &Ap, double svThreshold = 1e-6) const
1123  {
1124 #if defined(VISP_HAVE_LAPACK)
1125  return pseudoInverseLapack(Ap, svThreshold);
1126 #else
1127  (void)Ap;
1128  (void)svThreshold;
1129  throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
1130 #endif
1131  }
1132 
1136  unsigned int pseudoInverseGsl(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const
1137  {
1138 #if defined(VISP_HAVE_LAPACK)
1139  return pseudoInverseLapack(Ap, sv, svThreshold);
1140 #else
1141  (void)Ap;
1142  (void)sv;
1143  (void)svThreshold;
1144  throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
1145 #endif
1146  }
1147 
1151  unsigned int pseudoInverseGsl(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt,
1152  vpMatrix &kerAt) const
1153  {
1154 #if defined(VISP_HAVE_LAPACK)
1155  return pseudoInverseLapack(Ap, sv, svThreshold, imA, imAt, kerAt);
1156 #else
1157  (void)Ap;
1158  (void)sv;
1159  (void)svThreshold;
1160  (void)imA;
1161  (void)imAt;
1162  (void)kerAt;
1163  throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
1164 #endif
1165  }
1166 
1170  void svdGsl(vpColVector &w, vpMatrix &V)
1171  {
1172 #if defined(VISP_HAVE_LAPACK)
1173  svdLapack(w, V);
1174 #else
1175  (void)w;
1176  (void)V;
1177  throw(vpException(vpException::fatalError, "Undefined svdLapack(). Install Lapack 3rd party"));
1178 #endif
1179  }
1180 
1181 #endif // ifndef DOXYGEN_SHOULD_SKIP_THIS
1183 #endif
1184 
1185 private:
1186  static unsigned int m_lapack_min_size;
1187  static const unsigned int m_lapack_min_size_default;
1188 
1189 #if defined(VISP_HAVE_LAPACK)
1190  static void blas_dgemm(char trans_a, char trans_b, unsigned int M_, unsigned int N_, unsigned int K_, double alpha,
1191  double *a_data, unsigned int lda_, double *b_data, unsigned int ldb_, double beta,
1192  double *c_data, unsigned int ldc_);
1193  static void blas_dgemv(char trans, unsigned int M_, unsigned int N_, double alpha, double *a_data, unsigned int lda_,
1194  double *x_data, int incx_, double beta, double *y_data, int incy_);
1195  static void blas_dsyev(char jobz, char uplo, unsigned int n_, double *a_data, unsigned int lda_, double *w_data,
1196  double *work_data, int lwork_, int &info_);
1197 #endif
1198 
1199  static void computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS, const vpMatrix &Ls,
1200  vpMatrix &Js, vpColVector &deltaP);
1201 };
1202 
1204 #if defined(VISP_USE_MSVC) && defined(visp_EXPORTS)
1205 const __declspec(selectany) unsigned int vpMatrix::m_lapack_min_size_default = 0;
1206 __declspec(selectany) unsigned int vpMatrix::m_lapack_min_size = vpMatrix::m_lapack_min_size_default;
1207 #endif
1208 
1209 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1210 VISP_EXPORT
1211 #endif
1212 vpMatrix operator*(const double &x, const vpMatrix &A);
1213 #endif
Implementation of a generic 2D array used as base class for matrices and vectors.
Definition: vpArray2D.h:133
static bool load(const std::string &filename, vpArray2D< Type > &A, bool binary=false, char *header=NULL)
Definition: vpArray2D.h:546
unsigned int getCols() const
Definition: vpArray2D.h:282
static bool saveYAML(const std::string &filename, const vpArray2D< Type > &A, const char *header="")
Definition: vpArray2D.h:832
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:499
static bool loadYAML(const std::string &filename, vpArray2D< Type > &A, char *header=NULL)
Definition: vpArray2D.h:657
unsigned int getRows() const
Definition: vpArray2D.h:292
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition: vpArray2D.h:415
vpArray2D< Type > hadamard(const vpArray2D< Type > &m) const
Definition: vpArray2D.h:941
static bool save(const std::string &filename, const vpArray2D< Type > &A, bool binary=false, const char *header="")
Definition: vpArray2D.h:741
Implementation of column vector and the associated operations.
Definition: vpColVector.h:172
error that can be emited by ViSP classes.
Definition: vpException.h:72
@ fatalError
Fatal error.
Definition: vpException.h:96
Implementation of an homogeneous matrix and operations on such kind of matrices.
VISP_EXPORT vpImagePoint operator*(const vpImagePoint &ip1, double scale)
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:154
static void setLapackMatrixMinSize(unsigned int min_size)
Definition: vpMatrix.h:260
int pseudoInverseOpenCV(vpMatrix &Ap, int rank_in) const
vpMatrix(unsigned int r, unsigned int c)
Definition: vpMatrix.h:177
vpMatrix(unsigned int r, unsigned int c, double val)
Definition: vpMatrix.h:186
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 bool loadMatrixYAML(const std::string &filename, vpArray2D< double > &M, char *header=NULL)
Definition: vpMatrix.h:847
static bool loadMatrix(const std::string &filename, vpArray2D< double > &M, bool binary=false, char *header=NULL)
Definition: vpMatrix.h:772
static unsigned int getLapackMatrixMinSize()
Definition: vpMatrix.h:246
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
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:1016
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:201
unsigned int pseudoInverseEigen3(vpMatrix &Ap, double svThreshold=1e-6) const
static vp_deprecated vpMatrix stackMatrices(const vpMatrix &A, const vpMatrix &B)
Definition: vpMatrix.h:1021
vpMatrix()
Definition: vpMatrix.h:169
unsigned int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold=1e-6) const
vpMatrix pseudoInverseLapack(int rank_in) const
virtual ~vpMatrix()
Destructor (Memory de-allocation)
Definition: vpMatrix.h:213
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:203
vp_deprecated void init()
Definition: vpMatrix.h:1011
void clear()
Definition: vpMatrix.h:219
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:996
static vp_deprecated void stackMatrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
Definition: vpMatrix.h:1026
unsigned int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold=1e-6) const
static bool saveMatrix(const std::string &filename, const vpArray2D< double > &M, bool binary=false, const char *header="")
Definition: vpMatrix.h:920
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:116
Class that consider the case of a translation vector.
vpColVector operator*(const double &x, const vpColVector &v)