Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpSubMatrix Class Reference

#include <visp3/core/vpSubMatrix.h>

+ Inheritance diagram for vpSubMatrix:

Public Types

enum  vpDetMethod { LU_DECOMPOSITION }
 

Public Member Functions

 vpSubMatrix ()
 
 vpSubMatrix (vpMatrix &m, const unsigned int &row, const unsigned int &col, const unsigned int &nrows, const unsigned int &ncols)
 
 ~vpSubMatrix ()
 
void init (vpMatrix &m, const unsigned int &row, const unsigned int &col, const unsigned int &nrows, const unsigned int &ncols)
 
void checkParentStatus () const
 
vpSubMatrixoperator= (const vpSubMatrix &B)
 
vpSubMatrixoperator= (const vpMatrix &B)
 
vpSubMatrixoperator= (const double &x)
 
void clear ()
 
Setting a diagonal matrix
void diag (const double &val=1.0)
 
void diag (const vpColVector &A)
 
void eye ()
 
Assignment operators
vpMatrixoperator<< (double *)
 
Stacking
void stack (const vpMatrix &A)
 
void stack (const vpRowVector &r)
 
void stackColumns (vpColVector &out)
 
vpColVector stackColumns ()
 
void stackRows (vpRowVector &out)
 
vpRowVector stackRows ()
 
Matrix insertion
void insert (const vpMatrix &A, const unsigned int r, const unsigned int c)
 
Columns, rows, sub-matrices extraction
vpRowVector getRow (const unsigned int i) const
 
vpRowVector getRow (const unsigned int i, const unsigned int j_begin, const unsigned int size) const
 
vpColVector getCol (const unsigned int j) const
 
vpColVector getCol (const unsigned int j, const unsigned int i_begin, const unsigned int size) const
 
void init (const vpMatrix &M, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols)
 
Matrix operations
vpMatrixoperator+= (const vpMatrix &B)
 
vpMatrixoperator+= (const double x)
 
vpMatrixoperator-= (const vpMatrix &B)
 
vpMatrixoperator-= (const double x)
 
vpMatrix operator* (const vpMatrix &B) const
 
vpMatrix operator* (const vpRotationMatrix &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 double x) const
 
vpMatrix operator+ (const vpMatrix &B) const
 
vpMatrix operator- (const vpMatrix &B) const
 
vpMatrix operator- () const
 
vpMatrixoperator*= (const double x)
 
vpMatrixoperator/= (double x)
 
vpMatrix operator/ (const double x) const
 
double sum () const
 
double sumSquare () const
 
double det (vpDetMethod method=LU_DECOMPOSITION) const
 
vpMatrix expm () const
 
Kronecker product
void kron (const vpMatrix &m1, vpMatrix &out) const
 
vpMatrix kron (const vpMatrix &m1) const
 
Transpose
vpMatrix t () const
 
vpMatrix transpose () const
 
void transpose (vpMatrix &C) const
 
vpMatrix AAt () const
 
void AAt (vpMatrix &B) const
 
vpMatrix AtA () const
 
void AtA (vpMatrix &B) const
 
Matrix inversion
vpMatrix inverseByLU () const
 
vpMatrix inverseByCholesky () const
 
vpMatrix inverseByCholeskyLapack () const
 
vpMatrix inverseByQR () const
 
vpMatrix inverseByQRLapack () 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 &kerA) const
 
SVD decomposition
void svd (vpColVector &w, vpMatrix &v)
 
void solveBySVD (const vpColVector &B, vpColVector &x) const
 
vpColVector solveBySVD (const vpColVector &B) const
 
unsigned int kernel (vpMatrix &KerA, double svThreshold=1e-6) const
 
double cond () const
 
Eigen values
vpColVector eigenValues () const
 
void eigenValues (vpColVector &evalue, vpMatrix &evector) const
 
Norms
double euclideanNorm () const
 
double infinityNorm () const
 
Printing
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, char const *intro=0) const
 
void printSize () const
 
Inherited functionalities from vpArray2D
double getMinValue () const
 
double getMaxValue () const
 
unsigned int getRows () const
 
unsigned int getCols () const
 
unsigned int size () const
 
void resize (const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true)
 
double * operator[] (unsigned int i)
 
double * operator[] (unsigned int i) const
 

Static Public Member Functions

Stacking with Static Public Member Functions
static vpMatrix stack (const vpMatrix &A, const vpMatrix &B)
 
static vpMatrix stack (const vpMatrix &A, const vpRowVector &r)
 
static void stack (const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
 
static void stack (const vpMatrix &A, const vpRowVector &r, vpMatrix &C)
 
static vpMatrix juxtaposeMatrices (const vpMatrix &A, const vpMatrix &B)
 
static void juxtaposeMatrices (const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
 
Matrix insertion with Static Public Member Functions
static vpMatrix insert (const vpMatrix &A, const vpMatrix &B, const unsigned int r, const unsigned int c)
 
static void insert (const vpMatrix &A, const vpMatrix &B, vpMatrix &C, const unsigned int r, const unsigned int c)
 
Kronecker product with Static Public Member Functions
static void kron (const vpMatrix &m1, const vpMatrix &m2, vpMatrix &out)
 
static vpMatrix kron (const vpMatrix &m1, const vpMatrix &m2)
 
Setting a diagonal matrix with Static Public Member Functions
static void createDiagonalMatrix (const vpColVector &A, vpMatrix &DA)
 
Matrix operations with Static Public Member Functions
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)
 
Covariance computation with Static Public Member Functions
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)
 
Matrix I/O with Static Public Member Functions
static bool loadMatrix (const std::string &filename, vpArray2D< double > &M, const bool binary=false, char *header=NULL)
 
static bool loadMatrixYAML (const std::string &filename, vpArray2D< double > &M, char *header=NULL)
 
static bool saveMatrix (const std::string &filename, const vpArray2D< double > &M, const 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
static bool load (const std::string &filename, vpArray2D< double > &A, const bool binary=false, char *header=NULL)
 
static bool loadYAML (const std::string &filename, vpArray2D< double > &A, char *header=NULL)
 
static bool save (const std::string &filename, const vpArray2D< double > &A, const bool binary=false, const char *header="")
 
static bool saveYAML (const std::string &filename, const vpArray2D< double > &A, const char *header="")
 

Public Attributes

double * data
 

Protected Attributes

unsigned int pRowNum
 
unsigned int pColNum
 
vpMatrixparent
 
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)
 
enum  vpGEMMmethod
 

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 (const unsigned int i)
 
vp_deprecated vpColVector column (const 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)
 

Detailed Description

Definition of the vpSubMatrix vpSubMatrix class provides a mask on a vpMatrix all properties of vpMatrix are available with a vpSubMatrix.

Author
Jean Laneurit (IRISA - INRIA Rennes)
See Also
vpMatrix vpColvector vpRowVector

Definition at line 62 of file vpSubMatrix.h.

Member Enumeration Documentation

enum vpMatrix::vpDetMethod
inherited

Method used to compute the determinant of a square matrix.

See Also
det()
Enumerator
LU_DECOMPOSITION 

LU decomposition method.

Definition at line 104 of file vpMatrix.h.

Constructor & Destructor Documentation

vpSubMatrix::vpSubMatrix ( )

Default constructor.

Definition at line 44 of file vpSubMatrix.cpp.

vpSubMatrix::vpSubMatrix ( vpMatrix m,
const unsigned int &  row_offset,
const unsigned int &  col_offset,
const unsigned int &  nrows,
const unsigned int &  ncols 
)

Constructor.

Parameters
m: parent matrix
row_offset: row offset
col_offset: col offset
nrows: number of rows of the sub matrix
ncols: number of columns of the sub matrix

Definition at line 57 of file vpSubMatrix.cpp.

References vpMatrix::init().

vpSubMatrix::~vpSubMatrix ( )

Destructor.

Definition at line 175 of file vpSubMatrix.cpp.

References vpArray2D< double >::data.

Member Function Documentation

vpMatrix vpMatrix::AAt ( ) const
inherited

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

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

Definition at line 272 of file vpMatrix.cpp.

void vpMatrix::AAt ( vpMatrix B) const
inherited

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 292 of file vpMatrix.cpp.

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

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

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 915 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 vpMatrix::operator+().

void vpMatrix::add2Matrices ( const vpColVector A,
const vpColVector B,
vpColVector C 
)
staticinherited
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 953 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.

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

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 882 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.

void vpMatrix::AtA ( vpMatrix B) const
inherited

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 331 of file vpMatrix.cpp.

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

void vpSubMatrix::checkParentStatus ( ) const

Check is parent vpRowVector has changed since initialization.

This method can be used to detect if the parent matrix always exits or its size have not changed and throw an exception is not.

Definition at line 106 of file vpSubMatrix.cpp.

References vpArray2D< double >::data, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), vpMatrixException::incorrectMatrixSizeError, parent, pColNum, pRowNum, and vpERROR_TRACE.

void vpMatrix::clear ( )
inlineinherited

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

Definition at line 150 of file vpMatrix.h.

vpColVector vpMatrix::column ( const unsigned int  j)
inherited
Deprecated:
This method is deprecated. You should use getCol().

Return the j-th columns of the matrix.

Warning
notice column(1) is the 0-th column.
Parameters
j: Index of the column to extract.

Definition at line 3652 of file vpMatrix.cpp.

References vpArray2D< double >::getRows().

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

Compute the covariance matrix of the parameters x from a least squares minimisation 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(), vpMatrix::pseudoInverse(), and vpMatrix::t().

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

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

Compute the covariance matrix of the parameters x from a least squares minimisation 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 87 of file vpMatrix_covariance.cpp.

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

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

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 139 of file vpMatrix_covariance.cpp.

References vpMatrix::computeCovarianceMatrix().

Referenced by vpMatrix::computeCovarianceMatrixVVS(), vpMbEdgeMultiTracker::computeVVS(), vpMbEdgeKltTracker::computeVVS(), vpMbEdgeKltMultiTracker::computeVVS(), vpMbEdgeTracker::computeVVS(), vpMbKltTracker::computeVVSCovariance(), and vpPose::poseVirtualVS().

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

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 117 of file vpMatrix_covariance.cpp.

References vpMatrix::computeCovarianceMatrix(), and vpMatrix::computeCovarianceMatrixVVS().

double vpMatrix::cond ( ) const
inherited
Returns
The condition number, the ratio of the largest singular value of the matrix to the smallest.

Definition at line 3500 of file vpMatrix.cpp.

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

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

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

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 2888 of file vpMatrix.cpp.

References vpArray2D< double >::getRows().

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

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 545 of file vpMatrix.cpp.

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

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

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 2838 of file vpMatrix.cpp.

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

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

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.det(vpMatrix::LU_DECOMPOSITION ) << std::endl;
}
Examples:
testMatrixInverse.cpp.

Definition at line 3352 of file vpMatrix.cpp.

References vpMatrix::LU_DECOMPOSITION.

Referenced by vpTemplateTrackerTriangle::init().

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

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

Definition at line 524 of file vpMatrix.cpp.

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

Referenced by vpMbEdgeMultiTracker::computeVVS(), vpMbEdgeKltTracker::computeVVS(), vpMbEdgeKltMultiTracker::computeVVS(), vpMbEdgeTracker::computeVVS(), and vpMbKltTracker::computeVVSCovariance().

void vpMatrix::diag ( const vpColVector A)
inherited

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;
}

Matrix A is now equal to:

1 0 0
0 2 0
0 0 3

Definition at line 478 of file vpMatrix.cpp.

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

vpColVector vpMatrix::eigenValues ( ) const
inherited

Compute the eigenvalues of a n-by-n real symmetric matrix.

Returns
The eigenvalues of a n-by-n real symmetric matrix.
Warning
This method is only available if the Gnu Scientific Library (GSL) is detected as a third party library.
Exceptions
vpException::dimensionErrorIf the matrix is not square.
vpException::fatalErrorIf the matrix is not symmetric.
vpException::functionNotImplementedErrorIf the GSL library 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 3067 of file vpMatrix.cpp.

References vpArray2D< double >::colNum, vpException::dimensionError, vpException::fatalError, vpException::functionNotImplementedError, vpArray2D< double >::rowNum, and vpMatrix::t().

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

Compute the eigenvalues of a n-by-n real symmetric matrix.

Returns
The eigenvalues of a n-by-n real symmetric matrix.
Warning
This method is only available if the Gnu Scientific Library (GSL) is detected as a third party library.
Parameters
evalue: Eigenvalues of the matrix.
evector: Eigenvector of the matrix.
Exceptions
vpException::dimensionErrorIf the matrix is not square.
vpException::fatalErrorIf the matrix is not symmetric.
vpException::functionNotImplementedErrorIf the GSL library 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;
}
See Also
eigenValues()

Definition at line 3179 of file vpMatrix.cpp.

References vpException::dimensionError, vpException::fatalError, vpException::functionNotImplementedError, vpArray2D< Type >::resize(), and vpMatrix::t().

double vpMatrix::euclideanNorm ( ) const
inherited

Compute and return the Euclidean norm $ ||x|| = \sqrt{ \sum{A_{ij}^2}} $.

Returns
The Euclidean norm if the matrix is initialized, 0 otherwise.
See Also
infinityNorm()

Definition at line 3552 of file vpMatrix.cpp.

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

vpMatrix vpMatrix::expm ( ) const
inherited

Compute the exponential matrix of a square matrix.

Returns
Return the exponential matrix.

Definition at line 3372 of file vpMatrix.cpp.

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

Referenced by vpTemplateTrackerWarpHomographySL3::computeCoeff().

vpColVector vpMatrix::getCol ( const unsigned int  j) const
inherited

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

Definition at line 2235 of file vpMatrix.cpp.

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

Referenced by vpHomography::DLT(), vpMatrix::kernel(), vpPose::poseDementhonPlan(), vpPose::poseFromRectangle(), and vpServo::secondaryTaskJointLimitAvoidance().

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

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 2185 of file vpMatrix.cpp.

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

double vpArray2D< double >::getMaxValue ( ) const
inherited

Return the array max value.

Examples:
servoMomentImage.cpp.
double vpArray2D< double >::getMinValue ( ) const
inherited

Return the array min value.

Examples:
servoMomentImage.cpp.
vpRowVector vpMatrix::getRow ( const unsigned int  i) const
inherited

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;
}

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

Definition at line 2282 of file vpMatrix.cpp.

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

Referenced by vpMatrix::pseudoInverse().

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

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 2331 of file vpMatrix.cpp.

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

double vpMatrix::infinityNorm ( ) const
inherited

Compute and return the infinity norm $ {||x||}_{\infty} = max\left(\sum_{j=0}^{n}{\mid x_{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
euclideanNorm()

Definition at line 3573 of file vpMatrix.cpp.

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

void vpSubMatrix::init ( vpMatrix m,
const unsigned int &  row_offset,
const unsigned int &  col_offset,
const unsigned int &  nrows,
const unsigned int &  ncols 
)

Initialisation of vpMatrix.

Initialisation of a sub matrix.

Parameters
m: parent matrix
row_offset: row offset
col_offset: col offset
nrows: number of rows of the sub matrix
ncols: number of columns of the sub matrix

Definition at line 72 of file vpSubMatrix.cpp.

References vpArray2D< double >::colNum, vpArray2D< Type >::data, vpArray2D< double >::data, vpArray2D< double >::dsize, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), vpMatrixException::incorrectMatrixSizeError, parent, pColNum, pRowNum, vpArray2D< double >::rowNum, vpArray2D< double >::rowPtrs, vpMatrixException::subMatrixError, and vpERROR_TRACE.

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

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 ");
}

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
Examples:
testMatrix.cpp.

Definition at line 137 of file vpMatrix.cpp.

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

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

Definition at line 587 of file vpMatrix.h.

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

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

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

Warning
Throw vpException::dimensionError if the dimensions of the matrices do not allow the operation.
Parameters
A: The matrix 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 3011 of file vpMatrix.cpp.

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

Referenced by vpNurbs::curveKnotIns(), and vpMatrix::insert().

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

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 2482 of file vpMatrix.cpp.

References vpMatrix::insert().

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

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 2511 of file vpMatrix.cpp.

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

vpMatrix vpMatrix::inverseByCholesky ( ) const
inherited

Compute the inverse of a n-by-n matrix using the Cholesky decomposition. The matrix must be real and symmetric. Only available if lapack is installed.

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;
}
See Also
pseudoInverse()

Definition at line 113 of file vpMatrix_cholesky.cpp.

References vpArray2D< double >::colNum, vpMatrix::inverseByCholeskyLapack(), vpMatrixException::matrixError, vpArray2D< double >::rowNum, and vpERROR_TRACE.

vpMatrix vpMatrix::inverseByCholeskyLapack ( ) const
inherited
vpMatrix vpMatrix::inverseByLU ( ) const
inherited

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

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.inverseByLU();
std::cout << "Inverse by LU: \n" << A_1 << std::endl;
std::cout << "A*A^-1: \n" << A * A_1 << std::endl;
}
See Also
pseudoInverse()
Examples:
photometricVisualServoing.cpp.

Definition at line 231 of file vpMatrix_lu.cpp.

References vpArray2D< double >::colNum, vpArray2D< Type >::getRows(), vpMatrixException::matrixError, vpArray2D< double >::rowNum, and vpERROR_TRACE.

Referenced by vpMatrix::expm(), vpKalmanFilter::filtering(), vpTemplateTrackerWarpHomographySL3::findWarp(), vpTemplateTrackerWarpAffine::getParamInverse(), vpTemplateTrackerTriangle::init(), vpTemplateTrackerSSDInverseCompositional::initCompInverse(), vpTemplateTrackerZNCCForwardAdditional::initHessienDesired(), vpTemplateTrackerMIForwardCompositional::initHessienDesired(), vpTemplateTrackerZNCCInverseCompositional::initHessienDesired(), vpTemplateTrackerMIESM::initHessienDesired(), vpTemplateTrackerMIForwardAdditional::initHessienDesired(), vpTemplateTrackerMIInverseCompositional::initHessienDesired(), vpTemplateTrackerSSDForwardCompositional::trackNoPyr(), vpTemplateTrackerMIForwardCompositional::trackNoPyr(), vpTemplateTrackerSSDForwardAdditional::trackNoPyr(), vpTemplateTrackerMIESM::trackNoPyr(), vpTemplateTrackerMIForwardAdditional::trackNoPyr(), and vpTemplateTrackerMIInverseCompositional::trackNoPyr().

vpMatrix vpMatrix::inverseByQR ( ) const
inherited

Compute the inverse of a n-by-n matrix using the QR decomposition. Only available if lapack is installed.

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.inverseByQR();
std::cout << "Inverse by QR: \n" << A_1 << std::endl;
std::cout << "A*A^-1: \n" << A * A_1 << std::endl;
}
See Also
pseudoInverse()

Definition at line 224 of file vpMatrix_qr.cpp.

References vpArray2D< double >::colNum, vpMatrix::inverseByQRLapack(), vpMatrixException::matrixError, vpArray2D< double >::rowNum, and vpERROR_TRACE.

vpMatrix vpMatrix::inverseByQRLapack ( ) const
inherited
vpMatrix vpMatrix::juxtaposeMatrices ( const vpMatrix A,
const vpMatrix B 
)
staticinherited

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 column

Definition at line 2552 of file vpMatrix.cpp.

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

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 2579 of file vpMatrix.cpp.

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

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

Function to compute the null space (the kernel) of the interaction matrix A which is not full rank. The null space ( the kernel ) of a matrix A is defined as Null(A) = Ker(A) = {X : A*X =0}.

Parameters
kerA: The matrix to contain the null space (kernel) of A defined by the row vectors (A*KerA.t()=0)
svThreshold: Specify the used threshold in the svd(...) function (a function to compute the singular value decomposition)
Returns
the rank of the matrix.
Examples:
servoViper850Point2DArtVelocity-jointAvoidance-basic.cpp.

Definition at line 3260 of file vpMatrix.cpp.

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

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

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 1404 of file vpMatrix.cpp.

Referenced by vpMatrix::kron().

vpMatrix vpMatrix::kron ( const vpMatrix m) const
inherited

Compute Kronecker product matrix.

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

Definition at line 1446 of file vpMatrix.cpp.

References vpMatrix::kron().

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

Compute Kronecker product matrix.

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

Definition at line 1369 of file vpMatrix.cpp.

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

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

Compute Kronecker product matrix.

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

Definition at line 1415 of file vpMatrix.cpp.

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

static bool vpArray2D< double >::load ( const std::string &  filename,
vpArray2D< double > &  A,
const bool  binary = false,
char *  header = NULL 
)
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 308 of file vpArray2D.h.

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

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

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 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 no problem appends.
Examples:
testMatrix.cpp.

Definition at line 523 of file vpMatrix.h.

References vpArray2D< Type >::load().

Referenced by vpDot2::defineDots().

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

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

Parameters
filename: absolute file name.
M: matrix to be loaded from the file.
header: Header of the file is loaded in this parameter.
Returns
Returns true if no problem appends.
Examples:
testMatrix.cpp.

Definition at line 538 of file vpMatrix.h.

References vpArray2D< Type >::loadYAML().

static bool vpArray2D< double >::loadYAML ( const std::string &  filename,
vpArray2D< double > &  A,
char *  header = NULL 
)
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()

Definition at line 417 of file vpArray2D.h.

References vpArray2D< Type >::resize().

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

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 2797 of file vpMatrix.cpp.

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

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

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 2756 of file vpMatrix.cpp.

References vpArray2D< double >::getRows().

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

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 643 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 vpMatrix::operator*().

void vpMatrix::mult2Matrices ( const vpMatrix A,
const vpMatrix B,
vpRotationMatrix C 
)
staticinherited
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 689 of file vpMatrix.cpp.

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

void vpMatrix::mult2Matrices ( const vpMatrix A,
const vpMatrix B,
vpHomogeneousMatrix C 
)
staticinherited
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 728 of file vpMatrix.cpp.

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

void vpMatrix::mult2Matrices ( const vpMatrix A,
const vpColVector B,
vpColVector C 
)
staticinherited
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 766 of file vpMatrix.cpp.

References vpMatrix::multMatrixVector().

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

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 606 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.

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

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

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 1124 of file vpMatrix.cpp.

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

Referenced by vpMatrix::operator-().

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

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

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

Definition at line 775 of file vpMatrix.cpp.

References vpMatrix::mult2Matrices().

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

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

Definition at line 788 of file vpMatrix.cpp.

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

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

Operator that allow to multiply a matrix by a velocity twist matrix. The matrix should be of dimension m-by-6.

Definition at line 817 of file vpMatrix.cpp.

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

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

Operator that allow to multiply a matrix by a force/torque twist matrix. The matrix should be of dimension m-by-6.

Definition at line 846 of file vpMatrix.cpp.

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

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

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

Definition at line 565 of file vpMatrix.cpp.

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

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

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 591 of file vpMatrix.cpp.

References vpMatrix::multMatrixVector().

vpMatrix vpMatrix::operator* ( const double  x) const
inherited

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

Definition at line 1203 of file vpMatrix.cpp.

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

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

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 1266 of file vpMatrix.cpp.

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

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

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

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

Definition at line 983 of file vpMatrix.cpp.

References vpMatrix::add2Matrices().

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

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

Definition at line 1242 of file vpMatrix.cpp.

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

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

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

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

Definition at line 1072 of file vpMatrix.cpp.

References vpMatrix::sub2Matrices().

vpMatrix vpMatrix::operator- ( void  ) const
inherited

Operation C = -A (A is unchanged).

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

Definition at line 1146 of file vpMatrix.cpp.

References vpMatrix::negateMatrix().

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

Substract x to all the element of the matrix : Aij = Aij - x.

Definition at line 1253 of file vpMatrix.cpp.

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

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

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

Definition at line 1276 of file vpMatrix.cpp.

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

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

Assigment 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 431 of file vpMatrix.cpp.

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

vpSubMatrix & vpSubMatrix::operator= ( const vpSubMatrix B)
vpSubMatrix & vpSubMatrix::operator= ( const vpMatrix B)
vpSubMatrix & vpSubMatrix::operator= ( const double &  x)

Operation such as subA = x.

Operation A = x.

Parameters
x: a scalar

Definition at line 166 of file vpSubMatrix.cpp.

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

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

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

Definition at line 259 of file vpArray2D.h.

References vpArray2D< Type >::rowPtrs.

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

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

Definition at line 261 of file vpArray2D.h.

References vpArray2D< Type >::rowPtrs.

int vpMatrix::print ( std::ostream &  s,
unsigned int  length,
char const *  intro = 0 
) const
inherited

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

Parameters
sStream used for the printing.
lengthThe suggested width of each matrix element. The actual width grows in order to accomodate the whole integral part, and shrinks if the whole extent is not needed for all the numbers.
introThe 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.

Definition at line 2634 of file vpMatrix.cpp.

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

void vpMatrix::printSize ( ) const
inlineinherited

Definition at line 422 of file vpMatrix.h.

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

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

Compute the pseudo inverse of the matrix using the SVD.

Compute and return the pseudo inverse of a n-by-m matrix : $ A^+ $

Parameters
svThreshold: Threshold used to test the singular values.
Returns
Pseudo inverse of the matrix.

Here an example to compute the inverse of a n-by-n matrix. If the matrix is n-by-n it is also possible to use inverseByLU().

#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.pseudoInverse();
std::cout << "Inverse by pseudo inverse: \n" << A_1 << std::endl;
std::cout << "A*A^-1: \n" << A * A_1 << std::endl;
}
See Also
inverseByLU()
Examples:
testRobotViper650-frames.cpp, and testRobotViper850-frames.cpp.

Definition at line 1741 of file vpMatrix.cpp.

Referenced by vpCalibration::calibrationTsai(), vpSimulatorAfma6::computeArticularVelocity(), vpSimulatorViper850::computeArticularVelocity(), vpServo::computeControlLaw(), vpMatrix::computeCovarianceMatrix(), vpMbEdgeKltTracker::computeVVS(), vpMbEdgeKltMultiTracker::computeVVS(), vpMbEdgeTracker::computeVVSFirstPhasePoseEstimation(), vpMbKltTracker::computeVVSPoseEstimation(), vpMbEdgeTracker::computeVVSSecondPhasePoseEstimation(), vpNurbs::globalCurveApprox(), vpNurbs::globalCurveInterp(), vpMeEllipse::initTracking(), vpHomography::inverse(), vpMeLine::leastSquare(), vpPose::poseDementhonNonPlan(), vpPose::poseFromRectangle(), vpPose::poseVirtualVS(), vpMatrix::pseudoInverse(), vpHomography::robust(), and vpMatrix::solveBySVD().

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

Compute the pseudo inverse of the matrix using the SVD. return the rank

Compute the pseudo inverse of the matrix $Ap = A^+$

Parameters
Ap: The pseudo inverse $ A^+ $.
svThreshold: Threshold used to test the singular values.
Returns
Return the rank of the matrix A

Definition at line 1701 of file vpMatrix.cpp.

References vpMatrix::pseudoInverse().

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

Compute the pseudo inverse of the matrix using the SVD. return the rank and the singular value

Compute the pseudo inverse of the matrix $Ap = A^+$

Parameters
Ap: The pseudo inverse $ A^+ $.
sv: Singular values.
svThreshold: Threshold used to test the singular values.
Returns
Return the rank of the matrix A

Definition at line 1757 of file vpMatrix.cpp.

References vpMatrix::pseudoInverse().

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

Compute the pseudo inverse of the matrix using the SVD. return the rank and the singular value, image

Compute the pseudo inverse of the matrix $Ap = A^+$ along with Ker A, Ker $A^T$, Im A and Im $A^T$

Pseudo inverse, kernel and image are computed using the SVD decomposition.

A is an m x n matrix, if m >=n the svd works on A other wise it works on $A^T$.

Therefore if m>=n we have

\[ {\bf A}_{m\times n} = {\bf U}_{m\times m} {\bf S}_{m\times n} {\bf V^\top}_{n\times n} \]

\[ {\bf A}_{m\times n} = \left[\begin{array}{ccc}\mbox{Im} {\bf A} & | & \mbox{Ker} {\bf A^\top} \end{array} \right] {\bf S} \left[ \begin{array}{c} (\mbox{Im} {\bf A^\top})^\top \\ (\mbox{Ker}{\bf A})^\top \end{array}\right] \]

where Im(A) is an m x r matrix (r is the rank of A) and Im(A^T) is an r x n matrix

Parameters
Ap: The pseudo inverse $ A^+ $.
sv: Singular values.
svThreshold: Threshold used to test the singular values.
imAt: Image A^T
imAImage A
Returns
Return the rank of the matrix A

Definition at line 1795 of file vpMatrix.cpp.

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

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

Compute the pseudo inverse of the matrix using the SVD. return the rank and the singular value, image, kernel.

Compute the pseudo inverse of the matrix $Ap = A^+$ along with Ker A, Ker $A^T$, Im A and Im $A^T$

Pseudo inverse, kernel and image are computed using the SVD decomposition.

A is an m x n matrix, if m >=n the svd works on A other wise it works on $A^T$.

Therefore if m>=n we have

\[ {\bf A}_{m\times n} = {\bf U}_{m\times m} {\bf S}_{m\times n} {\bf V^\top}_{n\times n} \]

\[ {\bf A}_{m\times n} = \left[\begin{array}{ccc}\mbox{Im} {\bf A} & | & \mbox{Ker} {\bf A^\top} \end{array} \right] {\bf S} \left[ \begin{array}{c} (\mbox{Im} {\bf A^\top})^\top \\ (\mbox{Ker}{\bf A})^\top \end{array}\right] \]

where Im(A) is an m x r matrix (r is the rank of A) and Im(A^T) is an r x n matrix

Parameters
Ap: The pseudo inverse $ A^+ $.
sv: Singular values.
svThreshold: Threshold used to test the singular values.
imAImage A
imAt: Image A^T
kerA: null space of A
Returns
Return the rank of the matrix A

Definition at line 1971 of file vpMatrix.cpp.

References vpArray2D< double >::getCols(), vpArray2D< Type >::getCols(), vpMatrix::getRow(), vpArray2D< double >::getRows(), vpArray2D< Type >::resize(), vpColVector::resize(), vpRowVector::sumSquare(), vpMatrix::svd(), and vpMatrix::t().

void vpArray2D< double >::resize ( const unsigned int  nrows,
const unsigned int  ncols,
const bool  flagNullify = 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.
Examples:
testArray2D.cpp, testMatrix.cpp, testMatrixInverse.cpp, and testSvd.cpp.

Definition at line 167 of file vpArray2D.h.

References vpArray2D< Type >::colNum, vpArray2D< Type >::data, vpArray2D< Type >::dsize, vpException::memoryAllocationError, vpArray2D< Type >::rowNum, and vpArray2D< Type >::rowPtrs.

Referenced by vpMatrix::diag(), vpMatrix::eye(), vpMatrix::init(), and vpMatrix::operator=().

vpRowVector vpMatrix::row ( const unsigned int  i)
inherited
Deprecated:
This method is deprecated. You should use getRow().

Return the i-th row of the matrix.

Warning
notice row(1) is the 0th row.

Definition at line 3636 of file vpMatrix.cpp.

References vpArray2D< double >::getCols().

static bool vpArray2D< double >::save ( const std::string &  filename,
const vpArray2D< double > &  A,
const 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 499 of file vpArray2D.h.

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

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

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

Parameters
filename: absolute file name.
M: matrix to be saved.
binary: If true the matrix is save 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 no problem appends.

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

Examples:
testMatrix.cpp.

Definition at line 555 of file vpMatrix.h.

References vpArray2D< Type >::save().

Referenced by vpDot2::defineDots().

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

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. Should be YAML-formatted and will adapt to the indentation if any.
Returns
Returns true if success.
Examples:
testMatrix.cpp.

Definition at line 572 of file vpMatrix.h.

References vpArray2D< Type >::saveYAML().

static bool vpArray2D< double >::saveYAML ( const std::string &  filename,
const vpArray2D< double > &  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");

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]

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 588 of file vpArray2D.h.

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

void vpMatrix::setIdentity ( const double &  val = 1.0)
inherited
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 3667 of file vpMatrix.cpp.

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

Referenced by vpServo::secondaryTask().

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

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 &)

Definition at line 1502 of file vpMatrix.cpp.

References vpMatrix::pseudoInverse().

Referenced by vpMatrix::solveBySVD().

vpColVector vpMatrix::solveBySVD ( const vpColVector B) const
inherited

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 1557 of file vpMatrix.cpp.

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

void vpMatrix::stack ( const vpRowVector r)
inherited

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

Definition at line 2992 of file vpMatrix.cpp.

References vpArray2D< double >::rowNum, and vpMatrix::stack().

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

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 2351 of file vpMatrix.cpp.

References vpMatrix::stack().

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

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

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

Definition at line 2375 of file vpMatrix.cpp.

References vpMatrix::stack().

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

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.

Definition at line 2399 of file vpMatrix.cpp.

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

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

Stack row vector v 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.

Definition at line 2441 of file vpMatrix.cpp.

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

void vpMatrix::stackColumns ( vpColVector out)
inherited
vpColVector vpMatrix::stackColumns ( )
inherited

Stacks columns of a matrix in a vector.

Returns
a vpColVector.

Definition at line 1326 of file vpMatrix.cpp.

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

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

Definition at line 591 of file vpMatrix.h.

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

Definition at line 595 of file vpMatrix.h.

References vpMatrix::stack().

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

Definition at line 599 of file vpMatrix.h.

References vpMatrix::stack().

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

Definition at line 3619 of file vpMatrix.cpp.

References vpMatrix::stack().

void vpMatrix::stackMatrices ( const vpMatrix A,
const vpRowVector B,
vpMatrix C 
)
staticinherited
vpMatrix vpMatrix::stackMatrices ( const vpColVector A,
const vpColVector B 
)
staticinherited
void vpMatrix::stackMatrices ( const vpColVector A,
const vpColVector B,
vpColVector C 
)
staticinherited
void vpMatrix::stackRows ( vpRowVector out)
inherited
vpRowVector vpMatrix::stackRows ( )
inherited

Stacks rows of a matrix in a vector.

Returns
a vpRowVector.

Definition at line 1356 of file vpMatrix.cpp.

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

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

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 1042 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 vpMatrix::operator-().

void vpMatrix::sub2Matrices ( const vpColVector A,
const vpColVector B,
vpColVector C 
)
staticinherited
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 1005 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.

double vpMatrix::sum ( ) const
inherited

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

Returns
Value of $\sum a_{ij}$

Definition at line 1155 of file vpMatrix.cpp.

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

Referenced by vpMatrix::expm().

double vpMatrix::sumSquare ( ) const
inherited

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 3593 of file vpMatrix.cpp.

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

void vpMatrix::svd ( vpColVector w,
vpMatrix v 
)
inherited

Singular value decomposition (SVD).

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

Warning
Destructive method wrt. to the matrix $ M $ to decompose. You should make a COPY of that matrix if needed not to CHANGE.
Parameters
w: Vector of singular values. $ \Sigma = diag(w) $.
v: Matrix $ V $.
Returns
Matrix $ U $.
Warning
If the GNU Scientific Library (GSL) third party library is used to compute the SVD decomposition, the singular values $ \Sigma_{i,i} $ are ordered in decreasing fashion in w. This is not the case, if the GSL is not detected by ViSP.

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.svd(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;
}
Examples:
servoMomentImage.cpp.

Definition at line 1631 of file vpMatrix.cpp.

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

Referenced by vpMatrix::cond(), vpHomography::DLT(), vpMatrix::kernel(), vpPose::poseDementhonPlan(), and vpMatrix::pseudoInverse().

vpMatrix vpMatrix::transpose ( ) const
inherited

Compute and return the transpose of the matrix.

See Also
t()

Definition at line 233 of file vpMatrix.cpp.

Referenced by vpServo::computeProjectionOperators(), vpTemplateTrackerWarpSRT::getParamInverse(), and vpTemplateTrackerWarpRT::getParamInverse().

void vpMatrix::transpose ( vpMatrix At) const
inherited

Compute At the transpose of the matrix.

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

Definition at line 245 of file vpMatrix.cpp.

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

Friends And Related Function Documentation

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

Allow to multiply a scalar by a matrix.

Definition at line 1185 of file vpMatrix.cpp.

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

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 57 of file vpGEMM.h.

Member Data Documentation

double * vpArray2D< double >::data
inherited

Address of the first element of the data array.

Examples:
testDisplacement.cpp, testMatrix.cpp, testPoseVector.cpp, and testTranslationVector.cpp.

Definition at line 84 of file vpArray2D.h.

Referenced by vpMatrix::AtA(), vpHomogeneousMatrix::buildFrom(), vpRzyxVector::buildFrom(), vpRzyzVector::buildFrom(), vpRxyzVector::buildFrom(), vpThetaUVector::buildFrom(), vpSubColVector::checkParentStatus(), vpSubRowVector::checkParentStatus(), checkParentStatus(), vpColVector::clear(), vpHomogeneousMatrix::convert(), vpTranslationVector::euclideanNorm(), vpRowVector::euclideanNorm(), vpMatrix::euclideanNorm(), vpMatrix::expm(), vpThetaUVector::extract(), vpThetaUVector::getTheta(), vpThetaUVector::getU(), vpSubColVector::init(), vpSubRowVector::init(), init(), vpTranslationVector::operator*(), vpRowVector::operator*(), vpColVector::operator*(), vpHomography::operator*(), vpTranslationVector::operator-(), vpRowVector::operator-(), vpColVector::operator-(), vpTranslationVector::operator/(), vpRowVector::operator/(), vpColVector::operator/(), vpHomography::operator/(), vpHomography::operator/=(), vpSubColVector::operator=(), vpSubRowVector::operator=(), vpQuaternionVector::operator=(), vpTranslationVector::operator=(), vpRowVector::operator=(), vpRzyxVector::operator=(), vpRzyzVector::operator=(), vpRxyzVector::operator=(), vpColVector::operator=(), vpMatrix::operator=(), vpThetaUVector::operator=(), vpColVector::operator[](), vpRowVector::reshape(), vpColVector::reshape(), vpQuaternionVector::set(), vpMatrix::stackRows(), vpColVector::sum(), vpColVector::sumSquare(), vpRotationVector::t(), vpTranslationVector::t(), vpPoseVector::t(), vpRowVector::t(), vpColVector::t(), vpQuaternionVector::vpQuaternionVector(), vpRxyzVector::vpRxyzVector(), vpRzyxVector::vpRzyxVector(), vpRzyzVector::vpRzyzVector(), vpThetaUVector::vpThetaUVector(), vpQuaternionVector::w(), vpQuaternionVector::x(), vpQuaternionVector::y(), vpQuaternionVector::z(), vpSubColVector::~vpSubColVector(), ~vpSubMatrix(), and vpSubRowVector::~vpSubRowVector().

vpMatrix* vpSubMatrix::parent
protected

Definition at line 76 of file vpSubMatrix.h.

Referenced by checkParentStatus(), and init().

unsigned int vpSubMatrix::pColNum
protected

Definition at line 75 of file vpSubMatrix.h.

Referenced by checkParentStatus(), and init().

unsigned int vpSubMatrix::pRowNum
protected

Definition at line 74 of file vpSubMatrix.h.

Referenced by checkParentStatus(), and init().

unsigned int vpArray2D< double >::rowNum
protectedinherited

Number of rows in the array.

Definition at line 74 of file vpArray2D.h.

Referenced by vpMatrix::AAt(), vpMatrix::AtA(), vpColVector::clear(), vpMatrix::diag(), vpMatrix::eigenValues(), vpMatrix::expm(), vpColVector::extract(), vpMatrix::eye(), vpColVector::infinityNorm(), vpMatrix::infinityNorm(), vpSubColVector::init(), vpSubRowVector::init(), init(), vpMatrix::insert(), vpMatrix::inverseByCholesky(), vpMatrix::inverseByLU(), vpMatrix::inverseByQR(), vpRotationMatrix::operator*(), vpTranslationVector::operator*(), vpHomogeneousMatrix::operator*(), vpColVector::operator*(), vpMatrix::operator*(), vpRotationMatrix::operator*=(), vpTranslationVector::operator*=(), vpColVector::operator*=(), vpMatrix::operator*=(), vpColVector::operator+(), vpColVector::operator+=(), vpMatrix::operator+=(), vpColVector::operator-(), vpColVector::operator-=(), vpMatrix::operator-=(), vpColVector::operator/(), vpMatrix::operator/(), vpTranslationVector::operator/=(), vpColVector::operator/=(), vpMatrix::operator/=(), vpMatrix::operator<<(), vpColVector::operator<<(), vpSubColVector::operator=(), vpSubRowVector::operator=(), operator=(), vpTranslationVector::operator=(), vpRowVector::operator=(), vpColVector::operator=(), vpMatrix::operator=(), vpColVector::reshape(), vpMatrix::setIdentity(), vpMatrix::stack(), vpColVector::stack(), vpMatrix::stackColumns(), vpMatrix::stackRows(), vpColVector::sum(), vpMatrix::sum(), vpRotationVector::sumSquare(), vpTranslationVector::sumSquare(), vpColVector::sumSquare(), vpMatrix::sumSquare(), vpTranslationVector::t(), vpPoseVector::t(), vpColVector::t(), vpMatrix::t(), and vpMatrix::transpose().