Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
vpMatrix.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Matrix manipulation.
32 */
33
34#ifndef vpMatrix_H
35#define vpMatrix_H
36
37#include <visp3/core/vpArray2D.h>
38#include <visp3/core/vpConfig.h>
39#include <visp3/core/vpException.h>
40#include <visp3/core/vpForceTwistMatrix.h>
41#include <visp3/core/vpHomogeneousMatrix.h>
42#include <visp3/core/vpRotationMatrix.h>
43#include <visp3/core/vpTime.h>
44#include <visp3/core/vpVelocityTwistMatrix.h>
45
46#include <iostream>
47#include <math.h>
48
49class vpRowVector;
50class vpColVector;
55
151class VISP_EXPORT vpMatrix : public vpArray2D<double>
152{
153public:
158 typedef enum
159 {
160 LU_DECOMPOSITION
161 } vpDetMethod;
162
163public:
168 vpMatrix() : vpArray2D<double>(0, 0) { }
169
176 vpMatrix(unsigned int r, unsigned int c) : vpArray2D<double>(r, c) { }
177
185 vpMatrix(unsigned int r, unsigned int c, double val) : vpArray2D<double>(r, c, val) { }
186 vpMatrix(const vpMatrix &M, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols);
187
200 vpMatrix(const vpArray2D<double> &A) : vpArray2D<double>(A) { }
201
202 vpMatrix(const vpMatrix &A) : vpArray2D<double>(A) { }
203
204#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
205 vpMatrix(vpMatrix &&A);
206 explicit vpMatrix(const std::initializer_list<double> &list);
207 explicit vpMatrix(unsigned int nrows, unsigned int ncols, const std::initializer_list<double> &list);
208 explicit vpMatrix(const std::initializer_list<std::initializer_list<double> > &lists);
209#endif
210
212 virtual ~vpMatrix() { }
213
218 void clear()
219 {
220 if (data != NULL) {
221 free(data);
222 data = NULL;
223 }
224
225 if (rowPtrs != NULL) {
226 free(rowPtrs);
227 rowPtrs = NULL;
228 }
229 rowNum = colNum = dsize = 0;
230 }
231
232 //-------------------------------------------------
233 // Setting a diagonal matrix
234 //-------------------------------------------------
245 static unsigned int getLapackMatrixMinSize() { return m_lapack_min_size; }
246
259 static void setLapackMatrixMinSize(unsigned int min_size) { m_lapack_min_size = min_size; }
261
262 //-------------------------------------------------
263 // Setting a diagonal matrix
264 //-------------------------------------------------
267 void diag(const double &val = 1.0);
268 void diag(const vpColVector &A);
269 // Initialize an identity matrix n-by-n
270 void eye();
271 void eye(unsigned int n);
272 // Initialize an identity matrix m-by-n
273 void eye(unsigned int m, unsigned int n);
275
276 //---------------------------------
277 // Assignment
278 //---------------------------------
281 vpMatrix &operator<<(double *);
282 vpMatrix &operator<<(double val);
283 vpMatrix &operator,(double val);
285#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
286 vpMatrix &operator=(const vpMatrix &A);
288
289 vpMatrix &operator=(const std::initializer_list<double> &list);
290 vpMatrix &operator=(const std::initializer_list<std::initializer_list<double> > &lists);
291#endif
292 vpMatrix &operator=(double x);
294
295 //-------------------------------------------------
296 // Stacking
297 //-------------------------------------------------
300 // Stack the matrix A below the current one, copy if not initialized this =
301 // [ this A ]^T
302 void stack(const vpMatrix &A);
303 void stack(const vpRowVector &r);
304 void stack(const vpColVector &c);
305 // Stacks columns of a matrix in a vector
306 void stackColumns(vpColVector &out);
307
308 // Stacks columns of a matrix in a vector
309 vpColVector stackColumns();
310
311 // Stacks columns of a matrix in a vector
312 void stackRows(vpRowVector &out);
313
314 // Stacks columns of a matrix in a vector
315 vpRowVector stackRows();
317
318 //---------------------------------
319 // Matrix insertion
320 //---------------------------------
323 // Insert matrix A in the current matrix at the given position (r, c).
324 void insert(const vpMatrix &A, unsigned int r, unsigned int c);
326
327 //-------------------------------------------------
328 // Columns, Rows, Diag extraction, SubMatrix
329 //-------------------------------------------------
332 vpMatrix extract(unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols) const;
333 vpColVector getCol(unsigned int j) const;
334 vpColVector getCol(unsigned int j, unsigned int i_begin, unsigned int size) const;
335 vpRowVector getRow(unsigned int i) const;
336 vpRowVector getRow(unsigned int i, unsigned int j_begin, unsigned int size) const;
337 vpColVector getDiag() const;
338 void init(const vpMatrix &M, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols);
340
341 //---------------------------------
342 // Matrix operations.
343 //---------------------------------
346 // return the determinant of the matrix.
347 double det(vpDetMethod method = LU_DECOMPOSITION) const;
348 double detByLU() const;
349#if defined(VISP_HAVE_EIGEN3)
350 double detByLUEigen3() const;
351#endif
352#if defined(VISP_HAVE_LAPACK)
353 double detByLULapack() const;
354#endif
355#if defined(VISP_HAVE_OPENCV)
356 double detByLUOpenCV() const;
357#endif
358
359 // Compute the exponential matrix of a square matrix
360 vpMatrix expm() const;
361
362 // operation A = A + B
363 vpMatrix &operator+=(const vpMatrix &B);
364 // operation A = A - B
365 vpMatrix &operator-=(const vpMatrix &B);
366 vpMatrix operator*(const vpMatrix &B) const;
367 vpMatrix operator*(const vpRotationMatrix &R) const;
368 vpMatrix operator*(const vpHomogeneousMatrix &R) const;
370 vpMatrix operator*(const vpForceTwistMatrix &V) const;
371 // operation t_out = A * t (A is unchanged, t and t_out are translation
372 // vectors)
374 vpColVector operator*(const vpColVector &v) const;
375 vpMatrix operator+(const vpMatrix &B) const;
376 vpMatrix operator-(const vpMatrix &B) const;
377 vpMatrix operator-() const;
378
380 vpMatrix &operator+=(double x);
382 vpMatrix &operator-=(double x);
384 vpMatrix &operator*=(double x);
386 vpMatrix &operator/=(double x);
387
388 // Cij = Aij * x (A is unchanged)
389 vpMatrix operator*(double x) const;
390 // Cij = Aij / x (A is unchanged)
391 vpMatrix operator/(double x) const;
392
398 double sum() const;
399 double sumSquare() const;
400
401 //-------------------------------------------------
402 // Hadamard product
403 //-------------------------------------------------
405 vpMatrix hadamard(const vpMatrix &m) const;
406
407 //-------------------------------------------------
408 // Kronecker product
409 //-------------------------------------------------
412 // Compute Kronecker product matrix
413 void kron(const vpMatrix &m1, vpMatrix &out) const;
414
415 // Compute Kronecker product matrix
416 vpMatrix kron(const vpMatrix &m1) const;
418
419 //-------------------------------------------------
420 // Transpose
421 //-------------------------------------------------
424 // Compute the transpose C = A^T
425 vpMatrix t() const;
426
427 // Compute the transpose C = A^T
428 vpMatrix transpose() const;
429 void transpose(vpMatrix &At) const;
430
431 vpMatrix AAt() const;
432 void AAt(vpMatrix &B) const;
433
434 vpMatrix AtA() const;
435 void AtA(vpMatrix &B) const;
437
438 //-------------------------------------------------
439 // Matrix inversion
440 //-------------------------------------------------
443 // inverse matrix A using the LU decomposition
444 vpMatrix inverseByLU() const;
445
446#if defined(VISP_HAVE_EIGEN3)
447 vpMatrix inverseByLUEigen3() const;
448#endif
449#if defined(VISP_HAVE_LAPACK)
450 vpMatrix inverseByLULapack() const;
451#endif
452#if defined(VISP_HAVE_OPENCV)
453 vpMatrix inverseByLUOpenCV() const;
454#endif
455
456 // inverse matrix A using the Cholesky decomposition (only for real
457 // symmetric matrices)
458 vpMatrix inverseByCholesky() const;
459
460#if defined(VISP_HAVE_LAPACK)
461 vpMatrix inverseByCholeskyLapack() const;
462#endif
463#if defined(VISP_HAVE_OPENCV)
464 vpMatrix inverseByCholeskyOpenCV() const;
465#endif
466
467 // inverse matrix A using the QR decomposition
468 vpMatrix inverseByQR() const;
469#if defined(VISP_HAVE_LAPACK)
470 vpMatrix inverseByQRLapack() const;
471#endif
472
473 // inverse triangular matrix
474 vpMatrix inverseTriangular(bool upper = true) const;
475
476 vpMatrix pseudoInverse(double svThreshold = 1e-6) const;
477 unsigned int pseudoInverse(vpMatrix &Ap, double svThreshold = 1e-6) const;
478 unsigned int pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
479 unsigned int pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt) const;
480 unsigned int pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt,
481 vpMatrix &kerAt) const;
482 vpMatrix pseudoInverse(int rank_in) const;
483 int pseudoInverse(vpMatrix &Ap, int rank_in) const;
484 int pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
485 int pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt) const;
486 int pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
487
488#if defined(VISP_HAVE_LAPACK)
489 vpMatrix pseudoInverseLapack(double svThreshold = 1e-6) const;
490 unsigned int pseudoInverseLapack(vpMatrix &Ap, double svThreshold = 1e-6) const;
491 unsigned int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
492 unsigned int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt,
493 vpMatrix &kerAt) const;
494 vpMatrix pseudoInverseLapack(int rank_in) const;
495 int pseudoInverseLapack(vpMatrix &Ap, int rank_in) const;
496 int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
497 int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt,
498 vpMatrix &kerAt) const;
499#endif
500#if defined(VISP_HAVE_EIGEN3)
501 vpMatrix pseudoInverseEigen3(double svThreshold = 1e-6) const;
502 unsigned int pseudoInverseEigen3(vpMatrix &Ap, double svThreshold = 1e-6) const;
503 unsigned int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
504 unsigned int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt,
505 vpMatrix &kerAt) const;
506 vpMatrix pseudoInverseEigen3(int rank_in) const;
507 int pseudoInverseEigen3(vpMatrix &Ap, int rank_in) const;
508 int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
509 int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt,
510 vpMatrix &kerAt) const;
511#endif
512#if defined(VISP_HAVE_OPENCV)
513 vpMatrix pseudoInverseOpenCV(double svThreshold = 1e-6) const;
514 unsigned int pseudoInverseOpenCV(vpMatrix &Ap, double svThreshold = 1e-6) const;
515 unsigned int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
516 unsigned int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt,
517 vpMatrix &kerAt) const;
518 vpMatrix pseudoInverseOpenCV(int rank_in) const;
519 int pseudoInverseOpenCV(vpMatrix &Ap, int rank_in) const;
520 int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
521 int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt,
522 vpMatrix &kerAt) const;
523#endif
525
526 //-------------------------------------------------
527 // SVD decomposition
528 //-------------------------------------------------
529
532 double cond(double svThreshold = 1e-6) const;
533 unsigned int kernel(vpMatrix &kerAt, double svThreshold = 1e-6) const;
534 unsigned int nullSpace(vpMatrix &kerA, double svThreshold = 1e-6) const;
535 unsigned int nullSpace(vpMatrix &kerA, int dim) const;
536
537 // solve Ax=B using the SVD decomposition (usage A = solveBySVD(B,x) )
538 void solveBySVD(const vpColVector &B, vpColVector &x) const;
539 // solve Ax=B using the SVD decomposition (usage x=A.solveBySVD(B))
540 vpColVector solveBySVD(const vpColVector &B) const;
541
542 // singular value decomposition SVD
543 void svd(vpColVector &w, vpMatrix &V);
544#ifdef VISP_HAVE_EIGEN3
545 void svdEigen3(vpColVector &w, vpMatrix &V);
546#endif
547#if defined(VISP_HAVE_LAPACK)
548 void svdLapack(vpColVector &w, vpMatrix &V);
549#endif
550#if defined(VISP_HAVE_OPENCV) // Require opencv >= 2.1.1
551 void svdOpenCV(vpColVector &w, vpMatrix &V);
552#endif
554
555 //-------------------------------------------------
556 // QR decomposition
557 //-------------------------------------------------
558
561 unsigned int qr(vpMatrix &Q, vpMatrix &R, bool full = false, bool squareR = false, double tol = 1e-6) const;
562 unsigned int qrPivot(vpMatrix &Q, vpMatrix &R, vpMatrix &P, bool full = false, bool squareR = false,
563 double tol = 1e-6) const;
564 void solveByQR(const vpColVector &b, vpColVector &x) const;
565 vpColVector solveByQR(const vpColVector &b) const;
567
568 //-------------------------------------------------
569 // Eigen values and vectors
570 //-------------------------------------------------
574 // Compute the eigen values using Lapack.
575 vpColVector eigenValues() const;
576 void eigenValues(vpColVector &evalue, vpMatrix &evector) const;
578
579 //-------------------------------------------------
580 // Norms
581 //-------------------------------------------------
584 double frobeniusNorm() const;
585 double inducedL2Norm() const;
586 double infinityNorm() const;
588
589 //---------------------------------
590 // Printing
591 //---------------------------------
594 std::ostream &cppPrint(std::ostream &os, const std::string &matrixName = "A", bool octet = false) const;
595 std::ostream &csvPrint(std::ostream &os) const;
596 std::ostream &maplePrint(std::ostream &os) const;
597 std::ostream &matlabPrint(std::ostream &os) const;
598 int print(std::ostream &s, unsigned int length, const std::string &intro = "") const;
599 void printSize() const { std::cout << getRows() << " x " << getCols() << " "; }
601
602 //------------------------------------------------------------------
603 // Static functionalities
604 //------------------------------------------------------------------
605
606 //---------------------------------
607 // Setting a diagonal matrix with Static Public Member Functions
608 //---------------------------------
611 // Create a diagonal matrix with the element of a vector DAii = Ai
612 static void createDiagonalMatrix(const vpColVector &A, vpMatrix &DA);
614
615 //---------------------------------
616 // Matrix insertion with Static Public Member Functions
617 //---------------------------------
620 // Insert matrix B in matrix A at the given position (r, c).
621 static vpMatrix insert(const vpMatrix &A, const vpMatrix &B, unsigned int r, unsigned int c);
622 // Insert matrix B in matrix A (not modified) at the given position (r, c),
623 // the result is given in matrix C.
624 static void insert(const vpMatrix &A, const vpMatrix &B, vpMatrix &C, unsigned int r, unsigned int c);
625
626 //---------------------------------
627 // Stacking with Static Public Member Functions
628 //---------------------------------
631 // Juxtapose to matrices C = [ A B ]
632 static vpMatrix juxtaposeMatrices(const vpMatrix &A, const vpMatrix &B);
633 // Juxtapose to matrices C = [ A B ]
634 static void juxtaposeMatrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
635 // Stack two matrices C = [ A B ]^T
636 static vpMatrix stack(const vpMatrix &A, const vpMatrix &B);
637 static vpMatrix stack(const vpMatrix &A, const vpRowVector &r);
638 static vpMatrix stack(const vpMatrix &A, const vpColVector &c);
639
640 // Stack two matrices C = [ A B ]^T
641 static void stack(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
642 static void stack(const vpMatrix &A, const vpRowVector &r, vpMatrix &C);
643 static void stack(const vpMatrix &A, const vpColVector &c, vpMatrix &C);
645
646 //---------------------------------
647 // Matrix operations Static Public Member Functions
648 //---------------------------------
651 static void add2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
652 static void add2Matrices(const vpColVector &A, const vpColVector &B, vpColVector &C);
653 static void add2WeightedMatrices(const vpMatrix &A, const double &wA, const vpMatrix &B, const double &wB,
654 vpMatrix &C);
655 static void computeHLM(const vpMatrix &H, const double &alpha, vpMatrix &HLM);
656 static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
657 static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpRotationMatrix &C);
658 static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpHomogeneousMatrix &C);
659 static void mult2Matrices(const vpMatrix &A, const vpColVector &B, vpColVector &C);
660 static void multMatrixVector(const vpMatrix &A, const vpColVector &v, vpColVector &w);
661 static void negateMatrix(const vpMatrix &A, vpMatrix &C);
662 static void sub2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
663 static void sub2Matrices(const vpColVector &A, const vpColVector &B, vpColVector &C);
665
666 //---------------------------------
667 // Kronecker product Static Public Member Functions
668 //---------------------------------
671 // Compute Kronecker product matrix
672 static void kron(const vpMatrix &m1, const vpMatrix &m2, vpMatrix &out);
673
674 // Compute Kronecker product matrix
675 static vpMatrix kron(const vpMatrix &m1, const vpMatrix &m2);
677
678 //---------------------------------
679 // Covariance computation Static Public Member Functions
680 //---------------------------------
683 static vpMatrix computeCovarianceMatrix(const vpMatrix &A, const vpColVector &x, const vpColVector &b);
684 static vpMatrix computeCovarianceMatrix(const vpMatrix &A, const vpColVector &x, const vpColVector &b,
685 const vpMatrix &w);
686 static vpMatrix computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS,
687 const vpMatrix &Ls, const vpMatrix &W);
688 static vpMatrix computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS,
689 const vpMatrix &Ls);
691
692 //---------------------------------
693 // Matrix I/O Static Public Member Functions
694 //---------------------------------
763 static inline bool loadMatrix(const std::string &filename, vpArray2D<double> &M, bool binary = false,
764 char *header = NULL)
765 {
766 return vpArray2D<double>::load(filename, M, binary, header);
767 }
768
838 static inline bool loadMatrixYAML(const std::string &filename, vpArray2D<double> &M, char *header = NULL)
839 {
840 return vpArray2D<double>::loadYAML(filename, M, header);
841 }
842
911 static inline bool saveMatrix(const std::string &filename, const vpArray2D<double> &M, bool binary = false,
912 const char *header = "")
913 {
914 return vpArray2D<double>::save(filename, M, binary, header);
915 }
916
987 static inline bool saveMatrixYAML(const std::string &filename, const vpArray2D<double> &M, const char *header = "")
988 {
989 return vpArray2D<double>::saveYAML(filename, M, header);
990 }
992
993#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
994 vp_deprecated double euclideanNorm() const;
995
1004 vp_deprecated void init() { }
1005
1009 vp_deprecated void stackMatrices(const vpMatrix &A) { stack(A); }
1014 vp_deprecated static vpMatrix stackMatrices(const vpMatrix &A, const vpMatrix &B) { return stack(A, B); }
1019 vp_deprecated static void stackMatrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C) { stack(A, B, C); }
1024 vp_deprecated static vpMatrix stackMatrices(const vpMatrix &A, const vpRowVector &B);
1029 vp_deprecated static void stackMatrices(const vpMatrix &A, const vpRowVector &B, vpMatrix &C);
1034 vp_deprecated static vpMatrix stackMatrices(const vpColVector &A, const vpColVector &B);
1039 vp_deprecated static void stackMatrices(const vpColVector &A, const vpColVector &B, vpColVector &C);
1040
1044 vp_deprecated void setIdentity(const double &val = 1.0);
1045
1046 vp_deprecated vpRowVector row(unsigned int i);
1047 vp_deprecated vpColVector column(unsigned int j);
1048
1049 // Deprecated functions using GSL
1050#ifndef DOXYGEN_SHOULD_SKIP_THIS
1054 vp_deprecated double detByLUGsl() const
1055 {
1056#if defined(VISP_HAVE_LAPACK)
1057 return detByLULapack();
1058#else
1059 throw(vpException(vpException::fatalError, "Undefined detByLULapack(). Install Lapack 3rd party"));
1060#endif
1061 }
1062
1066 vp_deprecated vpMatrix inverseByLUGsl() const
1067 {
1068#if defined(VISP_HAVE_LAPACK)
1069 return inverseByLULapack();
1070#else
1071 throw(vpException(vpException::fatalError, "Undefined inverseByLULapack(). Install Lapack 3rd party"));
1072#endif
1073 }
1074
1078 vpMatrix inverseByCholeskyGsl() const
1079 {
1080#if defined(VISP_HAVE_LAPACK)
1081 return inverseByCholeskyLapack();
1082#else
1083 throw(vpException(vpException::fatalError, "Undefined inverseByCholeskyLapack(). Install Lapack 3rd party"));
1084#endif
1085 }
1086
1090 vpMatrix inverseByQRGsl() const
1091 {
1092#if defined(VISP_HAVE_LAPACK)
1093 return inverseByQRLapack();
1094#else
1095 throw(vpException(vpException::fatalError, "Undefined inverseByQRLapack(). Install Lapack 3rd party"));
1096#endif
1097 }
1098
1102 vpMatrix pseudoInverseGsl(double svThreshold = 1e-6) const
1103 {
1104#if defined(VISP_HAVE_LAPACK)
1105 return pseudoInverseLapack(svThreshold);
1106#else
1107 (void)svThreshold;
1108 throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
1109#endif
1110 }
1111
1115 unsigned int pseudoInverseGsl(vpMatrix &Ap, double svThreshold = 1e-6) const
1116 {
1117#if defined(VISP_HAVE_LAPACK)
1118 return pseudoInverseLapack(Ap, svThreshold);
1119#else
1120 (void)Ap;
1121 (void)svThreshold;
1122 throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
1123#endif
1124 }
1125
1129 unsigned int pseudoInverseGsl(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const
1130 {
1131#if defined(VISP_HAVE_LAPACK)
1132 return pseudoInverseLapack(Ap, sv, svThreshold);
1133#else
1134 (void)Ap;
1135 (void)sv;
1136 (void)svThreshold;
1137 throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
1138#endif
1139 }
1140
1144 unsigned int pseudoInverseGsl(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt,
1145 vpMatrix &kerAt) const
1146 {
1147#if defined(VISP_HAVE_LAPACK)
1148 return pseudoInverseLapack(Ap, sv, svThreshold, imA, imAt, kerAt);
1149#else
1150 (void)Ap;
1151 (void)sv;
1152 (void)svThreshold;
1153 (void)imA;
1154 (void)imAt;
1155 (void)kerAt;
1156 throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
1157#endif
1158 }
1159
1163 void svdGsl(vpColVector &w, vpMatrix &V)
1164 {
1165#if defined(VISP_HAVE_LAPACK)
1166 svdLapack(w, V);
1167#else
1168 (void)w;
1169 (void)V;
1170 throw(vpException(vpException::fatalError, "Undefined svdLapack(). Install Lapack 3rd party"));
1171#endif
1172 }
1173
1174#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS
1176#endif
1177
1178private:
1179 static unsigned int m_lapack_min_size;
1180 static const unsigned int m_lapack_min_size_default;
1181
1182#if defined(VISP_HAVE_LAPACK)
1183 static void blas_dgemm(char trans_a, char trans_b, unsigned int M_, unsigned int N_, unsigned int K_, double alpha,
1184 double *a_data, unsigned int lda_, double *b_data, unsigned int ldb_, double beta,
1185 double *c_data, unsigned int ldc_);
1186 static void blas_dgemv(char trans, unsigned int M_, unsigned int N_, double alpha, double *a_data, unsigned int lda_,
1187 double *x_data, int incx_, double beta, double *y_data, int incy_);
1188 static void blas_dsyev(char jobz, char uplo, unsigned int n_, double *a_data, unsigned int lda_, double *w_data,
1189 double *work_data, int lwork_, int &info_);
1190#endif
1191
1192 static void computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS, const vpMatrix &Ls,
1193 vpMatrix &Js, vpColVector &deltaP);
1194};
1195
1197#if defined(VISP_USE_MSVC) && defined(visp_EXPORTS)
1198const __declspec(selectany) unsigned int vpMatrix::m_lapack_min_size_default = 0;
1199__declspec(selectany) unsigned int vpMatrix::m_lapack_min_size = vpMatrix::m_lapack_min_size_default;
1200#endif
1201
1202#ifndef DOXYGEN_SHOULD_SKIP_THIS
1203VISP_EXPORT
1204#endif
1205vpMatrix operator*(const double &x, const vpMatrix &A);
1206#endif
Implementation of a generic 2D array used as base class for matrices and vectors.
Definition vpArray2D.h:131
static bool load(const std::string &filename, vpArray2D< Type > &A, bool binary=false, char *header=NULL)
Definition vpArray2D.h:582
unsigned int getCols() const
Definition vpArray2D.h:280
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition vpArray2D.h:445
void insert(const vpArray2D< Type > &A, unsigned int r, unsigned int c)
Definition vpArray2D.h:417
static bool saveYAML(const std::string &filename, const vpArray2D< Type > &A, const char *header="")
Definition vpArray2D.h:877
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition vpArray2D.h:529
vpArray2D< Type > t() const
Compute the transpose of the array.
Definition vpArray2D.h:1059
static bool loadYAML(const std::string &filename, vpArray2D< Type > &A, char *header=NULL)
Definition vpArray2D.h:696
unsigned int getRows() const
Definition vpArray2D.h:290
vpArray2D< Type > hadamard(const vpArray2D< Type > &m) const
Definition vpArray2D.h:1043
static bool save(const std::string &filename, const vpArray2D< Type > &A, bool binary=false, const char *header="")
Definition vpArray2D.h:784
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
Definition vpException.h:59
@ fatalError
Fatal error.
Definition vpException.h:84
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:152
static void setLapackMatrixMinSize(unsigned int min_size)
Definition vpMatrix.h:259
int pseudoInverseOpenCV(vpMatrix &Ap, int rank_in) const
vpMatrix(unsigned int r, unsigned int c)
Definition vpMatrix.h:176
vpMatrix(unsigned int r, unsigned int c, double val)
Definition vpMatrix.h:185
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:838
static bool loadMatrix(const std::string &filename, vpArray2D< double > &M, bool binary=false, char *header=NULL)
Definition vpMatrix.h:763
static unsigned int getLapackMatrixMinSize()
Definition vpMatrix.h:245
vpMatrix pseudoInverseEigen3(double svThreshold=1e-6) const
unsigned int pseudoInverseOpenCV(vpMatrix &Ap, double svThreshold=1e-6) const
void printSize() const
Definition vpMatrix.h:599
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:1009
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:200
unsigned int pseudoInverseEigen3(vpMatrix &Ap, double svThreshold=1e-6) const
static vp_deprecated vpMatrix stackMatrices(const vpMatrix &A, const vpMatrix &B)
Definition vpMatrix.h:1014
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:212
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:202
vp_deprecated void init()
Definition vpMatrix.h:1004
void clear()
Definition vpMatrix.h:218
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:987
static vp_deprecated void stackMatrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
Definition vpMatrix.h:1019
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:911
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.
Class that consider the case of a translation vector.
vpColVector operator*(const double &x, const vpColVector &v)