Maven module :un.api : api-math :
Class : un.api.math.Matrix
Extends/Implements : un.api.math.transform.Transform
Subclasses : -

author  Johann Sorel


Variables : -
Functions : getNbRow, getNbCol, getValuesCopy, getRow, getColumn, getColumnTuple, getLastColumn, getLastColumnTuple, getMatrix, getMatrix, getMatrix, getMatrix, get, isIdentity, add, subtract, scale, multiply, invert, add, subtract, scale, multiply, invert, transpose, dot, transform, transform, transform, transform, transform, norm1, norm2, normInf, normF, lu, qr, chol, svd, eig, solve, solveTranspose, det, rank, cond, trace, copy, toColumnPackedCopy, toRowPackedCopy, toArrayDouble, toArrayDoubleColOrder, toArrayFloat, toArrayFloatColOrder, toArrayFloatColOrder, allEquals



int getNbRow ()

int getNbCol ()



double[][] getValuesCopy ()

double[] getRow (int row)

double[] getColumn (int col)

Vector getColumnTuple (int col)

double[] getLastColumn ()

Vector getLastColumnTuple ()


Get a submatrix.
param  i0 Initial row index
param  i1 Final row index
param  j0 Initial column index
param  j1 Final column index
return  A(i0:i1,j0:j1)
exception  ArrayIndexOutOfBoundsException Submatrix indices
MatrixRW getMatrix (int i0, int i1, int j0, int j1)


Get a submatrix.
param  r Array of row indices.
param  c Array of column indices.
return  A(r(:),c(:))
exception  ArrayIndexOutOfBoundsException Submatrix indices
MatrixRW getMatrix (int[] r, int[] c)


Get a submatrix.
param  i0 Initial row index
param  i1 Final row index
param  c Array of column indices.
return  A(i0:i1,c(:))
exception  ArrayIndexOutOfBoundsException Submatrix indices
MatrixRW getMatrix (int i0, int i1, int[] c)


Get a submatrix.
param  r Array of row indices.
param  j0 Initial column index
param  j1 Final column index
return  A(r(:),j0:j1)
exception  ArrayIndexOutOfBoundsException Submatrix indices
MatrixRW getMatrix (int[] r, int j0, int j1)

double get (int row, int col)

boolean isIdentity ()



MatrixRW add (Matrix other)

MatrixRW subtract (Matrix other)

MatrixRW scale (double scale)

MatrixRW multiply (Matrix other)

MatrixRW invert ()



MatrixRW add (Matrix other, MatrixRW buffer)

MatrixRW subtract (Matrix other, MatrixRW buffer)

MatrixRW scale (double scale, MatrixRW buffer)

MatrixRW multiply (Matrix other, MatrixRW buffer)


invert matrix
MatrixRW invert (MatrixRW buffer)

MatrixRW transpose ()

double dot (Matrix other)



double[] transform (double[] vector)

double[] transform (double[] vector, double fillValue)

Tuple transform (Tuple vector)

Tuple transform (Tuple vector, double fillValue)

Tuple transform (Tuple vector, Tuple buffer, double fillValue)


One norm
return  maximum column sum.
double norm1 ()


Two norm
return  maximum singular value.
double norm2 ()


Infinity norm
return  maximum row sum.
double normInf ()


Frobenius norm
return  sqrt of sum of squares of all elements.
double normF ()


LU Decomposition
return  LUDecomposition
see  LUDecomposition
LUDecomposition lu ()


QR Decomposition
return  QRDecomposition
see  QRDecomposition
QRDecomposition qr ()


Cholesky Decomposition
return  CholeskyDecomposition
see  CholeskyDecomposition
CholeskyDecomposition chol ()


Singular Value Decomposition
return  SingularValueDecomposition
see  SingularValueDecomposition
SingularValueDecomposition svd ()


Eigenvalue Decomposition
return  EigenvalueDecomposition
see  EigenvalueDecomposition
EigenvalueDecomposition eig ()


Solve A*X = B
param  B right hand side
return  solution if A is square, least squares solution otherwise
MatrixRW solve (MatrixRW B)


Solve X*A = B, which is also A'*X' = B'
@param B right hand side
@return solution if A is square, least squares solution otherwise.
MatrixRW solveTranspose (MatrixRW B)


Matrix determinant
return  determinant
double det ()


Matrix rank
return  effective numerical rank, obtained from SVD.
int rank ()


Matrix condition (2 norm)
return  ratio of largest to smallest singular value.
double cond ()


Matrix trace.
return  sum of the diagonal elements.
double trace ()

MatrixRW copy ()


Make a one-dimensional column packed copy of the internal array.
return  Matrix elements packed in a one-dimensional array by columns.
double[] toColumnPackedCopy ()


Make a one-dimensional row packed copy of the internal array.
return  Matrix elements packed in a one-dimensional array by rows.
double[] toRowPackedCopy ()

double[] toArrayDouble ()


Matrix as 1D double array, in column order.
return  1D double array, in column order.
double[] toArrayDoubleColOrder ()


Matrix as 1D float array, in row order.
return  1D float array, in row order.
float[] toArrayFloat ()


Matrix as 1D float array, in column order.
return  1D float array, in column order.
float[] toArrayFloatColOrder ()

float[] toArrayFloatColOrder (float[] array)


Test if all cells in the matrix equals given value.
param  scalar scalar
param  tolerance tolerance
return  true if all values match
boolean allEquals (double scalar, double tolerance)