SubMatrix

class SubMatrix(*args, **kwargs)

Bases: Matrix

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

Note

See vpMatrix vpColVector vpRowVector

Overloaded function.

  1. __init__(self: visp._visp.core.SubMatrix) -> None

Default constructor.

  1. __init__(self: visp._visp.core.SubMatrix, m: visp._visp.core.Matrix, row: int, col: int, nrows: int, ncols: int) -> None

Constructor.

Parameters:
m

parent matrix

nrows

number of rows of the sub matrix

ncols

number of columns of the sub matrix

Methods

__init__

Overloaded function.

checkParentStatus

Check is parent vpRowVector has changed since initialization.

init

Overloaded function.

Inherited Methods

mult2Matrices

Overloaded function.

kron

Overloaded function.

svdLapack

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

LU_DECOMPOSITION

kronStatic

Overloaded function.

sum

Return the sum of all the \(a_{ij}\) elements of the matrix.

insert

Overloaded function.

inverseByLULapack

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

getCols

Return the number of columns of the 2D array.

computeCovarianceMatrixVVS

Overloaded function.

saveMatrix

Save a matrix to a file.

multMatrixVector

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

computeHLM

Compute \({\bf H} + \alpha * diag({\bf H})\)

infinityNorm

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.

detByLUOpenCV

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

AtA

Overloaded function.

getRows

Return the number of rows of the 2D array.

strCsv

Returns the CSV representation of this data array (see csvPrint in the C++ documentation)

inverseByLUOpenCV

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

detByLULapack

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

pseudoInverseEigen3

Overloaded function.

sub2Matrices

Overloaded function.

svdOpenCV

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

sumSquare

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

inverseByLU

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

printSize

t

Overloaded function.

qr

Compute the QR decomposition of a (m x n) matrix of rank r.

stackRow

Overloaded function.

stackColumns

Overloaded function.

numpy

Numpy view of the underlying array data.

resize

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

computeCovarianceMatrix

Overloaded function.

insertStatic

Insert array B in array A at the given position.

strMatlab

Returns the Matlab representation of this data array (see matlabPrint in the C++ documentation)

solveByQR

Overloaded function.

reshape

stackColumn

Overloaded function.

getMinValue

Return the array min value.

eigenValues

Overloaded function.

clear

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

expm

Compute the exponential matrix of a square matrix.

inverseByQR

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

inverseByCholeskyOpenCV

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

stack

Overloaded function.

print

Pretty print a matrix.

inverseTriangular

Compute the inverse of a full-rank n-by-n triangular matrix.

insertMatrixInMatrix

Overloaded function.

cond

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

DetMethod

Method used to compute the determinant of a square matrix.

inducedL2Norm

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

qrPivot

Compute the QR pivot decomposition of a (m x n) matrix of rank r.

inverseByLUEigen3

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

setLapackMatrixMinSize

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

strCppCode

Returns a C++ code representation of this data array (see cppPrint in the C++ documentation)

pseudoInverseLapack

Overloaded function.

detByLUEigen3

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

stackRows

Overloaded function.

detByLU

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

nullSpace

Overloaded function.

saveMatrixYAML

Save a matrix in a YAML-formatted file.

eye

Overloaded function.

inverseByCholesky

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

negateMatrix

Operation C = -A.

juxtaposeMatrices

Overloaded function.

createDiagonalMatrix

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

det

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

AAt

Overloaded function.

frobeniusNorm

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

kernel

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

inverseByQRLapack

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

strMaple

Returns the CSV representation of this data array (see maplePrint in the C++ documentation)

pseudoInverseOpenCV

Overloaded function.

getDiag

Extract a diagonal vector from a matrix.

add2Matrices

Overloaded function.

inverseByCholeskyLapack

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

stackMatrices

Overloaded function.

getCol

Overloaded function.

svd

Matrix singular value decomposition (SVD).

getLapackMatrixMinSize

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

add2WeightedMatrices

Operation C = A*wA + B*wB

extract

Extract a sub matrix from a matrix M .

pseudoInverse

Overloaded function.

save

Overloaded function.

size

Return the number of elements of the 2D array.

svdEigen3

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

transpose

Overloaded function.

getMaxValue

Return the array max value.

getRow

Overloaded function.

hadamard

Overloaded function.

saveYAML

Save an array in a YAML-formatted file.

diag

Overloaded function.

conv2

Overloaded function.

solveBySVD

Overloaded function.

Operators

__doc__

__init__

Overloaded function.

__module__

Attributes

LU_DECOMPOSITION

__annotations__

__hash__

class DetMethod(self, value: int)

Bases: pybind11_object

Method used to compute the determinant of a square matrix.

Note

See det()

Values:

  • LU_DECOMPOSITION: LU decomposition method.

__and__(self, other: object) object
__eq__(self, other: object) bool
__ge__(self, other: object) bool
__getstate__(self) int
__gt__(self, other: object) bool
__hash__(self) int
__index__(self) int
__init__(self, value: int)
__int__(self) int
__invert__(self) object
__le__(self, other: object) bool
__lt__(self, other: object) bool
__ne__(self, other: object) bool
__or__(self, other: object) object
__rand__(self, other: object) object
__ror__(self, other: object) object
__rxor__(self, other: object) object
__setstate__(self, state: int) None
__xor__(self, other: object) object
property name : str
AAt(*args, **kwargs)

Overloaded function.

  1. AAt(self: visp._visp.core.Matrix) -> visp._visp.core.Matrix

Note

See AAt(vpMatrix &) const

Returns:

\(A*A^T\)

  1. AAt(self: visp._visp.core.Matrix, B: visp._visp.core.Matrix) -> None

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.

Note

See AAt()

AtA(*args, **kwargs)

Overloaded function.

  1. AtA(self: visp._visp.core.Matrix) -> visp._visp.core.Matrix

Note

See AtA(vpMatrix &) const

Returns:

\(A^T*A\)

  1. AtA(self: visp._visp.core.Matrix, B: visp._visp.core.Matrix) -> None

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.

Note

See AtA()

__add__(self, B: visp._visp.core.Matrix) visp._visp.core.Matrix

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

Note

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

__eq__(*args, **kwargs)

Overloaded function.

  1. __eq__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool

Equal to comparison operator of a 2D array.

  1. __eq__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool

Equal to comparison operator of a 2D array.

  1. __eq__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool

Equal to comparison operator of a 2D array.

__getitem__(*args, **kwargs)

Overloaded function.

  1. __getitem__(self: visp._visp.core.Matrix, arg0: tuple[int, int]) -> float

  2. __getitem__(self: visp._visp.core.Matrix, arg0: int) -> numpy.ndarray[numpy.float64]

  3. __getitem__(self: visp._visp.core.Matrix, arg0: slice) -> numpy.ndarray[numpy.float64]

  4. __getitem__(self: visp._visp.core.Matrix, arg0: tuple) -> numpy.ndarray[numpy.float64]

__iadd__(*args, **kwargs)

Overloaded function.

  1. __iadd__(self: visp._visp.core.Matrix, B: visp._visp.core.Matrix) -> visp._visp.core.Matrix

Operation A = A + B.

  1. __iadd__(self: visp._visp.core.Matrix, x: float) -> visp._visp.core.Matrix

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

__imul__(self, x: float) visp._visp.core.Matrix

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.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: visp._visp.core.SubMatrix) -> None

Default constructor.

  1. __init__(self: visp._visp.core.SubMatrix, m: visp._visp.core.Matrix, row: int, col: int, nrows: int, ncols: int) -> None

Constructor.

Parameters:
m

parent matrix

nrows

number of rows of the sub matrix

ncols

number of columns of the sub matrix

__isub__(*args, **kwargs)

Overloaded function.

  1. __isub__(self: visp._visp.core.Matrix, B: visp._visp.core.Matrix) -> visp._visp.core.Matrix

Operation A = A - B.

  1. __isub__(self: visp._visp.core.Matrix, x: float) -> visp._visp.core.Matrix

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

__itruediv__(self, x: float) visp._visp.core.Matrix

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

__mul__(*args, **kwargs)

Overloaded function.

  1. __mul__(self: visp._visp.core.Matrix, B: visp._visp.core.Matrix) -> visp._visp.core.Matrix

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

Note

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

  1. __mul__(self: visp._visp.core.Matrix, R: visp._visp.core.RotationMatrix) -> visp._visp.core.Matrix

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

  1. __mul__(self: visp._visp.core.Matrix, R: visp._visp.core.HomogeneousMatrix) -> visp._visp.core.Matrix

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

  1. __mul__(self: visp._visp.core.Matrix, V: visp._visp.core.VelocityTwistMatrix) -> visp._visp.core.Matrix

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

  1. __mul__(self: visp._visp.core.Matrix, V: visp._visp.core.ForceTwistMatrix) -> visp._visp.core.Matrix

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

  1. __mul__(self: visp._visp.core.Matrix, tv: visp._visp.core.TranslationVector) -> visp._visp.core.TranslationVector

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

  1. __mul__(self: visp._visp.core.Matrix, v: visp._visp.core.ColVector) -> visp._visp.core.ColVector

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

Note

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

  1. __mul__(self: visp._visp.core.Matrix, x: float) -> visp._visp.core.Matrix

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

__ne__(*args, **kwargs)

Overloaded function.

  1. __ne__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool

Not equal to comparison operator of a 2D array.

  1. __ne__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool

Not equal to comparison operator of a 2D array.

  1. __ne__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool

Not equal to comparison operator of a 2D array.

__neg__(self) visp._visp.core.Matrix

Operation C = -A (A is unchanged).

Note

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

__sub__(self, B: visp._visp.core.Matrix) visp._visp.core.Matrix

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

Note

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

__truediv__(self, x: float) visp._visp.core.Matrix

Cij = Aij / x (A is unchanged)

static add2Matrices(*args, **kwargs)

Overloaded function.

  1. add2Matrices(A: visp._visp.core.Matrix, B: visp._visp.core.Matrix, C: visp._visp.core.Matrix) -> None

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

Note

See operator+()

  1. add2Matrices(A: visp._visp.core.ColVector, B: visp._visp.core.ColVector, C: visp._visp.core.ColVector) -> None

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

Note

See vpColVector::operator+()

static add2WeightedMatrices(A: visp._visp.core.Matrix, wA: float, B: visp._visp.core.Matrix, wB: float, C: visp._visp.core.Matrix) None

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

Note

See operator+()

checkParentStatus(self) None

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.

clear(self) None

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

static computeCovarianceMatrix(*args, **kwargs)

Overloaded function.

  1. computeCovarianceMatrix(A: visp._visp.core.Matrix, x: visp._visp.core.ColVector, b: visp._visp.core.ColVector) -> visp._visp.core.Matrix

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.

  1. computeCovarianceMatrix(A: visp._visp.core.Matrix, x: visp._visp.core.ColVector, b: visp._visp.core.ColVector, w: visp._visp.core.Matrix) -> visp._visp.core.Matrix

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.

static computeCovarianceMatrixVVS(*args, **kwargs)

Overloaded function.

  1. computeCovarianceMatrixVVS(cMo: visp._visp.core.HomogeneousMatrix, deltaS: visp._visp.core.ColVector, Ls: visp._visp.core.Matrix, W: visp._visp.core.Matrix) -> visp._visp.core.Matrix

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.

  1. computeCovarianceMatrixVVS(cMo: visp._visp.core.HomogeneousMatrix, deltaS: visp._visp.core.ColVector, Ls: visp._visp.core.Matrix) -> visp._visp.core.Matrix

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

static computeHLM(H: visp._visp.core.Matrix, alpha: float, HLM: visp._visp.core.Matrix) None

Compute \({\bf H} + \alpha * diag({\bf H})\)

Parameters:
H: visp._visp.core.Matrix

input Matrix \({\bf H}\) . This matrix should be square.

alpha: float

Scalar \(\alpha\)

HLM: visp._visp.core.Matrix

Resulting operation.

cond(self, svThreshold: float = 1e-6) float
Parameters:
svThreshold: float = 1e-6

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 condition number, the ratio of the largest singular value of the matrix to the smallest.

static conv2(*args, **kwargs)

Overloaded function.

  1. conv2(M: visp._visp.core.ArrayDouble2D, kernel: visp._visp.core.ArrayDouble2D, mode: str) -> visp._visp.core.ArrayDouble2D

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

<unparsed image <doxmlparser.compound.docImageType object at 0x7ff6a36292a0>>

Note

This is a very basic implementation that does not use FFT.

Parameters:
M

First matrix.

kernel

Second matrix.

mode

Convolution mode: “full” (default), “same”, “valid”.

  1. conv2(M: visp._visp.core.ArrayDouble2D, kernel: visp._visp.core.ArrayDouble2D, res: visp._visp.core.ArrayDouble2D, mode: str) -> None

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

<unparsed image <doxmlparser.compound.docImageType object at 0x7ff6a362aec0>>

Note

This is a very basic implementation that does not use FFT.

Parameters:
M

First array.

kernel

Second array.

res

Result.

mode

Convolution mode: “full” (default), “same”, “valid”.

static createDiagonalMatrix(A: visp._visp.core.ColVector, DA: visp._visp.core.Matrix) None

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

Note

See diag()

Parameters:
A: visp._visp.core.ColVector

Vector which element will be put in the diagonal.

DA: visp._visp.core.Matrix

Diagonal matrix DA[i][i] = A[i]

det(self, method: visp._visp.core.Matrix.DetMethod) float

Compute the determinant of a n-by-n 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;
}
Parameters:
method: visp._visp.core.Matrix.DetMethod

Method used to compute the determinant. Default LU decomposition method is faster than the method based on Gaussian elimination.

Returns:

Determinant of the matrix.

detByLU(self) float

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

This function calls the first following function that is available:

  • detByLULapack() if Lapack 3rd party is installed

  • detByLUEigen3() if Eigen3 3rd party is installed

  • detByLUOpenCV() if OpenCV 3rd party is installed.

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

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

Note

See detByLULapack() , detByLUEigen3() , detByLUOpenCV()

Returns:

The determinant of the matrix if the matrix is square.

detByLUEigen3(self) float

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

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

Note

See detByLU() , detByLUOpenCV() , detByLULapack()

Returns:

The determinant of the matrix if the matrix is square.

detByLULapack(self) float

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

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

Note

See detByLU() , detByLUEigen3() , detByLUOpenCV()

Returns:

The determinant of the matrix if the matrix is square.

detByLUOpenCV(self) float

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

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

Note

See detByLU() , detByLUEigen3() , detByLULapack()

Returns:

Determinant of the matrix.

diag(*args, **kwargs)

Overloaded function.

  1. diag(self: visp._visp.core.Matrix, val: float = 1.0) -> None

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.

Note

See 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
Parameters:
val

Value to set.

  1. diag(self: visp._visp.core.Matrix, A: visp._visp.core.ColVector) -> None

Create a diagonal matrix with the element of a vector.

Note

See createDiagonalMatrix()

#include <iostream>

#include <visp3/core/vpColVector.h>
#include <visp3/core/vpMatrix.h>

int main()
{
  vpMatrix A;
  vpColVector v(3);

  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
Parameters:
A

Vector which element will be put in the diagonal.

eigenValues(*args, **kwargs)

Overloaded function.

  1. eigenValues(self: visp._visp.core.Matrix) -> visp._visp.core.ColVector

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

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

Note

See eigenValues(vpColVector &, vpMatrix &)

Returns:

The eigenvalues of a n-by-n real symmetric matrix, sorted in ascending order.

  1. eigenValues(self: visp._visp.core.Matrix, evalue: visp._visp.core.ColVector, evector: visp._visp.core.Matrix) -> None

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

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;

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

Note

See eigenValues()

Parameters:
evalue

Eigenvalues of the matrix, sorted in ascending order.

evector

Corresponding eigenvectors of the matrix.

expm(self) visp._visp.core.Matrix

Compute the exponential matrix of a square matrix.

Returns:

Return the exponential matrix.

extract(self, r: int, c: int, nrows: int, ncols: int) visp._visp.core.Matrix

Extract a sub matrix from a matrix M .

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

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

Note

See init (const vpMatrix &, unsigned int, unsigned int, unsigned int, unsigned int)

Parameters:
r: int

row index in matrix M .

c: int

column index in matrix M .

nrows: int

Number of rows of the matrix that should be extracted.

ncols: int

Number of columns of the matrix that should be extracted.

eye(*args, **kwargs)

Overloaded function.

  1. eye(self: visp._visp.core.Matrix) -> None

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

  1. eye(self: visp._visp.core.Matrix, n: int) -> None

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

  1. eye(self: visp._visp.core.Matrix, m: int, n: int) -> None

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

frobeniusNorm(self) float

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

Note

See infinityNorm() , inducedL2Norm()

Returns:

The Frobenius norm (also called Euclidean norm) if the matrix is initialized, 0 otherwise.

getCol(*args, **kwargs)

Overloaded function.

  1. getCol(self: visp._visp.core.Matrix, j: int) -> visp._visp.core.ColVector

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
Parameters:
j

Index of the column to extract. If j=0, the first column is extracted.

Returns:

The extracted column vector.

  1. getCol(self: visp._visp.core.Matrix, j: int, i_begin: int, size: int) -> visp._visp.core.ColVector

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

Returns:

The extracted column vector.

getCols(self) int

Return the number of columns of the 2D array.

Note

See getRows() , size()

getDiag(self) visp._visp.core.ColVector

Extract a diagonal vector from a 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
Returns:

The diagonal of the matrix.

static getLapackMatrixMinSize() int

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.

Note

See setLapackMatrixMinSize()

getMaxValue(self) float

Return the array max value.

getMinValue(self) float

Return the array min value.

getRow(*args, **kwargs)

Overloaded function.

  1. getRow(self: visp._visp.core.Matrix, i: int) -> visp._visp.core.RowVector

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
Parameters:
i

Index of the row to extract. If i=0, the first row is extracted.

Returns:

The extracted row vector.

  1. getRow(self: visp._visp.core.Matrix, i: int, j_begin: int, size: int) -> visp._visp.core.RowVector

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

Returns:

The extracted row vector.

getRows(self) int

Return the number of rows of the 2D array.

Note

See getCols() , size()

hadamard(*args, **kwargs)

Overloaded function.

  1. hadamard(self: visp._visp.core.Matrix, m: visp._visp.core.Matrix) -> visp._visp.core.Matrix

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}\)

  1. hadamard(self: visp._visp.core.ArrayDouble2D, m: visp._visp.core.ArrayDouble2D) -> visp._visp.core.ArrayDouble2D

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}\)

inducedL2Norm(self) float

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

Note

See infinityNorm() , frobeniusNorm()

Returns:

The induced L2 norm if the matrix is initialized, 0 otherwise.

infinityNorm(self) float

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.

Note

See frobeniusNorm() , inducedL2Norm()

Returns:

The infinity norm if the matrix is initialized, 0 otherwise.

init(*args, **kwargs)

Overloaded function.

  1. init(self: visp._visp.core.SubMatrix, m: visp._visp.core.Matrix, row: int, col: int, nrows: int, ncols: int) -> None

Initialisation of vpMatrix .

Initialisation of a sub matrix.

Parameters:
m

parent matrix

nrows

number of rows of the sub matrix

ncols

number of columns of the sub matrix

  1. init(self: visp._visp.core.Matrix, M: visp._visp.core.Matrix, r: int, c: int, nrows: int, ncols: int) -> None

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

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

  vpMatrix N;
  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

Note

See extract()

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.

insert(*args, **kwargs)

Overloaded function.

  1. insert(self: visp._visp.core.Matrix, A: visp._visp.core.Matrix, r: int, c: int) -> None

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.

  1. insert(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D, r: int, c: int) -> None

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.

  1. insert(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D, B: visp._visp.core.ArrayDouble2D, r: int, c: int) -> visp._visp.core.ArrayDouble2D

Insert array B in array A at the given position.

Warning

Throw exception if the sizes of the arrays do not allow the insertion.

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.

static insertMatrixInMatrix(*args, **kwargs)

Overloaded function.

  1. insertMatrixInMatrix(A: visp._visp.core.Matrix, B: visp._visp.core.Matrix, r: int, c: int) -> visp._visp.core.Matrix

Insert matrix B in matrix A at the given position.

Warning

Throw exception if the sizes of the matrices do not allow the insertion.

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.

  1. insertMatrixInMatrix(A: visp._visp.core.Matrix, B: visp._visp.core.Matrix, C: visp._visp.core.Matrix, r: int, c: int) -> None

Insert matrix B in matrix A at the given position.

Warning

Throw exception if the sizes of the matrices do not allow the insertion.

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.

static insertStatic(A: visp._visp.core.ArrayDouble2D, B: visp._visp.core.ArrayDouble2D, C: visp._visp.core.ArrayDouble2D, r: int, c: int) None

Insert array B in array A at the given position.

Warning

Throw exception if the sizes of the arrays do not allow the insertion.

Parameters:
A: visp._visp.core.ArrayDouble2D

Main array.

B: visp._visp.core.ArrayDouble2D

Array to insert.

C: visp._visp.core.ArrayDouble2D

Result array.

r: int

Index of the row where to insert array B.

c: int

Index of the column where to insert array B.

inverseByCholesky(self) visp._visp.core.Matrix

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:

  • inverseByCholeskyLapack() if Lapack 3rd party is installed

  • inverseByLUOpenCV() if OpenCV 3rd party is installed.

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

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

Note

See pseudoInverse()

Returns:

The inverse matrix.

inverseByCholeskyLapack(self) visp._visp.core.Matrix

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.

Here an example:

#include <visp3/core/vpMatrix.h>

int main()
{
  unsigned int n = 4;
  vpMatrix A(n, n);
  vpMatrix I;
  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
  vpMatrix A_1 = A.inverseByCholeskyLapack();
  std::cout << "Inverse by Cholesky (Lapack): \n" << A_1 << std::endl;

  std::cout << "A*A^-1: \n" << A * A_1 << std::endl;
}

Note

See inverseByCholesky() , inverseByCholeskyOpenCV()

Returns:

The inverse matrix.

inverseByCholeskyOpenCV(self) visp._visp.core.Matrix

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.

Here an example:

#include <visp3/core/vpMatrix.h>

int main()
{
  unsigned int n = 4;
  vpMatrix A(n, n);
  vpMatrix I;
  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
  vpMatrix A_1 = A.inverseByCholeskyOpenCV();
  std::cout << "Inverse by Cholesky (OpenCV): \n" << A_1 << std::endl;

  std::cout << "A*A^-1: \n" << A * A_1 << std::endl;
}

Note

See inverseByCholesky() , inverseByCholeskyLapack()

Returns:

The inverse matrix.

inverseByLU(self) visp._visp.core.Matrix

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

This function calls the first following function that is available:

  • inverseByLULapack() if Lapack 3rd party is installed

  • inverseByLUEigen3() if Eigen3 3rd party is installed

  • inverseByLUOpenCV() if OpenCV 3rd party is installed

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

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

Note

See inverseByLULapack() , inverseByLUEigen3() , inverseByLUOpenCV() , pseudoInverse()

Returns:

The inverse matrix.

inverseByLUEigen3(self) visp._visp.core.Matrix

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

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

Note

See inverseByLU() , inverseByLULapack() , inverseByLUOpenCV()

Returns:

The inverse matrix.

inverseByLULapack(self) visp._visp.core.Matrix

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

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

Note

See inverseByLU() , inverseByLUEigen3() , inverseByLUOpenCV()

Returns:

The inverse matrix.

inverseByLUOpenCV(self) visp._visp.core.Matrix

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

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

Note

See inverseByLU() , inverseByLUEigen3() , inverseByLULapack()

Returns:

The inverse matrix.

inverseByQR(self) visp._visp.core.Matrix

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.

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

Note

See inverseByLU() , inverseByCholesky()

Returns:

The inverse matrix.

inverseByQRLapack(self) visp._visp.core.Matrix

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

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.inverseByQRLapack();
  std::cout << "Inverse by QR: \n" << A_1 << std::endl;

  std::cout << "A*A^-1: \n" << A * A_1 << std::endl;
}

Note

See inverseByQR()

Returns:

The inverse matrix.

inverseTriangular(self, upper: bool = true) visp._visp.core.Matrix

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.

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

Parameters:
upper: bool = true

if it is an upper triangular matrix

Returns:

The inverse matrix

static juxtaposeMatrices(*args, **kwargs)

Overloaded function.

  1. juxtaposeMatrices(A: visp._visp.core.Matrix, B: visp._visp.core.Matrix) -> visp._visp.core.Matrix

Juxtapose to matrices C = [ A B ].

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

Warning

A and B must have the same number of rows.

Parameters:
A

Left matrix.

B

Right matrix.

Returns:

Juxtaposed matrix C = [ A B ]

  1. juxtaposeMatrices(A: visp._visp.core.Matrix, B: visp._visp.core.Matrix, C: visp._visp.core.Matrix) -> None

Juxtapose to matrices C = [ A B ].

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

Warning

A and B must have the same number of rows.

Parameters:
A

Left matrix.

B

Right matrix.

C

Juxtaposed matrix C = [ A B ]

kernel(self, kerAt: visp._visp.core.Matrix, svThreshold: float = 1e-6) int

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:
kerAt: visp._visp.core.Matrix

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})\) .

svThreshold: float = 1e-6

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.

kron(*args, **kwargs)

Overloaded function.

  1. kron(self: visp._visp.core.Matrix, m1: visp._visp.core.Matrix, out: visp._visp.core.Matrix) -> None

Compute Kronecker product matrix.

Parameters:
out

If m1.kron(m2) out contains the kronecker product’s result : \(m1 \otimes m2\) .

  1. kron(self: visp._visp.core.Matrix, m1: visp._visp.core.Matrix) -> visp._visp.core.Matrix

Returns:

m1.kron(m2) The kronecker product : \(m1 \otimes m2\)

static kronStatic(*args, **kwargs)

Overloaded function.

  1. kronStatic(m1: visp._visp.core.Matrix, m2: visp._visp.core.Matrix, out: visp._visp.core.Matrix) -> None

Compute Kronecker product matrix.

Parameters:
m1

vpMatrix ;

m2

vpMatrix ;

out

The kronecker product : \(m1 \otimes m2\)

  1. kronStatic(m1: visp._visp.core.Matrix, m2: visp._visp.core.Matrix) -> visp._visp.core.Matrix

Parameters:
m1

vpMatrix ;

m2

vpMatrix ;

Returns:

The kronecker product : \(m1 \otimes m2\)

static mult2Matrices(*args, **kwargs)

Overloaded function.

  1. mult2Matrices(A: visp._visp.core.Matrix, B: visp._visp.core.Matrix, C: visp._visp.core.Matrix) -> None

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

Note

See operator*()

  1. mult2Matrices(A: visp._visp.core.Matrix, B: visp._visp.core.Matrix, C: visp._visp.core.RotationMatrix) -> None

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

  1. mult2Matrices(A: visp._visp.core.Matrix, B: visp._visp.core.Matrix, C: visp._visp.core.HomogeneousMatrix) -> None

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

  1. mult2Matrices(A: visp._visp.core.Matrix, B: visp._visp.core.ColVector, C: visp._visp.core.ColVector) -> None

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

Note

See multMatrixVector()

static multMatrixVector(A: visp._visp.core.Matrix, v: visp._visp.core.ColVector, w: visp._visp.core.ColVector) None

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

Note

See operator*(const vpColVector &v) const

static negateMatrix(A: visp._visp.core.Matrix, C: visp._visp.core.Matrix) None

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

Note

See operator-(void)

nullSpace(*args, **kwargs)

Overloaded function.

  1. nullSpace(self: visp._visp.core.Matrix, kerA: visp._visp.core.Matrix, svThreshold: float = 1e-6) -> int

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:
kerA

The 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).

svThreshold

Threshold 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\) .

  1. nullSpace(self: visp._visp.core.Matrix, kerA: visp._visp.core.Matrix, dim: int) -> int

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:
kerA

The 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).

dim

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

numpy(self) numpy.ndarray[numpy.float64]

Numpy view of the underlying array data. This numpy view can be used to directly modify the array.

print(self: visp._visp.core.Matrix, s: std::ostream, length: int, intro: str =) int

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 .

Note

See std::ostream & operator<<(std::ostream &s, const vpArray2D<Type> &A)

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.

printSize(self) None
pseudoInverse(*args, **kwargs)

Overloaded function.

  1. pseudoInverse(self: visp._visp.core.Matrix, svThreshold: float = 1e-6) -> visp._visp.core.Matrix

Compute and return the Moore-Penros pseudo inverse \(A^+\) of a m-by-n 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 = A.pseudoInverse();

  A_p.print(std::cout, 10, "A^+ (pseudo-inverse): ");
}

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
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^+\) .

  1. pseudoInverse(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, svThreshold: float = 1e-6) -> int

Compute the Moore-Penros pseudo inverse \(A^+\) of a m-by-n matrix \(\bf A\) and return 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
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.

  1. pseudoInverse(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, svThreshold: float = 1e-6) -> int

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.

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;
  vpColVector sv;
  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
Parameters:
Ap

The Moore-Penros pseudo inverse \(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.

Returns:

The rank of the matrix \(\bf A\) .

  1. pseudoInverse(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, svThreshold: float, imA: visp._visp.core.Matrix, imAt: visp._visp.core.Matrix) -> int

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.

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

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
Parameters:
Ap

The Moore-Penros pseudo inverse \(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

math:mbox{Im}({bf A}) that is a m-by-r matrix.

imAt

math:mbox{Im}({bf A}^T) that is n-by-r matrix.

Returns:

The rank of the matrix \(\bf A\) .

  1. pseudoInverse(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, svThreshold: float, imA: visp._visp.core.Matrix, imAt: visp._visp.core.Matrix, kerAt: visp._visp.core.Matrix) -> int

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.

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

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

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

math:mbox { Im }({ bf A }) that is a m - by - r matrix.

imAt

math: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\) .

  1. pseudoInverse(self: visp._visp.core.Matrix, rank_in: int) -> visp._visp.core.Matrix

Compute and return the Moore-Penros pseudo inverse \(A^+\) of a m-by-n 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);

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

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
Parameters:
rank_in

Known rank of the matrix.

Returns:

The Moore-Penros pseudo inverse \(A^+\) .

  1. pseudoInverse(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, rank_in: int) -> int

Compute the Moore-Penros pseudo inverse \(A^+\) of a m-by-n matrix \(\bf A\) and return 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
Parameters:
Ap

The Moore-Penros pseudo inverse \(A^+\) .

rank_in

Known rank of the matrix.

Returns:

The rank of the matrix.

  1. pseudoInverse(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, rank_in: int) -> int

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.

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;
  vpColVector sv;
  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
Parameters:
Ap

The Moore-Penros pseudo inverse \(A^+\) .

sv

Vector corresponding to matrix \(A\) singular values. The size of this vector is equal to min(m, n).

rank_in

Known rank of the matrix.

Returns:

The rank of the matrix \(\bf A\) .

  1. pseudoInverse(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, rank_in: int, imA: visp._visp.core.Matrix, imAt: visp._visp.core.Matrix) -> int

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.

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;
  vpColVector sv;
  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
Parameters:
Ap

The Moore-Penros pseudo inverse \(A^+\) .

sv

Vector corresponding to matrix \(A\) singular values. The size of this vector is equal to min(m, n).

rank_in

Known rank of the matrix.

imA

math:mbox{Im}({bf A}) that is a m-by-r matrix.

imAt

math:mbox{Im}({bf A}^T) that is n-by-r matrix.

Returns:

The rank of the matrix \(\bf A\) .

  1. pseudoInverse(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, rank_in: int, imA: visp._visp.core.Matrix, imAt: visp._visp.core.Matrix, kerAt: visp._visp.core.Matrix) -> int

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.

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

  vpColVector sv;
  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
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).

rank_in

Known rank of the matrix.

imA

math:mbox { Im }({ bf A }) that is a m - by - r matrix.

imAt

math: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\) .

pseudoInverseEigen3(*args, **kwargs)

Overloaded function.

  1. pseudoInverseEigen3(self: visp._visp.core.Matrix, svThreshold: float = 1e-6) -> visp._visp.core.Matrix

  2. pseudoInverseEigen3(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, svThreshold: float = 1e-6) -> int

  3. pseudoInverseEigen3(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, svThreshold: float = 1e-6) -> int

  4. pseudoInverseEigen3(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, svThreshold: float, imA: visp._visp.core.Matrix, imAt: visp._visp.core.Matrix, kerAt: visp._visp.core.Matrix) -> int

  5. pseudoInverseEigen3(self: visp._visp.core.Matrix, rank_in: int) -> visp._visp.core.Matrix

  6. pseudoInverseEigen3(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, rank_in: int) -> int

  7. pseudoInverseEigen3(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, rank_in: int) -> int

  8. pseudoInverseEigen3(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, rank_in: int, imA: visp._visp.core.Matrix, imAt: visp._visp.core.Matrix, kerAt: visp._visp.core.Matrix) -> int

pseudoInverseLapack(*args, **kwargs)

Overloaded function.

  1. pseudoInverseLapack(self: visp._visp.core.Matrix, svThreshold: float = 1e-6) -> visp._visp.core.Matrix

  2. pseudoInverseLapack(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, svThreshold: float = 1e-6) -> int

  3. pseudoInverseLapack(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, svThreshold: float = 1e-6) -> int

  4. pseudoInverseLapack(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, svThreshold: float, imA: visp._visp.core.Matrix, imAt: visp._visp.core.Matrix, kerAt: visp._visp.core.Matrix) -> int

  5. pseudoInverseLapack(self: visp._visp.core.Matrix, rank_in: int) -> visp._visp.core.Matrix

  6. pseudoInverseLapack(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, rank_in: int) -> int

  7. pseudoInverseLapack(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, rank_in: int) -> int

  8. pseudoInverseLapack(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, rank_in: int, imA: visp._visp.core.Matrix, imAt: visp._visp.core.Matrix, kerAt: visp._visp.core.Matrix) -> int

pseudoInverseOpenCV(*args, **kwargs)

Overloaded function.

  1. pseudoInverseOpenCV(self: visp._visp.core.Matrix, svThreshold: float = 1e-6) -> visp._visp.core.Matrix

  2. pseudoInverseOpenCV(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, svThreshold: float = 1e-6) -> int

  3. pseudoInverseOpenCV(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, svThreshold: float = 1e-6) -> int

  4. pseudoInverseOpenCV(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, svThreshold: float, imA: visp._visp.core.Matrix, imAt: visp._visp.core.Matrix, kerAt: visp._visp.core.Matrix) -> int

  5. pseudoInverseOpenCV(self: visp._visp.core.Matrix, rank_in: int) -> visp._visp.core.Matrix

  6. pseudoInverseOpenCV(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, rank_in: int) -> int

  7. pseudoInverseOpenCV(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, rank_in: int) -> int

  8. pseudoInverseOpenCV(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, rank_in: int, imA: visp._visp.core.Matrix, imAt: visp._visp.core.Matrix, kerAt: visp._visp.core.Matrix) -> int

qr(self, Q: visp._visp.core.Matrix, R: visp._visp.core.Matrix, full: bool = false, squareR: bool = false, tol: float = 1e-6) int

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.

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

Note

See qrPivot()

Parameters:
Q: visp._visp.core.Matrix

orthogonal matrix (will be modified).

R: visp._visp.core.Matrix

upper-triangular matrix (will be modified).

full: bool = false

whether or not we want full decomposition.

squareR: bool = false

will return only the square (min(m,n) x min(m,n)) part of R.

tol: float = 1e-6

tolerance to test the rank of R.

Returns:

The rank r of the matrix.

qrPivot(self, Q: visp._visp.core.Matrix, R: visp._visp.core.Matrix, P: visp._visp.core.Matrix, full: bool = false, squareR: bool = false, tol: float = 1e-6) int

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.

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

Note

See qrPivot()

Parameters:
Q: visp._visp.core.Matrix

orthogonal matrix (will be modified).

R: visp._visp.core.Matrix

upper-triangular matrix (will be modified).

P: visp._visp.core.Matrix

the (n x n) permutation matrix.

full: bool = false

whether or not we want full decomposition.

squareR: bool = false

will return only the (r x r) part of R and the (r x n) part of P.

tol: float = 1e-6

tolerance to test the rank of R.

Returns:

The rank r of the matrix.

reshape(self, nrows: int, ncols: int) None
resize(self, nrows: int, ncols: int, flagNullify: bool = true, recopy_: bool = true) None

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

Parameters:
nrows: int

number of rows.

ncols: int

number of column.

flagNullify: bool = true

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_: bool = true

if true, will perform an explicit recopy of the old data.

static save(*args, **kwargs)

Overloaded function.

  1. save(filename: str, A: visp._visp.core.ArrayDouble2D, binary: bool = false, header: str = ) -> bool

Save a matrix to a file.

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

Note

See load()

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.

  1. save(filename: str, A: visp._visp.core.ArrayDouble2D, binary: bool = false, header: str = ) -> bool

Save a matrix to a file.

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

Note

See load()

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.

  1. save(filename: str, A: visp._visp.core.ArrayDouble2D, binary: bool = false, header: str = ) -> bool

Save a matrix to a file.

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

Note

See load()

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.

static saveMatrix(filename: str, M: visp._visp.core.ArrayDouble2D, binary: bool = false, header: str =) bool

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

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;
    }
  }
  {
    vpMatrix N;
    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??@@@%

Note

See loadMatrix() , saveMatrixYAML() , loadMatrixYAML()

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.

static saveMatrixYAML(filename: str, M: visp._visp.core.ArrayDouble2D, header: str =) bool

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

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;
    }
  }
  {
    vpMatrix N;
    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]

Note

See saveMatrix() , loadMatrix() , loadMatrixYAML()

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.

static saveYAML(filename: str, A: visp._visp.core.ArrayDouble2D, header: str =) bool

Save an array in a YAML-formatted file.

Here is an example of outputs.

vpArray2D<double> M(3,4);
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
data:
  - [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
data:
    - [0, 0, 0, 0]
    - [0, 0, 0, 0]
    - [0, 0, 0, 0]

Note

See loadYAML()

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.

static setLapackMatrixMinSize(min_size: int) None

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

To get more info see tutorial-basic-linear-algebra.

Note

See getLapackMatrixMinSize()

Parameters:
min_size: int

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.

size(self) int

Return the number of elements of the 2D array.

solveByQR(*args, **kwargs)

Overloaded function.

  1. solveByQR(self: visp._visp.core.Matrix, b: visp._visp.core.ColVector, x: visp._visp.core.ColVector) -> None

Solve a linear system Ax = b using QR Decomposition.

Non destructive wrt. A and b.

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

Note

See qrPivot()

Parameters:
b

Vector b

x

Vector x

  1. solveByQR(self: visp._visp.core.Matrix, b: visp._visp.core.ColVector) -> visp._visp.core.ColVector

Solve a linear system Ax = b using QR Decomposition.

Non destructive wrt. A and B.

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

Note

See qrPivot()

Parameters:
b

Vector b

Returns:

Vector x

solveBySVD(*args, **kwargs)

Overloaded function.

  1. solveBySVD(self: visp._visp.core.Matrix, B: visp._visp.core.ColVector, x: visp._visp.core.ColVector) -> None

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

Non destructive wrt. A and B.

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

Note

See solveBySVD(const vpColVector &)

Parameters:
x

Vector \(X\) .

  1. solveBySVD(self: visp._visp.core.Matrix, B: visp._visp.core.ColVector) -> visp._visp.core.ColVector

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

Non destructive wrt. A and B.

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

Note

See solveBySVD(const vpColVector &, vpColVector &)

Parameters:
B

Vector \(B\) .

Returns:

Vector \(X\) .

stack(*args, **kwargs)

Overloaded function.

  1. stack(self: visp._visp.core.Matrix, A: visp._visp.core.Matrix) -> None

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

  1. stack(self: visp._visp.core.Matrix, r: visp._visp.core.RowVector) -> None

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 :

vpMatrix A;
vpColVector v(6);
for(unsigned int i = 0;i<100;i++)
{
  robot.getVelocity(vpRobot::ARTICULAR_FRAME, v);
  Velocities.stack(v.t());
}
  1. stack(self: visp._visp.core.Matrix, c: visp._visp.core.ColVector) -> None

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:

vpMatrix log;
vpColVector v(6);
for(unsigned int i = 0; i<100;i++)
{
  robot.getVelocity(vpRobot::ARTICULAR_FRAME, v);
  log.stack(v);
}

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

static stackColumn(*args, **kwargs)

Overloaded function.

  1. stackColumn(A: visp._visp.core.Matrix, c: visp._visp.core.ColVector) -> visp._visp.core.Matrix

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

Warning

A and c must have the same number of rows.

Parameters:
A

Left matrix.

c

Right column vector.

Returns:

Stacked matrix [ A c ]

  1. stackColumn(A: visp._visp.core.Matrix, c: visp._visp.core.ColVector, C: visp._visp.core.Matrix) -> None

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

Warning

A and c must have the same number of rows. A and C must be two different objects.

Parameters:
A

Left matrix.

c

Right column vector.

C

Stacked matrix C = [ A c ]

stackColumns(*args, **kwargs)

Overloaded function.

  1. stackColumns(self: visp._visp.core.Matrix, out: visp._visp.core.ColVector) -> None

Stacks columns of a matrix in a vector.

Parameters:
out

a vpColVector .

  1. stackColumns(self: visp._visp.core.Matrix) -> visp._visp.core.ColVector

Returns:

a vpColVector .

static stackMatrices(*args, **kwargs)

Overloaded function.

  1. stackMatrices(A: visp._visp.core.Matrix, B: visp._visp.core.Matrix) -> visp._visp.core.Matrix

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

Warning

A and B must have the same number of columns.

Parameters:
A

Upper matrix.

B

Lower matrix.

Returns:

Stacked matrix [ A B ]^T

  1. stackMatrices(A: visp._visp.core.Matrix, B: visp._visp.core.Matrix, C: visp._visp.core.Matrix) -> None

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

Warning

A and B must have the same number of columns. A and C, B and C must be two different objects.

Parameters:
A

Upper matrix.

B

Lower matrix.

C

Stacked matrix C = [ A B ]^T

static stackRow(*args, **kwargs)

Overloaded function.

  1. stackRow(A: visp._visp.core.Matrix, r: visp._visp.core.RowVector) -> visp._visp.core.Matrix

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

Warning

A and r must have the same number of columns.

Parameters:
A

Upper matrix.

r

Lower row vector.

Returns:

Stacked matrix [ A r ]^T

  1. stackRow(A: visp._visp.core.Matrix, r: visp._visp.core.RowVector, C: visp._visp.core.Matrix) -> None

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

Warning

A and r must have the same number of columns. A and C must be two different objects.

Parameters:
A

Upper matrix.

r

Lower row vector.

C

Stacked matrix C = [ A r ]^T

stackRows(*args, **kwargs)

Overloaded function.

  1. stackRows(self: visp._visp.core.Matrix, out: visp._visp.core.RowVector) -> None

Stacks rows of a matrix in a vector

Parameters:
out

a vpRowVector .

  1. stackRows(self: visp._visp.core.Matrix) -> visp._visp.core.RowVector

Returns:

a vpRowVector .

strCppCode(self, name: str, byte_per_byte: bool = False) str

Returns a C++ code representation of this data array (see cppPrint in the C++ documentation)

Parameters:
name: str

variable name of the matrix.

byte_per_byte: bool = False

Whether to print byte per byte defaults to false.

strCsv(self) str

Returns the CSV representation of this data array (see csvPrint in the C++ documentation)

strMaple(self) str

Returns the CSV representation of this data array (see maplePrint in the C++ documentation)

strMatlab(self) str

Returns the Matlab representation of this data array (see matlabPrint in the C++ documentation)

static sub2Matrices(*args, **kwargs)

Overloaded function.

  1. sub2Matrices(A: visp._visp.core.Matrix, B: visp._visp.core.Matrix, C: visp._visp.core.Matrix) -> None

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

Note

See operator-()

  1. sub2Matrices(A: visp._visp.core.ColVector, B: visp._visp.core.ColVector, C: visp._visp.core.ColVector) -> None

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

Note

See vpColVector::operator-()

sum(self) float

Return the sum of all the \(a_{ij}\) elements of the matrix.

Returns:

Value of \(\sum a_{ij}\)

sumSquare(self) float

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

Returns:

The value \(\sum A_{ij}^{2}\) .

svd(self, w: visp._visp.core.ColVector, V: visp._visp.core.Matrix) None

Matrix singular value decomposition (SVD).

This function calls the first following function that is available:

  • svdLapack() if Lapack 3rd party is installed

  • svdEigen3() if Eigen3 3rd party is installed

  • svdOpenCV() if OpenCV 3rd party is installed.

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.

The matrix object (*this) is updated with :math:`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;

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

Note

See svdLapack() , svdEigen3() , svdOpenCV()

Parameters:
w: visp._visp.core.ColVector

Vector of singular values: \(\Sigma = diag(w)\) .

V: visp._visp.core.Matrix

Matrix \(V\) .

svdEigen3(self, w: visp._visp.core.ColVector, V: visp._visp.core.Matrix) None

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.

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 V;
  vpColVector w;
  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;
}

Note

See svd() , svdLapack() , svdOpenCV()

Parameters:
w: visp._visp.core.ColVector

Vector of singular values: \(\Sigma = diag(w)\) .

V: visp._visp.core.Matrix

Matrix \(V\) .

svdLapack(self, w: visp._visp.core.ColVector, V: visp._visp.core.Matrix) None

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.

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 V;
  vpColVector w;
  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;
}

Note

See svd() , svdEigen3() , svdOpenCV()

Parameters:
w: visp._visp.core.ColVector

Vector of singular values: \(\Sigma = diag(w)\) .

V: visp._visp.core.Matrix

Matrix \(V\) .

svdOpenCV(self, w: visp._visp.core.ColVector, V: visp._visp.core.Matrix) None

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.

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 V;
  vpColVector w;
  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;
}

Note

See svd() , svdEigen3() , svdLapack()

Parameters:
w: visp._visp.core.ColVector

Vector of singular values: \(\Sigma = diag(w)\) .

V: visp._visp.core.Matrix

Matrix \(V\) .

t(*args, **kwargs)

Overloaded function.

  1. t(self: visp._visp.core.Matrix) -> visp._visp.core.Matrix

Compute and return the transpose of the matrix.

  1. t(self: visp._visp.core.ArrayDouble2D) -> visp._visp.core.ArrayDouble2D

Compute the transpose of the array.

Returns:

vpArray2D<Type> C = A^T

transpose(*args, **kwargs)

Overloaded function.

  1. transpose(self: visp._visp.core.Matrix) -> visp._visp.core.Matrix

Compute and return the transpose of the matrix.

Note

See t()

  1. transpose(self: visp._visp.core.Matrix, At: visp._visp.core.Matrix) -> None

Compute At the transpose of the matrix.

Note

See t()

Parameters:
At

(output) : Resulting transpose matrix.

__hash__ = None