# Class Matrix

All Implemented Interfaces:
`Serializable`, `Cloneable`

public class Matrix extends IMatrix
Dense matrix of double precision values.
• ## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static class `
`Matrix.Cholesky`
The Cholesky decomposition of a symmetric, positive-definite matrix.
`static class `
`Matrix.EVD`
Eigenvalue decomposition.
`static class `
`Matrix.LU`
The LU decomposition.
`static class `
`Matrix.QR`
The QR decomposition.
`static class `
`Matrix.SVD`
Singular Value Decomposition.

## Nested classes/interfaces inherited from class smile.math.matrix.IMatrix

`IMatrix.Preconditioner`
• ## Constructor Summary

Constructors
Constructor
Description
```Matrix(int m, int n)```
Constructor of zero matrix.
```Matrix(int m, int n, double a)```
Constructor.
```Matrix(int m, int n, int ld, double[] A)```
Constructor.
• ## Method Summary

Modifier and Type
Method
Description
`Matrix`
`aat()`
Returns `A * A'`.
`static Matrix`
```adb(Transpose transA, Matrix A, double[] D, Transpose transB, Matrix B)```
Returns `A * D * B`, where D is a diagonal matrix.
`Matrix`
`add(double b)`
A += b
`Matrix`
```add(double alpha, double[] x, double[] y)```
Rank-1 update A += alpha * x * y'
`Matrix`
```add(double alpha, double beta, Matrix B)```
Element-wise addition A = alpha * A + beta * B
`Matrix`
```add(double beta, Matrix B)```
Element-wise addition A += beta * B
`Matrix`
```add(double alpha, Matrix A, double beta, Matrix B)```
Element-wise addition C = alpha * A + beta * B
`double`
```add(int i, int j, double b)```
A[i,j] += b
`Matrix`
`add(Matrix B)`
`Matrix`
```add2(double alpha, double beta, Matrix B)```
Element-wise addition A = alpha * A + beta * B^2
`Matrix`
`addDiag(double b)`
A[i, i] += b
`Matrix`
`addDiag(double[] b)`
A[i, i] += b[i]
`Matrix`
`ata()`
Returns `A' * A`.
`Matrix.Cholesky`
`cholesky()`
Cholesky decomposition for symmetric and positive definite matrix.
`Matrix.Cholesky`
`cholesky(boolean overwrite)`
Cholesky decomposition for symmetric and positive definite matrix.
`Matrix`
`clone()`
Returns a deep copy of matrix.
`double[]`
`col(int j)`
Returns the j-th column.
`static Collector<double[],List<double[]>,Matrix>`
`collector()`
Returns a stream collector that accumulates elements into a Matrix.
`double[]`
`colMeans()`
Returns the mean of each column.
`Matrix`
`cols(int... cols)`
Returns the matrix of selected columns.
`double[]`
`colSds()`
Returns the standard deviations of each column.
`double[]`
`colSums()`
Returns the sum of each column.
`static Matrix`
`column(double[] A)`
Returns a column vector/matrix.
`static Matrix`
```column(double[] A, int offset, int length)```
Returns a column vector/matrix.
`static Matrix`
`diag(double[] diag)`
Returns a square diagonal matrix.
`static Matrix`
```diag(int n, double diag)```
Returns a square diagonal matrix.
`static Matrix`
```diag(int m, int n, double diag)```
Returns an m-by-n diagonal matrix.
`Matrix`
`div(double b)`
A /= b
`double`
```div(int i, int j, double b)```
A[i,j] /= b
`Matrix`
`div(Matrix B)`
Element-wise division A /= B
`Matrix.EVD`
`eigen()`
Eigenvalue Decomposition.
`Matrix.EVD`
```eigen(boolean vl, boolean vr, boolean overwrite)```
Eigenvalue Decomposition.
`boolean`
`equals(Object o)`

`boolean`
```equals(Matrix o, double epsilon)```
Returns true if two matrices equal in given precision.
`static Matrix`
`eye(int n)`
Returns an identity matrix.
`static Matrix`
```eye(int m, int n)```
Returns an m-by-n identity matrix.
`void`
`fill(double x)`
Fills the matrix with a value.
`Matrix`
```get(int[] rows, int[] cols)```
Returns the matrix of selected rows and columns.
`double`
```get(int i, int j)```
Returns `A[i,j]`.
`protected int`
```index(int i, int j)```
Returns the linearized index of matrix element.
`Matrix`
`inverse()`
Returns the inverse of matrix.
`boolean`
`isSymmetric()`
Return true if the matrix is symmetric (`uplo != null && diag == null`).
`Layout`
`layout()`
Returns the matrix layout.
`int`
`ld()`
`Matrix.LU`
`lu()`
LU decomposition.
`Matrix.LU`
`lu(boolean overwrite)`
LU decomposition.
`Matrix`
```mm(Transpose transA, Matrix A, Transpose transB, Matrix B)```
Matrix-matrix multiplication.
`Matrix`
```mm(Transpose transA, Matrix A, Transpose transB, Matrix B, double alpha, double beta)```
Matrix-matrix multiplication.
`Matrix`
`mm(Matrix B)`
Returns matrix multiplication `A * B`.
`Matrix`
`mt(Matrix B)`
Returns matrix multiplication `A * B'`.
`Matrix`
`mul(double b)`
A *= b
`double`
```mul(int i, int j, double b)```
A[i,j] *= b
`Matrix`
`mul(Matrix B)`
Element-wise multiplication A *= B
`void`
```mv(double[] work, int inputOffset, int outputOffset)```
Matrix-vector multiplication `A * x`.
`void`
```mv(Transpose trans, double alpha, double[] x, double beta, double[] y)```
Matrix-vector multiplication.
`int`
`ncol()`
Returns the number of columns.
`double`
`norm()`
L2 matrix norm that is the maximum singular value.
`double`
`norm1()`
L1 matrix norm that is the maximum of column sums.
`double`
`norm2()`
L2 matrix norm that is the maximum singular value.
`double`
`normFro()`
Frobenius matrix norm that is the square root of sum of squares of all elements.
`double`
`normInf()`
L matrix norm that is the maximum of row sums.
`int`
`nrow()`
Returns the number of rows.
`static Matrix`
`of(double[][] A)`
Returns a matrix from a two-dimensional array.
`Matrix.QR`
`qr()`
QR Decomposition.
`Matrix.QR`
`qr(boolean overwrite)`
QR Decomposition.
`static Matrix`
```rand(int m, int n)```
Returns a uniformly distributed random matrix in [0, 1).
`static Matrix`
```rand(int m, int n, double lo, double hi)```
Returns a uniformly distributed random matrix in given range.
`static Matrix`
```rand(int m, int n, Distribution distribution)```
Returns a random matrix.
`static Matrix`
```randn(int m, int n)```
Returns a random matrix of standard normal distribution.
`Matrix`
`replaceNaN(double x)`
Replaces NaN's with given value.
`static Matrix`
`row(double[] A)`
Returns a row vector/matrix.
`static Matrix`
```row(double[] A, int offset, int length)```
Returns a row vector/matrix.
`double[]`
`row(int i)`
Returns the i-th row.
`double[]`
`rowMeans()`
Returns the mean of each row.
`Matrix`
`rows(int... rows)`
Returns the matrix of selected rows.
`double[]`
`rowSds()`
Returns the standard deviations of each row.
`double[]`
`rowSums()`
Returns the sum of each row.
`Matrix`
```scale(double[] center, double[] scale)```
Centers and scales the columns of matrix.
`void`
```set(int i, int j, double x)```
Sets `A[i,j] = x`.
`Matrix`
`set(Matrix b)`
Sets the matrix value.
`long`
`size()`
Returns the number of stored matrix elements.
`Matrix`
`standardize()`
Standardizes the columns of matrix.
`Matrix`
`sub(double b)`
A -= b
`double`
```sub(int i, int j, double b)```
A[i,j] -= b
`Matrix`
`sub(Matrix B)`
Element-wise subtraction A -= B
`Matrix`
```submatrix(int i, int j, int k, int l)```
Returns the submatrix which top left at (i, j) and bottom right at (k, l).
`double`
`sum()`
Returns the sum of all elements.
`Matrix.SVD`
`svd()`
Singular Value Decomposition.
`Matrix.SVD`
```svd(boolean vectors, boolean overwrite)```
Singular Value Decomposition.
`Matrix`
`tm(Matrix B)`
Returns matrix multiplication `A' * B`.
`double[][]`
`toArray()`
Return the two-dimensional array of matrix.
`static Matrix`
`toeplitz(double[] a)`
Returns a symmetric Toeplitz matrix in which each descending diagonal from left to right is constant.
`static Matrix`
```toeplitz(double[] kl, double[] ku)```
Returns a Toeplitz matrix in which each descending diagonal from left to right is constant.
`Matrix`
`transpose()`
Returns the transpose of matrix.
`Matrix`
`transpose(boolean share)`
Returns the transpose of matrix.
`Diag`
`triangular()`
Gets the flag if a triangular matrix has unit diagonal elements.
`Matrix`
`triangular(Diag diag)`
Sets/unsets if the matrix is triangular.
`Matrix`
`tt(Matrix B)`
Returns matrix multiplication `A' * B'`.
`void`
```tv(double[] work, int inputOffset, int outputOffset)```
Matrix-vector multiplication `A' * x`.
`UPLO`
`uplo()`
Gets the format of packed matrix.
`Matrix`
`uplo(UPLO uplo)`
Sets the format of packed matrix.
`double`
`xAx(double[] x)`
Returns the quadratic form `x' * A * x`.

### Methods inherited from class smile.math.matrix.IMatrix

`apply, colName, colNames, colNames, diag, eigen, eigen, Jacobi, market, mv, mv, mv, rowName, rowNames, rowNames, solve, solve, square, toString, toString, toString, trace, tv, tv, tv, update`

### Methods inherited from class java.lang.Object

`finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• ## Constructor Details

• ### Matrix

public Matrix(int m, int n)
Constructor of zero matrix.
Parameters:
`m` - the number of rows.
`n` - the number of columns.
• ### Matrix

public Matrix(int m, int n, double a)
Constructor. Fills the matrix with given value.
Parameters:
`m` - the number of rows.
`n` - the number of columns.
`a` - the initial value.
• ### Matrix

public Matrix(int m, int n, int ld, double[] A)
Constructor.
Parameters:
`m` - the number of rows.
`n` - the number of columns.
`ld` - the leading dimension.
`A` - the matrix storage.
• ## Method Details

• ### of

public static Matrix of(double[][] A)
Returns a matrix from a two-dimensional array.
Parameters:
`A` - the two-dimensional array.
Returns:
the matrix.
• ### column

public static Matrix column(double[] A)
Returns a column vector/matrix.
Parameters:
`A` - the column vector.
Returns:
the column vector/matrix.
• ### column

public static Matrix column(double[] A, int offset, int length)
Returns a column vector/matrix.
Parameters:
`A` - the column vector.
`offset` - the offset of the subarray to be used; must be non-negative and no larger than array.length.
`length` - the length of the subarray to be used; must be non-negative and no larger than array.length - offset.
Returns:
the column vector/matrix.
• ### row

public static Matrix row(double[] A)
Returns a row vector/matrix.
Parameters:
`A` - the row vector.
Returns:
the row vector/matrix.
• ### row

public static Matrix row(double[] A, int offset, int length)
Returns a row vector/matrix.
Parameters:
`A` - the row vector.
`offset` - the offset of the subarray to be used; must be non-negative and no larger than array.length.
`length` - the length of the subarray to be used; must be non-negative and no larger than array.length - offset.
Returns:
the row vector/matrix.
• ### rand

public static Matrix rand(int m, int n, Distribution distribution)
Returns a random matrix.
Parameters:
`m` - the number of rows.
`n` - the number of columns.
`distribution` - the distribution of random numbers.
Returns:
the random matrix.
• ### randn

public static Matrix randn(int m, int n)
Returns a random matrix of standard normal distribution.
Parameters:
`m` - the number of rows.
`n` - the number of columns.
Returns:
the random matrix.
• ### rand

public static Matrix rand(int m, int n)
Returns a uniformly distributed random matrix in [0, 1).
Parameters:
`m` - the number of rows.
`n` - the number of columns.
Returns:
the random matrix.
• ### rand

public static Matrix rand(int m, int n, double lo, double hi)
Returns a uniformly distributed random matrix in given range.
Parameters:
`m` - the number of rows.
`n` - the number of columns.
`lo` - the lower bound of uniform distribution.
`hi` - the upper bound of uniform distribution.
Returns:
the random matrix.
• ### eye

public static Matrix eye(int n)
Returns an identity matrix.
Parameters:
`n` - the number of rows/columns.
Returns:
the identity matrix.
• ### eye

public static Matrix eye(int m, int n)
Returns an m-by-n identity matrix.
Parameters:
`m` - the number of rows.
`n` - the number of columns.
Returns:
the identity matrix.
• ### diag

public static Matrix diag(int n, double diag)
Returns a square diagonal matrix.
Parameters:
`n` - the number of rows/columns.
`diag` - the diagonal value.
Returns:
the diagonal matrix.
• ### diag

public static Matrix diag(int m, int n, double diag)
Returns an m-by-n diagonal matrix.
Parameters:
`m` - the number of rows.
`n` - the number of columns.
`diag` - the diagonal value.
Returns:
the diagonal matrix.
• ### diag

public static Matrix diag(double[] diag)
Returns a square diagonal matrix.
Parameters:
`diag` - the diagonal elements.
Returns:
the diagonal matrix.
• ### toeplitz

public static Matrix toeplitz(double[] a)
Returns a symmetric Toeplitz matrix in which each descending diagonal from left to right is constant.
Parameters:
`a` - A[i, j] = a[i - j] for `i >= j` (or a[j - i] when `j > i`)
Returns:
the Toeplitz matrix.
• ### toeplitz

public static Matrix toeplitz(double[] kl, double[] ku)
Returns a Toeplitz matrix in which each descending diagonal from left to right is constant.
Parameters:
`kl` - `A[i, j] = kl[i - j]` for `i > j`
`ku` - `A[i, j] = ku[j - i]` for `i <= j`
Returns:
the Toeplitz matrix.
• ### collector

public static Collector<double[],List<double[]>,Matrix> collector()
Returns a stream collector that accumulates elements into a Matrix.
Returns:
the stream collector.
• ### nrow

public int nrow()
Description copied from class: `IMatrix`
Returns the number of rows.
Specified by:
`nrow` in class `IMatrix`
Returns:
the number of rows.
• ### ncol

public int ncol()
Description copied from class: `IMatrix`
Returns the number of columns.
Specified by:
`ncol` in class `IMatrix`
Returns:
the number of columns.
• ### size

public long size()
Description copied from class: `IMatrix`
Returns the number of stored matrix elements. For conventional matrix, it is simply nrow * ncol. But it is usually much less for band, packed or sparse matrix.
Specified by:
`size` in class `IMatrix`
Returns:
the number of stored matrix elements.
• ### layout

public Layout layout()
Returns the matrix layout.
Returns:
the matrix layout.
• ### ld

public int ld()
Returns:
• ### isSymmetric

public boolean isSymmetric()
Return true if the matrix is symmetric (`uplo != null && diag == null`).
Returns:
true if the matrix is symmetric.
• ### uplo

public Matrix uplo(UPLO uplo)
Sets the format of packed matrix.
Parameters:
`uplo` - the format of packed matrix..
Returns:
this matrix.
• ### uplo

public UPLO uplo()
Gets the format of packed matrix.
Returns:
the format of packed matrix.
• ### triangular

public Matrix triangular(Diag diag)
Sets/unsets if the matrix is triangular.
Parameters:
`diag` - if not null, it specifies if the triangular matrix has unit diagonal elements.
Returns:
this matrix.
• ### triangular

public Diag triangular()
Gets the flag if a triangular matrix has unit diagonal elements. Returns null if the matrix is not triangular.
Returns:
the flag if a triangular matrix has unit diagonal elements.
• ### clone

public Matrix clone()
Returns a deep copy of matrix.
Overrides:
`clone` in class `Object`
• ### toArray

public double[][] toArray()
Return the two-dimensional array of matrix.
Returns:
the two-dimensional array of matrix.
• ### set

public Matrix set(Matrix b)
Sets the matrix value. If the matrices have the same layout, this matrix will share the underlying storage with b.
Parameters:
`b` - the right hand side of assignment.
Returns:
this matrix.
• ### index

protected int index(int i, int j)
Returns the linearized index of matrix element.
Parameters:
`i` - the row index.
`j` - the column index.
Returns:
the linearized index.
• ### get

public double get(int i, int j)
Description copied from class: `IMatrix`
Returns `A[i,j]`.
Overrides:
`get` in class `IMatrix`
Parameters:
`i` - the row index.
`j` - the column index.
Returns:
the matrix cell value.
• ### set

public void set(int i, int j, double x)
Description copied from class: `IMatrix`
Sets `A[i,j] = x`.
Overrides:
`set` in class `IMatrix`
Parameters:
`i` - the row index.
`j` - the column index.
`x` - the matrix cell value.
• ### get

public Matrix get(int[] rows, int[] cols)
Returns the matrix of selected rows and columns. Negative index -i means the i-th row/column from the end.
Parameters:
`rows` - the row indices.
`cols` - the column indices.
Returns:
the submatrix.
• ### row

public double[] row(int i)
Returns the i-th row. Negative index -i means the i-th row from the end.
Parameters:
`i` - the row index.
Returns:
the row.
• ### col

public double[] col(int j)
Returns the j-th column. Negative index -j means the j-th row from the end.
Parameters:
`j` - the column index.
Returns:
the column.
• ### rows

public Matrix rows(int... rows)
Returns the matrix of selected rows. Negative index -i means the i-th row from the end.
Parameters:
`rows` - the row indices.
Returns:
the submatrix.
• ### cols

public Matrix cols(int... cols)
Returns the matrix of selected columns.
Parameters:
`cols` - the column indices.
Returns:
the submatrix.
• ### submatrix

public Matrix submatrix(int i, int j, int k, int l)
Returns the submatrix which top left at (i, j) and bottom right at (k, l).
Parameters:
`i` - the beginning row, inclusive.
`j` - the beginning column, inclusive,
`k` - the ending row, inclusive.
`l` - the ending column, inclusive.
Returns:
the submatrix.
• ### fill

public void fill(double x)
Fills the matrix with a value.
Parameters:
`x` - the value.
• ### transpose

public Matrix transpose()
Returns the transpose of matrix. The transpose shares the storage with this matrix. Changes to this matrix's content will be visible in the transpose, and vice versa.
Returns:
the transpose of matrix.
• ### transpose

public Matrix transpose(boolean share)
Returns the transpose of matrix.
Parameters:
`share` - if true, the transpose shares the storage with this matrix. Changes to this matrix's content will be visible in the transpose, and vice versa.
Returns:
the transpose of matrix.
• ### equals

public boolean equals(Object o)
Overrides:
`equals` in class `Object`
• ### equals

public boolean equals(Matrix o, double epsilon)
Returns true if two matrices equal in given precision.
Parameters:
`o` - the other matrix.
`epsilon` - a number close to zero.
Returns:
true if two matrices equal in given precision.

public double add(int i, int j, double b)
A[i,j] += b
Parameters:
`i` - the row index.
`j` - the column index.
`b` - the operand.
Returns:
the updated cell value.
• ### sub

public double sub(int i, int j, double b)
A[i,j] -= b
Parameters:
`i` - the row index.
`j` - the column index.
`b` - the operand.
Returns:
the updated cell value.
• ### mul

public double mul(int i, int j, double b)
A[i,j] *= b
Parameters:
`i` - the row index.
`j` - the column index.
`b` - the operand.
Returns:
the updated cell value.
• ### div

public double div(int i, int j, double b)
A[i,j] /= b
Parameters:
`i` - the row index.
`j` - the column index.
`b` - the operand.
Returns:
the updated cell value.

A[i, i] += b
Parameters:
`b` - the operand.
Returns:
this matrix.

A[i, i] += b[i]
Parameters:
`b` - the operand.
Returns:
this matrix.

A += b
Parameters:
`b` - the operand.
Returns:
this matrix.
• ### sub

public Matrix sub(double b)
A -= b
Parameters:
`b` - the operand.
Returns:
this matrix.
• ### mul

public Matrix mul(double b)
A *= b
Parameters:
`b` - the operand.
Returns:
this matrix.
• ### div

public Matrix div(double b)
A /= b
Parameters:
`b` - the operand.
Returns:
this matrix.

Parameters:
`B` - the operand.
Returns:
this matrix.
• ### sub

public Matrix sub(Matrix B)
Element-wise subtraction A -= B
Parameters:
`B` - the operand.
Returns:
this matrix.
• ### mul

public Matrix mul(Matrix B)
Element-wise multiplication A *= B
Parameters:
`B` - the operand.
Returns:
this matrix.
• ### div

public Matrix div(Matrix B)
Element-wise division A /= B
Parameters:
`B` - the operand.
Returns:
this matrix.

public Matrix add(double beta, Matrix B)
Element-wise addition A += beta * B
Parameters:
`beta` - the scalar alpha.
`B` - the operand.
Returns:
this matrix.

public Matrix add(double alpha, double beta, Matrix B)
Element-wise addition A = alpha * A + beta * B
Parameters:
`alpha` - the scalar alpha.
`beta` - the scalar beta.
`B` - the operand.
Returns:
this matrix.

public Matrix add2(double alpha, double beta, Matrix B)
Element-wise addition A = alpha * A + beta * B^2
Parameters:
`alpha` - the scalar alpha.
`beta` - the scalar beta.
`B` - the operand.
Returns:
this matrix.

public Matrix add(double alpha, Matrix A, double beta, Matrix B)
Element-wise addition C = alpha * A + beta * B
Parameters:
`alpha` - the scalar alpha.
`A` - the operand.
`beta` - the scalar beta.
`B` - the operand.
Returns:
this matrix.

public Matrix add(double alpha, double[] x, double[] y)
Rank-1 update A += alpha * x * y'
Parameters:
`alpha` - the scalar alpha.
`x` - the column vector.
`y` - the row vector.
Returns:
this matrix.
• ### replaceNaN

public Matrix replaceNaN(double x)
Replaces NaN's with given value.
Parameters:
`x` - a real number.
Returns:
this matrix.
• ### sum

public double sum()
Returns the sum of all elements.
Returns:
the sum of all elements.
• ### norm1

public double norm1()
L1 matrix norm that is the maximum of column sums.
Returns:
L1 matrix norm.
• ### norm2

public double norm2()
L2 matrix norm that is the maximum singular value.
Returns:
L2 matrix norm.
• ### norm

public double norm()
L2 matrix norm that is the maximum singular value.
Returns:
L2 matrix norm.
• ### normInf

public double normInf()
L matrix norm that is the maximum of row sums.
Returns:
L matrix norm.
• ### normFro

public double normFro()
Frobenius matrix norm that is the square root of sum of squares of all elements.
Returns:
Frobenius matrix norm.
• ### xAx

public double xAx(double[] x)
Returns the quadratic form `x' * A * x`. The left upper submatrix of A is used in the computation based on the size of x.
Parameters:
`x` - the vector.
Returns:
• ### rowSums

public double[] rowSums()
Returns the sum of each row.
Returns:
the sum of each row.
• ### rowMeans

public double[] rowMeans()
Returns the mean of each row.
Returns:
the mean of each row.
• ### rowSds

public double[] rowSds()
Returns the standard deviations of each row.
Returns:
the standard deviations of each row.
• ### colSums

public double[] colSums()
Returns the sum of each column.
Returns:
the sum of each column.
• ### colMeans

public double[] colMeans()
Returns the mean of each column.
Returns:
the mean of each column.
• ### colSds

public double[] colSds()
Returns the standard deviations of each column.
Returns:
the standard deviations of each column.
• ### standardize

public Matrix standardize()
Standardizes the columns of matrix.
Returns:
a new matrix with zero mean and unit variance for each column.
• ### scale

public Matrix scale(double[] center, double[] scale)
Centers and scales the columns of matrix.
Parameters:
`center` - column center. If null, no centering.
`scale` - column scale. If null, no scaling.
Returns:
a new matrix with zero mean and unit variance for each column.
• ### inverse

public Matrix inverse()
Returns the inverse of matrix.
Returns:
the inverse of matrix.
• ### mv

public void mv(Transpose trans, double alpha, double[] x, double beta, double[] y)
Description copied from class: `IMatrix`
Matrix-vector multiplication.
``````
y = alpha * op(A) * x + beta * y
``````
where op is the transpose operation.
Specified by:
`mv` in class `IMatrix`
Parameters:
`trans` - normal, transpose, or conjugate transpose operation on the matrix.
`alpha` - the scalar alpha.
`x` - the input vector.
`beta` - the scalar beta. When beta is supplied as zero, y need not be set on input.
`y` - the input and output vector.
• ### mv

public void mv(double[] work, int inputOffset, int outputOffset)
Description copied from class: `IMatrix`
Matrix-vector multiplication `A * x`.
Specified by:
`mv` in class `IMatrix`
Parameters:
`work` - the workspace for both input and output vector.
`inputOffset` - the offset of input vector in workspace.
`outputOffset` - the offset of output vector in workspace.
• ### tv

public void tv(double[] work, int inputOffset, int outputOffset)
Description copied from class: `IMatrix`
Matrix-vector multiplication `A' * x`.
Specified by:
`tv` in class `IMatrix`
Parameters:
`work` - the workspace for both input and output vector.
`inputOffset` - the offset of input vector in workspace.
`outputOffset` - the offset of output vector in workspace.
• ### mm

public Matrix mm(Transpose transA, Matrix A, Transpose transB, Matrix B)
Matrix-matrix multiplication.
``````
C := A*B
``````
Parameters:
`transA` - normal, transpose, or conjugate transpose operation on the matrix A.
`A` - the operand.
`transB` - normal, transpose, or conjugate transpose operation on the matrix B.
`B` - the operand.
Returns:
this matrix.
• ### mm

public Matrix mm(Transpose transA, Matrix A, Transpose transB, Matrix B, double alpha, double beta)
Matrix-matrix multiplication.
``````
C := alpha*A*B + beta*C
``````
Parameters:
`transA` - normal, transpose, or conjugate transpose operation on the matrix A.
`A` - the operand.
`transB` - normal, transpose, or conjugate transpose operation on the matrix B.
`B` - the operand.
`alpha` - the scalar alpha.
`beta` - the scalar beta.
Returns:
this matrix.
• ### ata

public Matrix ata()
Returns `A' * A`.
Returns:
`A' * A`.
• ### aat

public Matrix aat()
Returns `A * A'`.
Returns:
`A * A'`.

public static Matrix adb(Transpose transA, Matrix A, double[] D, Transpose transB, Matrix B)
Returns `A * D * B`, where D is a diagonal matrix.
Parameters:
`transA` - normal, transpose, or conjugate transpose operation on the matrix A.
`A` - the operand.
`D` - the diagonal matrix.
`transB` - normal, transpose, or conjugate transpose operation on the matrix B.
`B` - the operand.
Returns:
the multiplication.
• ### mm

public Matrix mm(Matrix B)
Returns matrix multiplication `A * B`.
Parameters:
`B` - the operand.
Returns:
the multiplication.
• ### mt

public Matrix mt(Matrix B)
Returns matrix multiplication `A * B'`.
Parameters:
`B` - the operand.
Returns:
the multiplication.
• ### tm

public Matrix tm(Matrix B)
Returns matrix multiplication `A' * B`.
Parameters:
`B` - the operand.
Returns:
the multiplication.
• ### tt

public Matrix tt(Matrix B)
Returns matrix multiplication `A' * B'`.
Parameters:
`B` - the operand.
Returns:
the multiplication.
• ### lu

public Matrix.LU lu()
LU decomposition.
Returns:
LU decomposition.
• ### lu

public Matrix.LU lu(boolean overwrite)
LU decomposition.
Parameters:
`overwrite` - The flag if the decomposition overwrites this matrix.
Returns:
LU decomposition.
• ### cholesky

public Matrix.Cholesky cholesky()
Cholesky decomposition for symmetric and positive definite matrix.
Returns:
Cholesky decomposition.
Throws:
`ArithmeticException` - if the matrix is not positive definite.
• ### cholesky

public Matrix.Cholesky cholesky(boolean overwrite)
Cholesky decomposition for symmetric and positive definite matrix.
Parameters:
`overwrite` - The flag if the decomposition overwrites this matrix.
Returns:
Cholesky decomposition.
Throws:
`ArithmeticException` - if the matrix is not positive definite.
• ### qr

public Matrix.QR qr()
QR Decomposition.
Returns:
QR decomposition.
• ### qr

public Matrix.QR qr(boolean overwrite)
QR Decomposition.
Parameters:
`overwrite` - The flag if the decomposition overwrites this matrix.
Returns:
QR decomposition.
• ### svd

public Matrix.SVD svd()
Singular Value Decomposition. Returns a compact SVD of m-by-n matrix A:
• `m > n` — Only the first n columns of U are computed, and S is n-by-n.
• `m = n` — Equivalent to full SVD.
• `m < n` — Only the first m columns of V are computed, and S is m-by-m.
The compact decomposition removes extra rows or columns of zeros from the diagonal matrix of singular values, S, along with the columns in either U or V that multiply those zeros in the expression A = U*S*V'. Removing these zeros and columns can improve execution time and reduce storage requirements without compromising the accuracy of the decomposition.
Returns:
singular value decomposition.
• ### svd

public Matrix.SVD svd(boolean vectors, boolean overwrite)
Singular Value Decomposition. Returns a compact SVD of m-by-n matrix A:
• `m > n` — Only the first n columns of U are computed, and S is n-by-n.
• `m = n` — Equivalent to full SVD.
• `m < n` — Only the first m columns of V are computed, and S is m-by-m.
The compact decomposition removes extra rows or columns of zeros from the diagonal matrix of singular values, S, along with the columns in either U or V that multiply those zeros in the expression A = U*S*V'. Removing these zeros and columns can improve execution time and reduce storage requirements without compromising the accuracy of the decomposition.
Parameters:
`vectors` - The flag if computing the singular vectors.
`overwrite` - The flag if the decomposition overwrites this matrix.
Returns:
singular value decomposition.
• ### eigen

public Matrix.EVD eigen()
Eigenvalue Decomposition. For a symmetric matrix, all eigenvalues are real values. Otherwise, the eigenvalues may be complex numbers.

By default `eigen` does not always return the eigenvalues and eigenvectors in sorted order. Use the `EVD.sort` function to put the eigenvalues in descending order and reorder the corresponding eigenvectors.

Returns:
eign value decomposition.
• ### eigen

public Matrix.EVD eigen(boolean vl, boolean vr, boolean overwrite)
Eigenvalue Decomposition. For a symmetric matrix, all eigenvalues are real values. Otherwise, the eigenvalues may be complex numbers.

By default `eigen` does not always return the eigenvalues and eigenvectors in sorted order. Use the `sort` function to put the eigenvalues in descending order and reorder the corresponding eigenvectors.

Parameters:
`vl` - The flag if computing the left eigenvectors.
`vr` - The flag if computing the right eigenvectors.
`overwrite` - The flag if the decomposition overwrites this matrix.
Returns:
eigen value decomposition.