Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpMatrix.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2024 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
40
41#ifndef VP_MATRIX_H
42#define VP_MATRIX_H
43
44#include <visp3/core/vpConfig.h>
45
47class vpRowVector;
48class vpColVector;
53END_VISP_NAMESPACE
54
55#include <visp3/core/vpArray2D.h>
56#include <visp3/core/vpException.h>
57#include <visp3/core/vpForceTwistMatrix.h>
58#include <visp3/core/vpHomogeneousMatrix.h>
59#include <visp3/core/vpRotationMatrix.h>
60#include <visp3/core/vpTime.h>
61#include <visp3/core/vpVelocityTwistMatrix.h>
62
63#include <iostream>
64#include <math.h>
65
67
174class VISP_EXPORT vpMatrix : public vpArray2D<double>
175{
176public:
181 typedef enum
182 {
184 } vpDetMethod;
185
186public:
191 vpMatrix() : vpArray2D<double>(0, 0) { }
192
199 vpMatrix(unsigned int r, unsigned int c) : vpArray2D<double>(r, c) { }
200
208 vpMatrix(unsigned int r, unsigned int c, double val) : vpArray2D<double>(r, c, val) { }
209 vpMatrix(const vpMatrix &M, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols);
210
223 VP_EXPLICIT vpMatrix(const vpArray2D<double> &A) : vpArray2D<double>(A) { }
224 vpMatrix(const vpMatrix &A) : vpArray2D<double>(A) { }
225 VP_EXPLICIT vpMatrix(const vpHomogeneousMatrix &R);
226 VP_EXPLICIT vpMatrix(const vpRotationMatrix &R);
227 VP_EXPLICIT vpMatrix(const vpVelocityTwistMatrix &V);
228 VP_EXPLICIT vpMatrix(const vpForceTwistMatrix &F);
229 VP_EXPLICIT vpMatrix(const vpColVector &v);
230 VP_EXPLICIT vpMatrix(const vpRowVector &v);
231 VP_EXPLICIT vpMatrix(const vpTranslationVector &t);
232
233 static vpMatrix view(double *data, unsigned int rows, unsigned int cols);
234 static void view(vpMatrix &v, double *data, unsigned int rows, unsigned int cols);
235
236#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
237 vpMatrix(vpMatrix &&A);
238 VP_EXPLICIT vpMatrix(const std::initializer_list<double> &list);
239 VP_EXPLICIT vpMatrix(unsigned int nrows, unsigned int ncols, const std::initializer_list<double> &list);
240 VP_EXPLICIT vpMatrix(const std::initializer_list<std::initializer_list<double> > &lists);
241#endif
242
247 void clear()
248 {
249 if (data != nullptr) {
250 free(data);
251 data = nullptr;
252 }
253
254 if (rowPtrs != nullptr) {
255 free(rowPtrs);
256 rowPtrs = nullptr;
257 }
258 rowNum = 0;
259 colNum = 0;
260 dsize = 0;
261 }
262
263 //-------------------------------------------------
264 // Setting a diagonal matrix
265 //-------------------------------------------------
268
276 static unsigned int getLapackMatrixMinSize() { return m_lapack_min_size; }
277
290 static void setLapackMatrixMinSize(unsigned int min_size) { m_lapack_min_size = min_size; }
292
293 //-------------------------------------------------
294 // Setting a diagonal matrix
295 //-------------------------------------------------
298 void diag(const double &val = 1.0);
299 void diag(const vpColVector &A);
300 // Initialize an identity matrix n-by-n
301 void eye();
302 void eye(unsigned int n);
303 // Initialize an identity matrix m-by-n
304 void eye(unsigned int m, unsigned int n);
306
307 //---------------------------------
308 // Assignment
309 //---------------------------------
312 vpMatrix &operator<<(double *p);
313 vpMatrix &operator<<(double val);
314 vpMatrix &operator,(double val);
316 vpMatrix &operator=(const vpMatrix &A);
321 vpMatrix &operator=(const vpColVector &v);
322 vpMatrix &operator=(const vpRowVector &v);
324
325#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
327
328 vpMatrix &operator=(const std::initializer_list<double> &list);
329 vpMatrix &operator=(const std::initializer_list<std::initializer_list<double> > &lists);
330#endif
331 vpMatrix &operator=(double x);
333
334 //-------------------------------------------------
335 // Stacking
336 //-------------------------------------------------
339 // Stack the matrix A below the current one, copy if not initialized this =
340 // [ this A ]^T
341 void stack(const vpMatrix &A);
342 void stack(const vpRowVector &r);
343 void stack(const vpColVector &c);
344 // Stacks columns of a matrix in a vector
345 void stackColumns(vpColVector &out);
346
347 // Stacks columns of a matrix in a vector
348 vpColVector stackColumns();
349
350 // Stacks columns of a matrix in a vector
351 void stackRows(vpRowVector &out);
352
353 // Stacks columns of a matrix in a vector
354 vpRowVector stackRows();
356
357 //---------------------------------
358 // Matrix insertion
359 //---------------------------------
362 // Insert matrix A in the current matrix at the given position (r, c).
363 void insert(const vpMatrix &A, unsigned int r, unsigned int c);
365
366 //-------------------------------------------------
367 // Columns, Rows, Diag extraction, SubMatrix
368 //-------------------------------------------------
371 vpMatrix extract(unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols) const;
372 vpColVector getCol(unsigned int j) const;
373 vpColVector getCol(unsigned int j, unsigned int i_begin, unsigned int size) const;
374 vpRowVector getRow(unsigned int i) const;
375 vpRowVector getRow(unsigned int i, unsigned int j_begin, unsigned int size) const;
376 vpColVector getDiag() const;
377 void init(const vpMatrix &M, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols);
379
380 //---------------------------------
381 // Matrix operations.
382 //---------------------------------
385
396 static vpMatrix conv2(const vpMatrix &M, const vpMatrix &kernel, const std::string &mode);
397
410 static void conv2(const vpMatrix &M, const vpMatrix &kernel, vpMatrix &res, const std::string &mode);
411
412 // return the determinant of the matrix.
413 double det(vpDetMethod method = LU_DECOMPOSITION) const;
414 double detByLU() const;
415#if defined(VISP_HAVE_EIGEN3)
416 double detByLUEigen3() const;
417#endif
418#if defined(VISP_HAVE_LAPACK)
419 double detByLULapack() const;
420#endif
421#if defined(VISP_HAVE_OPENCV)
422 double detByLUOpenCV() const;
423#endif
424 vpMatrix cholesky() const;
425#if defined(VISP_HAVE_EIGEN3)
426 vpMatrix choleskyByEigen3() const;
427#endif
428#if defined(VISP_HAVE_LAPACK)
429 vpMatrix choleskyByLapack() const;
430#endif
431#if defined(VISP_HAVE_OPENCV)
432 vpMatrix choleskyByOpenCV() const;
433#endif
434
435 // Compute the exponential matrix of a square matrix
436 vpMatrix expm() const;
437
438 // operation A = A + B
439 vpMatrix &operator+=(const vpMatrix &B);
440 // operation A = A - B
441 vpMatrix &operator-=(const vpMatrix &B);
442 vpMatrix operator*(const vpMatrix &B) const;
443 vpMatrix operator*(const vpRotationMatrix &R) const;
444 vpMatrix operator*(const vpHomogeneousMatrix &R) const;
445 vpMatrix operator*(const vpVelocityTwistMatrix &V) const;
446 vpMatrix operator*(const vpForceTwistMatrix &V) const;
447 // operation t_out = A * t (A is unchanged, t and t_out are translation
448 // vectors)
449 vpTranslationVector operator*(const vpTranslationVector &tv) const;
450 vpColVector operator*(const vpColVector &v) const;
451 vpMatrix operator+(const vpMatrix &B) const;
452 vpMatrix operator-(const vpMatrix &B) const;
453 vpMatrix operator-() const;
454
456 vpMatrix &operator+=(double x);
458 vpMatrix &operator-=(double x);
460 vpMatrix &operator*=(double x);
462 vpMatrix &operator/=(double x);
463
464 // Cij = Aij * x (A is unchanged)
465 vpMatrix operator*(double x) const;
466 // Cij = Aij / x (A is unchanged)
467 vpMatrix operator/(double x) const;
468
474 double sum() const;
475 double sumSquare() const;
476
477 //-------------------------------------------------
478 // Hadamard product
479 //-------------------------------------------------
481 vpMatrix hadamard(const vpMatrix &m) const;
482
483 //-------------------------------------------------
484 // Kronecker product
485 //-------------------------------------------------
488 // Compute Kronecker product matrix
489 void kron(const vpMatrix &m1, vpMatrix &out) const;
490
491 // Compute Kronecker product matrix
492 vpMatrix kron(const vpMatrix &m1) const;
494
495 //-------------------------------------------------
496 // Transpose
497 //-------------------------------------------------
500 // Compute the transpose C = A^T
501 vpMatrix t() const;
502
503 // Compute the transpose C = A^T
504 vpMatrix transpose() const;
505 void transpose(vpMatrix &At) const;
506
507 vpMatrix AAt() const;
508 void AAt(vpMatrix &B) const;
509
510 vpMatrix AtA() const;
511 void AtA(vpMatrix &B) const;
513
514 //-------------------------------------------------
515 // Matrix inversion
516 //-------------------------------------------------
519 // inverse matrix A using the LU decomposition
520 vpMatrix inverseByLU() const;
521
522#if defined(VISP_HAVE_EIGEN3)
523 vpMatrix inverseByLUEigen3() const;
524#endif
525#if defined(VISP_HAVE_LAPACK)
526 vpMatrix inverseByLULapack() const;
527#endif
528#if defined(VISP_HAVE_OPENCV)
529 vpMatrix inverseByLUOpenCV() const;
530#endif
531
532 // inverse matrix A using the Cholesky decomposition (only for real
533 // symmetric matrices)
534 vpMatrix inverseByCholesky() const;
535
536#if defined(VISP_HAVE_LAPACK)
537 vpMatrix inverseByCholeskyLapack() const;
538#endif
539#if defined(VISP_HAVE_OPENCV)
540 vpMatrix inverseByCholeskyOpenCV() const;
541#endif
542
543 // inverse matrix A using the QR decomposition
544 vpMatrix inverseByQR() const;
545#if defined(VISP_HAVE_LAPACK)
546 vpMatrix inverseByQRLapack() const;
547#endif
548
549 // inverse triangular matrix
550 vpMatrix inverseTriangular(bool upper = true) const;
551
552 vpMatrix pseudoInverse(double svThreshold = 1e-6) const;
553 unsigned int pseudoInverse(vpMatrix &Ap, double svThreshold = 1e-6) const;
554 unsigned int pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
555 unsigned int pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt) const;
556 unsigned int pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
557 vpMatrix pseudoInverse(int rank_in) const;
558 int pseudoInverse(vpMatrix &Ap, int rank_in) const;
559 int pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
560 int pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt) const;
561 int pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
562
563#if defined(VISP_HAVE_LAPACK)
564 vpMatrix pseudoInverseLapack(double svThreshold = 1e-6) const;
565 unsigned int pseudoInverseLapack(vpMatrix &Ap, double svThreshold = 1e-6) const;
566 unsigned int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
567 unsigned int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
568 vpMatrix pseudoInverseLapack(int rank_in) const;
569 int pseudoInverseLapack(vpMatrix &Ap, int rank_in) const;
570 int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
571 int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
572#endif
573#if defined(VISP_HAVE_EIGEN3)
574 vpMatrix pseudoInverseEigen3(double svThreshold = 1e-6) const;
575 unsigned int pseudoInverseEigen3(vpMatrix &Ap, double svThreshold = 1e-6) const;
576 unsigned int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
577 unsigned int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
578 vpMatrix pseudoInverseEigen3(int rank_in) const;
579 int pseudoInverseEigen3(vpMatrix &Ap, int rank_in) const;
580 int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
581 int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
582#endif
583#if defined(VISP_HAVE_OPENCV)
584 vpMatrix pseudoInverseOpenCV(double svThreshold = 1e-6) const;
585 unsigned int pseudoInverseOpenCV(vpMatrix &Ap, double svThreshold = 1e-6) const;
586 unsigned int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const;
587 unsigned int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
588 vpMatrix pseudoInverseOpenCV(int rank_in) const;
589 int pseudoInverseOpenCV(vpMatrix &Ap, int rank_in) const;
590 int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, int rank_in) const;
591 int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const;
592#endif
593
594 vpMatrix dampedInverse(const double &ratioOfMaxSvd = 1e-4) const;
596
597 //-------------------------------------------------
598 // SVD decomposition
599 //-------------------------------------------------
600
603 double cond(double svThreshold = 1e-6) const;
604 unsigned int kernel(vpMatrix &kerAt, double svThreshold = 1e-6) const;
605 unsigned int nullSpace(vpMatrix &kerA, double svThreshold = 1e-6) const;
606 unsigned int nullSpace(vpMatrix &kerA, int dim) const;
607
608 // solve Ax=B using the SVD decomposition (usage A = solveBySVD(B,x) )
609 void solveBySVD(const vpColVector &B, vpColVector &x) const;
610 // solve Ax=B using the SVD decomposition (usage x=A.solveBySVD(B))
611 vpColVector solveBySVD(const vpColVector &B) const;
612
613 // singular value decomposition SVD
614 void svd(vpColVector &w, vpMatrix &V);
615#ifdef VISP_HAVE_EIGEN3
616 void svdEigen3(vpColVector &w, vpMatrix &V);
617#endif
618#if defined(VISP_HAVE_LAPACK)
619 void svdLapack(vpColVector &w, vpMatrix &V);
620#endif
621#if defined(VISP_HAVE_OPENCV) // Require opencv >= 2.1.1
622 void svdOpenCV(vpColVector &w, vpMatrix &V);
623#endif
625
626 //-------------------------------------------------
627 // QR decomposition
628 //-------------------------------------------------
629
632 unsigned int qr(vpMatrix &Q, vpMatrix &R, bool full = false, bool squareR = false, double tol = 1e-6) const;
633 unsigned int qrPivot(vpMatrix &Q, vpMatrix &R, vpMatrix &P, bool full = false, bool squareR = false,
634 double tol = 1e-6) const;
635 void solveByQR(const vpColVector &b, vpColVector &x) const;
636 vpColVector solveByQR(const vpColVector &b) const;
638
639 //-------------------------------------------------
640 // Eigen values and vectors
641 //-------------------------------------------------
643
645 // Compute the eigen values using Lapack.
646 vpColVector eigenValues() const;
647 void eigenValues(vpColVector &evalue, vpMatrix &evector) const;
649
650 //-------------------------------------------------
651 // Norms
652 //-------------------------------------------------
655 double frobeniusNorm() const;
656 double inducedL2Norm() const;
657 double infinityNorm() const;
659
660 //---------------------------------
661 // Printing
662 //---------------------------------
665 std::ostream &cppPrint(std::ostream &os, const std::string &matrixName = "A", bool octet = false) const;
666 std::ostream &csvPrint(std::ostream &os) const;
667 std::ostream &maplePrint(std::ostream &os) const;
668 std::ostream &matlabPrint(std::ostream &os) const;
669 int print(std::ostream &s, unsigned int length, const std::string &intro = "") const;
670 void printSize() const { std::cout << getRows() << " x " << getCols() << " "; }
672
673 //------------------------------------------------------------------
674 // Static functionalities
675 //------------------------------------------------------------------
676
677 //---------------------------------
678 // Setting a diagonal matrix with Static Public Member Functions
679 //---------------------------------
682 // Create a diagonal matrix with the element of a vector DAii = Ai
683 static void createDiagonalMatrix(const vpColVector &A, vpMatrix &DA);
685
686 //---------------------------------
687 // Matrix insertion with Static Public Member Functions
688 //---------------------------------
691 // Insert matrix B in matrix A at the given position (r, c).
692 static vpMatrix insert(const vpMatrix &A, const vpMatrix &B, unsigned int r, unsigned int c);
693 // Insert matrix B in matrix A (not modified) at the given position (r, c),
694 // the result is given in matrix C.
695 static void insert(const vpMatrix &A, const vpMatrix &B, vpMatrix &C, unsigned int r, unsigned int c);
696
697 //---------------------------------
698 // Stacking with Static Public Member Functions
699 //---------------------------------
702 // Juxtapose to matrices C = [ A B ]
703 static vpMatrix juxtaposeMatrices(const vpMatrix &A, const vpMatrix &B);
704 // Juxtapose to matrices C = [ A B ]
705 static void juxtaposeMatrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
706 // Stack two matrices C = [ A B ]^T
707 static vpMatrix stack(const vpMatrix &A, const vpMatrix &B);
708 static vpMatrix stack(const vpMatrix &A, const vpRowVector &r);
709 static vpMatrix stack(const vpMatrix &A, const vpColVector &c);
710
711 // Stack two matrices C = [ A B ]^T
712 static void stack(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
713 static void stack(const vpMatrix &A, const vpRowVector &r, vpMatrix &C);
714 static void stack(const vpMatrix &A, const vpColVector &c, vpMatrix &C);
716
717 //---------------------------------
718 // Matrix operations Static Public Member Functions
719 //---------------------------------
722 static void add2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
723 static void add2Matrices(const vpColVector &A, const vpColVector &B, vpColVector &C);
724 static void add2WeightedMatrices(const vpMatrix &A, const double &wA, const vpMatrix &B, const double &wB,
725 vpMatrix &C);
726 static void computeHLM(const vpMatrix &H, const double &alpha, vpMatrix &HLM);
727 static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
728 static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpRotationMatrix &C);
729 static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpHomogeneousMatrix &C);
730 static void mult2Matrices(const vpMatrix &A, const vpColVector &B, vpColVector &C);
731 static void mult2Matrices(const vpMatrix &A, const vpRotationMatrix &B, vpMatrix &C);
732 static void mult2Matrices(const vpRotationMatrix &A, const vpMatrix &B, vpMatrix &C);
733
734 static void multMatrixVector(const vpMatrix &A, const vpColVector &v, vpColVector &w);
735 static void negateMatrix(const vpMatrix &A, vpMatrix &C);
736 static void sub2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C);
737 static void sub2Matrices(const vpColVector &A, const vpColVector &B, vpColVector &C);
739
740 //---------------------------------
741 // Kronecker product Static Public Member Functions
742 //---------------------------------
745 // Compute Kronecker product matrix
746 static void kron(const vpMatrix &m1, const vpMatrix &m2, vpMatrix &out);
747
748 // Compute Kronecker product matrix
749 static vpMatrix kron(const vpMatrix &m1, const vpMatrix &m2);
751
752 //---------------------------------
753 // Covariance computation Static Public Member Functions
754 //---------------------------------
757 static vpMatrix computeCovarianceMatrix(const vpMatrix &A, const vpColVector &x, const vpColVector &b);
758 static vpMatrix computeCovarianceMatrix(const vpMatrix &A, const vpColVector &x, const vpColVector &b,
759 const vpMatrix &w);
760 static vpMatrix computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS,
761 const vpMatrix &Ls, const vpMatrix &W);
762 static vpMatrix computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS,
763 const vpMatrix &Ls);
765
766 //---------------------------------
767 // Matrix I/O Static Public Member Functions
768 //---------------------------------
771
841 static inline bool loadMatrix(const std::string &filename, vpArray2D<double> &M, bool binary = false,
842 char *header = nullptr)
843 {
844 return vpArray2D<double>::load(filename, M, binary, header);
845 }
846
920 static inline bool loadMatrixYAML(const std::string &filename, vpArray2D<double> &M, char *header = nullptr)
921 {
922 return vpArray2D<double>::loadYAML(filename, M, header);
923 }
924
997 static inline bool saveMatrix(const std::string &filename, const vpArray2D<double> &M, bool binary = false,
998 const char *header = "")
999 {
1000 return vpArray2D<double>::save(filename, M, binary, header);
1001 }
1002
1077 static inline bool saveMatrixYAML(const std::string &filename, const vpArray2D<double> &M, const char *header = "")
1078 {
1079 return vpArray2D<double>::saveYAML(filename, M, header);
1080 }
1081
1082
1083#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
1084 VP_DEPRECATED double euclideanNorm() const;
1085
1090
1094 VP_DEPRECATED void init() { }
1095
1099 VP_DEPRECATED void stackMatrices(const vpMatrix &A) { stack(A); }
1104 VP_DEPRECATED static vpMatrix stackMatrices(const vpMatrix &A, const vpMatrix &B) { return stack(A, B); }
1109 VP_DEPRECATED static void stackMatrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C) { stack(A, B, C); }
1114 VP_DEPRECATED static vpMatrix stackMatrices(const vpMatrix &A, const vpRowVector &B);
1119 VP_DEPRECATED static void stackMatrices(const vpMatrix &A, const vpRowVector &B, vpMatrix &C);
1124 VP_DEPRECATED static vpMatrix stackMatrices(const vpColVector &A, const vpColVector &B);
1129 VP_DEPRECATED static void stackMatrices(const vpColVector &A, const vpColVector &B, vpColVector &C);
1130
1134 VP_DEPRECATED void setIdentity(const double &val = 1.0);
1135
1136 VP_DEPRECATED vpRowVector row(unsigned int i);
1137 VP_DEPRECATED vpColVector column(unsigned int j);
1138
1139 // Deprecated functions using GSL
1140#ifndef DOXYGEN_SHOULD_SKIP_THIS
1144 VP_DEPRECATED double detByLUGsl() const
1145 {
1146#if defined(VISP_HAVE_LAPACK)
1147 return detByLULapack();
1148#else
1149 throw(vpException(vpException::fatalError, "Undefined detByLULapack(). Install Lapack 3rd party"));
1150#endif
1151 }
1152
1156 VP_DEPRECATED vpMatrix inverseByLUGsl() const
1157 {
1158#if defined(VISP_HAVE_LAPACK)
1159 return inverseByLULapack();
1160#else
1161 throw(vpException(vpException::fatalError, "Undefined inverseByLULapack(). Install Lapack 3rd party"));
1162#endif
1163 }
1164
1168 VP_DEPRECATED vpMatrix inverseByCholeskyGsl() const
1169 {
1170#if defined(VISP_HAVE_LAPACK)
1171 return inverseByCholeskyLapack();
1172#else
1173 throw(vpException(vpException::fatalError, "Undefined inverseByCholeskyLapack(). Install Lapack 3rd party"));
1174#endif
1175 }
1176
1180 VP_DEPRECATED vpMatrix inverseByQRGsl() const
1181 {
1182#if defined(VISP_HAVE_LAPACK)
1183 return inverseByQRLapack();
1184#else
1185 throw(vpException(vpException::fatalError, "Undefined inverseByQRLapack(). Install Lapack 3rd party"));
1186#endif
1187 }
1188
1192 VP_DEPRECATED vpMatrix pseudoInverseGsl(double svThreshold = 1e-6) const
1193 {
1194#if defined(VISP_HAVE_LAPACK)
1195 return pseudoInverseLapack(svThreshold);
1196#else
1197 (void)svThreshold;
1198 throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
1199#endif
1200 }
1201
1205 VP_DEPRECATED unsigned int pseudoInverseGsl(vpMatrix &Ap, double svThreshold = 1e-6) const
1206 {
1207#if defined(VISP_HAVE_LAPACK)
1208 return pseudoInverseLapack(Ap, svThreshold);
1209#else
1210 (void)Ap;
1211 (void)svThreshold;
1212 throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
1213#endif
1214 }
1215
1219 VP_DEPRECATED unsigned int pseudoInverseGsl(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const
1220 {
1221#if defined(VISP_HAVE_LAPACK)
1222 return pseudoInverseLapack(Ap, sv, svThreshold);
1223#else
1224 (void)Ap;
1225 (void)sv;
1226 (void)svThreshold;
1227 throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
1228#endif
1229 }
1230
1234 VP_DEPRECATED unsigned int pseudoInverseGsl(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt,
1235 vpMatrix &kerAt) const
1236 {
1237#if defined(VISP_HAVE_LAPACK)
1238 return pseudoInverseLapack(Ap, sv, svThreshold, imA, imAt, kerAt);
1239#else
1240 (void)Ap;
1241 (void)sv;
1242 (void)svThreshold;
1243 (void)imA;
1244 (void)imAt;
1245 (void)kerAt;
1246 throw(vpException(vpException::fatalError, "Undefined pseudoInverseLapack(). Install Lapack 3rd party"));
1247#endif
1248 }
1249
1253 VP_DEPRECATED void svdGsl(vpColVector &w, vpMatrix &V)
1254 {
1255#if defined(VISP_HAVE_LAPACK)
1256 svdLapack(w, V);
1257#else
1258 (void)w;
1259 (void)V;
1260 throw(vpException(vpException::fatalError, "Undefined svdLapack(). Install Lapack 3rd party"));
1261#endif
1262 }
1263
1264#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS
1266#endif
1267
1268private:
1269 static unsigned int m_lapack_min_size;
1270 static const unsigned int m_lapack_min_size_default;
1271
1272#if defined(VISP_HAVE_LAPACK)
1273 static void blas_dgemm(char trans_a, char trans_b, unsigned int M_, unsigned int N_, unsigned int K_, double alpha,
1274 double *a_data, unsigned int lda_, double *b_data, unsigned int ldb_, double beta,
1275 double *c_data, unsigned int ldc_);
1276 static void blas_dgemv(char trans, unsigned int M_, unsigned int N_, double alpha, double *a_data, unsigned int lda_,
1277 double *x_data, int incx_, double beta, double *y_data, int incy_);
1278 static void blas_dsyev(char jobz, char uplo, unsigned int n_, double *a_data, unsigned int lda_, double *w_data,
1279 double *work_data, int lwork_, int &info_);
1280
1281 unsigned int qrPivotLapack(vpMatrix &Q, vpMatrix &R, vpMatrix &P, bool full, bool squareR,
1282 double tol) const;
1283
1284#ifdef VISP_HAVE_GSL
1285 unsigned int qrPivotLapackGSL(vpMatrix &Q, vpMatrix &R, vpMatrix &P, bool full, bool squareR,
1286 double tol) const;
1287#endif
1288#endif
1289
1290 static void computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS, const vpMatrix &Ls,
1291 vpMatrix &Js, vpColVector &deltaP);
1292};
1293
1295#if defined(VISP_USE_MSVC) && defined(visp_EXPORTS)
1296const __declspec(selectany) unsigned int vpMatrix::m_lapack_min_size_default = 0;
1297__declspec(selectany) unsigned int vpMatrix::m_lapack_min_size = vpMatrix::m_lapack_min_size_default;
1298#endif
1299
1300#ifndef DOXYGEN_SHOULD_SKIP_THIS
1301VISP_EXPORT
1302#endif
1303vpMatrix operator*(const double &x, const vpMatrix &A);
1304
1305END_VISP_NAMESPACE
1306#endif
Implementation of a generic 2D array used as base class for matrices and vectors.
Definition vpArray2D.h:146
unsigned int getCols() const
Definition vpArray2D.h:423
static bool loadYAML(const std::string &filename, vpArray2D< Type > &A, char *header=nullptr)
Definition vpArray2D.h:874
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition vpArray2D.h:615
void insert(const vpArray2D< Type > &A, unsigned int r, unsigned int c)
Definition vpArray2D.h:586
static bool saveYAML(const std::string &filename, const vpArray2D< Type > &A, const char *header="")
Definition vpArray2D.h:1061
static vpArray2D< Type > view(const vpArray2D< Type > &A)
Creates a view of the Matrix A. A view shares the same underlying memory as the original array....
Definition vpArray2D.h:324
unsigned int rowNum
Definition vpArray2D.h:1201
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition vpArray2D.h:705
static vpArray2D< Type > conv2(const vpArray2D< Type > &M, const vpArray2D< Type > &kernel, const std::string &mode)
Definition vpArray2D.h:1284
unsigned int dsize
Definition vpArray2D.h:1207
static bool load(const std::string &filename, vpArray2D< Type > &A, bool binary=false, char *header=nullptr)
Definition vpArray2D.h:760
vpArray2D< Type > t() const
Compute the transpose of the array.
Definition vpArray2D.h:1273
unsigned int getRows() const
Definition vpArray2D.h:433
vpArray2D< Type > hadamard(const vpArray2D< Type > &m) const
Definition vpArray2D.h:1257
static bool save(const std::string &filename, const vpArray2D< Type > &A, bool binary=false, const char *header="")
Definition vpArray2D.h:965
unsigned int colNum
Definition vpArray2D.h:1203
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ fatalError
Fatal error.
Definition vpException.h:72
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:175
static void setLapackMatrixMinSize(unsigned int min_size)
Definition vpMatrix.h:290
int pseudoInverseOpenCV(vpMatrix &Ap, int rank_in) const
void svdLapack(vpColVector &w, vpMatrix &V)
vpMatrix(unsigned int r, unsigned int c)
Definition vpMatrix.h:199
vpColVector eigenValues() const
vpMatrix(unsigned int r, unsigned int c, double val)
Definition vpMatrix.h:208
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
std::ostream & cppPrint(std::ostream &os, const std::string &matrixName="A", bool octet=false) const
double cond(double svThreshold=1e-6) const
static unsigned int getLapackMatrixMinSize()
Definition vpMatrix.h:276
VP_DEPRECATED void stackMatrices(const vpMatrix &A)
Definition vpMatrix.h:1099
vpMatrix pseudoInverseEigen3(double svThreshold=1e-6) const
unsigned int qr(vpMatrix &Q, vpMatrix &R, bool full=false, bool squareR=false, double tol=1e-6) const
unsigned int pseudoInverseOpenCV(vpMatrix &Ap, double svThreshold=1e-6) const
void printSize() const
Definition vpMatrix.h:670
unsigned int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const
VP_EXPLICIT vpMatrix(const vpArray2D< double > &A)
Definition vpMatrix.h:223
int print(std::ostream &s, unsigned int length, const std::string &intro="") const
Definition vpMatrix.cpp:836
int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, int rank_in) const
std::ostream & maplePrint(std::ostream &os) const
unsigned int kernel(vpMatrix &kerAt, double svThreshold=1e-6) const
static bool loadMatrix(const std::string &filename, vpArray2D< double > &M, bool binary=false, char *header=nullptr)
Definition vpMatrix.h:841
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
vpMatrix dampedInverse(const double &ratioOfMaxSvd=1e-4) const
void stack(const vpMatrix &A)
unsigned int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold=1e-6) const
static VP_DEPRECATED vpMatrix stackMatrices(const vpMatrix &A, const vpMatrix &B)
Definition vpMatrix.h:1104
static VP_DEPRECATED void stackMatrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
Definition vpMatrix.h:1109
void solveBySVD(const vpColVector &B, vpColVector &x) const
int pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, int rank_in) const
void svd(vpColVector &w, vpMatrix &V)
unsigned int pseudoInverseEigen3(vpMatrix &Ap, double svThreshold=1e-6) const
void svdOpenCV(vpColVector &w, vpMatrix &V)
unsigned int qrPivot(vpMatrix &Q, vpMatrix &R, vpMatrix &P, bool full=false, bool squareR=false, double tol=1e-6) const
unsigned int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold=1e-6) const
vpMatrix pseudoInverseLapack(int rank_in) const
double inducedL2Norm() const
unsigned int pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const
vpMatrix pseudoInverseEigen3(int rank_in) const
double infinityNorm() const
double frobeniusNorm() 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
void solveByQR(const vpColVector &b, vpColVector &x) const
vpMatrix pseudoInverseLapack(double svThreshold=1e-6) const
vpMatrix(const vpMatrix &A)
Definition vpMatrix.h:224
void clear()
Definition vpMatrix.h:247
int pseudoInverseEigen3(vpMatrix &Ap, int rank_in) const
VP_DEPRECATED void init()
Definition vpMatrix.h:1094
static bool saveMatrixYAML(const std::string &filename, const vpArray2D< double > &M, const char *header="")
Definition vpMatrix.h:1077
void svdEigen3(vpColVector &w, vpMatrix &V)
unsigned int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold=1e-6) const
static bool loadMatrixYAML(const std::string &filename, vpArray2D< double > &M, char *header=nullptr)
Definition vpMatrix.h:920
@ LU_DECOMPOSITION
Definition vpMatrix.h:183
static bool saveMatrix(const std::string &filename, const vpArray2D< double > &M, bool binary=false, const char *header="")
Definition vpMatrix.h:997
unsigned int pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const
std::ostream & csvPrint(std::ostream &os) const
unsigned int nullSpace(vpMatrix &kerA, double svThreshold=1e-6) const
std::ostream & matlabPrint(std::ostream &os) const
Definition vpMatrix.cpp:959
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.