Class Matrix

java.lang.Object
smile.math.matrix.fp32.IMatrix
smile.math.matrix.fp32.Matrix
All Implemented Interfaces:
Serializable, Cloneable

public class Matrix extends IMatrix
Dense matrix.
See Also:
  • Nested Class Summary

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

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

    IMatrix.Preconditioner
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    aat()
    Returns A * A'.
    static Matrix
    adb(Transpose transA, Matrix A, float[] D, Transpose transB, Matrix B)
    Returns A * D * B, where D is a diagonal matrix.
    add(float b)
    A += b
    add(float alpha, float[] x, float[] y)
    Rank-1 update A += alpha * x * y'
    add(float alpha, float beta, Matrix B)
    Element-wise addition A = alpha * A + beta * B
    add(float beta, Matrix B)
    Element-wise addition A += beta * B
    add(float alpha, Matrix A, float beta, Matrix B)
    Element-wise addition C = alpha * A + beta * B
    float
    add(int i, int j, float b)
    A[i,j] += b
    Element-wise addition A += B
    add2(float alpha, float beta, Matrix B)
    Element-wise addition A = alpha * A + beta * B^2
    addDiag(float b)
    A[i, i] += b
    addDiag(float[] b)
    A[i, i] += b[i]
    ata()
    Returns A' * A.
    Cholesky decomposition for symmetric and positive definite matrix.
    cholesky(boolean overwrite)
    Cholesky decomposition for symmetric and positive definite matrix.
    Returns a deep copy of matrix.
    float[]
    col(int j)
    Returns the j-th column.
    float[]
    Returns the mean of each column.
    cols(int... cols)
    Returns the matrix of selected columns.
    float[]
    Returns the standard deviations of each column.
    float[]
    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
    column(float[] A)
    Returns a column vector/matrix.
    static Matrix
    column(float[] A, int offset, int length)
    Returns a column vector/matrix.
    static Matrix
    diag(float[] diag)
    Returns a square diagonal matrix.
    static Matrix
    diag(int n, float diag)
    Returns a square diagonal matrix.
    static Matrix
    diag(int m, int n, float diag)
    Returns an m-by-n diagonal matrix.
    div(float b)
    A /= b
    float
    div(int i, int j, float b)
    A[i,j] /= b
    Element-wise division A /= B
    Eigenvalue Decomposition.
    eigen(boolean vl, boolean vr, boolean overwrite)
    Eigenvalue Decomposition.
    boolean
     
    boolean
    equals(Matrix o, float 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(float x)
    Fills the matrix with a value.
    get(int[] rows, int[] cols)
    Returns the matrix of selected rows and columns.
    float
    get(int i, int j)
    Returns A[i,j].
    protected int
    index(int i, int j)
    Returns the linearized index of matrix element.
    Returns the inverse of matrix.
    boolean
    Return true if the matrix is symmetric (uplo != null && diag == null).
    Returns the matrix layout.
    int
    ld()
    Returns the leading dimension.
    lu()
    LU decomposition.
    lu(boolean overwrite)
    LU decomposition.
    mm(Transpose transA, Matrix A, Transpose transB, Matrix B)
    Matrix-matrix multiplication.
    mm(Transpose transA, Matrix A, Transpose transB, Matrix B, float alpha, float beta)
    Matrix-matrix multiplication.
    Returns matrix multiplication A * B.
    Returns matrix multiplication A * B'.
    mul(float b)
    A *= b
    float
    mul(int i, int j, float b)
    A[i,j] *= b
    Element-wise multiplication A *= B
    void
    mv(float[] work, int inputOffset, int outputOffset)
    Matrix-vector multiplication A * x.
    void
    mv(Transpose trans, float alpha, float[] x, float beta, float[] y)
    Matrix-vector multiplication.
    int
    Returns the number of columns.
    float
    L2 matrix norm that is the maximum singular value.
    float
    L1 matrix norm that is the maximum of column sums.
    float
    L2 matrix norm that is the maximum singular value.
    float
    Frobenius matrix norm that is the square root of sum of squares of all elements.
    float
    L matrix norm that is the maximum of row sums.
    int
    Returns the number of rows.
    static Matrix
    of(double[][] A)
    Returns a matrix from a two-dimensional array.
    static Matrix
    of(float[][] A)
    Returns a matrix from a two-dimensional array.
    qr()
    QR Decomposition.
    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, float lo, float 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.
    replaceNaN(float 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.
    static Matrix
    row(float[] A)
    Returns a row vector/matrix.
    static Matrix
    row(float[] A, int offset, int length)
    Returns a row vector/matrix.
    float[]
    row(int i)
    Returns the i-th row.
    float[]
    Returns the mean of each row.
    rows(int... rows)
    Returns the matrix of selected rows.
    float[]
    Returns the standard deviations of each row.
    float[]
    Returns the sum of each row.
    scale(float[] center, float[] scale)
    Centers and scales the columns of matrix.
    void
    set(int i, int j, float x)
    Sets A[i,j] = x.
    Sets the matrix value.
    long
    Returns the number of stored matrix elements.
    Standardizes the columns of matrix.
    sub(float b)
    A -= b
    float
    sub(int i, int j, float b)
    A[i,j] -= b
    Element-wise subtraction A -= B
    submatrix(int i, int j, int k, int l)
    Returns the submatrix which top left at (i, j) and bottom right at (k, l).
    float
    sum()
    Returns the sum of all elements.
    svd()
    Singular Value Decomposition.
    svd(boolean vectors, boolean overwrite)
    Singular Value Decomposition.
    Returns matrix multiplication A' * B.
    float[][]
    Return the two-dimensional array of matrix.
    static Matrix
    toeplitz(float[] a)
    Returns a symmetric Toeplitz matrix in which each descending diagonal from left to right is constant.
    static Matrix
    toeplitz(float[] kl, float[] ku)
    Returns a Toeplitz matrix in which each descending diagonal from left to right is constant.
    Returns the transpose of matrix.
    transpose(boolean share)
    Returns the transpose of matrix.
    Gets the flag if a triangular matrix has unit diagonal elements.
    Sets/unsets if the matrix is triangular.
    Returns matrix multiplication A' * B'.
    void
    tv(float[] work, int inputOffset, int outputOffset)
    Matrix-vector multiplication A' * x.
    Gets the format of packed matrix.
    uplo(UPLO uplo)
    Sets the format of packed matrix.
    float
    xAx(float[] x)
    Returns the quadratic form x' * A * x.

    Methods inherited from class smile.math.matrix.fp32.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, float 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, float[] 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(float[][] A)
      Returns a matrix from a two-dimensional array.
      Parameters:
      A - the two-dimensional array.
      Returns:
      the matrix.
    • 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(float[] A)
      Returns a column vector/matrix.
      Parameters:
      A - the column vector.
      Returns:
      the column vector/matrix.
    • column

      public static Matrix column(float[] 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.
    • 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(float[] A)
      Returns a row vector/matrix.
      Parameters:
      A - the row vector.
      Returns:
      the row vector/matrix.
    • row

      public static Matrix row(float[] 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.
    • 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, float lo, float 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, float 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, float 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(float[] diag)
      Returns a square diagonal matrix.
      Parameters:
      diag - the diagonal elements.
      Returns:
      the diagonal matrix.
    • toeplitz

      public static Matrix toeplitz(float[] 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(float[] kl, float[] 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.
    • 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 the leading dimension.
      Returns:
      the leading dimension.
    • 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 float[][] 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 float 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, float 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 float[] 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 float[] 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(float 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, float 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.
    • add

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

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

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

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

      public Matrix addDiag(float b)
      A[i, i] += b
      Parameters:
      b - the operand.
      Returns:
      this matrix.
    • addDiag

      public Matrix addDiag(float[] b)
      A[i, i] += b[i]
      Parameters:
      b - the operand.
      Returns:
      this matrix.
    • add

      public Matrix add(float b)
      A += b
      Parameters:
      b - the operand.
      Returns:
      this matrix.
    • sub

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

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

      public Matrix div(float b)
      A /= b
      Parameters:
      b - the operand.
      Returns:
      this matrix.
    • add

      public Matrix add(Matrix B)
      Element-wise addition A += B
      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.
    • add

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

      public Matrix add(float alpha, float 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.
    • add2

      public Matrix add2(float alpha, float 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.
    • add

      public Matrix add(float alpha, Matrix A, float 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.
    • add

      public Matrix add(float alpha, float[] x, float[] 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(float x)
      Replaces NaN's with given value.
      Parameters:
      x - a real number.
      Returns:
      this matrix.
    • sum

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

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

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

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

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

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

      public float xAx(float[] 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:
      the quadratic form.
    • rowSums

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

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

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

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

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

      public float[] 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(float[] center, float[] 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, float alpha, float[] x, float beta, float[] 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(float[] 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(float[] 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, float alpha, float 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'.
    • adb

      public static Matrix adb(Transpose transA, Matrix A, float[] 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.