Visual Servoing Platform  version 3.6.1 under development (2024-04-27)
vpMatrix Class Reference

#include <visp3/core/vpMatrix.h>

+ Inheritance diagram for vpMatrix:

Public Types

enum  vpDetMethod { LU_DECOMPOSITION }
 

Public Member Functions

 vpMatrix ()
 
 vpMatrix (unsigned int r, unsigned int c)
 
 vpMatrix (unsigned int r, unsigned int c, double val)
 
 vpMatrix (const vpMatrix &M, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols)
 
 vpMatrix (const vpArray2D< double > &A)
 
 vpMatrix (const vpMatrix &A)
 
 vpMatrix (vpMatrix &&A)
 
 vpMatrix (const std::initializer_list< double > &list)
 
 vpMatrix (unsigned int nrows, unsigned int ncols, const std::initializer_list< double > &list)
 
 vpMatrix (const std::initializer_list< std::initializer_list< double > > &lists)
 
void clear ()
 
Setting a diagonal matrix <br>
void diag (const double &val=1.0)
 
void diag (const vpColVector &A)
 
void eye ()
 
void eye (unsigned int n)
 
void eye (unsigned int m, unsigned int n)
 
Assignment operators
vpMatrixoperator<< (double *)
 
vpMatrixoperator<< (double val)
 
vpMatrixoperator, (double val)
 
vpMatrixoperator= (const vpArray2D< double > &A)
 
vpMatrixoperator= (const vpMatrix &A)
 
vpMatrixoperator= (vpMatrix &&A)
 
vpMatrixoperator= (const std::initializer_list< double > &list)
 
vpMatrixoperator= (const std::initializer_list< std::initializer_list< double > > &lists)
 
vpMatrixoperator= (double x)
 
Stacking <br>
void stack (const vpMatrix &A)
 
void stack (const vpRowVector &r)
 
void stack (const vpColVector &c)
 
void stackColumns (vpColVector &out)
 
vpColVector stackColumns ()
 
void stackRows (vpRowVector &out)
 
vpRowVector stackRows ()
 
Matrix insertion
void insert (const vpMatrix &A, unsigned int r, unsigned int c)
 
Columns, rows, sub-matrices extraction
vpMatrix extract (unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols) const
 
vpColVector getCol (unsigned int j) const
 
vpColVector getCol (unsigned int j, unsigned int i_begin, unsigned int size) const
 
vpRowVector getRow (unsigned int i) const
 
vpRowVector getRow (unsigned int i, unsigned int j_begin, unsigned int size) const
 
vpColVector getDiag () const
 
void init (const vpMatrix &M, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols)
 
Matrix operations <br>
double det (vpDetMethod method=LU_DECOMPOSITION) const
 
double detByLU () const
 
double detByLUEigen3 () const
 
double detByLULapack () const
 
double detByLUOpenCV () const
 
vpMatrix expm () const
 
vpMatrixoperator+= (const vpMatrix &B)
 
vpMatrixoperator-= (const vpMatrix &B)
 
vpMatrix operator* (const vpMatrix &B) const
 
vpMatrix operator* (const vpRotationMatrix &R) const
 
vpMatrix operator* (const vpHomogeneousMatrix &R) const
 
vpMatrix operator* (const vpVelocityTwistMatrix &V) const
 
vpMatrix operator* (const vpForceTwistMatrix &V) const
 
vpTranslationVector operator* (const vpTranslationVector &tv) const
 
vpColVector operator* (const vpColVector &v) const
 
vpMatrix operator+ (const vpMatrix &B) const
 
vpMatrix operator- (const vpMatrix &B) const
 
vpMatrix operator- () const
 
vpMatrixoperator+= (double x)
 
vpMatrixoperator-= (double x)
 
vpMatrixoperator*= (double x)
 
vpMatrixoperator/= (double x)
 
vpMatrix operator* (double x) const
 
vpMatrix operator/ (double x) const
 
double sum () const
 
double sumSquare () const
 
Hadamard product <br>
vpMatrix hadamard (const vpMatrix &m) const
 
Kronecker product <br>
void kron (const vpMatrix &m1, vpMatrix &out) const
 
vpMatrix kron (const vpMatrix &m1) const
 
Transpose <br>
vpMatrix t () const
 
vpMatrix transpose () const
 
void transpose (vpMatrix &At) const
 
vpMatrix AAt () const
 
void AAt (vpMatrix &B) const
 
vpMatrix AtA () const
 
void AtA (vpMatrix &B) const
 
Matrix inversion <br>
vpMatrix inverseByLU () const
 
vpMatrix inverseByLUEigen3 () const
 
vpMatrix inverseByLULapack () const
 
vpMatrix inverseByLUOpenCV () const
 
vpMatrix inverseByCholesky () const
 
vpMatrix inverseByCholeskyLapack () const
 
vpMatrix inverseByCholeskyOpenCV () const
 
vpMatrix inverseByQR () const
 
vpMatrix inverseByQRLapack () const
 
vpMatrix inverseTriangular (bool upper=true) const
 
vpMatrix pseudoInverse (double svThreshold=1e-6) const
 
unsigned int pseudoInverse (vpMatrix &Ap, double svThreshold=1e-6) const
 
unsigned int pseudoInverse (vpMatrix &Ap, vpColVector &sv, double svThreshold=1e-6) const
 
unsigned int pseudoInverse (vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt) const
 
unsigned int pseudoInverse (vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const
 
vpMatrix pseudoInverse (int rank_in) const
 
int pseudoInverse (vpMatrix &Ap, int rank_in) const
 
int pseudoInverse (vpMatrix &Ap, vpColVector &sv, int rank_in) const
 
int pseudoInverse (vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt) const
 
int pseudoInverse (vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const
 
vpMatrix pseudoInverseLapack (double svThreshold=1e-6) const
 
unsigned int pseudoInverseLapack (vpMatrix &Ap, double svThreshold=1e-6) const
 
unsigned int pseudoInverseLapack (vpMatrix &Ap, vpColVector &sv, double svThreshold=1e-6) const
 
unsigned int pseudoInverseLapack (vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const
 
vpMatrix pseudoInverseLapack (int rank_in) const
 
int pseudoInverseLapack (vpMatrix &Ap, int rank_in) const
 
int pseudoInverseLapack (vpMatrix &Ap, vpColVector &sv, int rank_in) const
 
int pseudoInverseLapack (vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const
 
vpMatrix pseudoInverseEigen3 (double svThreshold=1e-6) const
 
unsigned int pseudoInverseEigen3 (vpMatrix &Ap, double svThreshold=1e-6) const
 
unsigned int pseudoInverseEigen3 (vpMatrix &Ap, vpColVector &sv, double svThreshold=1e-6) const
 
unsigned int pseudoInverseEigen3 (vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const
 
vpMatrix pseudoInverseEigen3 (int rank_in) const
 
int pseudoInverseEigen3 (vpMatrix &Ap, int rank_in) const
 
int pseudoInverseEigen3 (vpMatrix &Ap, vpColVector &sv, int rank_in) const
 
int pseudoInverseEigen3 (vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const
 
vpMatrix pseudoInverseOpenCV (double svThreshold=1e-6) const
 
unsigned int pseudoInverseOpenCV (vpMatrix &Ap, double svThreshold=1e-6) const
 
unsigned int pseudoInverseOpenCV (vpMatrix &Ap, vpColVector &sv, double svThreshold=1e-6) const
 
unsigned int pseudoInverseOpenCV (vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const
 
vpMatrix pseudoInverseOpenCV (int rank_in) const
 
int pseudoInverseOpenCV (vpMatrix &Ap, int rank_in) const
 
int pseudoInverseOpenCV (vpMatrix &Ap, vpColVector &sv, int rank_in) const
 
int pseudoInverseOpenCV (vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const
 
SVD decomposition <br>
double cond (double svThreshold=1e-6) const
 
unsigned int kernel (vpMatrix &kerAt, double svThreshold=1e-6) const
 
unsigned int nullSpace (vpMatrix &kerA, double svThreshold=1e-6) const
 
unsigned int nullSpace (vpMatrix &kerA, int dim) const
 
void solveBySVD (const vpColVector &B, vpColVector &x) const
 
vpColVector solveBySVD (const vpColVector &B) const
 
void svd (vpColVector &w, vpMatrix &V)
 
void svdEigen3 (vpColVector &w, vpMatrix &V)
 
void svdLapack (vpColVector &w, vpMatrix &V)
 
void svdOpenCV (vpColVector &w, vpMatrix &V)
 
QR decomposition <br>
unsigned int qr (vpMatrix &Q, vpMatrix &R, bool full=false, bool squareR=false, double tol=1e-6) const
 
unsigned int qrPivot (vpMatrix &Q, vpMatrix &R, vpMatrix &P, bool full=false, bool squareR=false, double tol=1e-6) const
 
void solveByQR (const vpColVector &b, vpColVector &x) const
 
vpColVector solveByQR (const vpColVector &b) const
 
Eigen values <br>
vpColVector eigenValues () const
 
void eigenValues (vpColVector &evalue, vpMatrix &evector) const
 
Norms <br>
double frobeniusNorm () const
 
double inducedL2Norm () const
 
double infinityNorm () const
 
Printing <br>
std::ostream & cppPrint (std::ostream &os, const std::string &matrixName="A", bool octet=false) const
 
std::ostream & csvPrint (std::ostream &os) const
 
std::ostream & maplePrint (std::ostream &os) const
 
std::ostream & matlabPrint (std::ostream &os) const
 
int print (std::ostream &s, unsigned int length, const std::string &intro="") const
 
void printSize () const
 
Inherited functionalities from vpArray2D
unsigned int getCols () const
 
double getMaxValue () const
 
double getMinValue () const
 
unsigned int getRows () const
 
unsigned int size () const
 
void resize (unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
 
void reshape (unsigned int nrows, unsigned int ncols)
 
void insert (const vpArray2D< double > &A, unsigned int r, unsigned int c)
 
bool operator== (const vpArray2D< double > &A) const
 
bool operator!= (const vpArray2D< double > &A) const
 
double * operator[] (unsigned int i)
 
double * operator[] (unsigned int i) const
 
vpArray2D< double > hadamard (const vpArray2D< double > &m) const
 

Static Public Member Functions

Linear algebra optimization <br>
static unsigned int getLapackMatrixMinSize ()
 
static void setLapackMatrixMinSize (unsigned int min_size)
 
Setting a diagonal matrix with Static Public Member Functions <br>
static void createDiagonalMatrix (const vpColVector &A, vpMatrix &DA)
 
Matrix insertion with Static Public Member Functions <br>
static vpMatrix insert (const vpMatrix &A, const vpMatrix &B, unsigned int r, unsigned int c)
 
static void insert (const vpMatrix &A, const vpMatrix &B, vpMatrix &C, unsigned int r, unsigned int c)
 
Stacking with Static Public Member Functions <br>
static vpMatrix juxtaposeMatrices (const vpMatrix &A, const vpMatrix &B)
 
static void juxtaposeMatrices (const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
 
static vpMatrix stack (const vpMatrix &A, const vpMatrix &B)
 
static vpMatrix stack (const vpMatrix &A, const vpRowVector &r)
 
static vpMatrix stack (const vpMatrix &A, const vpColVector &c)
 
static void stack (const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
 
static void stack (const vpMatrix &A, const vpRowVector &r, vpMatrix &C)
 
static void stack (const vpMatrix &A, const vpColVector &c, vpMatrix &C)
 
Matrix operations with Static Public Member Functions <br>
static void add2Matrices (const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
 
static void add2Matrices (const vpColVector &A, const vpColVector &B, vpColVector &C)
 
static void add2WeightedMatrices (const vpMatrix &A, const double &wA, const vpMatrix &B, const double &wB, vpMatrix &C)
 
static void computeHLM (const vpMatrix &H, const double &alpha, vpMatrix &HLM)
 
static void mult2Matrices (const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
 
static void mult2Matrices (const vpMatrix &A, const vpMatrix &B, vpRotationMatrix &C)
 
static void mult2Matrices (const vpMatrix &A, const vpMatrix &B, vpHomogeneousMatrix &C)
 
static void mult2Matrices (const vpMatrix &A, const vpColVector &B, vpColVector &C)
 
static void multMatrixVector (const vpMatrix &A, const vpColVector &v, vpColVector &w)
 
static void negateMatrix (const vpMatrix &A, vpMatrix &C)
 
static void sub2Matrices (const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
 
static void sub2Matrices (const vpColVector &A, const vpColVector &B, vpColVector &C)
 
Kronecker product with Static Public Member Functions <br>
static void kron (const vpMatrix &m1, const vpMatrix &m2, vpMatrix &out)
 
static vpMatrix kron (const vpMatrix &m1, const vpMatrix &m2)
 
Covariance computation with Static Public Member Functions <br>
static vpMatrix computeCovarianceMatrix (const vpMatrix &A, const vpColVector &x, const vpColVector &b)
 
static vpMatrix computeCovarianceMatrix (const vpMatrix &A, const vpColVector &x, const vpColVector &b, const vpMatrix &w)
 
static vpMatrix computeCovarianceMatrixVVS (const vpHomogeneousMatrix &cMo, const vpColVector &deltaS, const vpMatrix &Ls, const vpMatrix &W)
 
static vpMatrix computeCovarianceMatrixVVS (const vpHomogeneousMatrix &cMo, const vpColVector &deltaS, const vpMatrix &Ls)
 

Public Attributes

double * data
 

Protected Attributes

unsigned int rowNum
 
unsigned int colNum
 
double ** rowPtrs
 
unsigned int dsize
 

Related Functions

(Note that these are not member functions.)

vpMatrix operator* (const double &x, const vpMatrix &B)
 
void insert (const vpMatrix &A, const vpMatrix &B, vpMatrix &C, unsigned int r, unsigned int c)
 
enum  vpGEMMmethod
 
bool operator== (const vpArray2D< double > &A) const
 
bool operator== (const vpArray2D< float > &A) const
 
bool operator!= (const vpArray2D< double > &A) const
 
void vpGEMM (const vpArray2D< double > &A, const vpArray2D< double > &B, const double &alpha, const vpArray2D< double > &C, const double &beta, vpArray2D< double > &D, const unsigned int &ops=0)
 

Deprecated functions

vp_deprecated void init ()
 
vp_deprecated void stackMatrices (const vpMatrix &A)
 
vp_deprecated void setIdentity (const double &val=1.0)
 
vp_deprecated vpRowVector row (unsigned int i)
 
vp_deprecated vpColVector column (unsigned int j)
 
static vp_deprecated vpMatrix stackMatrices (const vpMatrix &A, const vpMatrix &B)
 
static vp_deprecated void stackMatrices (const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
 
static vp_deprecated vpMatrix stackMatrices (const vpMatrix &A, const vpRowVector &B)
 
static vp_deprecated void stackMatrices (const vpMatrix &A, const vpRowVector &B, vpMatrix &C)
 
static vp_deprecated vpMatrix stackMatrices (const vpColVector &A, const vpColVector &B)
 
static vp_deprecated void stackMatrices (const vpColVector &A, const vpColVector &B, vpColVector &C)
 

Matrix I/O with Static Public Member Functions <br>

vp_deprecated double euclideanNorm () const
 
static bool loadMatrix (const std::string &filename, vpArray2D< double > &M, bool binary=false, char *header=nullptr)
 
static bool loadMatrixYAML (const std::string &filename, vpArray2D< double > &M, char *header=nullptr)
 
static bool saveMatrix (const std::string &filename, const vpArray2D< double > &M, bool binary=false, const char *header="")
 
static bool saveMatrixYAML (const std::string &filename, const vpArray2D< double > &M, const char *header="")
 

Inherited I/O from vpArray2D with Static Public Member Functions

vpArray2D< double > insert (const vpArray2D< double > &A, const vpArray2D< double > &B, unsigned int r, unsigned int c)
 
static bool load (const std::string &filename, vpArray2D< double > &A, bool binary=false, char *header=nullptr)
 
static bool loadYAML (const std::string &filename, vpArray2D< double > &A, char *header=nullptr)
 
static bool save (const std::string &filename, const vpArray2D< double > &A, bool binary=false, const char *header="")
 
static bool saveYAML (const std::string &filename, const vpArray2D< double > &A, const char *header="")
 
static vpArray2D< double > conv2 (const vpArray2D< double > &M, const vpArray2D< double > &kernel, const std::string &mode)
 
static void conv2 (const vpArray2D< double > &M, const vpArray2D< double > &kernel, vpArray2D< double > &res, const std::string &mode)
 
static void insert (const vpArray2D< double > &A, const vpArray2D< double > &B, vpArray2D< double > &C, unsigned int r, unsigned int c)
 

Detailed Description

Implementation of a matrix and operations on matrices.

This class needs one of the following third-party to compute matrix inverse, pseudo-inverse, singular value decomposition, determinant:

  • If Lapack is installed and detected by ViSP, this 3rd party is used by vpMatrix. Installation instructions are provided here https://visp.inria.fr/3rd_lapack;
  • else if Eigen3 is installed and detected by ViSP, this 3rd party is used by vpMatrix. Installation instructions are provided here https://visp.inria.fr/3rd_eigen;
  • else if OpenCV is installed and detected by ViSP, this 3rd party is used, Installation instructions are provided here https://visp.inria.fr/3rd_opencv;
  • If none of these previous 3rd parties is installed, we use by default a Lapack built-in version.

vpMatrix class provides a data structure for the matrices as well as a set of operations on these matrices.

The vpMatrix class is derived from vpArray2D<double>.

The code below shows how to create a 2-by-3 matrix of doubles, set the element values and access them:

#include <visp3/code/vpMatrix.h
int main()
{
vpMatrix M(2, 3);
M[0][0] = -1; M[0][1] = -2; M[0][2] = -3;
M[1][0] = 4; M[1][1] = 5.5; M[1][2] = 6.0f;
std::cout << "M:" << std::endl;
for (unsigned int i = 0; i < M.getRows(); ++i) {
for (unsigned int j = 0; j < M.getCols(); ++j) {
std::cout << M[i][j] << " ";
}
std::cout << std::endl;
}
}

Once build, this previous code produces the following output:

M:
-1 -2 -3
4 5.5 6

If ViSP is build with c++11 enabled, you can do the same using:

#include <visp3/code/vpMatrix.h
int main()
{
vpMatrix M( {-1, -2, -3}, {4, 5.5, 6.0f} );
std::cout << "M:\n" << M << std::endl;
}

You can also create and initialize a matrix this way:

#include <visp3/code/vpMatrix.h
int main()
{
vpMatrix M(2, 3, {-1, -2, -3, 4, 5.5, 6.0f} );
}

The Matrix could also be initialized using operator=(const std::initializer_list< std::initializer_list< double > > &)

int main()
{
M = { {-1, -2, -3}, {4, 5.5, 6.0f} };
}
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:146
See also
vpArray2D, vpRowVector, vpColVector, vpHomogeneousMatrix, vpRotationMatrix, vpVelocityTwistMatrix, vpForceTwistMatrix, vpHomography
Examples
manServo4PointsDisplay.cpp, manSimu4Dots.cpp, manSimu4Points.cpp, mbot-apriltag-2D-half-vs.cpp, mbot-apriltag-ibvs.cpp, mbot-apriltag-pbvs.cpp, photometricVisualServoingWithoutVpServo.cpp, quadprog.cpp, quadprog_eq.cpp, servoAfma4Point2DArtVelocity.cpp, servoAfma4Point2DCamVelocityKalman.cpp, servoAfma6FourPoints2DArtVelocity.cpp, servoAfma6Point2DArtVelocity.cpp, servoAfma6Points2DCamVelocityEyeToHand.cpp, servoBebop2.cpp, servoBiclopsPoint2DArtVelocity.cpp, servoFlirPtuIBVS.cpp, servoMomentImage.cpp, servoPioneerPanSegment3D.cpp, servoPioneerPoint2DDepth.cpp, servoPioneerPoint2DDepthWithoutVpServo.cpp, servoPololuPtuPoint2DJointVelocity.cpp, servoPtu46Point2DArtVelocity.cpp, servoSimu3D_cMcd_CamVelocityWithoutVpServo.cpp, servoSimu4Points.cpp, servoSimuCylinder.cpp, servoSimuFourPoints2DCamVelocity.cpp, servoSimuFourPoints2DCamVelocityDisplay.cpp, servoSimuFourPoints2DPolarCamVelocityDisplay.cpp, servoSimuPoint2DCamVelocity2.cpp, servoSimuPoint2DCamVelocity3.cpp, servoSimuPoint2DhalfCamVelocity2.cpp, servoSimuSphere.cpp, servoViper650FourPoints2DArtVelocityLs_cur.cpp, servoViper850FourPoints2DArtVelocityLs_cur.cpp, servoViper850FourPoints2DArtVelocityLs_des.cpp, servoViper850Point2DArtVelocity-jointAvoidance-basic.cpp, servoViper850Point2DArtVelocity-jointAvoidance-gpa.cpp, servoViper850Point2DArtVelocity-jointAvoidance-large.cpp, servoViper850Point2DArtVelocity.cpp, servoViper850Point2DCamVelocityKalman.cpp, simulateFourPoints2DCartesianCamVelocity.cpp, simulateFourPoints2DPolarCamVelocity.cpp, testColVector.cpp, testEigenConversion.cpp, testFeature.cpp, testFrankaCartVelocity-2.cpp, testFrankaGetPose.cpp, testImageFilter.cpp, testImageWarp.cpp, testMatrix.cpp, testMatrixConditionNumber.cpp, testMatrixConvolution.cpp, testMatrixDeterminant.cpp, testMatrixException.cpp, testMatrixInitialization.cpp, testMatrixInverse.cpp, testMatrixPseudoInverse.cpp, testPoseFeatures.cpp, testRobotViper650-frames.cpp, testRobotViper850-frames.cpp, testRowVector.cpp, testSvd.cpp, testTranslationVector.cpp, tutorial-bridge-opencv-matrix.cpp, tutorial-flir-ptu-ibvs.cpp, tutorial-ibvs-4pts-json.cpp, tutorial-image-filter.cpp, tutorial-matlab.cpp, tutorial-simu-pioneer-continuous-gain-adaptive.cpp, tutorial-simu-pioneer-continuous-gain-constant.cpp, tutorial-simu-pioneer-pan.cpp, and tutorial-simu-pioneer.cpp.

Definition at line 145 of file vpMatrix.h.

Member Enumeration Documentation

◆ vpDetMethod

Method used to compute the determinant of a square matrix.

See also
det()
Enumerator
LU_DECOMPOSITION 

LU decomposition method.

Definition at line 152 of file vpMatrix.h.

Constructor & Destructor Documentation

◆ vpMatrix() [1/10]

vpMatrix::vpMatrix ( )
inline

Basic constructor of a matrix of double. Number of columns and rows are zero.

Definition at line 162 of file vpMatrix.h.

Referenced by insert().

◆ vpMatrix() [2/10]

vpMatrix::vpMatrix ( unsigned int  r,
unsigned int  c 
)
inline

Constructor that initialize a matrix of double with 0.

Parameters
r: Matrix number of rows.
c: Matrix number of columns.

Definition at line 170 of file vpMatrix.h.

◆ vpMatrix() [3/10]

vpMatrix::vpMatrix ( unsigned int  r,
unsigned int  c,
double  val 
)
inline

Constructor that initialize a matrix of double with val.

Parameters
r: Matrix number of rows.
c: Matrix number of columns.
val: Each element of the matrix is set to val.

Definition at line 179 of file vpMatrix.h.

◆ vpMatrix() [4/10]

vpMatrix::vpMatrix ( const vpMatrix M,
unsigned int  r,
unsigned int  c,
unsigned int  nrows,
unsigned int  ncols 
)

Construct a matrix as a sub-matrix of the input matrix M.

See also
init(const vpMatrix &M, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols)

Definition at line 190 of file vpMatrix.cpp.

References vpArray2D< Type >::colNum, vpException::dimensionError, init(), and vpArray2D< Type >::rowNum.

◆ vpMatrix() [5/10]

vpMatrix::vpMatrix ( const vpArray2D< double > &  A)
inline

Create a matrix from a 2D array that could be one of the following container that inherit from vpArray2D such as vpMatrix, vpRotationMatrix, vpHomogeneousMatrix, vpPoseVector, vpColVector, vpRowVector...

The following example shows how to create a matrix from an homogeneous matrix:

vpMatrix M(R);
Implementation of a rotation matrix and operations on such kind of matrices.

Definition at line 194 of file vpMatrix.h.

◆ vpMatrix() [6/10]

vpMatrix::vpMatrix ( const vpMatrix A)
inline

Definition at line 196 of file vpMatrix.h.

◆ vpMatrix() [7/10]

◆ vpMatrix() [8/10]

vpMatrix::vpMatrix ( const std::initializer_list< double > &  list)
explicit

Construct a matrix from a list of double values.

Parameters
list: List of double.

The following code shows how to use this constructor to initialize a 2-by-3 matrix using reshape() function:

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix M( {-1, -2, -3, 4, 5.5, 6.0f} );
M.reshape(2, 3);
std::cout << "M:\n" << M << std::endl;
}
void reshape(unsigned int nrows, unsigned int ncols)
Definition: vpArray2D.h:443

It produces the following output:

M:
-1 -2 -3
4 5.5 6

Definition at line 243 of file vpMatrix.cpp.

◆ vpMatrix() [9/10]

vpMatrix::vpMatrix ( unsigned int  nrows,
unsigned int  ncols,
const std::initializer_list< double > &  list 
)
explicit

Construct a matrix from a list of double values.

Parameters
ncols,nrows: Matrix size.
list: List of double.

The following code shows how to use this constructor to initialize a 2-by-3 matrix:

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix M(2, 3, {-1, -2, -3, 4, 5.5, 6});
std::cout << "M:\n" << M << std::endl;
}

It produces the following output:

M:
-1 -2 -3
4 5.5 6

Definition at line 267 of file vpMatrix.cpp.

◆ vpMatrix() [10/10]

vpMatrix::vpMatrix ( const std::initializer_list< std::initializer_list< double > > &  lists)
explicit

Construct a matrix from a list of double values.

Parameters
lists: List of double. The following code shows how to use this constructor to initialize a 2-by-3 matrix function:
#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix M( { {-1, -2, -3}, {4, 5.5, 6} } );
std::cout << "M:\n" << M << std::endl;
}
It produces the following output:
M:
-1 -2 -3
4 5.5 6

Definition at line 291 of file vpMatrix.cpp.

Member Function Documentation

◆ AAt() [1/2]

vpMatrix vpMatrix::AAt ( ) const

Computes the $AA^T$ operation $B = A*A^T$

Returns
$A*A^T$
See also
AAt(vpMatrix &) const

Definition at line 517 of file vpMatrix.cpp.

Referenced by vpServo::computeControlLaw(), and vpServo::computeProjectionOperators().

◆ AAt() [2/2]

void vpMatrix::AAt ( vpMatrix B) const

Compute the AAt operation such as $B = A*A^T$.

The result is placed in the parameter B and not returned.

A new matrix won't be allocated for every use of the function. This results in a speed gain if used many times with the same result matrix size.

See also
AAt()

Definition at line 537 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, vpArray2D< Type >::colNum, vpArray2D< Type >::data, vpArray2D< double >::data, vpArray2D< Type >::resize(), vpArray2D< double >::rowNum, vpArray2D< Type >::rowNum, and vpArray2D< double >::rowPtrs.

◆ add2Matrices() [1/2]

void vpMatrix::add2Matrices ( const vpColVector A,
const vpColVector B,
vpColVector C 
)
static
Warning
This function is provided for compat with previous releases. You should rather use the functionalities provided in vpColVector class.

Operation C = A + B.

The result is placed in the third parameter C and not returned. A new vector won't be allocated for every use of the function (speed gain if used many times with the same result matrix size).

See also
vpColVector::operator+()

Definition at line 1455 of file vpMatrix.cpp.

References vpArray2D< Type >::colNum, vpException::dimensionError, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), vpColVector::resize(), vpArray2D< Type >::rowNum, and vpArray2D< Type >::rowPtrs.

◆ add2Matrices() [2/2]

void vpMatrix::add2Matrices ( const vpMatrix A,
const vpMatrix B,
vpMatrix C 
)
static

Operation C = A + B.

The result is placed in the third parameter C and not returned. A new matrix won't be allocated for every use of the function (speed gain if used many times with the same result matrix size).

See also
operator+()

Definition at line 1421 of file vpMatrix.cpp.

References vpArray2D< Type >::colNum, vpException::dimensionError, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), vpArray2D< Type >::resize(), vpArray2D< Type >::rowNum, and vpArray2D< Type >::rowPtrs.

Referenced by operator+().

◆ add2WeightedMatrices()

void vpMatrix::add2WeightedMatrices ( const vpMatrix A,
const double &  wA,
const vpMatrix B,
const double &  wB,
vpMatrix C 
)
static

Operation C = A*wA + B*wB

The result is placed in the third parameter C and not returned. A new matrix won't be allocated for every use of the function (Speed gain if used many times with the same result matrix size).

See also
operator+()

Definition at line 1389 of file vpMatrix.cpp.

References vpArray2D< Type >::colNum, vpException::dimensionError, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), vpArray2D< Type >::resize(), vpArray2D< Type >::rowNum, and vpArray2D< Type >::rowPtrs.

◆ AtA() [1/2]

◆ AtA() [2/2]

void vpMatrix::AtA ( vpMatrix B) const

Compute the AtA operation such as $B = A^T*A$.

The result is placed in the parameter B and not returned.

A new matrix won't be allocated for every use of the function. This results in a speed gain if used many times with the same result matrix size.

See also
AtA()

Definition at line 593 of file vpMatrix.cpp.

References vpArray2D< Type >::colNum, vpArray2D< double >::colNum, vpArray2D< Type >::data, vpArray2D< double >::data, vpArray2D< Type >::resize(), vpArray2D< double >::rowNum, and vpArray2D< Type >::rowNum.

◆ clear()

void vpMatrix::clear ( )
inline

Removes all elements from the matrix (which are destroyed), leaving the container with a size of 0.

Definition at line 209 of file vpMatrix.h.

◆ column()

vpColVector vpMatrix::column ( unsigned int  j)
Deprecated:
This method is deprecated. You should rather use getCol(). More precisely, the following code:
unsigned int column_index = ...;
... = L.column(column_index);

should be replaced with:

... = L.getCol(column_index - 1);
Warning
Notice column(1) is the 0-th column. This function returns the j-th columns of the matrix.
Parameters
j: Index of the column to extract noting that column index start at 1 to get the first column.

Definition at line 6680 of file vpMatrix.cpp.

References vpArray2D< double >::getRows().

◆ computeCovarianceMatrix() [1/2]

vpMatrix vpMatrix::computeCovarianceMatrix ( const vpMatrix A,
const vpColVector x,
const vpColVector b 
)
static

Compute the covariance matrix of the parameters x from a least squares minimization defined as: Ax = b

Parameters
A: Matrix A from Ax = b.
x: Vector x from Ax = b corresponding to the parameters to estimate.
b: Vector b from Ax = b.

Definition at line 59 of file vpMatrix_covariance.cpp.

References vpException::divideByZeroError, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), pseudoInverse(), and t().

Referenced by computeCovarianceMatrixVVS(), and vpPose::poseVirtualVSrobust().

◆ computeCovarianceMatrix() [2/2]

vpMatrix vpMatrix::computeCovarianceMatrix ( const vpMatrix A,
const vpColVector x,
const vpColVector b,
const vpMatrix W 
)
static

Compute the covariance matrix of the parameters x from a least squares minimization defined as: WAx = Wb

Parameters
A: Matrix A from WAx = Wb.
x: Vector x from WAx = Wb corresponding to the parameters to estimate.
b: Vector b from WAx = Wb.
W: Diagonal weigths matrix from WAx = Wb.

Definition at line 92 of file vpMatrix_covariance.cpp.

References vpException::divideByZeroError, vpArray2D< Type >::getCols(), pseudoInverse(), and t().

◆ computeCovarianceMatrixVVS() [1/2]

vpMatrix vpMatrix::computeCovarianceMatrixVVS ( const vpHomogeneousMatrix cMo,
const vpColVector deltaS,
const vpMatrix Ls 
)
static

Compute the covariance matrix of an image-based virtual visual servoing. This assumes the optimization has been done via v = Ls.pseudoInverse() * DeltaS.

Parameters
cMo: Pose matrix that has been computed with the v.
deltaS: Error vector used in v = Ls.pseudoInverse() * DeltaS
Ls: interaction matrix used in v = Ls.pseudoInverse() * DeltaS

Definition at line 127 of file vpMatrix_covariance.cpp.

References computeCovarianceMatrix(), and computeCovarianceMatrixVVS().

◆ computeCovarianceMatrixVVS() [2/2]

vpMatrix vpMatrix::computeCovarianceMatrixVVS ( const vpHomogeneousMatrix cMo,
const vpColVector deltaS,
const vpMatrix Ls,
const vpMatrix W 
)
static

Compute the covariance matrix of an image-based virtual visual servoing. This assumes the optimization has been done via v = (W * Ls).pseudoInverse() W * DeltaS.

Parameters
cMo: Pose matrix that has been computed with the v.
deltaS: Error vector used in v = (W * Ls).pseudoInverse() * W * DeltaS.
Ls: interaction matrix used in v = (W * Ls).pseudoInverse() * W * DeltaS.
W: Weight matrix used in v = (W * Ls).pseudoInverse() * W * DeltaS.

Definition at line 152 of file vpMatrix_covariance.cpp.

References computeCovarianceMatrix().

Referenced by vpMbTracker::computeCovarianceMatrixVVS(), computeCovarianceMatrixVVS(), and vpPose::poseVirtualVS().

◆ computeHLM()

◆ cond()

double vpMatrix::cond ( double  svThreshold = 1e-6) const
Returns
The condition number, the ratio of the largest singular value of the matrix to the smallest.
Parameters
svThresholdThreshold used to test the singular values. If a singular value is lower than this threshold we consider that the matrix is not full rank.
Examples
testMatrixConditionNumber.cpp.

Definition at line 6430 of file vpMatrix.cpp.

References vpArray2D< double >::getCols(), vpArray2D< double >::getRows(), insert(), vpColVector::resize(), vpArray2D< Type >::resize(), and svd().

Referenced by vpTemplateTrackerMIESM::trackNoPyr(), vpTemplateTrackerMIForwardAdditional::trackNoPyr(), vpTemplateTrackerMIForwardCompositional::trackNoPyr(), and vpTemplateTrackerMIInverseCompositional::trackNoPyr().

◆ conv2() [1/2]

vpArray2D< double > vpArray2D< double >::conv2 ( const vpArray2D< Type > &  M,
const vpArray2D< Type > &  kernel,
const std::string &  mode 
)
staticinherited

Perform a 2D convolution similar to Matlab conv2 function: $ M \star kernel $.

Parameters
M: First matrix.
kernel: Second matrix.
mode: Convolution mode: "full" (default), "same", "valid".
Convolution mode: full, same, valid (image credit: Theano doc).
Note
This is a very basic implementation that does not use FFT.
Examples
testMatrixConvolution.cpp.

Definition at line 1029 of file vpArray2D.h.

◆ conv2() [2/2]

void vpArray2D< double >::conv2 ( const vpArray2D< Type > &  M,
const vpArray2D< Type > &  kernel,
vpArray2D< Type > &  res,
const std::string &  mode 
)
staticinherited

Perform a 2D convolution similar to Matlab conv2 function: $ M \star kernel $.

Parameters
M: First array.
kernel: Second array.
res: Result.
mode: Convolution mode: "full" (default), "same", "valid".
Convolution mode: full, same, valid (image credit: Theano doc).
Note
This is a very basic implementation that does not use FFT.

Definition at line 1043 of file vpArray2D.h.

◆ cppPrint()

std::ostream & vpMatrix::cppPrint ( std::ostream &  os,
const std::string &  matrixName = "A",
bool  octet = false 
) const

Print to be used as part of a C++ code later.

Parameters
os: the stream to be printed in.
matrixName: name of the matrix, "A" by default.
octet: if false, print using double, if true, print byte per byte each bytes of the double array.

The following code shows how to use this function:

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix M(2,3);
int cpt = 0;
for (unsigned int i=0; i<M.getRows(); i++)
for (unsigned int j=0; j<M.getCols(); j++)
M[i][j] = cpt++;
M.cppPrint(std::cout, "M");
}

It produces the following output that could be copy/paste in a C++ code:

vpMatrix M (2, 3);
M[0][0] = 0;
M[0][1] = 1;
M[0][2] = 2;
M[1][0] = 3;
M[1][1] = 4;
M[1][2] = 5;

Definition at line 5642 of file vpMatrix.cpp.

References vpArray2D< double >::getCols(), and vpArray2D< double >::getRows().

◆ createDiagonalMatrix()

void vpMatrix::createDiagonalMatrix ( const vpColVector A,
vpMatrix DA 
)
static

Create a diagonal matrix with the element of a vector $ DA_{ii} = A_i $.

Parameters
A: Vector which element will be put in the diagonal.
DA: Diagonal matrix DA[i][i] = A[i]
See also
diag()

Definition at line 929 of file vpMatrix.cpp.

References vpArray2D< Type >::getRows(), and vpArray2D< Type >::resize().

◆ csvPrint()

std::ostream & vpMatrix::csvPrint ( std::ostream &  os) const

Print/save a matrix in csv format.

The following code

#include <visp3/core/vpMatrix.h>
int main()
{
std::ofstream ofs("log.csv", std::ofstream::out);
vpMatrix M(2,3);
int cpt = 0;
for (unsigned int i=0; i<M.getRows(); i++)
for (unsigned int j=0; j<M.getCols(); j++)
M[i][j] = cpt++;
M.csvPrint(ofs);
ofs.close();
}

produces log.csv file that contains:

0, 1, 2
3, 4, 5

Definition at line 5591 of file vpMatrix.cpp.

References vpArray2D< double >::getCols(), and vpArray2D< double >::getRows().

◆ det()

double vpMatrix::det ( vpDetMethod  method = LU_DECOMPOSITION) const

Compute the determinant of a n-by-n matrix.

Parameters
method: Method used to compute the determinant. Default LU decomposition method is faster than the method based on Gaussian elimination.
Returns
Determinant of the matrix.
#include <iostream>
#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(3,3);
A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.;
A[1][0] = 1/3.; A[1][1] = 1/4.; A[1][2] = 1/5.;
A[2][0] = 1/6.; A[2][1] = 1/7.; A[2][2] = 1/8.;
std::cout << "Initial matrix: \n" << A << std::endl;
// Compute the determinant
std:: cout << "Determinant by default method : " << A.det() << std::endl;
std:: cout << "Determinant by LU decomposition : " << A.detByLU() << std::endl;
std:: cout << "Determinant by LU decomposition (Lapack): " << A.detByLULapack() << std::endl;
std:: cout << "Determinant by LU decomposition (OpenCV): " << A.detByLUOpenCV() << std::endl;
std:: cout << "Determinant by LU decomposition (Eigen3): " << A.detByLUEigen3() << std::endl;
}
Examples
testMatrixInverse.cpp.

Definition at line 6275 of file vpMatrix.cpp.

References detByLU(), and LU_DECOMPOSITION.

Referenced by vpHomogeneousMatrix::compute3d3dTransformation(), detByLULapack(), detByLUOpenCV(), vpTemplateTrackerTriangle::init(), inverseByLU(), and vpRotationMatrix::orthogonalize().

◆ detByLU()

double vpMatrix::detByLU ( ) const

Compute the determinant of a square matrix using the LU decomposition.

This function calls the first following function that is available:

If none of these previous 3rd parties is installed, we use by default detByLULapack() with a Lapack built-in version.

Returns
The determinant of the matrix if the matrix is square.
#include <iostream>
#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(3,3);
A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.;
A[1][0] = 1/3.; A[1][1] = 1/4.; A[1][2] = 1/5.;
A[2][0] = 1/6.; A[2][1] = 1/7.; A[2][2] = 1/8.;
std::cout << "Initial matrix: \n" << A << std::endl;
// Compute the determinant
std:: cout << "Determinant by default method : " << A.det() << std::endl;
std:: cout << "Determinant by LU decomposition : " << A.detByLU() << std::endl;
}
See also
detByLULapack(), detByLUEigen3(), detByLUOpenCV()

Definition at line 224 of file vpMatrix_lu.cpp.

References vpArray2D< double >::colNum, detByLUEigen3(), detByLULapack(), detByLUOpenCV(), vpException::fatalError, and vpArray2D< double >::rowNum.

Referenced by det().

◆ detByLUEigen3()

double vpMatrix::detByLUEigen3 ( ) const

Compute the determinant of a square matrix using the LU decomposition with Eigen3 3rd party.

Returns
The determinant of the matrix if the matrix is square.
#include <iostream>
#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(3,3);
A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.;
A[1][0] = 1/3.; A[1][1] = 1/4.; A[1][2] = 1/5.;
A[2][0] = 1/6.; A[2][1] = 1/7.; A[2][2] = 1/8.;
std::cout << "Initial matrix: \n" << A << std::endl;
// Compute the determinant
std:: cout << "Determinant by LU decomposition (Eigen3): " << A.detByLUEigen3() << std::endl;
}
See also
detByLU(), detByLUOpenCV(), detByLULapack()

Definition at line 615 of file vpMatrix_lu.cpp.

References vpArray2D< double >::colNum, vpArray2D< double >::data, vpException::fatalError, vpArray2D< double >::getCols(), vpArray2D< double >::getRows(), and vpArray2D< double >::rowNum.

Referenced by detByLU().

◆ detByLULapack()

double vpMatrix::detByLULapack ( ) const

Compute the determinant of a square matrix using the LU decomposition with Lapack 3rd party.

Returns
The determinant of the matrix if the matrix is square.
#include <iostream>
#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(3,3);
A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.;
A[1][0] = 1/3.; A[1][1] = 1/4.; A[1][2] = 1/5.;
A[2][0] = 1/6.; A[2][1] = 1/7.; A[2][2] = 1/8.;
std::cout << "Initial matrix: \n" << A << std::endl;
// Compute the determinant
std:: cout << "Determinant by LU decomposition (Lapack): " << A.detByLULapack() << std::endl;
}
See also
detByLU(), detByLUEigen3(), detByLUOpenCV()

Definition at line 379 of file vpMatrix_lu.cpp.

References vpArray2D< double >::colNum, vpArray2D< Type >::data, det(), vpException::fatalError, and vpArray2D< double >::rowNum.

Referenced by detByLU().

◆ detByLUOpenCV()

double vpMatrix::detByLUOpenCV ( ) const

Compute the determinant of a n-by-n matrix using the LU decomposition with OpenCV 3rd party.

Returns
Determinant of the matrix.
#include <iostream>
#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(3,3);
A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.;
A[1][0] = 1/3.; A[1][1] = 1/4.; A[1][2] = 1/5.;
A[2][0] = 1/6.; A[2][1] = 1/7.; A[2][2] = 1/8.;
std::cout << "Initial matrix: \n" << A << std::endl;
// Compute the determinant
std:: cout << "Determinant by LU decomposition (OpenCV): " << A.detByLUOpenCV() << std::endl;
}
See also
detByLU(), detByLUEigen3(), detByLULapack()

Definition at line 525 of file vpMatrix_lu.cpp.

References vpArray2D< double >::colNum, vpArray2D< double >::data, det(), vpException::fatalError, and vpArray2D< double >::rowNum.

Referenced by detByLU().

◆ diag() [1/2]

void vpMatrix::diag ( const double &  val = 1.0)

Set the matrix as a diagonal matrix where each element on the diagonal is set to val. Elements that are not on the diagonal are set to 0.

Parameters
val: Value to set.
See also
eye()
#include <iostream>
#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(3, 4);
A.diag(2);
std::cout << "A:\n" << A << std::endl;
}

Matrix A is now equal to:

2 0 0 0
0 2 0 0
0 0 2 0
Examples
testSvd.cpp.

Definition at line 910 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, and vpArray2D< double >::rowNum.

Referenced by getDiag().

◆ diag() [2/2]

void vpMatrix::diag ( const vpColVector A)

Create a diagonal matrix with the element of a vector.

Parameters
A: Vector which element will be put in the diagonal.
See also
createDiagonalMatrix()
#include <iostream>
#include <visp3/core/vpColVector.h>
#include <visp3/core/vpMatrix.h>
int main()
{
v[0] = 1;
v[1] = 2;
v[2] = 3;
A.diag(v);
std::cout << "A:\n" << A << std::endl;
}
Implementation of column vector and the associated operations.
Definition: vpColVector.h:163
void diag(const double &val=1.0)
Definition: vpMatrix.cpp:910

Matrix A is now equal to:

1 0 0
0 2 0
0 0 3

Definition at line 869 of file vpMatrix.cpp.

References vpArray2D< Type >::getRows(), and vpArray2D< double >::resize().

◆ eigenValues() [1/2]

vpColVector vpMatrix::eigenValues ( ) const

Compute the eigenvalues of a n-by-n real symmetric matrix using Lapack 3rd party.

Returns
The eigenvalues of a n-by-n real symmetric matrix, sorted in ascending order.
Exceptions
vpException::dimensionErrorIf the matrix is not square.
vpException::fatalErrorIf the matrix is not symmetric.
vpException::functionNotImplementedErrorIf the Lapack 3rd party is not detected.

Here an example:

#include <iostream>
#include <visp3/core/vpColVector.h>
#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(3,3); // A is a symmetric matrix
A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.;
A[1][0] = 1/2.; A[1][1] = 1/3.; A[1][2] = 1/4.;
A[2][0] = 1/3.; A[2][1] = 1/4.; A[2][2] = 1/5.;
std::cout << "Initial symmetric matrix: \n" << A << std::endl;
// Compute the eigen values
vpColVector evalue; // Eigenvalues
evalue = A.eigenValues();
std::cout << "Eigen values: \n" << evalue << std::endl;
}
See also
eigenValues(vpColVector &, vpMatrix &)

Definition at line 5836 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, vpArray2D< Type >::data, vpException::dimensionError, vpException::fatalError, vpException::functionNotImplementedError, vpColVector::resize(), vpArray2D< double >::rowNum, and t().

Referenced by vpQuadProg::fromCanonicalCost(), and vpMath::lineFitting().

◆ eigenValues() [2/2]

void vpMatrix::eigenValues ( vpColVector evalue,
vpMatrix evector 
) const

Compute the eigenvalues of a n-by-n real symmetric matrix using Lapack 3rd party.

Parameters
evalue: Eigenvalues of the matrix, sorted in ascending order.
evector: Corresponding eigenvectors of the matrix.
Exceptions
vpException::dimensionErrorIf the matrix is not square.
vpException::fatalErrorIf the matrix is not symmetric.
vpException::functionNotImplementedErrorIf Lapack 3rd party is not detected.

Here an example:

#include <iostream>
#include <visp3/core/vpColVector.h>
#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(4,4); // A is a symmetric matrix
A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[0][3] = 1/4.;
A[1][0] = 1/2.; A[1][1] = 1/3.; A[1][2] = 1/4.; A[1][3] = 1/5.;
A[2][0] = 1/3.; A[2][1] = 1/4.; A[2][2] = 1/5.; A[2][3] = 1/6.;
A[3][0] = 1/4.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.;
std::cout << "Initial symmetric matrix: \n" << A << std::endl;
vpColVector d; // Eigenvalues
vpMatrix V; // Eigenvectors
// Compute the eigenvalues and eigenvectors
A.eigenValues(d, V);
std::cout << "Eigen values: \n" << d << std::endl;
std::cout << "Eigen vectors: \n" << V << std::endl;
D.diag(d); // Eigenvalues are on the diagonal
std::cout << "D: " << D << std::endl;
// Verification: A * V = V * D
std::cout << "AV-VD = 0 ? \n" << (A*V) - (V*D) << std::endl;
}
vpColVector eigenValues() const
Definition: vpMatrix.cpp:5836
See also
eigenValues()

Definition at line 5957 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, vpArray2D< Type >::data, vpException::dimensionError, vpException::fatalError, vpException::functionNotImplementedError, vpColVector::resize(), vpArray2D< Type >::resize(), vpArray2D< double >::rowNum, and t().

◆ euclideanNorm()

double vpMatrix::euclideanNorm ( ) const
Deprecated:
This function is deprecated. You should rather use frobeniusNorm().

Compute and return the Euclidean norm (also called Frobenius norm) $||A|| = \sqrt{ \sum{A_{ij}^2}}$.

Returns
The Euclidean norm (also called Frobenius norm) if the matrix is initialized, 0 otherwise.
See also
frobeniusNorm(), infinityNorm(), inducedL2Norm()

Definition at line 6619 of file vpMatrix.cpp.

References frobeniusNorm().

◆ expm()

vpMatrix vpMatrix::expm ( ) const

Compute the exponential matrix of a square matrix.

Returns
Return the exponential matrix.

Definition at line 6293 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, vpArray2D< Type >::data, vpArray2D< double >::data, vpException::dimensionError, eye(), inverseByLU(), vpArray2D< Type >::resize(), vpArray2D< double >::rowNum, and sum().

Referenced by vpTemplateTrackerWarpHomographySL3::computeCoeff().

◆ extract()

vpMatrix vpMatrix::extract ( unsigned int  r,
unsigned int  c,
unsigned int  nrows,
unsigned int  ncols 
) const

Extract a sub matrix from a matrix M.

Parameters
r: row index in matrix M.
c: column index in matrix M.
nrows: Number of rows of the matrix that should be extracted.
ncols: Number of columns of the matrix that should be extracted.

The following code shows how to use this function:

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix M(4,5);
int val = 0;
for(size_t i=0; i<M.getRows(); i++) {
for(size_t j=0; j<M.getCols(); j++) {
M[i][j] = val++;
}
}
M.print(std::cout, 4, "M ");
vpMatrix N = M.extract(0, 1, 2, 3);
N.print(std::cout, 4, "N ");
}
int print(std::ostream &s, unsigned int length, const std::string &intro="") const
Definition: vpMatrix.cpp:5382
vpMatrix extract(unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols) const
Definition: vpMatrix.cpp:404

It produces the following output:

M [4,5]=
0 1 2 3 4
5 6 7 8 9
10 11 12 13 14
15 16 17 18 19
N [2,3]=
1 2 3
6 7 8
See also
init(const vpMatrix &, unsigned int, unsigned int, unsigned int, unsigned int)

Definition at line 404 of file vpMatrix.cpp.

References vpException::dimensionError, vpArray2D< double >::getCols(), vpArray2D< double >::getRows(), and vpArray2D< Type >::resize().

Referenced by vpLinProg::colReduction(), vpLinProg::rowReduction(), and solveByQR().

◆ eye() [1/3]

◆ eye() [2/3]

void vpMatrix::eye ( unsigned int  m,
unsigned int  n 
)

Set an m-by-n matrix to identity with ones on the diagonal and zeros else where.

Definition at line 437 of file vpMatrix.cpp.

References eye(), and vpArray2D< double >::resize().

◆ eye() [3/3]

void vpMatrix::eye ( unsigned int  n)

Set an n-by-n matrix to identity with ones on the diagonal and zeros else where.

Definition at line 431 of file vpMatrix.cpp.

References eye().

◆ frobeniusNorm()

double vpMatrix::frobeniusNorm ( ) const

Compute and return the Frobenius norm (also called Euclidean norm) $||A|| = \sqrt{ \sum{A_{ij}^2}}$.

Returns
The Frobenius norm (also called Euclidean norm) if the matrix is initialized, 0 otherwise.
See also
infinityNorm(), inducedL2Norm()
Examples
testMatrixPseudoInverse.cpp, and testSvd.cpp.

Definition at line 6514 of file vpMatrix.cpp.

References vpArray2D< double >::data, and vpArray2D< double >::dsize.

Referenced by euclideanNorm().

◆ getCol() [1/2]

vpColVector vpMatrix::getCol ( unsigned int  j) const

Extract a column vector from a matrix.

Warning
All the indexes start from 0 in this function.
Parameters
j: Index of the column to extract. If j=0, the first column is extracted.
Returns
The extracted column vector.

The following example shows how to use this function:

#include <visp3/core/vpColVector.h>
#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(4,4);
for (unsigned int i = 0; i < A.getRows(); i++)
for (unsigned int j = 0; j < A.getCols(); j++)
A[i][j] = i*A.getCols()+j;
A.print(std::cout, 4);
vpColVector cv = A.getCol(1);
std::cout << "Column vector: \n" << cv << std::endl;
}

It produces the following output :

[4, 4] =
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
column vector :
1
5
9
13
vp_deprecated vpColVector column(unsigned int j)
Definition: vpMatrix.cpp:6680
Examples
testMatrix.cpp.

Definition at line 4975 of file vpMatrix.cpp.

References vpArray2D< double >::rowNum.

Referenced by vpLinProg::colReduction(), vpHomography::DLT(), vpMbtFaceDepthNormal::estimatePlaneEquationSVD(), kernel(), vpPose::poseFromRectangle(), vpServo::secondaryTaskJointLimitAvoidance(), and vpLinProg::simplex().

◆ getCol() [2/2]

vpColVector vpMatrix::getCol ( unsigned int  j,
unsigned int  i_begin,
unsigned int  column_size 
) const

Extract a column vector from a matrix.

Warning
All the indexes start from 0 in this function.
Parameters
j: Index of the column to extract. If col=0, the first column is extracted.
i_begin: Index of the row that gives the location of the first element of the column vector to extract.
column_size: Size of the column vector to extract.
Returns
The extracted column vector.

The following example shows how to use this function:

#include <visp3/core/vpColVector.h>
#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(4,4);
for(unsigned int i=0; i < A.getRows(); i++)
for(unsigned int j=0; j < A.getCols(); j++)
A[i][j] = i*A.getCols()+j;
A.print(std::cout, 4);
vpColVector cv = A.getCol(1, 1, 3);
std::cout << "Column vector: \n" << cv << std::endl;
}

It produces the following output :

[4, 4] =
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
column vector :
5
9
13

Definition at line 4923 of file vpMatrix.cpp.

References vpException::dimensionError, vpArray2D< double >::getCols(), and vpArray2D< double >::getRows().

◆ getCols()

◆ getDiag()

vpColVector vpMatrix::getDiag ( ) const

Extract a diagonal vector from a matrix.

Returns
The diagonal of the matrix.
Warning
An empty vector is returned if the matrix is empty.

The following example shows how to use this function:

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(3, 4);
for (unsigned int i = 0; i < A.getRows(); i++)
for (unsigned int j = 0; j < A.getCols(); j++)
A[i][j] = i*A.getCols()+j;
A.print(std::cout, 4);
vpColVector diag = A.getDiag();
std::cout << "Diag vector: \n" << diag.t() << std::endl;
}

It produces the following output :

[3, 4] =
0 1 2 3
4 5 6 7
8 9 10 11
Diag vector :
0 5 10

Definition at line 5102 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, diag(), and vpArray2D< double >::rowNum.

◆ getLapackMatrixMinSize()

static unsigned int vpMatrix::getLapackMatrixMinSize ( )
inlinestatic

Return the minimum size of rows and columns required to enable Blas/Lapack usage on matrices and vectors.

To get more info see Tutorial: Basic linear algebra operations.

See also
setLapackMatrixMinSize()

Definition at line 236 of file vpMatrix.h.

◆ getMaxValue()

double vpArray2D< double >::getMaxValue
inherited

Return the array max value.

Examples
servoMomentImage.cpp.

Definition at line 329 of file vpArray2D.h.

◆ getMinValue()

double vpArray2D< double >::getMinValue
inherited

Return the array min value.

Examples
servoMomentImage.cpp.

Definition at line 331 of file vpArray2D.h.

◆ getRow() [1/2]

vpRowVector vpMatrix::getRow ( unsigned int  i) const

Extract a row vector from a matrix.

Warning
All the indexes start from 0 in this function.
Parameters
i: Index of the row to extract. If i=0, the first row is extracted.
Returns
The extracted row vector.

The following example shows how to use this function:

#include <visp3/core/vpMatrix.h>
#include <visp3/core/vpRowVector.h>
int main()
{
vpMatrix A(4,4);
for(unsigned int i=0; i < A.getRows(); i++)
for(unsigned int j=0; j < A.getCols(); j++)
A[i][j] = i*A.getCols()+j;
A.print(std::cout, 4);
vpRowVector rv = A.getRow(1);
std::cout << "Row vector: \n" << rv << std::endl;
}
Implementation of row vector and the associated operations.
Definition: vpRowVector.h:107

It produces the following output:

[4,4]=
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
Row vector:
4 5 6 7
Examples
testMatrix.cpp.

Definition at line 5013 of file vpMatrix.cpp.

References vpArray2D< double >::colNum.

Referenced by vpLinProg::allClose(), vpLinProg::allLesser(), vpLinProg::solveLP(), and vpQuadProg::solveQPi().

◆ getRow() [2/2]

vpRowVector vpMatrix::getRow ( unsigned int  i,
unsigned int  j_begin,
unsigned int  row_size 
) const

Extract a row vector from a matrix.

Warning
All the indexes start from 0 in this function.
Parameters
i: Index of the row to extract. If i=0, the first row is extracted.
j_begin: Index of the column that gives the location of the first element of the row vector to extract.
row_size: Size of the row vector to extract.
Returns
The extracted row vector.

The following example shows how to use this function:

#include <visp3/core/vpMatrix.h>
#include <visp3/core/vpRowVector.h>
int main()
{
vpMatrix A(4,4);
for(unsigned int i=0; i < A.getRows(); i++)
for(unsigned int j=0; j < A.getCols(); j++)
A[i][j] = i*A.getCols()+j;
A.print(std::cout, 4);
vpRowVector rv = A.getRow(1, 1, 3);
std::cout << "Row vector: \n" << rv << std::endl;
}

It produces the following output :

[4, 4] =
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
Row vector :
5 6 7

Definition at line 5054 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, vpArray2D< Type >::data, vpArray2D< double >::data, vpException::dimensionError, and vpArray2D< double >::rowNum.

◆ getRows()

◆ hadamard() [1/2]

vpArray2D< double > vpArray2D< double >::hadamard ( const vpArray2D< Type > &  m) const
inherited

Compute the Hadamard product (element wise matrix multiplication).

Parameters
m: Second matrix;
Returns
m1.hadamard(m2) The Hadamard product : $ m1 \circ m2 = (m1 \circ m2)_{i,j} = (m1)_{i,j} (m2)_{i,j} $
Examples
testArray2D.cpp.

Definition at line 625 of file vpArray2D.h.

◆ hadamard() [2/2]

vpMatrix vpMatrix::hadamard ( const vpMatrix m) const

Compute the Hadamard product (element wise matrix multiplication).

Parameters
m: Second matrix;
Returns
m1.hadamard(m2) The Hadamard product : $ m1 \circ m2 = (m1 \circ m2)_{i,j} = (m1)_{i,j} (m2)_{i,j} $
Examples
testMatrix.cpp.

Definition at line 1863 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, vpArray2D< double >::data, vpArray2D< Type >::data, vpException::dimensionError, vpArray2D< double >::dsize, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), vpArray2D< Type >::resize(), and vpArray2D< double >::rowNum.

◆ inducedL2Norm()

double vpMatrix::inducedL2Norm ( ) const

Compute and return the induced L2 norm $||A|| = \Sigma_{max}(A)$ which is equal to the maximum singular value of the matrix.

Returns
The induced L2 norm if the matrix is initialized, 0 otherwise.
See also
infinityNorm(), frobeniusNorm()
Examples
testMatrixConditionNumber.cpp.

Definition at line 6533 of file vpMatrix.cpp.

References vpArray2D< double >::dsize, vpArray2D< double >::getCols(), vpArray2D< double >::getRows(), vpArray2D< Type >::size(), and svd().

◆ infinityNorm()

double vpMatrix::infinityNorm ( ) const

Compute and return the infinity norm $ {||A||}_{\infty} = max\left(\sum_{j=0}^{n}{\mid A_{ij} \mid}\right) $ with $i \in \{0, ..., m\}$ where $(m,n)$ is the matrix size.

Returns
The infinity norm if the matrix is initialized, 0 otherwise.
See also
frobeniusNorm(), inducedL2Norm()

Definition at line 6574 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, vpArray2D< double >::rowNum, and vpArray2D< double >::rowPtrs.

Referenced by vpLinProg::colReduction(), and vpLinProg::rowReduction().

◆ init() [1/2]

vp_deprecated void vpMatrix::init ( )
inline
Deprecated:
Only provided for compatibility with ViSP previous releases. This function does nothing.

Definition at line 989 of file vpMatrix.h.

Referenced by vpMatrix(), and vpSubMatrix::vpSubMatrix().

◆ init() [2/2]

void vpMatrix::init ( const vpMatrix M,
unsigned int  r,
unsigned int  c,
unsigned int  nrows,
unsigned int  ncols 
)

Initialize the matrix from a part of an input matrix M.

Parameters
M: Input matrix used for initialization.
r: row index in matrix M.
c: column index in matrix M.
nrows: Number of rows of the matrix that should be initialized.
ncols: Number of columns of the matrix that should be initialized.

The sub-matrix starting from M[r][c] element and ending on M[r+nrows-1][c+ncols-1] element is used to initialize the matrix.

The following code shows how to use this function:

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix M(4,5);
int val = 0;
for(size_t i=0; i<M.getRows(); i++) {
for(size_t j=0; j<M.getCols(); j++) {
M[i][j] = val++;
}
}
M.print(std::cout, 4, "M ");
N.init(M, 0, 1, 2, 3);
N.print(std::cout, 4, "N ");
}
void init(const vpMatrix &M, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols)
Definition: vpMatrix.cpp:340

It produces the following output:

M [4,5]=
0 1 2 3 4
5 6 7 8 9
10 11 12 13 14
15 16 17 18 19
N [2,3]=
1 2 3
6 7 8
See also
extract()
Examples
testMatrix.cpp.

Definition at line 340 of file vpMatrix.cpp.

References vpException::dimensionError, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), vpArray2D< double >::resize(), and vpArray2D< double >::rowPtrs.

◆ insert() [1/5]

vpArray2D< double > vpArray2D< double >::insert ( const vpArray2D< Type > &  A,
const vpArray2D< Type > &  B,
unsigned int  r,
unsigned int  c 
)
inherited

Insert array B in array A at the given position.

Parameters
A: Main array.
B: Array to insert.
r: Index of the row where to add the array.
c: Index of the column where to add the array.
Returns
Array with B insert in A.
Warning
Throw exception if the sizes of the arrays do not allow the insertion.

Definition at line 1057 of file vpArray2D.h.

◆ insert() [2/5]

void vpArray2D< double >::insert ( const vpArray2D< Type > &  A,
unsigned int  r,
unsigned int  c 
)
inlineinherited

Insert array A at the given position in the current array.

Warning
Throw vpException::dimensionError if the dimensions of the matrices do not allow the operation.
Parameters
A: The array to insert.
r: The index of the row to begin to insert data.
c: The index of the column to begin to insert data.

Definition at line 484 of file vpArray2D.h.

◆ insert() [3/5]

vpMatrix vpMatrix::insert ( const vpMatrix A,
const vpMatrix B,
unsigned int  r,
unsigned int  c 
)
static

Insert matrix B in matrix A at the given position.

Parameters
A: Main matrix.
B: Matrix to insert.
r: Index of the row where to add the matrix.
c: Index of the column where to add the matrix.
Returns
Matrix with B insert in A.
Warning
Throw exception if the sizes of the matrices do not allow the insertion.

Definition at line 5273 of file vpMatrix.cpp.

References vpArray2D< Type >::insert(), and vpMatrix().

◆ insert() [4/5]

void insert ( const vpMatrix A,
const vpMatrix B,
vpMatrix C,
unsigned int  r,
unsigned int  c 
)
static

Insert matrix B in matrix A at the given position.

Parameters
A: Main matrix.
B: Matrix to insert.
C: Result matrix.
r: Index of the row where to insert matrix B.
c: Index of the column where to insert matrix B.
Warning
Throw exception if the sizes of the matrices do not allow the insertion.

Definition at line 5295 of file vpMatrix.cpp.

References vpArray2D< Type >::insert().

◆ insert() [5/5]

void vpMatrix::insert ( const vpMatrix A,
unsigned int  r,
unsigned int  c 
)

◆ inverseByCholesky()

vpMatrix vpMatrix::inverseByCholesky ( ) const

Compute the inverse of a n-by-n matrix using the Cholesky decomposition. The matrix must be real symmetric positive defined.

This function calls the first following function that is available:

If none of these 3rd parties is installed we use a Lapack built-in version.

Returns
The inverse matrix.

Here an example:

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(4,4);
// Symmetric matrix
A[0][0] = 1/1.; A[0][1] = 1/5.; A[0][2] = 1/6.; A[0][3] = 1/7.;
A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.; A[1][3] = 1/5.;
A[2][0] = 1/6.; A[2][1] = 1/3.; A[2][2] = 1/2.; A[2][3] = 1/6.;
A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.;
// Compute the inverse
vpMatrix A_1; // A^-1
A_1 = A.inverseByCholesky();
std::cout << "Inverse by Cholesky: \n" << A_1 << std::endl;
std::cout << "A*A^-1: \n" << A * A_1 << std::endl;
}
vpMatrix inverseByCholesky() const
See also
pseudoInverse()

Definition at line 112 of file vpMatrix_cholesky.cpp.

References vpException::fatalError, inverseByCholeskyLapack(), and inverseByCholeskyOpenCV().

◆ inverseByCholeskyLapack()

vpMatrix vpMatrix::inverseByCholeskyLapack ( ) const

Compute the inverse of a n-by-n matrix using the Cholesky decomposition with Lapack 3rd party. The matrix must be real symmetric positive defined.

Returns
The inverse matrix.

Here an example:

#include <visp3/core/vpMatrix.h>
int main()
{
unsigned int n = 4;
vpMatrix A(n, n);
I.eye(4);
A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[0][3] = 1/4.;
A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.; A[1][3] = 1/5.;
A[2][0] = 1/6.; A[2][1] = 1/4.; A[2][2] = 1/2.; A[2][3] = 1/6.;
A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.;
// Make matrix symmetric positive
A = 0.5*(A+A.t());
A = A + n*I;
// Compute the inverse
std::cout << "Inverse by Cholesky (Lapack): \n" << A_1 << std::endl;
std::cout << "A*A^-1: \n" << A * A_1 << std::endl;
}
vpMatrix inverseByCholeskyLapack() const
See also
inverseByCholesky(), inverseByCholeskyOpenCV()

Definition at line 162 of file vpMatrix_cholesky.cpp.

References vpException::badValue, vpArray2D< double >::colNum, vpArray2D< Type >::data, vpException::fatalError, vpArray2D< Type >::getCols(), vpArray2D< double >::getRows(), vpArray2D< Type >::getRows(), vpMatrixException::matrixError, and vpArray2D< double >::rowNum.

Referenced by inverseByCholesky().

◆ inverseByCholeskyOpenCV()

vpMatrix vpMatrix::inverseByCholeskyOpenCV ( ) const

Compute the inverse of a n-by-n matrix using the Cholesky decomposition with OpenCV 3rd party. The matrix must be real symmetric positive defined.

Returns
The inverse matrix.

Here an example:

#include <visp3/core/vpMatrix.h>
int main()
{
unsigned int n = 4;
vpMatrix A(n, n);
I.eye(4);
A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[0][3] = 1/4.;
A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.; A[1][3] = 1/5.;
A[2][0] = 1/6.; A[2][1] = 1/4.; A[2][2] = 1/2.; A[2][3] = 1/6.;
A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.;
// Make matrix symmetric positive
A = 0.5*(A+A.t());
A = A + n*I;
// Compute the inverse
std::cout << "Inverse by Cholesky (OpenCV): \n" << A_1 << std::endl;
std::cout << "A*A^-1: \n" << A * A_1 << std::endl;
}
vpMatrix inverseByCholeskyOpenCV() const
See also
inverseByCholesky(), inverseByCholeskyLapack()

Definition at line 255 of file vpMatrix_cholesky.cpp.

References vpArray2D< double >::colNum, vpArray2D< Type >::data, vpArray2D< double >::data, vpException::fatalError, and vpArray2D< double >::rowNum.

Referenced by inverseByCholesky().

◆ inverseByLU()

vpMatrix vpMatrix::inverseByLU ( ) const

Compute the inverse of a n-by-n matrix using the LU decomposition.

This function calls the first following function that is available:

If none of these previous 3rd parties is installed, we use by default inverseByLULapack() with a Lapack built-in version.

Returns
The inverse matrix.

Here an example:

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(4,4);
A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[0][3] = 1/4.;
A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.; A[1][3] = 1/5.;
A[2][0] = 1/6.; A[2][1] = 1/4.; A[2][2] = 1/2.; A[2][3] = 1/6.;
A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.;
// Compute the inverse
vpMatrix A_1 = A.inverseByLU();
std::cout << "Inverse by LU ";
#if defined(VISP_HAVE_LAPACK)
std::cout << "(using Lapack)";
#elif defined(VISP_HAVE_EIGEN3)
std::cout << "(using Eigen3)";
#elif defined(VISP_HAVE_OPENCV)
std::cout << "(using OpenCV)";
#endif
std::cout << ": \n" << A_1 << std::endl;
std::cout << "A*A^-1: \n" << A * A_1 << std::endl;
}
vpMatrix inverseByLU() const
See also
inverseByLULapack(), inverseByLUEigen3(), inverseByLUOpenCV(), pseudoInverse()
Examples
photometricVisualServoingWithoutVpServo.cpp, and testMatrixConditionNumber.cpp.

Definition at line 127 of file vpMatrix_lu.cpp.

References vpArray2D< double >::colNum, det(), vpException::fatalError, inverseByLUEigen3(), inverseByLULapack(), inverseByLUOpenCV(), vpArray2D< Type >::resize(), and vpArray2D< double >::rowNum.

Referenced by expm(), vpKalmanFilter::filtering(), vpTemplateTrackerWarpHomographySL3::findWarp(), vpTemplateTrackerTriangle::init(), vpTemplateTrackerSSDInverseCompositional::initCompInverse(), vpTemplateTrackerZNCCForwardAdditional::initHessienDesired(), vpTemplateTrackerZNCCInverseCompositional::initHessienDesired(), vpTemplateTrackerMIESM::initHessienDesired(), vpTemplateTrackerMIForwardAdditional::initHessienDesired(), vpTemplateTrackerMIForwardCompositional::initHessienDesired(), vpTemplateTrackerMIInverseCompositional::initHessienDesired(), vpTemplateTracker::setHDes(), vpTemplateTrackerSSDForwardAdditional::trackNoPyr(), vpTemplateTrackerSSDForwardCompositional::trackNoPyr(), vpTemplateTrackerMIESM::trackNoPyr(), vpTemplateTrackerMIForwardAdditional::trackNoPyr(), vpTemplateTrackerMIForwardCompositional::trackNoPyr(), vpTemplateTrackerMIInverseCompositional::trackNoPyr(), and vpImageTools::warpImage().

◆ inverseByLUEigen3()

vpMatrix vpMatrix::inverseByLUEigen3 ( ) const

Compute the inverse of a n-by-n matrix using the LU decomposition with Eigen3 3rd party.

Returns
The inverse matrix.

Here an example:

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(4,4);
A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[0][3] = 1/4.;
A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.; A[1][3] = 1/5.;
A[2][0] = 1/6.; A[2][1] = 1/4.; A[2][2] = 1/2.; A[2][3] = 1/6.;
A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.;
// Compute the inverse
vpMatrix A_1; // A^-1
A_1 = A.inverseByLUEigen3();
std::cout << "Inverse by LU (Eigen3): \n" << A_1 << std::endl;
std::cout << "A*A^-1: \n" << A * A_1 << std::endl;
}
vpMatrix inverseByLUEigen3() const
See also
inverseByLU(), inverseByLULapack(), inverseByLUOpenCV()

Definition at line 573 of file vpMatrix_lu.cpp.

References vpArray2D< double >::colNum, vpArray2D< Type >::data, vpArray2D< double >::data, vpException::fatalError, vpArray2D< double >::getCols(), vpArray2D< double >::getRows(), and vpArray2D< double >::rowNum.

Referenced by inverseByLU().

◆ inverseByLULapack()

vpMatrix vpMatrix::inverseByLULapack ( ) const

Compute the inverse of a n-by-n matrix using the LU decomposition with Lapack 3rd party.

Returns
The inverse matrix.

Here an example:

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(4,4);
A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[0][3] = 1/4.;
A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.; A[1][3] = 1/5.;
A[2][0] = 1/6.; A[2][1] = 1/4.; A[2][2] = 1/2.; A[2][3] = 1/6.;
A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.;
// Compute the inverse
vpMatrix A_1; // A^-1
A_1 = A.inverseByLULapack();
std::cout << "Inverse by LU (Lapack): \n" << A_1 << std::endl;
std::cout << "A*A^-1: \n" << A * A_1 << std::endl;
}
vpMatrix inverseByLULapack() const
See also
inverseByLU(), inverseByLUEigen3(), inverseByLUOpenCV()

Definition at line 282 of file vpMatrix_lu.cpp.

References vpArray2D< double >::colNum, vpArray2D< Type >::data, vpException::fatalError, and vpArray2D< double >::rowNum.

Referenced by inverseByLU().

◆ inverseByLUOpenCV()

vpMatrix vpMatrix::inverseByLUOpenCV ( ) const

Compute the inverse of a n-by-n matrix using the LU decomposition with OpenCV 3rd party.

Returns
The inverse matrix.

Here an example:

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(4,4);
A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[0][3] = 1/4.;
A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.; A[1][3] = 1/5.;
A[2][0] = 1/6.; A[2][1] = 1/4.; A[2][2] = 1/2.; A[2][3] = 1/6.;
A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.;
// Compute the inverse
vpMatrix A_1; // A^-1
A_1 = A.inverseByLUOpenCV();
std::cout << "Inverse by LU (OpenCV): \n" << A_1 << std::endl;
std::cout << "A*A^-1: \n" << A * A_1 << std::endl;
}
vpMatrix inverseByLUOpenCV() const
See also
inverseByLU(), inverseByLUEigen3(), inverseByLULapack()

Definition at line 484 of file vpMatrix_lu.cpp.

References vpArray2D< double >::colNum, vpArray2D< Type >::data, vpArray2D< double >::data, vpException::fatalError, and vpArray2D< double >::rowNum.

Referenced by inverseByLU().

◆ inverseByQR()

vpMatrix vpMatrix::inverseByQR ( ) const

Compute the inverse of a n-by-n matrix using the QR decomposition. Only available if Lapack 3rd party is installed. If Lapack is not installed we use a Lapack built-in version.

Returns
The inverse matrix.

Here an example:

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(4,4);
A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[0][3] = 1/4.;
A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.; A[1][3] = 1/5.;
A[2][0] = 1/6.; A[2][1] = 1/4.; A[2][2] = 1/2.; A[2][3] = 1/6.;
A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.;
// Compute the inverse
vpMatrix A_1 = A.inverseByQR();
std::cout << "Inverse by QR: \n" << A_1 << std::endl;
std::cout << "A*A^-1: \n" << A * A_1 << std::endl;
}
vpMatrix inverseByQR() const
See also
inverseByLU(), inverseByCholesky()

Definition at line 381 of file vpMatrix_qr.cpp.

References vpException::fatalError, and inverseByQRLapack().

Referenced by vpLinProg::simplex().

◆ inverseByQRLapack()

vpMatrix vpMatrix::inverseByQRLapack ( ) const

Compute the inverse of a n-by-n matrix using the QR decomposition with Lapack 3rd party.

Returns
The inverse matrix.

Here an example:

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(4,4);
A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[0][3] = 1/4.;
A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.; A[1][3] = 1/5.;
A[2][0] = 1/6.; A[2][1] = 1/4.; A[2][2] = 1/2.; A[2][3] = 1/6.;
A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.;
// Compute the inverse
std::cout << "Inverse by QR: \n" << A_1 << std::endl;
std::cout << "A*A^-1: \n" << A * A_1 << std::endl;
}
vpMatrix inverseByQRLapack() const
See also
inverseByQR()

Definition at line 151 of file vpMatrix_qr.cpp.

References vpException::badValue, vpArray2D< Type >::colNum, vpArray2D< double >::colNum, vpArray2D< Type >::data, vpArray2D< double >::getCols(), vpArray2D< Type >::getRows(), vpArray2D< double >::getRows(), vpMatrixException::matrixError, vpArray2D< Type >::resize(), vpArray2D< Type >::rowNum, and vpArray2D< double >::rowNum.

Referenced by inverseByQR().

◆ inverseTriangular()

vpMatrix vpMatrix::inverseTriangular ( bool  upper = true) const

Compute the inverse of a full-rank n-by-n triangular matrix. Only available if Lapack 3rd party is installed. If Lapack is not installed we use a Lapack built-in version.

Parameters
upper: if it is an upper triangular matrix

The function does not check if the matrix is actually upper or lower triangular.

Returns
The inverse matrix

Definition at line 1010 of file vpMatrix_qr.cpp.

References vpException::badValue, vpArray2D< Type >::colNum, vpArray2D< double >::colNum, vpArray2D< Type >::data, vpException::dimensionError, vpException::fatalError, vpMatrixException::rankDeficient, vpArray2D< Type >::resize(), vpArray2D< Type >::rowNum, and vpArray2D< double >::rowNum.

Referenced by vpLinProg::colReduction(), vpLinProg::rowReduction(), and solveByQR().

◆ juxtaposeMatrices() [1/2]

vpMatrix vpMatrix::juxtaposeMatrices ( const vpMatrix A,
const vpMatrix B 
)
static

Juxtapose to matrices C = [ A B ].

$ C = \left( \begin{array}{cc} A & B \end{array}\right) $

Parameters
A: Left matrix.
B: Right matrix.
Returns
Juxtaposed matrix C = [ A B ]
Warning
A and B must have the same number of rows.
Examples
testMatrix.cpp.

Definition at line 5315 of file vpMatrix.cpp.

Referenced by vpLinProg::colReduction().

◆ juxtaposeMatrices() [2/2]

void juxtaposeMatrices ( const vpMatrix A,
const vpMatrix B,
vpMatrix C 
)
static

Juxtapose to matrices C = [ A B ].

$ C = \left( \begin{array}{cc} A & B \end{array}\right) $

Parameters
A: Left matrix.
B: Right matrix.
C: Juxtaposed matrix C = [ A B ]
Warning
A and B must have the same number of rows.

Definition at line 5336 of file vpMatrix.cpp.

References vpException::dimensionError, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), insert(), and vpArray2D< Type >::resize().

◆ kernel()

unsigned int vpMatrix::kernel ( vpMatrix kerAt,
double  svThreshold = 1e-6 
) const

Function to compute the null space (the kernel) of a m-by-n matrix $\bf A$.

The null space of a matrix $\bf A$ is defined as $\mbox{Ker}({\bf A}) = { {\bf X} : {\bf A}*{\bf X} = {\bf 0}}$.

Parameters
kerAtThe matrix that contains the null space (kernel) of $\bf A$ defined by the matrix ${\bf X}^T$. If matrix $\bf A$ is full rank, the dimension of kerAt is (0, n), otherwise the dimension is (n-r, n). This matrix is thus the transpose of $\mbox{Ker}({\bf A})$.
svThresholdThreshold used to test the singular values. If a singular value is lower than this threshold we consider that the matrix is not full rank.
Returns
The rank of the matrix.
Examples
servoViper850Point2DArtVelocity-jointAvoidance-basic.cpp, and testMatrixConditionNumber.cpp.

Definition at line 6056 of file vpMatrix.cpp.

References getCol(), vpArray2D< double >::getCols(), vpArray2D< Type >::getRows(), vpArray2D< double >::getRows(), insert(), vpColVector::resize(), vpArray2D< Type >::resize(), vpColVector::sumSquare(), and svd().

◆ kron() [1/4]

vpMatrix vpMatrix::kron ( const vpMatrix m) const

Compute Kronecker product matrix.

Parameters
m: vpMatrix;
Returns
m1.kron(m2) The kronecker product : $ m1 \otimes m2 $

Definition at line 1958 of file vpMatrix.cpp.

References kron().

◆ kron() [2/4]

vpMatrix vpMatrix::kron ( const vpMatrix m1,
const vpMatrix m2 
)
static

Compute Kronecker product matrix.

Parameters
m1: vpMatrix;
m2: vpMatrix;
Returns
The kronecker product : $ m1 \otimes m2 $

Definition at line 1927 of file vpMatrix.cpp.

References vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), and vpArray2D< Type >::resize().

◆ kron() [3/4]

void vpMatrix::kron ( const vpMatrix m1,
const vpMatrix m2,
vpMatrix out 
)
static

Compute Kronecker product matrix.

Parameters
m1: vpMatrix;
m2: vpMatrix;
out: The kronecker product : $ m1 \otimes m2 $

Definition at line 1889 of file vpMatrix.cpp.

References vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), and vpArray2D< Type >::resize().

◆ kron() [4/4]

void vpMatrix::kron ( const vpMatrix m,
vpMatrix out 
) const

Compute Kronecker product matrix.

Parameters
m: vpMatrix.
out: If m1.kron(m2) out contains the kronecker product's result : $ m1 \otimes m2 $.

Definition at line 1919 of file vpMatrix.cpp.

Referenced by kron().

◆ load()

static bool vpArray2D< double >::load ( const std::string &  filename,
vpArray2D< Type > &  A,
bool  binary = false,
char *  header = nullptr 
)
inlinestaticinherited

Load a matrix from a file.

Parameters
filename: Absolute file name.
A: Array to be loaded
binary: If true the matrix is loaded from a binary file, else from a text file.
header: Header of the file is loaded in this parameter.
Returns
Returns true if success.
See also
save()

Definition at line 653 of file vpArray2D.h.

◆ loadMatrix()

static bool vpMatrix::loadMatrix ( const std::string &  filename,
vpArray2D< double > &  M,
bool  binary = false,
char *  header = nullptr 
)
inlinestatic

Load a matrix from a file. This function overloads vpArray2D::load().

Parameters
filename: Absolute file name.
M: Matrix to be loaded.
binary: If true the matrix data are considered as binary, otherwise as human readable (text) data. Using binary data allows to keep data precision.
header: Header of the file is loaded in this parameter.
Returns
Returns true if success, false otherwise.

The following example shows how to use this function:

#include <visp3/core/vpMatrix.h>
int main()
{
std::string filename("matrix.bin");
bool binary_data = true;
{
vpMatrix M(2, 3);
M[0][0] = -1; M[0][1] = -2; M[0][2] = -3;
M[1][0] = 4; M[1][1] = 5.5; M[1][2] = 6.0f;
std::string header("My header");
if (vpMatrix::saveMatrix(filename, M, binary_data, header.c_str())) {
std::cout << "Matrix saved in " << filename << std::endl;
M.print(std::cout, 10, header);
} else {
std::cout << "Cannot save matrix in " << filename << std::endl;
}
}
{
char header[FILENAME_MAX];
if (vpMatrix::loadMatrix(filename, N, binary_data, header)) {
std::cout << "Matrix loaded from " << filename << std::endl;
N.print(std::cout, 10, header);
} else {
std::cout << "Cannot load matrix from " << filename << std::endl;
}
}
}
static bool loadMatrix(const std::string &filename, vpArray2D< double > &M, bool binary=false, char *header=nullptr)
Definition: vpMatrix.h:748
static bool saveMatrix(const std::string &filename, const vpArray2D< double > &M, bool binary=false, const char *header="")
Definition: vpMatrix.h:896

The output of this example is the following:

Matrix saved in matrix.bin
My header[2,3]=
  -1.0 -2.0 -3.0
   4.0  5.5  6.0
Matrix loaded from matrix.bin
My header[2,3]=
  -1.0 -2.0 -3.0
   4.0  5.5  6.0

And the content of matrix.bin file where data are saved as binary data is the following:

% cat matrix.bin
My header??@@@%
See also
saveMatrix(), saveMatrixYAML(), loadMatrixYAML()
Examples
testMatrix.cpp.

Definition at line 748 of file vpMatrix.h.

References vpArray2D< Type >::load().

Referenced by vpDot2::defineDots().

◆ loadMatrixYAML()

static bool vpMatrix::loadMatrixYAML ( const std::string &  filename,
vpArray2D< double > &  M,
char *  header = nullptr 
)
inlinestatic

Load a matrix from a YAML-formatted file. This function overloads vpArray2D::loadYAML().

Parameters
filename: Absolute YAML file name.
M: Matrix to be loaded from the file.
header: Header of the file is loaded in this parameter.
Returns
Returns true when success, false otherwise.

The following example shows how to use this function:

#include <visp3/core/vpMatrix.h>
int main()
{
std::string filename("matrix.yaml");
{
vpMatrix M(2, 3);
M[0][0] = -1; M[0][1] = -2; M[0][2] = -3;
M[1][0] = 4; M[1][1] = 5.5; M[1][2] = 6.0f;
std::string header("My header");
if (vpMatrix::saveMatrixYAML(filename, M, header.c_str())) {
std::cout << "Matrix saved in " << filename << std::endl;
M.print(std::cout, 10, header);
} else {
std::cout << "Cannot save matrix in " << filename << std::endl;
}
}
{
char header[FILENAME_MAX];
if (vpMatrix::loadMatrixYAML(filename, N, header)) {
std::cout << "Matrix loaded from " << filename << std::endl;
N.print(std::cout, 10, header);
} else {
std::cout << "Cannot load matrix from " << filename << std::endl;
}
}
}
static bool saveMatrixYAML(const std::string &filename, const vpArray2D< double > &M, const char *header="")
Definition: vpMatrix.h:972
static bool loadMatrixYAML(const std::string &filename, vpArray2D< double > &M, char *header=nullptr)
Definition: vpMatrix.h:823

The output of this example is the following:

Matrix saved in matrix.yaml
My header[2,3]=
  -1.0 -2.0 -3.0
   4.0  5.5  6.0
Matrix loaded from matrix.yaml
My header[2,3]=
  -1.0 -2.0 -3.0
   4.0  5.5  6.0

And the content of matrix.yaml file is the following:

% cat matrix.yaml
My header
rows: 2
cols: 3
data:
  - [-1, -2, -3]
  - [4, 5.5, 6]
See also
saveMatrixYAML(), saveMatrix(), loadMatrix()
Examples
testMatrix.cpp.

Definition at line 823 of file vpMatrix.h.

References vpArray2D< Type >::loadYAML().

◆ loadYAML()

static bool vpArray2D< double >::loadYAML ( const std::string &  filename,
vpArray2D< Type > &  A,
char *  header = nullptr 
)
inlinestaticinherited

Load an array from a YAML-formatted file.

Parameters
filename: absolute file name.
A: array to be loaded from the file.
header: header of the file is loaded in this parameter.
Returns
Returns true on success.
See also
saveYAML()
Examples
servoFlirPtuIBVS.cpp, servoFrankaIBVS.cpp, servoFrankaPBVS.cpp, servoUniversalRobotsIBVS.cpp, servoUniversalRobotsPBVS.cpp, tutorial-flir-ptu-ibvs.cpp, tutorial-hsv-segmentation-pcl-viewer.cpp, tutorial-hsv-segmentation-pcl.cpp, and tutorial-hsv-segmentation.cpp.

Definition at line 767 of file vpArray2D.h.

◆ maplePrint()

std::ostream & vpMatrix::maplePrint ( std::ostream &  os) const

Print using Maple syntax, to copy/paste in Maple later.

The following code

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix M(2,3);
int cpt = 0;
for (unsigned int i=0; i<M.getRows(); i++)
for (unsigned int j=0; j<M.getCols(); j++)
M[i][j] = cpt++;
std::cout << "M = "; M.maplePrint(std::cout);
}

produces this output:

M = ([
[0, 1, 2, ],
[3, 4, 5, ],
])

that could be copy/paste in Maple.

Definition at line 5548 of file vpMatrix.cpp.

References vpArray2D< double >::getCols(), and vpArray2D< double >::getRows().

◆ matlabPrint()

std::ostream & vpMatrix::matlabPrint ( std::ostream &  os) const

Print using Matlab syntax, to copy/paste in Matlab later.

The following code

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix M(2,3);
int cpt = 0;
for (unsigned int i=0; i<M.getRows(); i++)
for (unsigned int j=0; j<M.getCols(); j++)
M[i][j] = cpt++;
std::cout << "M = "; M.matlabPrint(std::cout);
}

produces this output:

M = [ 0, 1, 2, ;
3, 4, 5, ]

that could be copy/paste in Matlab:

>> M = [ 0, 1, 2, ;
3, 4, 5, ]
M =
0 1 2
3 4 5
>>

Definition at line 5501 of file vpMatrix.cpp.

References vpArray2D< double >::getCols(), and vpArray2D< double >::getRows().

◆ mult2Matrices() [1/4]

void vpMatrix::mult2Matrices ( const vpMatrix A,
const vpColVector B,
vpColVector C 
)
static
Warning
This function is provided for compat with previous releases. You should rather use multMatrixVector() that is more explicit.

Operation C = A * B.

The result is placed in the third parameter C and not returned. A new matrix won't be allocated for every use of the function (speed gain if used many times with the same result matrix size).

See also
multMatrixVector()

Definition at line 1189 of file vpMatrix.cpp.

References multMatrixVector().

◆ mult2Matrices() [2/4]

void vpMatrix::mult2Matrices ( const vpMatrix A,
const vpMatrix B,
vpHomogeneousMatrix C 
)
static
Warning
This function is provided for compat with previous releases. You should rather use the functionalities provided in vpHomogeneousMatrix class.

Operation C = A * B.

The result is placed in the third parameter C and not returned. A new matrix won't be allocated for every use of the function (speed gain if used many times with the same result matrix size).

Exceptions
vpException::dimensionErrorIf matrices are not 4-by-4 dimension.

Definition at line 1130 of file vpMatrix.cpp.

References vpArray2D< Type >::colNum, vpArray2D< Type >::data, vpException::dimensionError, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), vpArray2D< Type >::rowNum, and vpArray2D< Type >::rowPtrs.

◆ mult2Matrices() [3/4]

void vpMatrix::mult2Matrices ( const vpMatrix A,
const vpMatrix B,
vpMatrix C 
)
static

Operation C = A * B.

The result is placed in the third parameter C and not returned. A new matrix won't be allocated for every use of the function (speed gain if used many times with the same result matrix size).

See also
operator*()

Definition at line 1035 of file vpMatrix.cpp.

References vpArray2D< Type >::colNum, vpArray2D< Type >::data, vpException::dimensionError, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), vpArray2D< Type >::resize(), vpArray2D< Type >::rowNum, and vpArray2D< Type >::rowPtrs.

Referenced by operator*().

◆ mult2Matrices() [4/4]

void vpMatrix::mult2Matrices ( const vpMatrix A,
const vpMatrix B,
vpRotationMatrix C 
)
static
Warning
This function is provided for compat with previous releases. You should rather use the functionalities provided in vpRotationMatrix class.

Operation C = A * B.

The result is placed in the third parameter C and not returned. A new matrix won't be allocated for every use of the function (speed gain if used many times with the same result matrix size).

Exceptions
vpException::dimensionErrorIf matrices are not 3-by-3 dimension.

Definition at line 1093 of file vpMatrix.cpp.

References vpArray2D< Type >::colNum, vpException::dimensionError, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), vpArray2D< Type >::rowNum, and vpArray2D< Type >::rowPtrs.

◆ multMatrixVector()

void vpMatrix::multMatrixVector ( const vpMatrix A,
const vpColVector v,
vpColVector w 
)
static

Operation w = A * v (v and w are vectors).

A new matrix won't be allocated for every use of the function (Speed gain if used many times with the same result matrix size).

See also
operator*(const vpColVector &v) const

Definition at line 984 of file vpMatrix.cpp.

References vpArray2D< Type >::colNum, vpArray2D< Type >::data, vpException::dimensionError, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), vpColVector::resize(), vpArray2D< Type >::rowNum, and vpArray2D< Type >::rowPtrs.

Referenced by mult2Matrices(), and operator*().

◆ negateMatrix()

void vpMatrix::negateMatrix ( const vpMatrix A,
vpMatrix C 
)
static

Operation C = -A.

The result is placed in the second parameter C and not returned. A new matrix won't be allocated for every use of the function (Speed gain if used many times with the same result matrix size).

See also
operator-(void)

Definition at line 1617 of file vpMatrix.cpp.

References vpArray2D< Type >::colNum, vpArray2D< Type >::resize(), vpArray2D< Type >::rowNum, and vpArray2D< Type >::rowPtrs.

Referenced by operator-().

◆ nullSpace() [1/2]

unsigned int vpMatrix::nullSpace ( vpMatrix kerA,
double  svThreshold = 1e-6 
) const

Function to compute the null space (the kernel) of a m-by-n matrix $\bf A$.

The null space of a matrix $\bf A$ is defined as $\mbox{Ker}({\bf A}) = { {\bf X} : {\bf A}*{\bf X} = {\bf 0}}$.

Parameters
kerAThe matrix that contains the null space (kernel) of $\bf A$. If matrix $\bf A$ is full rank, the dimension of kerA is (n, 0), otherwise its dimension is (n, n-r).
svThresholdThreshold used to test the singular values. The dimension of kerA corresponds to the number of singular values lower than this threshold
Returns
The dimension of the nullspace, that is $ n - r $.

Definition at line 6130 of file vpMatrix.cpp.

References vpArray2D< double >::getCols(), vpArray2D< double >::getRows(), insert(), vpColVector::resize(), vpArray2D< Type >::resize(), and svd().

Referenced by vpMeEllipse::leastSquare(), and vpMeEllipse::leastSquareRobust().

◆ nullSpace() [2/2]

unsigned int vpMatrix::nullSpace ( vpMatrix kerA,
int  dim 
) const

Function to compute the null space (the kernel) of a m-by-n matrix $\bf A$.

The null space of a matrix $\bf A$ is defined as $\mbox{Ker}({\bf A}) = { {\bf X} : {\bf A}*{\bf X} = {\bf 0}}$.

Parameters
kerAThe matrix that contains the null space (kernel) of $\bf A$. If matrix $\bf A$ is full rank, the dimension of kerA is (n, 0), otherwise its dimension is (n, n-r).
dimthe dimension of the null space when it is known a priori
Returns
The estimated dimension of the nullspace, that is $ n - r $, by using 1e-6 as threshold for the sigular values.

Definition at line 6197 of file vpMatrix.cpp.

References vpArray2D< double >::getCols(), vpArray2D< double >::getRows(), insert(), vpColVector::resize(), vpArray2D< Type >::resize(), and svd().

◆ operator!=()

bool operator!= ( const vpArray2D< Type > &  A) const
inherited

Not equal to comparison operator of a 2D array.

Definition at line 509 of file vpArray2D.h.

◆ operator*() [1/8]

vpColVector vpMatrix::operator* ( const vpColVector v) const

Operation w = A * v (matrix A is unchanged, v and w are column vectors).

See also
multMatrixVector() to avoid matrix allocation for each use.

Definition at line 969 of file vpMatrix.cpp.

References multMatrixVector().

◆ operator*() [2/8]

vpMatrix vpMatrix::operator* ( const vpForceTwistMatrix V) const

◆ operator*() [3/8]

vpMatrix vpMatrix::operator* ( const vpHomogeneousMatrix M) const

Operator that allow to multiply a matrix by a homogeneous matrix. The matrix should be of dimension m-by-4.

Definition at line 1241 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, vpException::dimensionError, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), vpArray2D< Type >::resize(), vpArray2D< double >::rowNum, and vpArray2D< double >::rowPtrs.

◆ operator*() [4/8]

vpMatrix vpMatrix::operator* ( const vpMatrix B) const

Operation C = A * B (A is unchanged).

See also
mult2Matrices() to avoid matrix allocation for each use.

Definition at line 1198 of file vpMatrix.cpp.

References mult2Matrices().

◆ operator*() [5/8]

vpMatrix vpMatrix::operator* ( const vpRotationMatrix R) const

Operator that allow to multiply a matrix by a rotation matrix. The matrix should be of dimension m-by-3.

Definition at line 1211 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, vpException::dimensionError, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), vpArray2D< Type >::resize(), vpArray2D< double >::rowNum, and vpArray2D< double >::rowPtrs.

◆ operator*() [6/8]

vpTranslationVector vpMatrix::operator* ( const vpTranslationVector tv) const

Operator that allows to multiply a matrix by a translation vector. The matrix should be of dimension (3x3)

Definition at line 943 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, vpException::dimensionError, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), vpArray2D< double >::rowNum, and vpArray2D< double >::rowPtrs.

◆ operator*() [7/8]

vpMatrix vpMatrix::operator* ( const vpVelocityTwistMatrix V) const

◆ operator*() [8/8]

vpMatrix vpMatrix::operator* ( double  x) const

Operator that allows to multiply all the elements of a matrix by a scalar.

Definition at line 1693 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, vpArray2D< Type >::resize(), vpArray2D< double >::rowNum, and vpArray2D< double >::rowPtrs.

◆ operator*=()

vpMatrix & vpMatrix::operator*= ( double  x)

Multiply all the element of the matrix by x : Aij = Aij * x.

Operator that allows to multiply all the elements of a matrix by a scalar.

Definition at line 1764 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, vpArray2D< double >::rowNum, and vpArray2D< double >::rowPtrs.

◆ operator+()

vpMatrix vpMatrix::operator+ ( const vpMatrix B) const

Operation C = A + B (A is unchanged).

See also
add2Matrices() to avoid matrix allocation for each use.

Definition at line 1481 of file vpMatrix.cpp.

References add2Matrices().

◆ operator+=() [1/2]

◆ operator+=() [2/2]

vpMatrix & vpMatrix::operator+= ( double  x)

Add x to all the element of the matrix : Aij = Aij + x.

Definition at line 1737 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, vpArray2D< double >::rowNum, and vpArray2D< double >::rowPtrs.

◆ operator,()

vpMatrix & vpMatrix::operator, ( double  val)

◆ operator-() [1/2]

vpMatrix vpMatrix::operator- ( void  ) const

Operation C = -A (A is unchanged).

See also
negateMatrix() to avoid matrix allocation for each use.

Definition at line 1637 of file vpMatrix.cpp.

References negateMatrix().

◆ operator-() [2/2]

vpMatrix vpMatrix::operator- ( const vpMatrix B) const

Operation C = A - B (A is unchanged).

See also
sub2Matrices() to avoid matrix allocation for each use.

Definition at line 1563 of file vpMatrix.cpp.

References sub2Matrices().

◆ operator-=() [1/2]

◆ operator-=() [2/2]

vpMatrix & vpMatrix::operator-= ( double  x)

subtract x to all the element of the matrix : Aij = Aij - x

Definition at line 1749 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, vpArray2D< double >::rowNum, and vpArray2D< double >::rowPtrs.

◆ operator/()

vpMatrix vpMatrix::operator/ ( double  x) const

◆ operator/=()

vpMatrix & vpMatrix::operator/= ( double  x)

Divide all the element of the matrix by x : Aij = Aij / x.

Definition at line 1780 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, vpException::divideByZeroError, vpArray2D< double >::rowNum, and vpArray2D< double >::rowPtrs.

◆ operator<<() [1/2]

vpMatrix & vpMatrix::operator<< ( double *  x)

Assignment from an array of double. This method has to be used carefully since the array allocated behind x pointer should have the same dimension than the matrix.

Definition at line 810 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, vpArray2D< double >::rowNum, and vpArray2D< double >::rowPtrs.

◆ operator<<() [2/2]

vpMatrix & vpMatrix::operator<< ( double  val)

Definition at line 820 of file vpMatrix.cpp.

References vpArray2D< double >::resize(), and vpArray2D< double >::rowPtrs.

◆ operator=() [1/6]

vpMatrix & vpMatrix::operator= ( const std::initializer_list< double > &  list)

Set matrix elements from a list of values.

Parameters
list: List of double. Matrix size (number of columns multiplied by number of columns) should match the number of elements.
Returns
The modified Matrix. The following example shows how to set each element of a 2-by-3 matrix.
#include <visp3/core/vpMatrix.h>
int main()
{
M = { -1, -2, -3, -4, -5, -6 };
M.reshape(2, 3);
std::cout << "M:\n" << M << std::endl;
}

It produces the following printings:

M:
-1 -2 -3
-4 -5 -6
See also
operator<<()

Definition at line 745 of file vpMatrix.cpp.

References vpArray2D< double >::data, vpArray2D< double >::dsize, and vpArray2D< double >::resize().

◆ operator=() [2/6]

vpMatrix & vpMatrix::operator= ( const std::initializer_list< std::initializer_list< double > > &  lists)

Set matrix elements from a list of values.

Parameters
lists: List of double.
Returns
The modified Matrix. The following example shows how to set each element of a 2-by-3 matrix.
#include <visp3/core/vpMatrix.h>
int main()
{
M = { {-1, -2, -3}, {-4, -5, -6} };
std::cout << "M:\n" << M << std::endl;
}
It produces the following printings:
M:
-1 -2 -3
-4 -5 -6
See also
operator<<()

Definition at line 779 of file vpMatrix.cpp.

References vpArray2D< double >::resize(), vpArray2D< double >::rowNum, and vpArray2D< double >::rowPtrs.

◆ operator=() [3/6]

vpMatrix & vpMatrix::operator= ( const vpArray2D< double > &  A)

Copy operator that allows to convert on of the following container that inherit from vpArray2D such as vpMatrix, vpRotationMatrix, vpHomogeneousMatrix, vpPoseVector, vpColVector, vpRowVector... into a vpMatrix.

Parameters
A: 2D array to be copied.

The following example shows how to create a matrix from an homogeneous matrix:

Definition at line 670 of file vpMatrix.cpp.

References vpArray2D< double >::data, vpArray2D< Type >::data, vpArray2D< double >::dsize, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), and vpArray2D< double >::resize().

◆ operator=() [4/6]

◆ operator=() [5/6]

vpMatrix & vpMatrix::operator= ( double  x)

Set all the element of the matrix A to x.

Definition at line 799 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, vpArray2D< double >::data, and vpArray2D< double >::rowNum.

◆ operator=() [6/6]

◆ operator==()

bool vpArray2D< double >::operator== ( const vpArray2D< Type > &  A) const
inherited

Equal to comparison operator of a 2D array.

Definition at line 505 of file vpArray2D.h.

◆ operator[]() [1/2]

double * vpArray2D< double >::operator[] ( unsigned int  i)
inlineinherited

Set element $A_{ij} = x$ using A[i][j] = x.

Definition at line 591 of file vpArray2D.h.

◆ operator[]() [2/2]

double * vpArray2D< double >::operator[] ( unsigned int  i) const
inlineinherited

Get element $x = A_{ij}$ using x = A[i][j].

Definition at line 593 of file vpArray2D.h.

◆ print()

int vpMatrix::print ( std::ostream &  s,
unsigned int  length,
const std::string &  intro = "" 
) const

Pretty print a matrix. The data are tabulated. The common widths before and after the decimal point are set with respect to the parameter length.

Parameters
s: Stream used for the printing.
length: The suggested width of each matrix element. If needed, the used length grows in order to accommodate the whole integral part, and shrinks the decimal part to print only length digits.
intro: The introduction which is printed before the matrix. Can be set to zero (or omitted), in which case the introduction is not printed.
Returns
Returns the common total width for all matrix elements.
See also
std::ostream &operator<<(std::ostream &s, const vpArray2D<Type> &A)
Examples
testMatrix.cpp, and testMatrixConditionNumber.cpp.

Definition at line 5382 of file vpMatrix.cpp.

References vpArray2D< double >::getCols(), vpArray2D< double >::getRows(), vpMath::maximum(), and vpArray2D< double >::size().

Referenced by vpServo::computeControlLaw().

◆ printSize()

void vpMatrix::printSize ( ) const
inline

Definition at line 584 of file vpMatrix.h.

References vpArray2D< Type >::getCols(), and vpArray2D< Type >::getRows().

◆ pseudoInverse() [1/10]

vpMatrix vpMatrix::pseudoInverse ( double  svThreshold = 1e-6) const

Compute and return the Moore-Penros pseudo inverse $A^+$ of a m-by-n matrix $\bf A$.

Note
By default, this function uses Lapack 3rd party. It is also possible to use a specific 3rd party suffixing this function name with one of the following 3rd party names (Lapack, Eigen3 or OpenCV).
Warning
To inverse a square n-by-n matrix, you have to use rather one of the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that are kwown as faster.
Parameters
svThreshold: Threshold used to test the singular values. If a singular value is lower than this threshold we consider that the matrix is not full rank.
Returns
The Moore-Penros pseudo inverse $ A^+ $.

Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2.

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(2, 3);
A[0][0] = 2; A[0][1] = 3; A[0][2] = 5;
A[1][0] = -4; A[1][1] = 2; A[1][2] = 3;
A.print(std::cout, 10, "A: ");
A_p.print(std::cout, 10, "A^+ (pseudo-inverse): ");
}
vpMatrix pseudoInverse(double svThreshold=1e-6) const
Definition: vpMatrix.cpp:2343

Once build, the previous example produces the following output:

A: [2,3]=
2 3 5
-4 2 3
A^+ (pseudo-inverse): [3,2]=
0.117899 -0.190782
0.065380 0.039657
0.113612 0.052518
Examples
testFrankaCartVelocity-2.cpp, testMatrixConditionNumber.cpp, testRobotViper650-frames.cpp, and testRobotViper850-frames.cpp.

Definition at line 2343 of file vpMatrix.cpp.

References vpException::fatalError, pseudoInverseEigen3(), pseudoInverseLapack(), and pseudoInverseOpenCV().

Referenced by vpSimulatorAfma6::computeArticularVelocity(), vpSimulatorViper850::computeArticularVelocity(), vpServo::computeControlLaw(), computeCovarianceMatrix(), vpMbEdgeTracker::computeVVSFirstPhasePoseEstimation(), vpMbTracker::computeVVSPoseEstimation(), vpQuadProg::fromCanonicalCost(), vpNurbs::globalCurveApprox(), vpNurbs::globalCurveInterp(), vpHomography::inverse(), vpMeLine::leastSquare(), vpHomogeneousMatrix::mean(), vpRotationMatrix::mean(), vpPose::poseDementhonNonPlan(), vpPose::poseDementhonPlan(), vpPose::poseFromRectangle(), pseudoInverse(), vpHomography::robust(), solveBySVD(), and vpQuadProg::solveQPi().

◆ pseudoInverse() [2/10]

vpMatrix vpMatrix::pseudoInverse ( int  rank_in) const

Compute and return the Moore-Penros pseudo inverse $A^+$ of a m-by-n matrix $\bf A$.

Note
By default, this function uses Lapack 3rd party. It is also possible to use a specific 3rd party suffixing this function name with one of the following 3rd party names (Lapack, Eigen3 or OpenCV).
Warning
To inverse a square n-by-n matrix, you have to use rather one of the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that are kwown as faster.
Parameters
[in]rank_in: Known rank of the matrix.
Returns
The Moore-Penros pseudo inverse $ A^+ $.

Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2.

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(2, 3);
// This matrix rank is 2
A[0][0] = 2; A[0][1] = 3; A[0][2] = 5;
A[1][0] = -4; A[1][1] = 2; A[1][2] = 3;
A.print(std::cout, 10, "A: ");
int rank_in = 2;
vpMatrix A_p = A.pseudoInverseLapack(rank_in);
A_p.print(std::cout, 10, "A^+ (pseudo-inverse): ");
}
vpMatrix pseudoInverseLapack(double svThreshold=1e-6) const

Once build, the previous example produces the following output:

A: [2,3]=
2 3 5
-4 2 3
A^+ (pseudo-inverse): [3,2]=
0.117899 -0.190782
0.065380 0.039657
0.113612 0.052518

Definition at line 2408 of file vpMatrix.cpp.

References vpException::fatalError, pseudoInverseEigen3(), pseudoInverseLapack(), and pseudoInverseOpenCV().

◆ pseudoInverse() [3/10]

unsigned int vpMatrix::pseudoInverse ( vpMatrix Ap,
double  svThreshold = 1e-6 
) const

Compute the Moore-Penros pseudo inverse $A^+$ of a m-by-n matrix $\bf A$ and return the rank of the matrix.

Note
By default, this function uses Lapack 3rd party. It is also possible to use a specific 3rd party suffixing this function name with one of the following 3rd party names (Lapack, Eigen3 or OpenCV).
Warning
To inverse a square n-by-n matrix, you have to use rather one of the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that are kwown as faster.
Parameters
Ap: The Moore-Penros pseudo inverse $ A^+ $.
svThreshold: Threshold used to test the singular values. If a singular value is lower than this threshold we consider that the matrix is not full rank.
Returns
The rank of the matrix.

Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2.

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(2, 3);
A[0][0] = 2; A[0][1] = 3; A[0][2] = 5;
A[1][0] = -4; A[1][1] = 2; A[1][2] = 3;
A.print(std::cout, 10, "A: ");
vpMatrix A_p;
unsigned int rank = A.pseudoInverse(A_p);
A_p.print(std::cout, 10, "A^+ (pseudo-inverse): ");
std::cout << "Rank: " << rank << std::endl;
}

Once build, the previous example produces the following output:

A: [2,3]=
2 3 5
-4 2 3
A^+ (pseudo-inverse): [3,2]=
0.117899 -0.190782
0.065380 0.039657
0.113612 0.052518
Rank: 2

Definition at line 2201 of file vpMatrix.cpp.

References vpException::fatalError, pseudoInverseEigen3(), pseudoInverseLapack(), and pseudoInverseOpenCV().

◆ pseudoInverse() [4/10]

int vpMatrix::pseudoInverse ( vpMatrix Ap,
int  rank_in 
) const

Compute the Moore-Penros pseudo inverse $A^+$ of a m-by-n matrix $\bf A$ and return the rank of the matrix.

Note
By default, this function uses Lapack 3rd party. It is also possible to use a specific 3rd party suffixing this function name with one of the following 3rd party names (Lapack, Eigen3 or OpenCV).
Warning
To inverse a square n-by-n matrix, you have to use rather one of the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that are kwown as faster.
Parameters
Ap: The Moore-Penros pseudo inverse $ A^+ $.
[in]rank_in: Known rank of the matrix.
Returns
The rank of the matrix.

Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2.

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(2, 3);
// This matrix rank is 2
A[0][0] = 2; A[0][1] = 3; A[0][2] = 5;
A[1][0] = -4; A[1][1] = 2; A[1][2] = 3;
A.print(std::cout, 10, "A: ");
vpMatrix A_p;
int rank_in = 2;
int rank_out = A.pseudoInverse(A_p, rank_in);
if (rank_out != rank_in) {
std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl;
std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl;
}
A_p.print(std::cout, 10, "A^+ (pseudo-inverse): ");
std::cout << "Rank in : " << rank_in << std::endl;
std::cout << "Rank out: " << rank_out << std::endl;
}

Once build, the previous example produces the following output:

A: [2,3]=
2 3 5
-4 2 3
A^+ (pseudo-inverse): [3,2]=
0.117899 -0.190782
0.065380 0.039657
0.113612 0.052518
Rank in : 2
Rank out: 2

Definition at line 2277 of file vpMatrix.cpp.

References vpException::fatalError, pseudoInverseEigen3(), pseudoInverseLapack(), and pseudoInverseOpenCV().

◆ pseudoInverse() [5/10]

unsigned int vpMatrix::pseudoInverse ( vpMatrix Ap,
vpColVector sv,
double  svThreshold,
vpMatrix imA,
vpMatrix imAt 
) const

Compute the Moore-Penros pseudo inverse $A^+$ of a m-by-n matrix $\bf A$ along with singular values, $\mbox{Im}(A)$ and $\mbox{Im}(A^T)$ and return the rank of the matrix.

See pseudoInverse(vpMatrix &, vpColVector &, double, vpMatrix &, vpMatrix &, vpMatrix &) const for a complete description of this function.

Warning
To inverse a square n-by-n matrix, you have to use rather one of the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that are kwown as faster.
Parameters
Ap: The Moore-Penros pseudo inverse $ A^+ $.
svVector corresponding to matrix $A$ singular values. The size of this vector is equal to min(m, n).
svThreshold: Threshold used to test the singular values. If a singular value is lower than this threshold we consider that the matrix is not full rank.
imA$\mbox{Im}({\bf A})$ that is a m-by-r matrix.
imAt$\mbox{Im}({\bf A}^T)$ that is n-by-r matrix.
Returns
The rank of the matrix $\bf A$.

Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2.

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(2, 3);
A[0][0] = 2; A[0][1] = 3; A[0][2] = 5;
A[1][0] = -4; A[1][1] = 2; A[1][2] = 3;
A.print(std::cout, 10, "A: ");
vpMatrix A_p;
vpMatrix imA, imAt;
unsigned int rank = A.pseudoInverse(A_p, sv, 1e-6, imA, imAt);
A_p.print(std::cout, 10, "A^+ (pseudo-inverse): ");
std::cout << "Rank: " << rank << std::endl;
std::cout << "Singular values: " << sv.t() << std::endl;
imA.print(std::cout, 10, "Im(A): ");
imAt.print(std::cout, 10, "Im(A^T): ");
}
vpRowVector t() const

Once build, the previous example produces the following output:

A: [2,3]=
2 3 5
-4 2 3
A^+ (pseudo-inverse): [3,2]=
0.117899 -0.190782
0.065380 0.039657
0.113612 0.052518
Rank: 2
Singular values: 6.874359351 4.443330227
Im(A): [2,2]=
0.81458 -0.58003
0.58003 0.81458
Im(A^T): [3,2]=
-0.100515 -0.994397
0.524244 -0.024967
0.845615 -0.102722

Definition at line 4543 of file vpMatrix.cpp.

References pseudoInverse().

◆ pseudoInverse() [6/10]

unsigned int vpMatrix::pseudoInverse ( vpMatrix Ap,
vpColVector sv,
double  svThreshold,
vpMatrix imA,
vpMatrix imAt,
vpMatrix kerAt 
) const

Compute the Moore-Penros pseudo inverse $A^+$ of a m-by-n matrix $\bf A$ along with singular values, $\mbox{Im}(A)$, $\mbox{Im}(A^T)$ and $\mbox{Ker}(A)$ and return the rank of the matrix.

Note
By default, this function uses Lapack 3rd party. It is also possible to use a specific 3rd party suffixing this function name with one of the following 3rd party names (Lapack, Eigen3 or OpenCV).
Warning
To inverse a square n-by-n matrix, you have to use rather inverseByLU(), inverseByCholesky(), or inverseByQR() that are kwown as faster.
Parameters
Ap: The Moore-Penros pseudo inverse $ {\bf A}^+ $.
sv: Vector corresponding to matrix A singular values. The size of this vector is equal to min(m, n).
svThreshold: Threshold used to test the singular values.If a singular value is lower than this threshold we consider that the matrix is not full rank.
imA: $\mbox { Im }({ \bf A })$ that is a m - by - r matrix.
imAt: $\mbox { Im }({ \bf A } ^ T)$ that is n - by - r matrix.
kerAt: The matrix that contains the null space(kernel) of $\bf A$ defined by the matrix $ { \bf X } ^ T$.If matrix $\bf A$ is full rank, the dimension of kerAt is(0, n), otherwise the dimension is (n - r, n). This matrix is thus the transpose of $\mbox { Ker }({ \bf A })$.
Returns
The rank of the matrix $\bf A$.

Here an example to compute the pseudo - inverse of a 2 - by - 3 matrix that is rank 2.

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(2, 3);
A[0][0] = 2; A[0][1] = 3; A[0][2] = 5;
A[1][0] = -4; A[1][1] = 2; A[1][2] = 3;
A.print(std::cout, 10, "A: ");
vpMatrix A_p, imA, imAt, kerAt;
unsigned int rank = A.pseudoInverse(A_p, sv, 1e-6, imA, imAt, kerAt);
A_p.print(std::cout, 10, "A^+ (pseudo-inverse): ");
std::cout << "Rank: " << rank << std::endl;
std::cout << "Singular values: " << sv.t() << std::endl;
imA.print(std::cout, 10, "Im(A): ");
imAt.print(std::cout, 10, "Im(A^T): ");
if (kerAt.size()) {
kerAt.t().print(std::cout, 10, "Ker(A): ");
}
else {
std::cout << "Ker(A) empty " << std::endl;
}
// Reconstruct matrix A from ImA, ImAt, KerAt
vpMatrix S(rank, A.getCols());
for (unsigned int i = 0; i< rank; i++)
S[i][i] = sv[i];
vpMatrix Vt(A.getCols(), A.getCols());
Vt.insert(imAt.t(), 0, 0);
Vt.insert(kerAt, rank, 0);
(imA *S *Vt).print(std::cout, 10, "Im(A) * S * [Im(A^T) | Ker(A)]^T:");
}
unsigned int size() const
Return the number of elements of the 2D array.
Definition: vpArray2D.h:339
vpMatrix t() const
Definition: vpMatrix.cpp:465

Once build, the previous example produces the following output :

A: [2,3] =
2 3 5
-4 2 3
A^+(pseudo-inverse): [3,2]=
0.117899 -0.190782
0.065380 0.039657
0.113612 0.052518
Rank: 2
Singular values: 6.874359351 4.443330227
Im(A): [2,2]=
0.81458 -0.58003
0.58003 0.81458
Im(A^T): [3,2] =
-0.100515 -0.994397
0.524244 -0.024967
0.845615 -0.102722
Ker(A): [3,1]=
-0.032738
-0.851202
0.523816
Im(A) * S * [Im(A^T) | Ker(A)]^T: [2,3]=
2 3 5
-4 2 3

Definition at line 4734 of file vpMatrix.cpp.

References vpException::fatalError, pseudoInverseEigen3(), pseudoInverseLapack(), and pseudoInverseOpenCV().

◆ pseudoInverse() [7/10]

unsigned int vpMatrix::pseudoInverse ( vpMatrix Ap,
vpColVector sv,
double  svThreshold = 1e-6 
) const

Compute the Moore-Penros pseudo inverse $A^+$ of a m-by-n matrix $\bf A$ along with singular values and return the rank of the matrix.

Note
By default, this function uses Lapack 3rd party. It is also possible to use a specific 3rd party suffixing this function name with one of the following 3rd party names (Lapack, Eigen3 or OpenCV).
Warning
To inverse a square n-by-n matrix, you have to use rather one of the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that are kwown as faster.
Parameters
Ap: The Moore-Penros pseudo inverse $ A^+ $.
svVector corresponding to matrix $A$ singular values. The size of this vector is equal to min(m, n).
svThreshold: Threshold used to test the singular values. If a singular value is lower than this threshold we consider that the matrix is not full rank.
Returns
The rank of the matrix $\bf A$.

Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2.

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(2, 3);
A[0][0] = 2; A[0][1] = 3; A[0][2] = 5;
A[1][0] = -4; A[1][1] = 2; A[1][2] = 3;
A.print(std::cout, 10, "A: ");
vpMatrix A_p;
unsigned int rank = A.pseudoInverse(A_p, sv);
A_p.print(std::cout, 10, "A^+ (pseudo-inverse): ");
std::cout << "Rank: " << rank << std::endl;
std::cout << "Singular values: " << sv.t() << std::endl;
}

Once build, the previous example produces the following output:

A: [2,3]=
2 3 5
-4 2 3
A^+ (pseudo-inverse): [3,2]=
0.117899 -0.190782
0.065380 0.039657
0.113612 0.052518
Rank: 2
Singular values: 6.874359351 4.443330227

Definition at line 4370 of file vpMatrix.cpp.

References vpException::fatalError, pseudoInverseEigen3(), pseudoInverseLapack(), and pseudoInverseOpenCV().

◆ pseudoInverse() [8/10]

int vpMatrix::pseudoInverse ( vpMatrix Ap,
vpColVector sv,
int  rank_in 
) const

Compute the Moore-Penros pseudo inverse $A^+$ of a m-by-n matrix $\bf A$ along with singular values and return the rank of the matrix.

Note
By default, this function uses Lapack 3rd party. It is also possible to use a specific 3rd party suffixing this function name with one of the following 3rd party names (Lapack, Eigen3 or OpenCV).
Warning
To inverse a square n-by-n matrix, you have to use rather one of the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that are kwown as faster.
Parameters
Ap: The Moore-Penros pseudo inverse $ A^+ $.
svVector corresponding to matrix $A$ singular values. The size of this vector is equal to min(m, n).
[in]rank_in: Known rank of the matrix.
Returns
The rank of the matrix $\bf A$.

Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2.

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(2, 3);
A[0][0] = 2; A[0][1] = 3; A[0][2] = 5;
A[1][0] = -4; A[1][1] = 2; A[1][2] = 3;
A.print(std::cout, 10, "A: ");
vpMatrix A_p;
int rank_in = 2;
int rank_out = A.pseudoInverse(A_p, sv, rank_in);
if (rank_out != rank_in) {
std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl;
std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl;
}
A_p.print(std::cout, 10, "A^+ (pseudo-inverse): ");
std::cout << "Rank in : " << rank_in << std::endl;
std::cout << "Rank out: " << rank_out << std::endl;
std::cout << "Singular values: " << sv.t() << std::endl;
}

Once build, the previous example produces the following output:

A: [2,3]=
2 3 5
-4 2 3
A^+ (pseudo-inverse): [3,2]=
0.117899 -0.190782
0.065380 0.039657
0.113612 0.052518
Rank in : 2
Rank out: 2
Singular values: 6.874359351 4.443330227

Definition at line 4453 of file vpMatrix.cpp.

References vpException::fatalError, pseudoInverseEigen3(), pseudoInverseLapack(), and pseudoInverseOpenCV().

◆ pseudoInverse() [9/10]

int vpMatrix::pseudoInverse ( vpMatrix Ap,
vpColVector sv,
int  rank_in,
vpMatrix imA,
vpMatrix imAt 
) const

Compute the Moore-Penros pseudo inverse $A^+$ of a m-by-n matrix $\bf A$ along with singular values, $\mbox{Im}(A)$ and $\mbox{Im}(A^T)$ and return the rank of the matrix.

See pseudoInverse(vpMatrix &, vpColVector &, double, vpMatrix &, vpMatrix &, vpMatrix &) const for a complete description of this function.

Warning
To inverse a square n-by-n matrix, you have to use rather one of the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that are kwown as faster.
Parameters
Ap: The Moore-Penros pseudo inverse $ A^+ $.
svVector corresponding to matrix $A$ singular values. The size of this vector is equal to min(m, n).
[in]rank_in: Known rank of the matrix.
imA$\mbox{Im}({\bf A})$ that is a m-by-r matrix.
imAt$\mbox{Im}({\bf A}^T)$ that is n-by-r matrix.
Returns
The rank of the matrix $\bf A$.

Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2.

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(2, 3);
A[0][0] = 2; A[0][1] = 3; A[0][2] = 5;
A[1][0] = -4; A[1][1] = 2; A[1][2] = 3;
A.print(std::cout, 10, "A: ");
vpMatrix A_p;
vpMatrix imA, imAt;
int rank_in = 2;
int rank_out = A.pseudoInverse(A_p, sv, rank_in, imA, imAt);
if (rank_out != rank_in) {
std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl;
std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl;
}
A_p.print(std::cout, 10, "A^+ (pseudo-inverse): ");
std::cout << "Rank in : " << rank_in << std::endl;
std::cout << "Rank out: " << rank_in << std::endl;
std::cout << "Singular values: " << sv.t() << std::endl;
imA.print(std::cout, 10, "Im(A): ");
imAt.print(std::cout, 10, "Im(A^T): ");
}

Once build, the previous example produces the following output:

A: [2,3]=
2 3 5
-4 2 3
A^+ (pseudo-inverse): [3,2]=
0.117899 -0.190782
0.065380 0.039657
0.113612 0.052518
Rank: 2
Singular values: 6.874359351 4.443330227
Im(A): [2,2]=
0.81458 -0.58003
0.58003 0.81458
Im(A^T): [3,2]=
-0.100515 -0.994397
0.524244 -0.024967
0.845615 -0.102722

Definition at line 4627 of file vpMatrix.cpp.

References pseudoInverse().

◆ pseudoInverse() [10/10]

int vpMatrix::pseudoInverse ( vpMatrix Ap,
vpColVector sv,
int  rank_in,
vpMatrix imA,
vpMatrix imAt,
vpMatrix kerAt 
) const

Compute the Moore-Penros pseudo inverse $A^+$ of a m-by-n matrix $\bf A$ along with singular values, $\mbox{Im}(A)$, $\mbox{Im}(A^T)$ and $\mbox { Ker }(A)$ and return the rank of the matrix.

Note
By default, this function uses Lapack 3rd party.It is also possible to use a specific 3rd party suffixing this function name with one of the following 3rd party names(Lapack, Eigen3 or OpenCV).
Warning
To inverse a square n - by - n matrix, you have to use rather inverseByLU(), inverseByCholesky(), or inverseByQR() that are kwown as faster.
Parameters
Ap: The Moore - Penros pseudo inverse $ { \bf A } ^ +$.
sv: Vector corresponding to matrix $A$ singular values.The size of this vector is equal to min(m, n).
[in]rank_in: Known rank of the matrix.
imA: $\mbox { Im }({ \bf A })$ that is a m - by - r matrix.
imAt: $\mbox { Im }({ \bf A } ^T)$ that is n - by - r matrix.
kerAt: The matrix that contains the null space(kernel) of $\bf A$ defined by the matrix $ { \bf X } ^ T$.If matrix $\bf A$ is full rank, the dimension of kerAt is(0, n), otherwise the dimension is(n - r, n).This matrix is thus the transpose of $\mbox { Ker }({ \bf A })$.
Returns
The rank of the matrix $\bf A$.

Here an example to compute the pseudo - inverse of a 2 - by - 3 matrix that is rank 2.

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(2, 3);
A[0][0] = 2; A[0][1] = 3; A[0][2] = 5;
A[1][0] = -4; A[1][1] = 2; A[1][2] = 3;
A.print(std::cout, 10, "A: ");
vpMatrix A_p, imA, imAt, kerAt;
int rank_in = 2;
int rank_out = A.pseudoInverse(A_p, sv, rank_in, imA, imAt, kerAt);
if (rank_out != rank_in) {
std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl;
std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl;
}
A_p.print(std::cout, 10, "A^+ (pseudo-inverse): ");
std::cout << "Rank in : " << rank_in << std::endl;
std::cout << "Rank out: " << rank_out << std::endl;
std::cout << "Singular values: " << sv.t() << std::endl;
imA.print(std::cout, 10, "Im(A): ");
imAt.print(std::cout, 10, "Im(A^T): ");
if (kerAt.size()) {
kerAt.t().print(std::cout, 10, "Ker(A): ");
}
else {
std::cout << "Ker(A) empty " << std::endl;
}
// Reconstruct matrix A from ImA, ImAt, KerAt
vpMatrix S(rank, A.getCols());
for (unsigned int i = 0; i < rank_in; i++)
S[i][i] = sv[i];
vpMatrix Vt(A.getCols(), A.getCols());
Vt.insert(imAt.t(), 0, 0);
Vt.insert(kerAt, rank, 0);
(imA * S * Vt).print(std::cout, 10, "Im(A) * S * [Im(A^T) | Ker(A)]^T:");
}

Once build, the previous example produces the following output :

A : [2, 3] =
2 3 5
- 4 2 3
A ^ +(pseudo - inverse) : [3, 2] =
0.117899 - 0.190782
0.065380 0.039657
0.113612 0.052518
Rank in : 2
Rank out : 2
Singular values : 6.874359351 4.443330227
Im(A) : [2, 2] =
0.81458 - 0.58003
0.58003 0.81458
Im(A ^ T) : [3, 2] =
-0.100515 - 0.994397
0.524244 - 0.024967
0.845615 - 0.102722
Ker(A) : [3, 1] =
-0.032738
- 0.851202
0.523816
Im(A) * S *[Im(A ^ T) | Ker(A)] ^ T : [2, 3] =
2 3 5
- 4 2 3

Definition at line 4861 of file vpMatrix.cpp.

References vpException::fatalError, pseudoInverseEigen3(), pseudoInverseLapack(), and pseudoInverseOpenCV().

◆ pseudoInverseEigen3() [1/8]

vpMatrix vpMatrix::pseudoInverseEigen3 ( double  svThreshold = 1e-6) const

Referenced by pseudoInverse().

◆ pseudoInverseEigen3() [2/8]

vpMatrix vpMatrix::pseudoInverseEigen3 ( int  rank_in) const

◆ pseudoInverseEigen3() [3/8]

unsigned int vpMatrix::pseudoInverseEigen3 ( vpMatrix Ap,
double  svThreshold = 1e-6 
) const

◆ pseudoInverseEigen3() [4/8]

int vpMatrix::pseudoInverseEigen3 ( vpMatrix Ap,
int  rank_in 
) const

◆ pseudoInverseEigen3() [5/8]

unsigned int vpMatrix::pseudoInverseEigen3 ( vpMatrix Ap,
vpColVector sv,
double  svThreshold,
vpMatrix imA,
vpMatrix imAt,
vpMatrix kerAt 
) const

◆ pseudoInverseEigen3() [6/8]

unsigned int vpMatrix::pseudoInverseEigen3 ( vpMatrix Ap,
vpColVector sv,
double  svThreshold = 1e-6 
) const

◆ pseudoInverseEigen3() [7/8]

int vpMatrix::pseudoInverseEigen3 ( vpMatrix Ap,
vpColVector sv,
int  rank_in 
) const

◆ pseudoInverseEigen3() [8/8]

int vpMatrix::pseudoInverseEigen3 ( vpMatrix Ap,
vpColVector sv,
int  rank_in,
vpMatrix imA,
vpMatrix imAt,
vpMatrix kerAt 
) const

◆ pseudoInverseLapack() [1/8]

vpMatrix vpMatrix::pseudoInverseLapack ( double  svThreshold = 1e-6) const

Referenced by pseudoInverse().

◆ pseudoInverseLapack() [2/8]

vpMatrix vpMatrix::pseudoInverseLapack ( int  rank_in) const

◆ pseudoInverseLapack() [3/8]

unsigned int vpMatrix::pseudoInverseLapack ( vpMatrix Ap,
double  svThreshold = 1e-6 
) const

◆ pseudoInverseLapack() [4/8]

int vpMatrix::pseudoInverseLapack ( vpMatrix Ap,
int  rank_in 
) const

◆ pseudoInverseLapack() [5/8]

unsigned int vpMatrix::pseudoInverseLapack ( vpMatrix Ap,
vpColVector sv,
double  svThreshold,
vpMatrix imA,
vpMatrix imAt,
vpMatrix kerAt 
) const

◆ pseudoInverseLapack() [6/8]

unsigned int vpMatrix::pseudoInverseLapack ( vpMatrix Ap,
vpColVector sv,
double  svThreshold = 1e-6 
) const

◆ pseudoInverseLapack() [7/8]

int vpMatrix::pseudoInverseLapack ( vpMatrix Ap,
vpColVector sv,
int  rank_in 
) const

◆ pseudoInverseLapack() [8/8]

int vpMatrix::pseudoInverseLapack ( vpMatrix Ap,
vpColVector sv,
int  rank_in,
vpMatrix imA,
vpMatrix imAt,
vpMatrix kerAt 
) const

◆ pseudoInverseOpenCV() [1/8]

vpMatrix vpMatrix::pseudoInverseOpenCV ( double  svThreshold = 1e-6) const

Referenced by pseudoInverse().

◆ pseudoInverseOpenCV() [2/8]

vpMatrix vpMatrix::pseudoInverseOpenCV ( int  rank_in) const

◆ pseudoInverseOpenCV() [3/8]

unsigned int vpMatrix::pseudoInverseOpenCV ( vpMatrix Ap,
double  svThreshold = 1e-6 
) const

◆ pseudoInverseOpenCV() [4/8]

int vpMatrix::pseudoInverseOpenCV ( vpMatrix Ap,
int  rank_in 
) const

◆ pseudoInverseOpenCV() [5/8]

unsigned int vpMatrix::pseudoInverseOpenCV ( vpMatrix Ap,
vpColVector sv,
double  svThreshold,
vpMatrix imA,
vpMatrix imAt,
vpMatrix kerAt 
) const

◆ pseudoInverseOpenCV() [6/8]

unsigned int vpMatrix::pseudoInverseOpenCV ( vpMatrix Ap,
vpColVector sv,
double  svThreshold = 1e-6 
) const

◆ pseudoInverseOpenCV() [7/8]

int vpMatrix::pseudoInverseOpenCV ( vpMatrix Ap,
vpColVector sv,
int  rank_in 
) const

◆ pseudoInverseOpenCV() [8/8]

int vpMatrix::pseudoInverseOpenCV ( vpMatrix Ap,
vpColVector sv,
int  rank_in,
vpMatrix imA,
vpMatrix imAt,
vpMatrix kerAt 
) const

◆ qr()

unsigned int vpMatrix::qr ( vpMatrix Q,
vpMatrix R,
bool  full = false,
bool  squareR = false,
double  tol = 1e-6 
) const

Compute the QR decomposition of a (m x n) matrix of rank r. Only available if Lapack 3rd party is installed. If Lapack is not installed we use a Lapack built-in version.

Parameters
Q: orthogonal matrix (will be modified).
R: upper-triangular matrix (will be modified).
full: whether or not we want full decomposition.
squareR: will return only the square (min(m,n) x min(m,n)) part of R.
tol: tolerance to test the rank of R.
Returns
The rank r of the matrix.

If full is false (default) then Q is (m x min(n,m)) and R is (min(n,m) x n). We then have this = QR.

If full is true and m > n then Q is (m x m) and R is (n x n). In this case this = Q (R, 0)^T

If squareR is true and n > m then R is (m x m). If r = m then R is invertible.

Here an example:

#include <visp3/core/vpMatrix.h>
double residual(vpMatrix M1, vpMatrix M2)
{
return (M1 - M2).frobeniusNorm();
}
int main()
{
vpMatrix A(4,3);
A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.;
A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.;
A[2][0] = 1/6.; A[2][1] = 1/4.; A[2][2] = 1/2.;
A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/6.;
// Economic QR (Q 4x3, R 3x3)
vpMatrix Q, R;
int r = A.qr(A, R);
std::cout << "QR Residual: "
<< residual(A, Q*R) << std::endl;
// Full QR (Q 4x4, R 3x3)
r = A.qr(Q, R, true);
std::cout << "Full QR Residual: "
<< residual(A, Q.extract(0, 0, 4, 3)*R) << std::endl;
}
unsigned int qr(vpMatrix &Q, vpMatrix &R, bool full=false, bool squareR=false, double tol=1e-6) const
See also
qrPivot()

Definition at line 444 of file vpMatrix_qr.cpp.

References vpException::badValue, vpArray2D< Type >::colNum, vpArray2D< double >::colNum, vpArray2D< Type >::data, vpArray2D< double >::data, vpException::fatalError, vpArray2D< Type >::resize(), vpArray2D< Type >::rowNum, and vpArray2D< double >::rowNum.

Referenced by vpLinProg::colReduction().

◆ qrPivot()

unsigned int vpMatrix::qrPivot ( vpMatrix Q,
vpMatrix R,
vpMatrix P,
bool  full = false,
bool  squareR = false,
double  tol = 1e-6 
) const

Compute the QR pivot decomposition of a (m x n) matrix of rank r. Only available if Lapack 3rd party is installed. If Lapack is not installed we use a Lapack built-in version.

Parameters
Q: orthogonal matrix (will be modified).
R: upper-triangular matrix (will be modified).
P: the (n x n) permutation matrix.
full: whether or not we want full decomposition.
squareR: will return only the (r x r) part of R and the (r x n) part of P.
tol: tolerance to test the rank of R.
Returns
The rank r of the matrix.

If full is false (default) then Q is (m x min(n,m)) and R is (min(n,m) x n). We then have this.P = Q.R.

If full is true and m > n then Q is (m x m) and R is (n x n). In this case this.P = Q (R, 0)^T

If squareR is true then R is (r x r) invertible.

Here an example:

#include <visp3/core/vpMatrix.h>
double residual(vpMatrix M1, vpMatrix M2)
{
return (M1 - M2).frobeniusNorm();
}
int main()
{
vpMatrix A(4,3);
A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/2.;
A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.;
A[2][0] = 1/6.; A[2][1] = 1/4.; A[2][2] = 1/4.;
A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/5.;
// A is (4x3) but rank 2
// Economic QR (Q 4x3, R 3x3)
vpMatrix Q, R, P;
int r = A.qrPivot(Q, R, P);
std::cout << "A rank: " << r << std::endl;
std::cout << "Residual: " << residual(A*P, Q*R) << std::endl;
// Full QR (Q 4x4, R 3x3)
r = A.qrPivot(Q, R, P, true);
std::cout << "QRPivot Residual: " <<
residual(A*P, Q.extract(0, 0, 4, 3)*R) << std::endl;
// Using permutation matrix: keep only non-null part of R
Q.resize(4, r, false); // Q is 4 x 2
R = R.extract(0, 0, r, 3)*P.t(); // R is 2 x 3
std::cout << "Full QRPivot Residual: " <<
residual(A, Q*R) << std::endl;
}
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Definition: vpArray2D.h:352
unsigned int qrPivot(vpMatrix &Q, vpMatrix &R, vpMatrix &P, bool full=false, bool squareR=false, double tol=1e-6) const
See also
qrPivot()

Definition at line 726 of file vpMatrix_qr.cpp.

References vpException::badValue, vpArray2D< Type >::colNum, vpArray2D< double >::colNum, vpArray2D< Type >::data, vpArray2D< double >::data, vpException::fatalError, vpArray2D< Type >::resize(), vpArray2D< Type >::rowNum, and vpArray2D< double >::rowNum.

Referenced by vpLinProg::colReduction(), vpLinProg::rowReduction(), and solveByQR().

◆ reshape()

void vpArray2D< double >::reshape ( unsigned int  nrows,
unsigned int  ncols 
)
inlineinherited
Examples
testMatrixInitialization.cpp.

Definition at line 443 of file vpArray2D.h.

◆ resize()

void vpArray2D< double >::resize ( unsigned int  nrows,
unsigned int  ncols,
bool  flagNullify = true,
bool  recopy_ = true 
)
inlineinherited

Set the size of the array and initialize all the values to zero.

Parameters
nrows: number of rows.
ncols: number of column.
flagNullify: if true, then the array is re-initialized to 0 after resize. If false, the initial values from the common part of the array (common part between old and new version of the array) are kept. Default value is true.
recopy_: if true, will perform an explicit recopy of the old data.
Examples
testArray2D.cpp, testMatrix.cpp, testMatrixDeterminant.cpp, testMatrixInverse.cpp, testMatrixPseudoInverse.cpp, and testSvd.cpp.

Definition at line 352 of file vpArray2D.h.

◆ row()

vpRowVector vpMatrix::row ( unsigned int  i)
Deprecated:
This method is deprecated. You should rather use getRow(). More precisely, the following code:
unsigned int row_index = ...;
... = L.row(row_index);

should be replaced with:

... = L.getRow(row_index - 1);
Warning
Notice row(1) is the 0th row. This function returns the i-th row of the matrix.
Parameters
i: Index of the row to extract noting that row index start at 1 to get the first row.

Definition at line 6653 of file vpMatrix.cpp.

References vpArray2D< double >::getCols().

◆ save()

static bool vpArray2D< double >::save ( const std::string &  filename,
const vpArray2D< Type > &  A,
bool  binary = false,
const char *  header = "" 
)
inlinestaticinherited

Save a matrix to a file.

Parameters
filename: Absolute file name.
A: Array to be saved.
binary: If true the matrix is saved in a binary file, else a text file.
header: Optional line that will be saved at the beginning of the file.
Returns
Returns true if success.

Warning : If you save the matrix as in a text file the precision is less than if you save it in a binary file.

See also
load()

Definition at line 855 of file vpArray2D.h.

◆ saveMatrix()

static bool vpMatrix::saveMatrix ( const std::string &  filename,
const vpArray2D< double > &  M,
bool  binary = false,
const char *  header = "" 
)
inlinestatic

Save a matrix to a file. This function overloads vpArray2D::save().

Parameters
filename: Absolute file name.
M: Matrix to be saved.
binary: If true the matrix is save as a binary file, otherwise as a text file.
header: Optional line that will be saved at the beginning of the file as a header.
Returns
Returns true if no problem appends.
Warning
If you save the matrix as a text file the precision is less than if you save it as a binary file.

The following example shows how to use this function:

#include <visp3/core/vpMatrix.h>
int main()
{
std::string filename("matrix.bin");
bool binary_data = true;
{
vpMatrix M(2, 3);
M[0][0] = -1; M[0][1] = -2; M[0][2] = -3;
M[1][0] = 4; M[1][1] = 5.5; M[1][2] = 6.0f;
std::string header("My header");
if (vpMatrix::saveMatrix(filename, M, binary_data, header.c_str())) {
std::cout << "Matrix saved in " << filename << std::endl;
M.print(std::cout, 10, header);
} else {
std::cout << "Cannot save matrix in " << filename << std::endl;
}
}
{
char header[FILENAME_MAX];
if (vpMatrix::loadMatrix(filename, N, binary_data, header)) {
std::cout << "Matrix loaded from " << filename << std::endl;
N.print(std::cout, 10, header);
} else {
std::cout << "Cannot load matrix from " << filename << std::endl;
}
}
}

The output of this example is the following:

Matrix saved in matrix.bin
My header[2,3]=
  -1.0 -2.0 -3.0
   4.0  5.5  6.0
Matrix loaded from matrix.bin
My header[2,3]=
  -1.0 -2.0 -3.0
   4.0  5.5  6.0

And the content of matrix.bin file where data are saved as binary data is the following:

% cat matrix.bin
My header??@@@%
See also
loadMatrix(), saveMatrixYAML(), loadMatrixYAML()
Examples
testMatrix.cpp.

Definition at line 896 of file vpMatrix.h.

References vpArray2D< Type >::save().

Referenced by vpDot2::defineDots().

◆ saveMatrixYAML()

static bool vpMatrix::saveMatrixYAML ( const std::string &  filename,
const vpArray2D< double > &  M,
const char *  header = "" 
)
inlinestatic

Save a matrix in a YAML-formatted file. This function overloads vpArray2D::saveYAML().

Parameters
filename: Absolute file name.
M: Matrix to be saved in the file.
header: Optional lines that will be saved at the beginning of the file as a header.
Returns
Returns true if success.

The following example shows how to use this function:

#include <visp3/core/vpMatrix.h>
int main()
{
std::string filename("matrix.yaml");
{
vpMatrix M(2, 3);
M[0][0] = -1; M[0][1] = -2; M[0][2] = -3;
M[1][0] = 4; M[1][1] = 5.5; M[1][2] = 6.0f;
std::string header("My header");
if (vpMatrix::saveMatrixYAML(filename, M, header.c_str())) {
std::cout << "Matrix saved in " << filename << std::endl;
M.print(std::cout, 10, header);
} else {
std::cout << "Cannot save matrix in " << filename << std::endl;
}
}
{
char header[FILENAME_MAX];
if (vpMatrix::loadMatrixYAML(filename, N, header)) {
std::cout << "Matrix loaded from " << filename << std::endl;
N.print(std::cout, 10, header);
} else {
std::cout << "Cannot load matrix from " << filename << std::endl;
}
}
}

The output of this example is the following:

Matrix saved in matrix.yaml
My header[2,3]=
  -1.0 -2.0 -3.0
   4.0  5.5  6.0
Matrix loaded from matrix.yaml
My header[2,3]=
  -1.0 -2.0 -3.0
   4.0  5.5  6.0

And the content of matrix.yaml file is the following:

% cat matrix.yaml
My header
rows: 2
cols: 3
data:
  - [-1, -2, -3]
  - [4, 5.5, 6]
See also
saveMatrix(), loadMatrix(), loadMatrixYAML()
Examples
testMatrix.cpp.

Definition at line 972 of file vpMatrix.h.

References vpArray2D< Type >::saveYAML().

◆ saveYAML()

static bool vpArray2D< double >::saveYAML ( const std::string &  filename,
const vpArray2D< Type > &  A,
const char *  header = "" 
)
inlinestaticinherited

Save an array in a YAML-formatted file.

Parameters
filename: absolute file name.
A: array to be saved in the file.
header: optional lines that will be saved at the beginning of the file. Should be YAML-formatted and will adapt to the indentation if any.
Returns
Returns true if success.

Here is an example of outputs.

vpArray2D::saveYAML("matrix.yml", M, "example: a YAML-formatted header");
vpArray2D::saveYAML("matrixIndent.yml", M, "example:\n - a YAML-formatted \
header\n - with inner indentation");
static bool saveYAML(const std::string &filename, const vpArray2D< Type > &A, const char *header="")
Definition: vpArray2D.h:950

Content of matrix.yml:

example: a YAML-formatted header
rows: 3
cols: 4
- [0, 0, 0, 0]
- [0, 0, 0, 0]
- [0, 0, 0, 0]
double * data
Address of the first element of the data array.
Definition: vpArray2D.h:139

Content of matrixIndent.yml:

example:
- a YAML-formatted header
- with inner indentation
rows: 3
cols: 4
- [0, 0, 0, 0]
- [0, 0, 0, 0]
- [0, 0, 0, 0]
See also
loadYAML()

Definition at line 950 of file vpArray2D.h.

◆ setIdentity()

void vpMatrix::setIdentity ( const double &  val = 1.0)
Deprecated:
You should rather use diag(const double &)
Deprecated:
You should rather use diag(const double &)

Set the matrix diagonal elements to val. More generally set M[i][i] = val.

Definition at line 6696 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, and vpArray2D< double >::rowNum.

Referenced by vpServo::secondaryTask().

◆ setLapackMatrixMinSize()

static void vpMatrix::setLapackMatrixMinSize ( unsigned int  min_size)
inlinestatic

Modify default size used to determine if Blas/Lapack basic linear algebra operations are enabled.

To get more info see Tutorial: Basic linear algebra operations.

Parameters
min_size: Minimum size of rows and columns required for a matrix or a vector to use Blas/Lapack third parties like MKL, OpenBLAS, Netlib or Atlas. When matrix or vector size is lower or equal to this parameter, Blas/Lapack is not used. In that case we prefer use naive code that runs faster for small matrices.
See also
getLapackMatrixMinSize()

Definition at line 250 of file vpMatrix.h.

◆ size()

◆ solveByQR() [1/2]

vpColVector vpMatrix::solveByQR ( const vpColVector b) const

Solve a linear system Ax = b using QR Decomposition.

Non destructive wrt. A and B.

Parameters
b: Vector b
Returns
Vector x
Warning
If Ax = b does not have a solution, this method does not return the least-square minimizer. Use solveBySVD() to get this vector.

Here an example:

#include <visp3/core/vpColVector.h>
#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(3,3);
A[0][0] = 4.64;
A[0][1] = 0.288;
A[0][2] = -0.384;
A[1][0] = 0.288;
A[1][1] = 7.3296;
A[1][2] = 2.2272;
A[2][0] = -0.384;
A[2][1] = 2.2272;
A[2][2] = 6.0304;
vpColVector X(3), B(3);
B[0] = 1;
B[1] = 2;
B[2] = 3;
X = A.solveByQR(B);
// Obtained values of X
// X[0] = 0.2468;
// X[1] = 0.120782;
// X[2] = 0.468587;
std::cout << "X:\n" << X << std::endl;
}
See also
qrPivot()

Definition at line 1205 of file vpMatrix_qr.cpp.

References vpArray2D< double >::colNum, and solveByQR().

◆ solveByQR() [2/2]

void vpMatrix::solveByQR ( const vpColVector b,
vpColVector x 
) const

Solve a linear system Ax = b using QR Decomposition.

Non destructive wrt. A and b.

Parameters
b: Vector b
x: Vector x
Warning
If Ax = b does not have a solution, this method does not return the least-square minimizer. Use solveBySVD() to get this vector.

Here an example:

#include <visp3/core/vpColVector.h>
#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(3,3);
A[0][0] = 4.64;
A[0][1] = 0.288;
A[0][2] = -0.384;
A[1][0] = 0.288;
A[1][1] = 7.3296;
A[1][2] = 2.2272;
A[2][0] = -0.384;
A[2][1] = 2.2272;
A[2][2] = 6.0304;
vpColVector X(3), B(3);
B[0] = 1;
B[1] = 2;
B[2] = 3;
A.solveByQR(B, X);
// Obtained values of X
// X[0] = 0.2468;
// X[1] = 0.120782;
// X[2] = 0.468587;
std::cout << "X:\n" << X << std::endl;
}
See also
qrPivot()

Definition at line 1155 of file vpMatrix_qr.cpp.

References vpArray2D< double >::colNum, extract(), inverseTriangular(), qrPivot(), and t().

Referenced by solveByQR(), and vpQuadProg::solveSVDorQR().

◆ solveBySVD() [1/2]

vpColVector vpMatrix::solveBySVD ( const vpColVector B) const

Solve a linear system $ A X = B $ using Singular Value Decomposition (SVD).

Non destructive wrt. A and B.

Parameters
B: Vector $ B $.
Returns
Vector $ X $.

Here an example:

#include <visp3/core/vpColVector.h>
#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(3,3);
A[0][0] = 4.64;
A[0][1] = 0.288;
A[0][2] = -0.384;
A[1][0] = 0.288;
A[1][1] = 7.3296;
A[1][2] = 2.2272;
A[2][0] = -0.384;
A[2][1] = 2.2272;
A[2][2] = 6.0304;
vpColVector X(3), B(3);
B[0] = 1;
B[1] = 2;
B[2] = 3;
X = A.solveBySVD(B);
// Obtained values of X
// X[0] = 0.2468;
// X[1] = 0.120782;
// X[2] = 0.468587;
std::cout << "X:\n" << X << std::endl;
}
See also
solveBySVD(const vpColVector &, vpColVector &)

Definition at line 2061 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, and solveBySVD().

◆ solveBySVD() [2/2]

void vpMatrix::solveBySVD ( const vpColVector b,
vpColVector x 
) const

Solve a linear system $ A X = B $ using Singular Value Decomposition (SVD).

Non destructive wrt. A and B.

Parameters
b: Vector $ B $.
x: Vector $ X $.

Here an example:

#include <visp3/core/vpColVector.h>
#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix A(3,3);
A[0][0] = 4.64;
A[0][1] = 0.288;
A[0][2] = -0.384;
A[1][0] = 0.288;
A[1][1] = 7.3296;
A[1][2] = 2.2272;
A[2][0] = -0.384;
A[2][1] = 2.2272;
A[2][2] = 6.0304;
vpColVector X(3), B(3);
B[0] = 1;
B[1] = 2;
B[2] = 3;
A.solveBySVD(B, X);
// Obtained values of X
// X[0] = 0.2468;
// X[1] = 0.120782;
// X[2] = 0.468587;
std::cout << "X:\n" << X << std::endl;
}
See also
solveBySVD(const vpColVector &)
Examples
quadprog.cpp, and quadprog_eq.cpp.

Definition at line 2010 of file vpMatrix.cpp.

References pseudoInverse().

Referenced by vpMeEllipse::leastSquare(), vpMeEllipse::leastSquareRobust(), vpQuadProg::solveByProjection(), solveBySVD(), vpQuadProg::solveQPe(), and vpQuadProg::solveSVDorQR().

◆ stack() [1/9]

void vpMatrix::stack ( const vpColVector c)

Stack column vector c at the right of the current matrix, or copy if the matrix has no dimensions: this = [ this c ].

Here an example for a robot velocity log matrix:

for(unsigned int i = 0; i<100;i++)
{
log.stack(v);
}
void stack(const vpMatrix &A)
Definition: vpMatrix.cpp:5669
void getVelocity(const vpRobot::vpControlFrameType frame, vpColVector &velocity)
@ ARTICULAR_FRAME
Definition: vpRobot.h:78

Here the log matrix has size 6 rows by 100 columns.

Definition at line 5742 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, vpArray2D< Type >::data, vpArray2D< double >::data, vpException::dimensionError, vpArray2D< Type >::getRows(), vpArray2D< double >::resize(), vpArray2D< double >::rowNum, vpArray2D< double >::rowPtrs, and vpArray2D< Type >::size().

◆ stack() [2/9]

◆ stack() [3/9]

vpMatrix vpMatrix::stack ( const vpMatrix A,
const vpColVector c 
)
static

Stack column vector c to matrix A and return the resulting matrix [ A c ]

Parameters
A: Left matrix.
c: Right column vector.
Returns
Stacked matrix [ A c ]
Warning
A and c must have the same number of rows.

Definition at line 5231 of file vpMatrix.cpp.

References stack().

◆ stack() [4/9]

void vpMatrix::stack ( const vpMatrix A,
const vpColVector c,
vpMatrix C 
)
static

Stack column vector c to the end of matrix A and return the resulting matrix in C.

Parameters
A: Left matrix.
c: Right column vector.
C: Stacked matrix C = [ A c ]
Warning
A and c must have the same number of rows. A and C must be two different objects.

Definition at line 5250 of file vpMatrix.cpp.

References vpArray2D< Type >::data, and stack().

◆ stack() [5/9]

vpMatrix vpMatrix::stack ( const vpMatrix A,
const vpMatrix B 
)
static

Stack matrix B to the end of matrix A and return the resulting matrix [ A B ]^T

Parameters
A: Upper matrix.
B: Lower matrix.
Returns
Stacked matrix [ A B ]^T
Warning
A and B must have the same number of columns.

Definition at line 5128 of file vpMatrix.cpp.

References stack().

◆ stack() [6/9]

void vpMatrix::stack ( const vpMatrix A,
const vpMatrix B,
vpMatrix C 
)
static

Stack matrix B to the end of matrix A and return the resulting matrix in C.

Parameters
A: Upper matrix.
B: Lower matrix.
C: Stacked matrix C = [ A B ]^T
Warning
A and B must have the same number of columns. A and C, B and C must be two different objects.

Definition at line 5148 of file vpMatrix.cpp.

References vpArray2D< Type >::data, vpException::dimensionError, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), vpArray2D< Type >::resize(), and vpArray2D< Type >::size().

◆ stack() [7/9]

vpMatrix vpMatrix::stack ( const vpMatrix A,
const vpRowVector r 
)
static

Stack row vector r to matrix A and return the resulting matrix [ A r ]^T

Parameters
A: Upper matrix.
r: Lower row vector.
Returns
Stacked matrix [ A r ]^T
Warning
A and r must have the same number of columns.

Definition at line 5192 of file vpMatrix.cpp.

References stack().

◆ stack() [8/9]

void vpMatrix::stack ( const vpMatrix A,
const vpRowVector r,
vpMatrix C 
)
static

Stack row vector r to the end of matrix A and return the resulting matrix in C.

Parameters
A: Upper matrix.
r: Lower row vector.
C: Stacked matrix C = [ A r ]^T
Warning
A and r must have the same number of columns. A and C must be two different objects.

Definition at line 5211 of file vpMatrix.cpp.

References vpArray2D< Type >::data, and stack().

◆ stack() [9/9]

void vpMatrix::stack ( const vpRowVector r)

Stack row vector r at the end of the current matrix, or copy if the matrix has no dimensions: this = [ this r ]^T.

Here an example for a robot velocity log :

for(unsigned int i = 0;i<100;i++)
{
Velocities.stack(v.t());
}

Definition at line 5701 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, vpArray2D< Type >::data, vpArray2D< double >::data, vpException::dimensionError, vpArray2D< Type >::getCols(), vpArray2D< double >::resize(), vpArray2D< double >::rowNum, vpArray2D< double >::size(), and vpArray2D< Type >::size().

◆ stackColumns() [1/2]

vpColVector vpMatrix::stackColumns ( )

Stacks columns of a matrix in a vector.

Returns
a vpColVector.

Definition at line 1827 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, and vpArray2D< double >::rowNum.

◆ stackColumns() [2/2]

void vpMatrix::stackColumns ( vpColVector out)

◆ stackMatrices() [1/7]

vpMatrix vpMatrix::stackMatrices ( const vpColVector A,
const vpColVector B 
)
static
Deprecated:
You should rather use vpColVector::stack(const vpColVector &A, const vpColVector &B)

Definition at line 6621 of file vpMatrix.cpp.

References vpColVector::stack().

◆ stackMatrices() [2/7]

void vpMatrix::stackMatrices ( const vpColVector A,
const vpColVector B,
vpColVector C 
)
static
Deprecated:
You should rather use vpColVector::stack(const vpColVector &A, const vpColVector &B, vpColVector &C)

Definition at line 6626 of file vpMatrix.cpp.

References vpColVector::stack().

◆ stackMatrices() [3/7]

vp_deprecated void vpMatrix::stackMatrices ( const vpMatrix A)
inline
Deprecated:
You should rather use stack(const vpMatrix &A)

Definition at line 994 of file vpMatrix.h.

◆ stackMatrices() [4/7]

static vp_deprecated vpMatrix vpMatrix::stackMatrices ( const vpMatrix A,
const vpMatrix B 
)
inlinestatic
Deprecated:
You should rather use stack(const vpMatrix &A, const vpMatrix &B)

Definition at line 999 of file vpMatrix.h.

◆ stackMatrices() [5/7]

static vp_deprecated void vpMatrix::stackMatrices ( const vpMatrix A,
const vpMatrix B,
vpMatrix C 
)
inlinestatic
Deprecated:
You should rather use stack(const vpMatrix &A, const vpMatrix &B, vpMatrix &C)

Definition at line 1004 of file vpMatrix.h.

◆ stackMatrices() [6/7]

vpMatrix vpMatrix::stackMatrices ( const vpMatrix A,
const vpRowVector B 
)
static
Deprecated:
You should rather use stack(const vpMatrix &A, const vpMatrix &B)

Definition at line 6631 of file vpMatrix.cpp.

References stack().

◆ stackMatrices() [7/7]

void vpMatrix::stackMatrices ( const vpMatrix A,
const vpRowVector B,
vpMatrix C 
)
static
Deprecated:
You should rather use stack(const vpMatrix &A, const vpRowVector &B, vpMatrix &C)

Definition at line 6633 of file vpMatrix.cpp.

References stack().

◆ stackRows() [1/2]

vpRowVector vpMatrix::stackRows ( )

Stacks rows of a matrix in a vector.

Returns
a vpRowVector.

Definition at line 1850 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, and vpArray2D< double >::rowNum.

◆ stackRows() [2/2]

void vpMatrix::stackRows ( vpRowVector out)

◆ sub2Matrices() [1/2]

void vpMatrix::sub2Matrices ( const vpColVector A,
const vpColVector B,
vpColVector C 
)
static
Warning
This function is provided for compat with previous releases. You should rather use the functionalities provided in vpColVector class.

Operation C = A - B on column vectors.

The result is placed in the third parameter C and not returned. A new vector won't be allocated for every use of the function (speed gain if used many times with the same result matrix size).

Exceptions
vpException::dimensionErrorIf A and B vectors have not the same size.
See also
vpColVector::operator-()

Definition at line 1503 of file vpMatrix.cpp.

References vpArray2D< Type >::colNum, vpException::dimensionError, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), vpColVector::resize(), vpArray2D< Type >::rowNum, and vpArray2D< Type >::rowPtrs.

◆ sub2Matrices() [2/2]

void vpMatrix::sub2Matrices ( const vpMatrix A,
const vpMatrix B,
vpMatrix C 
)
static

Operation C = A - B.

The result is placed in the third parameter C and not returned. A new matrix won't be allocated for every use of the function (speed gain if used many times with the same result matrix size).

Exceptions
vpException::dimensionErrorIf A and B matrices have not the same size.
See also
operator-()

Definition at line 1537 of file vpMatrix.cpp.

References vpArray2D< Type >::colNum, vpException::dimensionError, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), vpArray2D< Type >::resize(), vpArray2D< Type >::rowNum, and vpArray2D< Type >::rowPtrs.

Referenced by operator-().

◆ sum()

double vpMatrix::sum ( ) const

Return the sum of all the $a_{ij}$ elements of the matrix.

Returns
Value of $\sum a_{ij}$

Definition at line 1644 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, vpArray2D< double >::rowNum, and vpArray2D< double >::rowPtrs.

Referenced by expm().

◆ sumSquare()

double vpMatrix::sumSquare ( ) const

Return the sum square of all the $A_{ij}$ elements of the matrix $A(m, n)$.

Returns
The value $\sum A_{ij}^{2}$.

Definition at line 6595 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, vpArray2D< double >::rowNum, and vpArray2D< double >::rowPtrs.

◆ svd()

void vpMatrix::svd ( vpColVector w,
vpMatrix V 
)

Matrix singular value decomposition (SVD).

This function calls the first following function that is available:

If none of these previous 3rd parties is installed, we use by default svdLapack() with a Lapack built-in version.

Given matrix $M$, this function computes it singular value decomposition such as

\[ M = U \Sigma V^{\top} \]

Warning
This method is destructive wrt. to the matrix $ M $ to decompose. You should make a COPY of that matrix if needed.
Parameters
w: Vector of singular values: $ \Sigma = diag(w) $.
V: Matrix $ V $.

The matrix object `(*this) is updated with $ U $.

Note
The singular values are ordered in decreasing fashion in w. It means that the highest singular value is in w[0].

Here an example of SVD decomposition of a non square Matrix M.

#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix M(3,2);
M[0][0] = 1; M[0][1] = 6;
M[1][0] = 2; M[1][1] = 8;
M[2][0] = 0.5; M[2][1] = 9;
vpMatrix V, Sigma, U = M;
U.svd(w, V);
// Construct the diagonal matrix from the singular values
Sigma.diag(w);
// Reconstruct the initial matrix using the decomposition
vpMatrix Mrec = U * Sigma * V.t();
// Here, Mrec is obtained equal to the initial value of M
// Mrec[0][0] = 1; Mrec[0][1] = 6;
// Mrec[1][0] = 2; Mrec[1][1] = 8;
// Mrec[2][0] = 0.5; Mrec[2][1] = 9;
std::cout << "Reconstructed M matrix: \n" << Mrec << std::endl;
}
void svd(vpColVector &w, vpMatrix &V)
Definition: vpMatrix.cpp:2132
See also
svdLapack(), svdEigen3(), svdOpenCV()
Examples
servoMomentImage.cpp.

Definition at line 2132 of file vpMatrix.cpp.

References vpException::fatalError, svdEigen3(), svdLapack(), and svdOpenCV().

Referenced by vpHomogeneousMatrix::compute3d3dTransformation(), cond(), vpHomography::DLT(), vpMbtFaceDepthNormal::estimatePlaneEquationSVD(), inducedL2Norm(), kernel(), nullSpace(), vpRotationMatrix::orthogonalize(), and svdEigen3().

◆ svdEigen3()

void vpMatrix::svdEigen3 ( vpColVector w,
vpMatrix V 
)

Singular value decomposition (SVD) using Eigen3 3rd party.

Given matrix $M$, this function computes it singular value decomposition such as

\[ M = U \Sigma V^{\top} \]

Warning
This method is destructive wrt. to the matrix $ M $ to decompose. You should make a COPY of that matrix if needed.
Parameters
w: Vector of singular values: $ \Sigma = diag(w) $.
V: Matrix $ V $.

The matrix object (*this) is updated with $ U $.

Note
The singular values are ordered in decreasing fashion in w. It means that the highest singular value is in w[0].

Here an example of SVD decomposition of a non square Matrix M.

#include <visp3/core/vpColVector.h>
#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix M(3,2);
M[0][0] = 1;
M[1][0] = 2;
M[2][0] = 0.5;
M[0][1] = 6;
M[1][1] = 8 ;
M[2][1] = 9 ;
vpMatrix Mrec;
vpMatrix Sigma;
M.svdEigen3(w, V);
// Here M is modified and is now equal to U
// Construct the diagonal matrix from the singular values
Sigma.diag(w);
// Reconstruct the initial matrix M using the decomposition
Mrec = M * Sigma * V.t();
// Here, Mrec is obtained equal to the initial value of M
// Mrec[0][0] = 1;
// Mrec[1][0] = 2;
// Mrec[2][0] = 0.5;
// Mrec[0][1] = 6;
// Mrec[1][1] = 8 ;
// Mrec[2][1] = 9 ;
std::cout << "Reconstructed M matrix: \n" << Mrec << std::endl;
}
void svdEigen3(vpColVector &w, vpMatrix &V)
See also
svd(), svdLapack(), svdOpenCV()

Definition at line 439 of file vpMatrix_svd.cpp.

References vpArray2D< double >::colNum, vpArray2D< Type >::data, vpArray2D< double >::data, vpArray2D< double >::getCols(), vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), vpArray2D< double >::getRows(), vpColVector::resize(), vpArray2D< double >::resize(), vpArray2D< Type >::resize(), vpArray2D< double >::rowNum, vpArray2D< Type >::size(), and svd().

Referenced by svd().

◆ svdLapack()

void vpMatrix::svdLapack ( vpColVector w,
vpMatrix V 
)

Singular value decomposition (SVD) using Lapack 3rd party.

Given matrix $M$, this function computes it singular value decomposition such as

\[ M = U \Sigma V^{\top} \]

Warning
This method is destructive wrt. to the matrix $ M $ to decompose. You should make a COPY of that matrix if needed.
Parameters
w: Vector of singular values: $ \Sigma = diag(w) $.
V: Matrix $ V $.

The matrix object (*this) is updated with $ U $.

Note
The singular values are ordered in decreasing fashion in w. It means that the highest singular value is in w[0].

Here an example of SVD decomposition of a non square Matrix M.

#include <visp3/core/vpColVector.h>
#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix M(3,2);
M[0][0] = 1;
M[1][0] = 2;
M[2][0] = 0.5;
M[0][1] = 6;
M[1][1] = 8 ;
M[2][1] = 9 ;
vpMatrix Mrec;
vpMatrix Sigma;
M.svdLapack(w, V);
// Here M is modified and is now equal to U
// Construct the diagonal matrix from the singular values
Sigma.diag(w);
// Reconstruct the initial matrix M using the decomposition
Mrec = M * Sigma * V.t();
// Here, Mrec is obtained equal to the initial value of M
// Mrec[0][0] = 1;
// Mrec[1][0] = 2;
// Mrec[2][0] = 0.5;
// Mrec[0][1] = 6;
// Mrec[1][1] = 8 ;
// Mrec[2][1] = 9 ;
std::cout << "Reconstructed M matrix: \n" << Mrec << std::endl;
}
void svdLapack(vpColVector &w, vpMatrix &V)
See also
svd(), svdEigen3(), svdOpenCV()

Definition at line 236 of file vpMatrix_svd.cpp.

References vpArray2D< double >::colNum, vpArray2D< Type >::data, vpArray2D< double >::data, vpException::fatalError, vpArray2D< double >::getCols(), vpArray2D< double >::getRows(), vpColVector::resize(), vpArray2D< Type >::resize(), vpArray2D< double >::rowNum, and transpose().

Referenced by svd().

◆ svdOpenCV()

void vpMatrix::svdOpenCV ( vpColVector w,
vpMatrix V 
)

Singular value decomposition (SVD) using OpenCV 3rd party.

Given matrix $M$, this function computes it singular value decomposition such as

\[ M = U \Sigma V^{\top} \]

Warning
This method is destructive wrt. to the matrix $ M $ to decompose. You should make a COPY of that matrix if needed.
Parameters
w: Vector of singular values: $ \Sigma = diag(w) $.
V: Matrix $ V $.

The matrix object (*this) is updated with $ U $.

Note
The singular values are ordered in decreasing fashion in w. It means that the highest singular value is in w[0].

Here an example of SVD decomposition of a non square Matrix M.

#include <visp3/core/vpColVector.h>
#include <visp3/core/vpMatrix.h>
int main()
{
vpMatrix M(3,2);
M[0][0] = 1;
M[1][0] = 2;
M[2][0] = 0.5;
M[0][1] = 6;
M[1][1] = 8 ;
M[2][1] = 9 ;
vpMatrix Mrec;
vpMatrix Sigma;
M.svdOpenCV(w, V);
// Here M is modified and is now equal to U
// Construct the diagonal matrix from the singular values
Sigma.diag(w);
// Reconstruct the initial matrix M using the decomposition
Mrec = M * Sigma * V.t();
// Here, Mrec is obtained equal to the initial value of M
// Mrec[0][0] = 1;
// Mrec[1][0] = 2;
// Mrec[2][0] = 0.5;
// Mrec[0][1] = 6;
// Mrec[1][1] = 8 ;
// Mrec[2][1] = 9 ;
std::cout << "Reconstructed M matrix: \n" << Mrec << std::endl;
}
void svdOpenCV(vpColVector &w, vpMatrix &V)
See also
svd(), svdEigen3(), svdLapack()

Definition at line 149 of file vpMatrix_svd.cpp.

References vpArray2D< Type >::data, vpArray2D< double >::data, vpArray2D< double >::getCols(), vpArray2D< double >::getRows(), vpColVector::resize(), vpArray2D< Type >::resize(), vpArray2D< double >::resize(), and transpose().

Referenced by svd().

◆ t()

◆ transpose() [1/2]

vpMatrix vpMatrix::transpose ( ) const

Compute and return the transpose of the matrix.

See also
t()
Examples
testMatrixPseudoInverse.cpp.

Definition at line 472 of file vpMatrix.cpp.

Referenced by vpLinProg::colReduction(), vpQuadProg::fromCanonicalCost(), vpLinProg::rowReduction(), vpLinProg::solveLP(), vpQuadProg::solveQPi(), svdLapack(), svdOpenCV(), and t().

◆ transpose() [2/2]

void vpMatrix::transpose ( vpMatrix At) const

Compute At the transpose of the matrix.

Parameters
At(output) : Resulting transpose matrix.
See also
t()

Definition at line 484 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, vpArray2D< Type >::data, vpArray2D< double >::data, vpArray2D< Type >::resize(), and vpArray2D< double >::rowNum.

Friends And Related Function Documentation

◆ insert() [1/2]

void vpArray2D< double >::insert ( const vpArray2D< Type > &  A,
const vpArray2D< Type > &  B,
vpArray2D< Type > &  C,
unsigned int  r,
unsigned int  c 
)
related

Insert array B in array A at the given position.

Parameters
A: Main array.
B: Array to insert.
C: Result array.
r: Index of the row where to insert array B.
c: Index of the column where to insert array B.
Warning
Throw exception if the sizes of the arrays do not allow the insertion.

Definition at line 1072 of file vpArray2D.h.

◆ insert() [2/2]

void insert ( const vpMatrix A,
const vpMatrix B,
vpMatrix C,
unsigned int  r,
unsigned int  c 
)
related

Insert matrix B in matrix A at the given position.

Parameters
A: Main matrix.
B: Matrix to insert.
C: Result matrix.
r: Index of the row where to insert matrix B.
c: Index of the column where to insert matrix B.
Warning
Throw exception if the sizes of the matrices do not allow the insertion.

Definition at line 5295 of file vpMatrix.cpp.

◆ operator!=()

bool operator!= ( const vpArray2D< Type > &  A) const
related

Definition at line 1300 of file vpArray2D.h.

◆ operator*()

vpMatrix operator* ( const double &  x,
const vpMatrix B 
)
related

Allow to multiply a scalar by a matrix.

Definition at line 1668 of file vpMatrix.cpp.

References vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), and vpArray2D< Type >::resize().

◆ operator==() [1/2]

bool operator== ( const vpArray2D< double > &  A) const
related

Definition at line 1264 of file vpArray2D.h.

◆ operator==() [2/2]

bool operator== ( const vpArray2D< float > &  A) const
related

Definition at line 1282 of file vpArray2D.h.

◆ vpGEMM()

void vpGEMM ( const vpArray2D< double > &  A,
const vpArray2D< double > &  B,
const double &  alpha,
const vpArray2D< double > &  C,
const double &  beta,
vpArray2D< double > &  D,
const unsigned int &  ops = 0 
)
related

This function performs generalized matrix multiplication: D = alpha*op(A)*op(B) + beta*op(C), where op(X) is X or X^T. Operation on A, B and C matrices is described by enumeration vpGEMMmethod().

For example, to compute D = alpha*A^T*B^T+beta*C we need to call :

vpGEMM(A, B, alpha, C, beta, D, VP_GEMM_A_T + VP_GEMM_B_T);
void vpGEMM(const vpArray2D< double > &A, const vpArray2D< double > &B, const double &alpha, const vpArray2D< double > &C, const double &beta, vpArray2D< double > &D, const unsigned int &ops=0)
Definition: vpGEMM.h:388

If C is not used, vpGEMM must be called using an empty array null. Thus to compute D = alpha*A^T*B, we have to call:

vpGEMM(A, B, alpha, null, 0, D, VP_GEMM_B_T);
Exceptions
vpException::incorrectMatrixSizeErrorif the sizes of the matrices do not allow the operations.
Parameters
A: An array that could be a vpMatrix.
B: An array that could be a vpMatrix.
alpha: A scalar.
C: An array that could be a vpMatrix.
beta: A scalar.
D: The resulting array that could be a vpMatrix.
ops: A scalar describing operation applied on the matrices. Possible values are the one defined in vpGEMMmethod(): VP_GEMM_A_T, VP_GEMM_B_T, VP_GEMM_C_T.

Definition at line 388 of file vpGEMM.h.

◆ vpGEMMmethod

enum vpGEMMmethod
related

Enumeration of the operations applied on matrices in vpGEMM() function.

Operations are :

  • VP_GEMM_A_T to use the transpose matrix of A instead of the matrix A
  • VP_GEMM_B_T to use the transpose matrix of B instead of the matrix B
  • VP_GEMM_C_T to use the transpose matrix of C instead of the matrix C

Definition at line 52 of file vpGEMM.h.

Member Data Documentation

◆ colNum

unsigned int vpArray2D< double >::colNum
protectedinherited

Number of columns in the array.

Definition at line 131 of file vpArray2D.h.

◆ data

double * vpArray2D< double >::data
inherited

◆ dsize

unsigned int vpArray2D< double >::dsize
protectedinherited

Current array size (rowNum * colNum)

Definition at line 135 of file vpArray2D.h.

◆ rowNum

unsigned int vpArray2D< double >::rowNum
protectedinherited

Number of rows in the array.

Definition at line 129 of file vpArray2D.h.

◆ rowPtrs

double ** vpArray2D< double >::rowPtrs
protectedinherited

Address of the first element of each rows.

Definition at line 133 of file vpArray2D.h.