Visual Servoing Platform  version 3.5.1 under development (2022-09-30)
vpMatrix.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 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  //---------------------------------
717  static inline bool loadMatrix(const std::string &filename, vpArray2D<double> &M, bool binary = false,
718  char *header = NULL)
719  {
720  return vpArray2D<double>::load(filename, M, binary, header);
721  }
722 
733  static inline bool loadMatrixYAML(const std::string &filename, vpArray2D<double> &M, char *header = NULL)
734  {
735  return vpArray2D<double>::loadYAML(filename, M, header);
736  }
737 
752  static inline bool saveMatrix(const std::string &filename, const vpArray2D<double> &M, bool binary = false,
753  const char *header = "")
754  {
755  return vpArray2D<double>::save(filename, M, binary, header);
756  }
757 
770  static inline bool saveMatrixYAML(const std::string &filename, const vpArray2D<double> &M, const char *header = "")
771  {
772  return vpArray2D<double>::saveYAML(filename, M, header);
773  }
775 
776 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
785  vp_deprecated void init() {}
786 
790  vp_deprecated void stackMatrices(const vpMatrix &A) { stack(A); }
795  vp_deprecated static vpMatrix stackMatrices(const vpMatrix &A, const vpMatrix &B) { return stack(A, B); }
800  vp_deprecated static void stackMatrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C) { stack(A, B, C); }
805  vp_deprecated static vpMatrix stackMatrices(const vpMatrix &A, const vpRowVector &B);
810  vp_deprecated static void stackMatrices(const vpMatrix &A, const vpRowVector &B, vpMatrix &C);
815  vp_deprecated static vpMatrix stackMatrices(const vpColVector &A, const vpColVector &B);
820  vp_deprecated static void stackMatrices(const vpColVector &A, const vpColVector &B, vpColVector &C);
821 
825  vp_deprecated void setIdentity(const double &val = 1.0);
826 
827  vp_deprecated vpRowVector row(unsigned int i);
828  vp_deprecated vpColVector column(unsigned int j);
829 
830  // Deprecated functions using GSL
831 #ifndef DOXYGEN_SHOULD_SKIP_THIS
835  vp_deprecated double detByLUGsl() const
836  {
837 #if defined(VISP_HAVE_LAPACK)
838  return detByLULapack();
839 #else
840  throw(vpException(vpException::fatalError, "Undefined detByLULapack(). Install Lapack 3rd party"));
841 #endif
842  }
843 
847  vp_deprecated vpMatrix inverseByLUGsl() const
848  {
849 #if defined(VISP_HAVE_LAPACK)
850  return inverseByLULapack();
851 #else
852  throw(vpException(vpException::fatalError, "Undefined inverseByLULapack(). Install Lapack 3rd party"));
853 #endif
854  }
855 
859  vpMatrix inverseByCholeskyGsl() const
860  {
861 #if defined(VISP_HAVE_LAPACK)
862  return inverseByCholeskyLapack();
863 #else
864  throw(vpException(vpException::fatalError, "Undefined inverseByCholeskyLapack(). Install Lapack 3rd party"));
865 #endif
866  }
867 
871  vpMatrix inverseByQRGsl() const
872  {
873 #if defined(VISP_HAVE_LAPACK)
874  return inverseByQRLapack();
875 #else
876  throw(vpException(vpException::fatalError, "Undefined inverseByQRLapack(). Install Lapack 3rd party"));
877 #endif
878  }
879 
883  vpMatrix pseudoInverseGsl(double svThreshold = 1e-6) const
884  {
885 #if defined(VISP_HAVE_LAPACK)
886  return pseudoInverseLapack(svThreshold);
887 #else
888  (void)svThreshold;
889  throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
890 #endif
891  }
892 
896  unsigned int pseudoInverseGsl(vpMatrix &Ap, double svThreshold = 1e-6) const
897  {
898 #if defined(VISP_HAVE_LAPACK)
899  return pseudoInverseLapack(Ap, svThreshold);
900 #else
901  (void)Ap;
902  (void)svThreshold;
903  throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
904 #endif
905  }
906 
910  unsigned int pseudoInverseGsl(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const
911  {
912 #if defined(VISP_HAVE_LAPACK)
913  return pseudoInverseLapack(Ap, sv, svThreshold);
914 #else
915  (void)Ap;
916  (void)sv;
917  (void)svThreshold;
918  throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
919 #endif
920  }
921 
925  unsigned int pseudoInverseGsl(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt,
926  vpMatrix &kerAt) const
927  {
928 #if defined(VISP_HAVE_LAPACK)
929  return pseudoInverseLapack(Ap, sv, svThreshold, imA, imAt, kerAt);
930 #else
931  (void)Ap;
932  (void)sv;
933  (void)svThreshold;
934  (void)imA;
935  (void)imAt;
936  (void)kerAt;
937  throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
938 #endif
939  }
940 
944  void svdGsl(vpColVector &w, vpMatrix &V)
945  {
946 #if defined(VISP_HAVE_LAPACK)
947  svdLapack(w, V);
948 #else
949  (void)w;
950  (void)V;
951  throw(vpException(vpException::fatalError, "Undefined svdLapack(). Install Lapack 3rd party"));
952 #endif
953  }
954 
955 #endif // ifndef DOXYGEN_SHOULD_SKIP_THIS
957 #endif
958 
959 private:
960  static unsigned int m_lapack_min_size;
961  static const unsigned int m_lapack_min_size_default;
962 
963 #if defined(VISP_HAVE_LAPACK)
964  static void blas_dgemm(char trans_a, char trans_b, unsigned int M_, unsigned int N_, unsigned int K_, double alpha,
965  double *a_data, unsigned int lda_, double *b_data, unsigned int ldb_, double beta,
966  double *c_data, unsigned int ldc_);
967  static void blas_dgemv(char trans, unsigned int M_, unsigned int N_, double alpha, double *a_data, unsigned int lda_,
968  double *x_data, int incx_, double beta, double *y_data, int incy_);
969  static void blas_dsyev(char jobz, char uplo, unsigned int n_, double *a_data, unsigned int lda_, double *w_data,
970  double *work_data, int lwork_, int &info_);
971 #endif
972 
973  static void computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS, const vpMatrix &Ls,
974  vpMatrix &Js, vpColVector &deltaP);
975 };
976 
978 #if defined(VISP_USE_MSVC) && defined(visp_EXPORTS)
979 const __declspec(selectany) unsigned int vpMatrix::m_lapack_min_size_default = 0;
980 __declspec(selectany) unsigned int vpMatrix::m_lapack_min_size = vpMatrix::m_lapack_min_size_default;
981 #endif
982 
983 #ifndef DOXYGEN_SHOULD_SKIP_THIS
984 VISP_EXPORT
985 #endif
986 vpMatrix operator*(const double &x, const vpMatrix &A);
987 #endif
Implementation of a generic 2D array used as base class for matrices and vectors.
Definition: vpArray2D.h:132
static bool load(const std::string &filename, vpArray2D< Type > &A, bool binary=false, char *header=NULL)
Definition: vpArray2D.h:541
unsigned int getCols() const
Definition: vpArray2D.h:281
static bool saveYAML(const std::string &filename, const vpArray2D< Type > &A, const char *header="")
Definition: vpArray2D.h:827
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:494
static bool loadYAML(const std::string &filename, vpArray2D< Type > &A, char *header=NULL)
Definition: vpArray2D.h:652
unsigned int getRows() const
Definition: vpArray2D.h:291
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition: vpArray2D.h:414
vpArray2D< Type > hadamard(const vpArray2D< Type > &m) const
Definition: vpArray2D.h:927
static bool save(const std::string &filename, const vpArray2D< Type > &A, bool binary=false, const char *header="")
Definition: vpArray2D.h:736
Implementation of column vector and the associated operations.
Definition: vpColVector.h:131
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:733
static bool loadMatrix(const std::string &filename, vpArray2D< double > &M, bool binary=false, char *header=NULL)
Definition: vpMatrix.h:717
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:790
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:795
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:785
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:770
static vp_deprecated void stackMatrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
Definition: vpMatrix.h:800
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:752
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)