Visual Servoing Platform  version 3.3.1 under development (2020-09-18)
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  * Authors:
35  * Eric Marchand
36  *
37  *****************************************************************************/
38 
39 #ifndef vpMatrix_H
40 #define vpMatrix_H
41 
42 #include <visp3/core/vpArray2D.h>
43 #include <visp3/core/vpConfig.h>
44 #include <visp3/core/vpException.h>
45 #include <visp3/core/vpForceTwistMatrix.h>
46 #include <visp3/core/vpHomogeneousMatrix.h>
47 #include <visp3/core/vpRotationMatrix.h>
48 #include <visp3/core/vpTime.h>
49 #include <visp3/core/vpVelocityTwistMatrix.h>
50 
51 #include <iostream>
52 #include <math.h>
53 
54 class vpRowVector;
55 class vpColVector;
59 class vpForceTwistMatrix;
60 
156 class VISP_EXPORT vpMatrix : public vpArray2D<double>
157 {
158 public:
163  typedef enum {
164  LU_DECOMPOSITION
165  } vpDetMethod;
166 
167 public:
172  vpMatrix() : vpArray2D<double>(0, 0) {}
173 
180  vpMatrix(unsigned int r, unsigned int c) : vpArray2D<double>(r, c) {}
181 
189  vpMatrix(unsigned int r, unsigned int c, double val) : vpArray2D<double>(r, c, val) {}
190  vpMatrix(const vpMatrix &M, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols);
191 
204  vpMatrix(const vpArray2D<double> &A) : vpArray2D<double>(A) {}
205 
206  vpMatrix(const vpMatrix &A) : vpArray2D<double>(A) {}
207 
208 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
209  vpMatrix(vpMatrix &&A);
210  explicit vpMatrix(const std::initializer_list<double> &list);
211  explicit vpMatrix(unsigned int nrows, unsigned int ncols, const std::initializer_list<double> &list);
212  explicit vpMatrix(const std::initializer_list<std::initializer_list<double> > &lists);
213 #endif
214 
216  virtual ~vpMatrix() {}
217 
222  void clear()
223  {
224  if (data != NULL) {
225  free(data);
226  data = NULL;
227  }
228 
229  if (rowPtrs != NULL) {
230  free(rowPtrs);
231  rowPtrs = NULL;
232  }
233  rowNum = colNum = dsize = 0;
234  }
235 
236  //-------------------------------------------------
237  // Setting a diagonal matrix
238  //-------------------------------------------------
249  static unsigned int getLapackMatrixMinSize() {
250  return m_lapack_min_size;
251  }
252 
265  static void setLapackMatrixMinSize(unsigned int min_size) {
266  m_lapack_min_size = min_size;
267  }
269 
270  //-------------------------------------------------
271  // Setting a diagonal matrix
272  //-------------------------------------------------
275  void diag(const double &val = 1.0);
276  void diag(const vpColVector &A);
277  // Initialize an identity matrix n-by-n
278  void eye();
279  void eye(unsigned int n);
280  // Initialize an identity matrix m-by-n
281  void eye(unsigned int m, unsigned int n);
283 
284  //---------------------------------
285  // Assignment
286  //---------------------------------
289  vpMatrix &operator<<(double *);
290  vpMatrix& operator<<(double val);
291  vpMatrix& operator,(double val);
293 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
294  vpMatrix &operator=(const vpMatrix &A);
296 
297  vpMatrix& operator=(const std::initializer_list<double> &list);
298  vpMatrix& operator=(const std::initializer_list<std::initializer_list<double> > &lists);
299 #endif
300  vpMatrix &operator=(double x);
302 
303  //-------------------------------------------------
304  // Stacking
305  //-------------------------------------------------
308  // Stack the matrix A below the current one, copy if not initialized this =
309  // [ this A ]^T
310  void stack(const vpMatrix &A);
311  void stack(const vpRowVector &r);
312  void stack(const vpColVector &c);
313  // Stacks columns of a matrix in a vector
314  void stackColumns(vpColVector &out);
315 
316  // Stacks columns of a matrix in a vector
317  vpColVector stackColumns();
318 
319  // Stacks columns of a matrix in a vector
320  void stackRows(vpRowVector &out);
321 
322  // Stacks columns of a matrix in a vector
323  vpRowVector stackRows();
325 
326  //---------------------------------
327  // Matrix insertion
328  //---------------------------------
331  // Insert matrix A in the current matrix at the given position (r, c).
332  void insert(const vpMatrix &A, unsigned int r, unsigned int c);
334 
335  //-------------------------------------------------
336  // Columns, Rows, Diag extraction, SubMatrix
337  //-------------------------------------------------
340  vpMatrix extract(unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols) const;
341  vpColVector getCol(unsigned int j) const;
342  vpColVector getCol(unsigned int j, unsigned int i_begin, unsigned int size) const;
343  vpRowVector getRow(unsigned int i) const;
344  vpRowVector getRow(unsigned int i, unsigned int j_begin, unsigned int size) const;
345  vpColVector getDiag() const;
346  void init(const vpMatrix &M, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols);
348 
349  //---------------------------------
350  // Matrix operations.
351  //---------------------------------
354  // return the determinant of the matrix.
355  double det(vpDetMethod method = LU_DECOMPOSITION) const;
356  double detByLU() const;
357 #ifdef VISP_HAVE_EIGEN3
358  double detByLUEigen3() const;
359 #endif
360 #if defined(VISP_HAVE_LAPACK)
361  double detByLULapack() const;
362 #endif
363 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
364  double detByLUOpenCV() const;
365 #endif
366 
367  // Compute the exponential matrix of a square matrix
368  vpMatrix expm() const;
369 
370  // operation A = A + B
371  vpMatrix &operator+=(const vpMatrix &B);
372  // operation A = A - B
373  vpMatrix &operator-=(const vpMatrix &B);
374  vpMatrix operator*(const vpMatrix &B) const;
375  vpMatrix operator*(const vpRotationMatrix &R) const;
376  vpMatrix operator*(const vpHomogeneousMatrix &R) const;
377  vpMatrix operator*(const vpVelocityTwistMatrix &V) const;
378  vpMatrix operator*(const vpForceTwistMatrix &V) const;
379  // operation t_out = A * t (A is unchanged, t and t_out are translation
380  // vectors)
381  vpTranslationVector operator*(const vpTranslationVector &tv) const;
382  vpColVector operator*(const vpColVector &v) const;
383  vpMatrix operator+(const vpMatrix &B) const;
384  vpMatrix operator-(const vpMatrix &B) const;
385  vpMatrix operator-() const;
386 
388  vpMatrix &operator+=(double x);
390  vpMatrix &operator-=(double x);
392  vpMatrix &operator*=(double x);
394  vpMatrix &operator/=(double x);
395 
396  // Cij = Aij * x (A is unchanged)
397  vpMatrix operator*(double x) const;
398  // Cij = Aij / x (A is unchanged)
399  vpMatrix operator/(double x) const;
400 
406  double sum() const;
407  double sumSquare() const;
408 
409  //-------------------------------------------------
410  // Hadamard product
411  //-------------------------------------------------
413  vpMatrix hadamard(const vpMatrix &m) const;
414 
415  //-------------------------------------------------
416  // Kronecker product
417  //-------------------------------------------------
420  // Compute Kronecker product matrix
421  void kron(const vpMatrix &m1, vpMatrix &out) const;
422 
423  // Compute Kronecker product matrix
424  vpMatrix kron(const vpMatrix &m1) const;
426 
427  //-------------------------------------------------
428  // Transpose
429  //-------------------------------------------------
432  // Compute the transpose C = A^T
433  vpMatrix t() const;
434 
435  // Compute the transpose C = A^T
436  vpMatrix transpose() const;
437  void transpose(vpMatrix &At) const;
438 
439  vpMatrix AAt() const;
440  void AAt(vpMatrix &B) const;
441 
442  vpMatrix AtA() const;
443  void AtA(vpMatrix &B) const;
445 
446  //-------------------------------------------------
447  // Matrix inversion
448  //-------------------------------------------------
451  // inverse matrix A using the LU decomposition
452  vpMatrix inverseByLU() const;
453 
454 #if defined(VISP_HAVE_EIGEN3)
455  vpMatrix inverseByLUEigen3() const;
456 #endif
457 #if defined(VISP_HAVE_LAPACK)
458  vpMatrix inverseByLULapack() const;
459 #endif
460 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
461  vpMatrix inverseByLUOpenCV() const;
462 #endif
463 
464  // inverse matrix A using the Cholesky decomposition (only for real
465  // symmetric matrices)
466  vpMatrix inverseByCholesky() const;
467 
468 #if defined(VISP_HAVE_LAPACK)
469  vpMatrix inverseByCholeskyLapack() const;
470 #endif
471 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
472  vpMatrix inverseByCholeskyOpenCV() const;
473 #endif
474 
475  // inverse matrix A using the QR decomposition
476  vpMatrix inverseByQR() const;
477 #if defined(VISP_HAVE_LAPACK)
478  vpMatrix inverseByQRLapack() const;
479 #endif
480 
481  // inverse triangular matrix
482  vpMatrix inverseTriangular(bool upper = true) const;
483 
484  vpMatrix pseudoInverse(double svThreshold = 1e-6) const;
485  unsigned int pseudoInverse(vpMatrix &Ap, double svThreshold = 1e-6) const;
486  unsigned int pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
487  unsigned int pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt) const;
488  unsigned int pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt,
489  vpMatrix &kerAt) const;
490 
491 #if defined(VISP_HAVE_LAPACK)
492  vpMatrix pseudoInverseLapack(double svThreshold = 1e-6) const;
493  unsigned int pseudoInverseLapack(vpMatrix &Ap, double svThreshold = 1e-6) const;
494  unsigned int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
495  unsigned int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt,
496  vpMatrix &kerAt) const;
497 #endif
498 #if defined(VISP_HAVE_EIGEN3)
499  vpMatrix pseudoInverseEigen3(double svThreshold = 1e-6) const;
500  unsigned int pseudoInverseEigen3(vpMatrix &Ap, double svThreshold = 1e-6) const;
501  unsigned int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
502  unsigned int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt,
503  vpMatrix &kerAt) const;
504 #endif
505 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
506  vpMatrix pseudoInverseOpenCV(double svThreshold = 1e-6) const;
507  unsigned int pseudoInverseOpenCV(vpMatrix &Ap, double svThreshold = 1e-6) const;
508  unsigned int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
509  unsigned int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt,
510  vpMatrix &kerAt) const;
511 #endif
512 
513 
514  //-------------------------------------------------
515  // SVD decomposition
516  //-------------------------------------------------
517 
520  double cond(double svThreshold = 1e-6) const;
521  unsigned int kernel(vpMatrix &kerAt, double svThreshold = 1e-6) const;
522 
523  // solve Ax=B using the SVD decomposition (usage A = solveBySVD(B,x) )
524  void solveBySVD(const vpColVector &B, vpColVector &x) const;
525  // solve Ax=B using the SVD decomposition (usage x=A.solveBySVD(B))
526  vpColVector solveBySVD(const vpColVector &B) const;
527 
528  // singular value decomposition SVD
529  void svd(vpColVector &w, vpMatrix &V);
530 #ifdef VISP_HAVE_EIGEN3
531  void svdEigen3(vpColVector &w, vpMatrix &V);
532 #endif
533 #if defined(VISP_HAVE_LAPACK)
534  void svdLapack(vpColVector &w, vpMatrix &V);
535 #endif
536 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1
537  void svdOpenCV(vpColVector &w, vpMatrix &V);
538 #endif
539 
540 
541  //-------------------------------------------------
542  // QR decomposition
543  //-------------------------------------------------
544 
547  unsigned int qr(vpMatrix &Q, vpMatrix &R, bool full = false, bool squareR = false, double tol = 1e-6) const;
548  unsigned int qrPivot(vpMatrix &Q, vpMatrix &R, vpMatrix &P, bool full = false, bool squareR = false, double tol = 1e-6) const;
549  void solveByQR(const vpColVector &b, vpColVector &x) const;
550  vpColVector solveByQR(const vpColVector &b) const;
552 
553  //-------------------------------------------------
554  // Eigen values and vectors
555  //-------------------------------------------------
559  // compute the eigen values using Lapack
560  vpColVector eigenValues() const;
561  void eigenValues(vpColVector &evalue, vpMatrix &evector) const;
563 
564  //-------------------------------------------------
565  // Norms
566  //-------------------------------------------------
569  double euclideanNorm() const;
570  double frobeniusNorm() const;
571  double inducedL2Norm() const;
572  double infinityNorm() const;
574 
575  //---------------------------------
576  // Printing
577  //---------------------------------
580  std::ostream &cppPrint(std::ostream &os, const std::string &matrixName = "A", bool octet = false) const;
581  std::ostream &csvPrint(std::ostream &os) const;
582  std::ostream &maplePrint(std::ostream &os) const;
583  std::ostream &matlabPrint(std::ostream &os) const;
584  int print(std::ostream &s, unsigned int length, const std::string &intro = "") const;
585  void printSize() const { std::cout << getRows() << " x " << getCols() << " "; }
587 
588  //------------------------------------------------------------------
589  // Static functionalities
590  //------------------------------------------------------------------
591 
592  //---------------------------------
593  // Setting a diagonal matrix with Static Public Member Functions
594  //---------------------------------
597  // Create a diagonal matrix with the element of a vector DAii = Ai
598  static void createDiagonalMatrix(const vpColVector &A, vpMatrix &DA);
600 
601  //---------------------------------
602  // Matrix insertion with Static Public Member Functions
603  //---------------------------------
606  // Insert matrix B in matrix A at the given position (r, c).
607  static vpMatrix insert(const vpMatrix &A, const vpMatrix &B, unsigned int r, unsigned int c);
608  // Insert matrix B in matrix A (not modified) at the given position (r, c),
609  // the result is given in matrix C.
610  static void insert(const vpMatrix &A, const vpMatrix &B, vpMatrix &C, unsigned int r, unsigned int c);
611 
612  //---------------------------------
613  // Stacking with Static Public Member Functions
614  //---------------------------------
617  // Juxtapose to matrices C = [ A B ]
618  static vpMatrix juxtaposeMatrices(const vpMatrix &A, const vpMatrix &B);
619  // Juxtapose to matrices C = [ A B ]
620  static void juxtaposeMatrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
621  // Stack two matrices C = [ A B ]^T
622  static vpMatrix stack(const vpMatrix &A, const vpMatrix &B);
623  static vpMatrix stack(const vpMatrix &A, const vpRowVector &r);
624  static vpMatrix stack(const vpMatrix &A, const vpColVector &c);
625 
626  // Stack two matrices C = [ A B ]^T
627  static void stack(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
628  static void stack(const vpMatrix &A, const vpRowVector &r, vpMatrix &C);
629  static void stack(const vpMatrix &A, const vpColVector &c, vpMatrix &C);
631 
632  //---------------------------------
633  // Matrix operations Static Public Member Functions
634  //---------------------------------
637  static void add2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
638  static void add2Matrices(const vpColVector &A, const vpColVector &B, vpColVector &C);
639  static void add2WeightedMatrices(const vpMatrix &A, const double &wA, const vpMatrix &B, const double &wB,
640  vpMatrix &C);
641  static void computeHLM(const vpMatrix &H, const double &alpha, vpMatrix &HLM);
642  static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
643  static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpRotationMatrix &C);
644  static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpHomogeneousMatrix &C);
645  static void mult2Matrices(const vpMatrix &A, const vpColVector &B, vpColVector &C);
646  static void multMatrixVector(const vpMatrix &A, const vpColVector &v, vpColVector &w);
647  static void negateMatrix(const vpMatrix &A, vpMatrix &C);
648  static void sub2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
649  static void sub2Matrices(const vpColVector &A, const vpColVector &B, vpColVector &C);
651 
652  //---------------------------------
653  // Kronecker product Static Public Member Functions
654  //---------------------------------
657  // Compute Kronecker product matrix
658  static void kron(const vpMatrix &m1, const vpMatrix &m2, vpMatrix &out);
659 
660  // Compute Kronecker product matrix
661  static vpMatrix kron(const vpMatrix &m1, const vpMatrix &m2);
663 
664  //-------------------------------------------------
665  // 2D Convolution Static Public Member Functions
666  //-------------------------------------------------
668  static vpMatrix conv2(const vpMatrix &M, const vpMatrix &kernel, const std::string &mode="full");
669  static void conv2(const vpMatrix &M, const vpMatrix &kernel, vpMatrix &res, const std::string &mode="full");
670 
671  //---------------------------------
672  // Covariance computation Static Public Member Functions
673  //---------------------------------
676  static vpMatrix computeCovarianceMatrix(const vpMatrix &A, const vpColVector &x, const vpColVector &b);
677  static vpMatrix computeCovarianceMatrix(const vpMatrix &A, const vpColVector &x, const vpColVector &b,
678  const vpMatrix &w);
679  static vpMatrix computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS,
680  const vpMatrix &Ls, const vpMatrix &W);
681  static vpMatrix computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS,
682  const vpMatrix &Ls);
684 
685  //---------------------------------
686  // Matrix I/O Static Public Member Functions
687  //---------------------------------
701  static inline bool loadMatrix(const std::string &filename, vpArray2D<double> &M, bool binary = false,
702  char *header = NULL)
703  {
704  return vpArray2D<double>::load(filename, M, binary, header);
705  }
706 
717  static inline bool loadMatrixYAML(const std::string &filename, vpArray2D<double> &M, char *header = NULL)
718  {
719  return vpArray2D<double>::loadYAML(filename, M, header);
720  }
721 
736  static inline bool saveMatrix(const std::string &filename, const vpArray2D<double> &M, bool binary = false,
737  const char *header = "")
738  {
739  return vpArray2D<double>::save(filename, M, binary, header);
740  }
741 
754  static inline bool saveMatrixYAML(const std::string &filename, const vpArray2D<double> &M, const char *header = "")
755  {
756  return vpArray2D<double>::saveYAML(filename, M, header);
757  }
759 
760 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
761 
769  vp_deprecated void init() {}
770 
774  vp_deprecated void stackMatrices(const vpMatrix &A) { stack(A); }
779  vp_deprecated static vpMatrix stackMatrices(const vpMatrix &A, const vpMatrix &B) { return stack(A, B); }
784  vp_deprecated static void stackMatrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C) { stack(A, B, C); }
789  vp_deprecated static vpMatrix stackMatrices(const vpMatrix &A, const vpRowVector &B);
794  vp_deprecated static void stackMatrices(const vpMatrix &A, const vpRowVector &B, vpMatrix &C);
799  vp_deprecated static vpMatrix stackMatrices(const vpColVector &A, const vpColVector &B);
804  vp_deprecated static void stackMatrices(const vpColVector &A, const vpColVector &B, vpColVector &C);
805 
809  vp_deprecated void setIdentity(const double &val = 1.0);
810 
811  vp_deprecated vpRowVector row(unsigned int i);
812  vp_deprecated vpColVector column(unsigned int j);
813 
814  // Deprecated functions using GSL
815 #ifndef DOXYGEN_SHOULD_SKIP_THIS
816 
819  vp_deprecated double detByLUGsl() const {
820 #if defined(VISP_HAVE_LAPACK)
821  return detByLULapack();
822 #else
824  "Undefined detByLULapack(). Install Lapack 3rd party"));
825 #endif
826  }
827 
831  vp_deprecated vpMatrix inverseByLUGsl() const {
832 #if defined(VISP_HAVE_LAPACK)
833  return inverseByLULapack();
834 #else
836  "Undefined inverseByLULapack(). Install Lapack 3rd party"));
837 #endif
838  }
839 
843  vpMatrix inverseByCholeskyGsl() const {
844 #if defined(VISP_HAVE_LAPACK)
845  return inverseByCholeskyLapack();
846 #else
848  "Undefined inverseByCholeskyLapack(). Install Lapack 3rd party"));
849 #endif
850  }
851 
855  vpMatrix inverseByQRGsl() const {
856 #if defined(VISP_HAVE_LAPACK)
857  return inverseByQRLapack();
858 #else
860  "Undefined inverseByQRLapack(). Install Lapack 3rd party"));
861 #endif
862  }
863 
867  vpMatrix pseudoInverseGsl(double svThreshold = 1e-6) const {
868 #if defined(VISP_HAVE_LAPACK)
869  return pseudoInverseLapack(svThreshold);
870 #else
871  (void)svThreshold;
873  "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
874 #endif
875  }
876 
880  unsigned int pseudoInverseGsl(vpMatrix &Ap, double svThreshold = 1e-6) const {
881 #if defined(VISP_HAVE_LAPACK)
882  return pseudoInverseLapack(Ap, svThreshold);
883 #else
884  (void)Ap;
885  (void)svThreshold;
887  "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
888 #endif
889  }
890 
894  unsigned int pseudoInverseGsl(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const {
895 #if defined(VISP_HAVE_LAPACK)
896  return pseudoInverseLapack(Ap, sv, svThreshold);
897 #else
898  (void)Ap;
899  (void)sv;
900  (void)svThreshold;
902  "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
903 #endif
904  }
905 
909  unsigned int pseudoInverseGsl(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt,
910  vpMatrix &kerAt) const {
911 #if defined(VISP_HAVE_LAPACK)
912  return pseudoInverseLapack(Ap, sv, svThreshold, imA, imAt, kerAt);
913 #else
914  (void)Ap;
915  (void)sv;
916  (void)svThreshold;
917  (void)imA;
918  (void)imAt;
919  (void)kerAt;
921  "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
922 #endif
923  }
924 
928  void svdGsl(vpColVector &w, vpMatrix &V) {
929 #if defined(VISP_HAVE_LAPACK)
930  svdLapack(w, V);
931 #else
932  (void)w;
933  (void)V;
935  "Undefined svdLapack(). Install Lapack 3rd party"));
936 #endif
937  }
938 
939 #endif // ifndef DOXYGEN_SHOULD_SKIP_THIS
940 
941 #endif
942 
943 private:
944  static unsigned int m_lapack_min_size;
945  static const unsigned int m_lapack_min_size_default;
946 
947 #if defined(VISP_HAVE_LAPACK)
948  static void blas_dgemm(char trans_a, char trans_b, unsigned int M_, unsigned int N_, unsigned int K_, double alpha,
949  double *a_data, unsigned int lda_, double *b_data, unsigned int ldb_, double beta, double *c_data,
950  unsigned int ldc_);
951  static void blas_dgemv(char trans, unsigned int M_, unsigned int N_, double alpha, double *a_data, unsigned int lda_,
952  double *x_data, int incx_, double beta, double *y_data, int incy_);
953  static void blas_dsyev(char jobz, char uplo, unsigned int n_, double *a_data, unsigned int lda_,
954  double *w_data, double *work_data, int lwork_, int &info_);
955 #endif
956 
957  static void computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS, const vpMatrix &Ls,
958  vpMatrix &Js, vpColVector &deltaP);
959 };
960 
962 #if defined(VISP_USE_MSVC) && defined(visp_EXPORTS)
963 const __declspec(selectany) unsigned int vpMatrix::m_lapack_min_size_default = 0;
964 __declspec(selectany) unsigned int vpMatrix::m_lapack_min_size = vpMatrix::m_lapack_min_size_default;
965 #endif
966 
967 #ifndef DOXYGEN_SHOULD_SKIP_THIS
968 VISP_EXPORT
969 #endif
970 vpMatrix operator*(const double &x, const vpMatrix &A);
971 #endif
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:156
static bool saveYAML(const std::string &filename, const vpArray2D< Type > &A, const char *header="")
Definition: vpArray2D.h:831
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition: vpArray2D.h:414
static bool loadYAML(const std::string &filename, vpArray2D< Type > &A, char *header=NULL)
Definition: vpArray2D.h:653
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of row vector and the associated operations.
Definition: vpRowVector.h:115
static bool save(const std::string &filename, const vpArray2D< Type > &A, bool binary=false, const char *header="")
Definition: vpArray2D.h:738
error that can be emited by ViSP classes.
Definition: vpException.h:71
unsigned int getRows() const
Definition: vpArray2D.h:289
vp_deprecated void stackMatrices(const vpMatrix &A)
Definition: vpMatrix.h:774
Implementation of a generic 2D array used as base class for matrices and vectors. ...
Definition: vpArray2D.h:131
static bool saveMatrix(const std::string &filename, const vpArray2D< double > &M, bool binary=false, const char *header="")
Definition: vpMatrix.h:736
vpMatrix(unsigned int r, unsigned int c, double val)
Definition: vpMatrix.h:189
vpMatrix()
Definition: vpMatrix.h:172
Implementation of a rotation matrix and operations on such kind of matrices.
unsigned int getCols() const
Definition: vpArray2D.h:279
static unsigned int getLapackMatrixMinSize()
Definition: vpMatrix.h:249
vpColVector operator*(const double &x, const vpColVector &v)
static vp_deprecated void stackMatrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
Definition: vpMatrix.h:784
vpMatrix(const vpMatrix &A)
Definition: vpMatrix.h:206
vp_deprecated void init()
Definition: vpMatrix.h:769
void clear()
Definition: vpMatrix.h:222
vpArray2D< Type > hadamard(const vpArray2D< Type > &m) const
Definition: vpArray2D.h:933
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:494
static void setLapackMatrixMinSize(unsigned int min_size)
Definition: vpMatrix.h:265
static vp_deprecated vpMatrix stackMatrices(const vpMatrix &A, const vpMatrix &B)
Definition: vpMatrix.h:779
vpMatrix(unsigned int r, unsigned int c)
Definition: vpMatrix.h:180
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
virtual ~vpMatrix()
Destructor (Memory de-allocation)
Definition: vpMatrix.h:216
void printSize() const
Definition: vpMatrix.h:585
static bool saveMatrixYAML(const std::string &filename, const vpArray2D< double > &M, const char *header="")
Definition: vpMatrix.h:754
vpMatrix(const vpArray2D< double > &A)
Definition: vpMatrix.h:204
Class that consider the case of a translation vector.
static bool loadMatrix(const std::string &filename, vpArray2D< double > &M, bool binary=false, char *header=NULL)
Definition: vpMatrix.h:701
static bool load(const std::string &filename, vpArray2D< Type > &A, bool binary=false, char *header=NULL)
Definition: vpArray2D.h:541
static bool loadMatrixYAML(const std::string &filename, vpArray2D< double > &M, char *header=NULL)
Definition: vpMatrix.h:717