Visual Servoing Platform  version 3.3.1 under development (2020-12-02)
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, vpMatrix &kerAt) const;
489  vpMatrix pseudoInverse(int rank_in) const;
490  int pseudoInverse(vpMatrix &Ap, int rank_in) const;
491  int pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
492  int pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt) const;
493  int pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
494 
495 #if defined(VISP_HAVE_LAPACK)
496  vpMatrix pseudoInverseLapack(double svThreshold = 1e-6) const;
497  unsigned int pseudoInverseLapack(vpMatrix &Ap, double svThreshold = 1e-6) const;
498  unsigned int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
499  unsigned int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
500  vpMatrix pseudoInverseLapack(int rank_in) const;
501  int pseudoInverseLapack(vpMatrix &Ap, int rank_in) const;
502  int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
503  int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
504 #endif
505 #if defined(VISP_HAVE_EIGEN3)
506  vpMatrix pseudoInverseEigen3(double svThreshold = 1e-6) const;
507  unsigned int pseudoInverseEigen3(vpMatrix &Ap, double svThreshold = 1e-6) const;
508  unsigned int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
509  unsigned int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
510  vpMatrix pseudoInverseEigen3(int rank_in) const;
511  int pseudoInverseEigen3(vpMatrix &Ap, int rank_in) const;
512  int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
513  int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
514 #endif
515 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
516  vpMatrix pseudoInverseOpenCV(double svThreshold = 1e-6) const;
517  unsigned int pseudoInverseOpenCV(vpMatrix &Ap, double svThreshold = 1e-6) const;
518  unsigned int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
519  unsigned int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
520  vpMatrix pseudoInverseOpenCV(int rank_in) const;
521  int pseudoInverseOpenCV(vpMatrix &Ap, int rank_in) const;
522  int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
523  int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
524 #endif
525 
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 
536  // solve Ax=B using the SVD decomposition (usage A = solveBySVD(B,x) )
537  void solveBySVD(const vpColVector &B, vpColVector &x) const;
538  // solve Ax=B using the SVD decomposition (usage x=A.solveBySVD(B))
539  vpColVector solveBySVD(const vpColVector &B) const;
540 
541  // singular value decomposition SVD
542  void svd(vpColVector &w, vpMatrix &V);
543 #ifdef VISP_HAVE_EIGEN3
544  void svdEigen3(vpColVector &w, vpMatrix &V);
545 #endif
546 #if defined(VISP_HAVE_LAPACK)
547  void svdLapack(vpColVector &w, vpMatrix &V);
548 #endif
549 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1
550  void svdOpenCV(vpColVector &w, vpMatrix &V);
551 #endif
552 
553 
554  //-------------------------------------------------
555  // QR decomposition
556  //-------------------------------------------------
557 
560  unsigned int qr(vpMatrix &Q, vpMatrix &R, bool full = false, bool squareR = false, double tol = 1e-6) const;
561  unsigned int qrPivot(vpMatrix &Q, vpMatrix &R, vpMatrix &P, bool full = false, bool squareR = false, double tol = 1e-6) const;
562  void solveByQR(const vpColVector &b, vpColVector &x) const;
563  vpColVector solveByQR(const vpColVector &b) const;
565 
566  //-------------------------------------------------
567  // Eigen values and vectors
568  //-------------------------------------------------
572  // compute the eigen values using Lapack
573  vpColVector eigenValues() const;
574  void eigenValues(vpColVector &evalue, vpMatrix &evector) const;
576 
577  //-------------------------------------------------
578  // Norms
579  //-------------------------------------------------
582  double euclideanNorm() const;
583  double frobeniusNorm() const;
584  double inducedL2Norm() const;
585  double infinityNorm() const;
587 
588  //---------------------------------
589  // Printing
590  //---------------------------------
593  std::ostream &cppPrint(std::ostream &os, const std::string &matrixName = "A", bool octet = false) const;
594  std::ostream &csvPrint(std::ostream &os) const;
595  std::ostream &maplePrint(std::ostream &os) const;
596  std::ostream &matlabPrint(std::ostream &os) const;
597  int print(std::ostream &s, unsigned int length, const std::string &intro = "") const;
598  void printSize() const { std::cout << getRows() << " x " << getCols() << " "; }
600 
601  //------------------------------------------------------------------
602  // Static functionalities
603  //------------------------------------------------------------------
604 
605  //---------------------------------
606  // Setting a diagonal matrix with Static Public Member Functions
607  //---------------------------------
610  // Create a diagonal matrix with the element of a vector DAii = Ai
611  static void createDiagonalMatrix(const vpColVector &A, vpMatrix &DA);
613 
614  //---------------------------------
615  // Matrix insertion with Static Public Member Functions
616  //---------------------------------
619  // Insert matrix B in matrix A at the given position (r, c).
620  static vpMatrix insert(const vpMatrix &A, const vpMatrix &B, unsigned int r, unsigned int c);
621  // Insert matrix B in matrix A (not modified) at the given position (r, c),
622  // the result is given in matrix C.
623  static void insert(const vpMatrix &A, const vpMatrix &B, vpMatrix &C, unsigned int r, unsigned int c);
624 
625  //---------------------------------
626  // Stacking with Static Public Member Functions
627  //---------------------------------
630  // Juxtapose to matrices C = [ A B ]
631  static vpMatrix juxtaposeMatrices(const vpMatrix &A, const vpMatrix &B);
632  // Juxtapose to matrices C = [ A B ]
633  static void juxtaposeMatrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
634  // Stack two matrices C = [ A B ]^T
635  static vpMatrix stack(const vpMatrix &A, const vpMatrix &B);
636  static vpMatrix stack(const vpMatrix &A, const vpRowVector &r);
637  static vpMatrix stack(const vpMatrix &A, const vpColVector &c);
638 
639  // Stack two matrices C = [ A B ]^T
640  static void stack(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
641  static void stack(const vpMatrix &A, const vpRowVector &r, vpMatrix &C);
642  static void stack(const vpMatrix &A, const vpColVector &c, vpMatrix &C);
644 
645  //---------------------------------
646  // Matrix operations Static Public Member Functions
647  //---------------------------------
650  static void add2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
651  static void add2Matrices(const vpColVector &A, const vpColVector &B, vpColVector &C);
652  static void add2WeightedMatrices(const vpMatrix &A, const double &wA, const vpMatrix &B, const double &wB,
653  vpMatrix &C);
654  static void computeHLM(const vpMatrix &H, const double &alpha, vpMatrix &HLM);
655  static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
656  static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpRotationMatrix &C);
657  static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpHomogeneousMatrix &C);
658  static void mult2Matrices(const vpMatrix &A, const vpColVector &B, vpColVector &C);
659  static void multMatrixVector(const vpMatrix &A, const vpColVector &v, vpColVector &w);
660  static void negateMatrix(const vpMatrix &A, vpMatrix &C);
661  static void sub2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
662  static void sub2Matrices(const vpColVector &A, const vpColVector &B, vpColVector &C);
664 
665  //---------------------------------
666  // Kronecker product Static Public Member Functions
667  //---------------------------------
670  // Compute Kronecker product matrix
671  static void kron(const vpMatrix &m1, const vpMatrix &m2, vpMatrix &out);
672 
673  // Compute Kronecker product matrix
674  static vpMatrix kron(const vpMatrix &m1, const vpMatrix &m2);
676 
677  //-------------------------------------------------
678  // 2D Convolution Static Public Member Functions
679  //-------------------------------------------------
681  static vpMatrix conv2(const vpMatrix &M, const vpMatrix &kernel, const std::string &mode="full");
682  static void conv2(const vpMatrix &M, const vpMatrix &kernel, vpMatrix &res, const std::string &mode="full");
683 
684  //---------------------------------
685  // Covariance computation Static Public Member Functions
686  //---------------------------------
689  static vpMatrix computeCovarianceMatrix(const vpMatrix &A, const vpColVector &x, const vpColVector &b);
690  static vpMatrix computeCovarianceMatrix(const vpMatrix &A, const vpColVector &x, const vpColVector &b,
691  const vpMatrix &w);
692  static vpMatrix computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS,
693  const vpMatrix &Ls, const vpMatrix &W);
694  static vpMatrix computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS,
695  const vpMatrix &Ls);
697 
698  //---------------------------------
699  // Matrix I/O Static Public Member Functions
700  //---------------------------------
714  static inline bool loadMatrix(const std::string &filename, vpArray2D<double> &M, bool binary = false,
715  char *header = NULL)
716  {
717  return vpArray2D<double>::load(filename, M, binary, header);
718  }
719 
730  static inline bool loadMatrixYAML(const std::string &filename, vpArray2D<double> &M, char *header = NULL)
731  {
732  return vpArray2D<double>::loadYAML(filename, M, header);
733  }
734 
749  static inline bool saveMatrix(const std::string &filename, const vpArray2D<double> &M, bool binary = false,
750  const char *header = "")
751  {
752  return vpArray2D<double>::save(filename, M, binary, header);
753  }
754 
767  static inline bool saveMatrixYAML(const std::string &filename, const vpArray2D<double> &M, const char *header = "")
768  {
769  return vpArray2D<double>::saveYAML(filename, M, header);
770  }
772 
773 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
774 
782  vp_deprecated void init() {}
783 
787  vp_deprecated void stackMatrices(const vpMatrix &A) { stack(A); }
792  vp_deprecated static vpMatrix stackMatrices(const vpMatrix &A, const vpMatrix &B) { return stack(A, B); }
797  vp_deprecated static void stackMatrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C) { stack(A, B, C); }
802  vp_deprecated static vpMatrix stackMatrices(const vpMatrix &A, const vpRowVector &B);
807  vp_deprecated static void stackMatrices(const vpMatrix &A, const vpRowVector &B, vpMatrix &C);
812  vp_deprecated static vpMatrix stackMatrices(const vpColVector &A, const vpColVector &B);
817  vp_deprecated static void stackMatrices(const vpColVector &A, const vpColVector &B, vpColVector &C);
818 
822  vp_deprecated void setIdentity(const double &val = 1.0);
823 
824  vp_deprecated vpRowVector row(unsigned int i);
825  vp_deprecated vpColVector column(unsigned int j);
826 
827  // Deprecated functions using GSL
828 #ifndef DOXYGEN_SHOULD_SKIP_THIS
829 
832  vp_deprecated double detByLUGsl() const {
833 #if defined(VISP_HAVE_LAPACK)
834  return detByLULapack();
835 #else
837  "Undefined detByLULapack(). Install Lapack 3rd party"));
838 #endif
839  }
840 
844  vp_deprecated vpMatrix inverseByLUGsl() const {
845 #if defined(VISP_HAVE_LAPACK)
846  return inverseByLULapack();
847 #else
849  "Undefined inverseByLULapack(). Install Lapack 3rd party"));
850 #endif
851  }
852 
856  vpMatrix inverseByCholeskyGsl() const {
857 #if defined(VISP_HAVE_LAPACK)
858  return inverseByCholeskyLapack();
859 #else
861  "Undefined inverseByCholeskyLapack(). Install Lapack 3rd party"));
862 #endif
863  }
864 
868  vpMatrix inverseByQRGsl() const {
869 #if defined(VISP_HAVE_LAPACK)
870  return inverseByQRLapack();
871 #else
873  "Undefined inverseByQRLapack(). Install Lapack 3rd party"));
874 #endif
875  }
876 
880  vpMatrix pseudoInverseGsl(double svThreshold = 1e-6) const {
881 #if defined(VISP_HAVE_LAPACK)
882  return pseudoInverseLapack(svThreshold);
883 #else
884  (void)svThreshold;
886  "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
887 #endif
888  }
889 
893  unsigned int pseudoInverseGsl(vpMatrix &Ap, double svThreshold = 1e-6) const {
894 #if defined(VISP_HAVE_LAPACK)
895  return pseudoInverseLapack(Ap, svThreshold);
896 #else
897  (void)Ap;
898  (void)svThreshold;
900  "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
901 #endif
902  }
903 
907  unsigned int pseudoInverseGsl(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const {
908 #if defined(VISP_HAVE_LAPACK)
909  return pseudoInverseLapack(Ap, sv, svThreshold);
910 #else
911  (void)Ap;
912  (void)sv;
913  (void)svThreshold;
915  "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
916 #endif
917  }
918 
922  unsigned int pseudoInverseGsl(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt,
923  vpMatrix &kerAt) const {
924 #if defined(VISP_HAVE_LAPACK)
925  return pseudoInverseLapack(Ap, sv, svThreshold, imA, imAt, kerAt);
926 #else
927  (void)Ap;
928  (void)sv;
929  (void)svThreshold;
930  (void)imA;
931  (void)imAt;
932  (void)kerAt;
934  "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
935 #endif
936  }
937 
941  void svdGsl(vpColVector &w, vpMatrix &V) {
942 #if defined(VISP_HAVE_LAPACK)
943  svdLapack(w, V);
944 #else
945  (void)w;
946  (void)V;
948  "Undefined svdLapack(). Install Lapack 3rd party"));
949 #endif
950  }
951 
952 #endif // ifndef DOXYGEN_SHOULD_SKIP_THIS
953 
954 #endif
955 
956 private:
957  static unsigned int m_lapack_min_size;
958  static const unsigned int m_lapack_min_size_default;
959 
960 #if defined(VISP_HAVE_LAPACK)
961  static void blas_dgemm(char trans_a, char trans_b, unsigned int M_, unsigned int N_, unsigned int K_, double alpha,
962  double *a_data, unsigned int lda_, double *b_data, unsigned int ldb_, double beta, double *c_data,
963  unsigned int ldc_);
964  static void blas_dgemv(char trans, unsigned int M_, unsigned int N_, double alpha, double *a_data, unsigned int lda_,
965  double *x_data, int incx_, double beta, double *y_data, int incy_);
966  static void blas_dsyev(char jobz, char uplo, unsigned int n_, double *a_data, unsigned int lda_,
967  double *w_data, double *work_data, int lwork_, int &info_);
968 #endif
969 
970  static void computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS, const vpMatrix &Ls,
971  vpMatrix &Js, vpColVector &deltaP);
972 };
973 
975 #if defined(VISP_USE_MSVC) && defined(visp_EXPORTS)
976 const __declspec(selectany) unsigned int vpMatrix::m_lapack_min_size_default = 0;
977 __declspec(selectany) unsigned int vpMatrix::m_lapack_min_size = vpMatrix::m_lapack_min_size_default;
978 #endif
979 
980 #ifndef DOXYGEN_SHOULD_SKIP_THIS
981 VISP_EXPORT
982 #endif
983 vpMatrix operator*(const double &x, const vpMatrix &A);
984 #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:830
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition: vpArray2D.h:413
static bool loadYAML(const std::string &filename, vpArray2D< Type > &A, char *header=NULL)
Definition: vpArray2D.h:652
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:737
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:787
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:749
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:797
vpMatrix(const vpMatrix &A)
Definition: vpMatrix.h:206
vp_deprecated void init()
Definition: vpMatrix.h:782
void clear()
Definition: vpMatrix.h:222
vpArray2D< Type > hadamard(const vpArray2D< Type > &m) const
Definition: vpArray2D.h:932
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:493
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:792
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:598
static bool saveMatrixYAML(const std::string &filename, const vpArray2D< double > &M, const char *header="")
Definition: vpMatrix.h:767
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:714
static bool load(const std::string &filename, vpArray2D< Type > &A, bool binary=false, char *header=NULL)
Definition: vpArray2D.h:540
static bool loadMatrixYAML(const std::string &filename, vpArray2D< double > &M, char *header=NULL)
Definition: vpMatrix.h:730