14.2.21 Class Matrix

mosek.fusion.Matrix

Base class for all matrix objects. It can be used to create and manipulate matrices of constant coefficients both in dense and sparse format. To operate with matrices containing variables and linear expressions use the classes Expr and Variable.

Members

Matrix.get – Get a single entry.

Matrix.getDataAsArray – Return a dense array of values.

Matrix.getDataAsTriplets – Return the matrix data in sparse triplet format.

Matrix.isSparse – Returns true if the matrix is sparse.

Matrix.numColumns – Returns the number of columns in the matrix.

Matrix.numNonzeros – Returns the number of non-zeros in the matrix.

Matrix.numRows – Returns the number of rows in the matrix.

Matrix.toString – Get a string representation of the matrix.

Matrix.transpose – Transpose the matrix.

Static members

Matrix.antidiag – Create a sparse square matrix with a given vector as anti-diagonal.

Matrix.dense – Create a dense matrix from the given data.

Matrix.diag – Create a sparse square matrix with a given vector as diagonal.

Matrix.eye – Create the identity matrix.

Matrix.ones – Create a matrix filled with all ones.

Matrix.sparse – Create a sparse matrix from the given data.

Matrix.antidiag
Matrix Matrix.antidiag(double[] d)
Matrix Matrix.antidiag(double[] d, int k)
Matrix Matrix.antidiag(int n, double val)
Matrix Matrix.antidiag(int n, double val, int k)

Create a sparse square matrix with a given vector as anti-diagonal.

Parameters
  • d (double[]) – The anti-diagonal vector.

  • k (int) – The anti-diagonal index. \(k=0\) is the default and means the main anti-diagonal. \(k>0\) means above, and \(k<0\) means below the main anti-diagonal.

  • n (int) – The dimension of the matrix.

  • val (double) – Use this value for all anti-diagonal elements.

Return

(Matrix)

Matrix.dense
Matrix Matrix.dense(double[][] data)
Matrix Matrix.dense(int dimi, int dimj, double[] data)
Matrix Matrix.dense(int dimi, int dimj, double value)
Matrix Matrix.dense(Matrix other)

Create a dense matrix from the given data.

Parameters
  • data (double[][]) – A one- or two-dimensional array of matrix coefficients.

  • data (double[]) – A one- or two-dimensional array of matrix coefficients.

  • dimi (int) – Number of rows.

  • dimj (int) – Number of columns.

  • value (double) – Use this value for all elements.

  • other (Matrix) – Create a dense matrix from another matrix.

Return

(Matrix)

Matrix.diag
Matrix Matrix.diag(double[] d)
Matrix Matrix.diag(double[] d, int k)
Matrix Matrix.diag(int n, double val)
Matrix Matrix.diag(int n, double val, int k)
Matrix Matrix.diag(Matrix[] md)
Matrix Matrix.diag(int num, Matrix mv)

Create a sparse square matrix with a given vector as diagonal.

Parameters
  • d (double[]) – The diagonal vector.

  • k (int) – The diagonal index. \(k=0\) is the default and means the main diagonal. \(k>0\) means above, and \(k<0\) means below the main diagonal.

  • n (int) – The dimension of the matrix.

  • val (double) – Use this value for all diagonal elements.

  • md (Matrix[]) – A list of square matrices that are used to create a block-diagonal square matrix.

  • num (int) – Number of times to repeat the mv matrix.

  • mv (Matrix) – A matrix to be repeated in all blocks of a block-diagonal square matrix.

Return

(Matrix)

Matrix.eye
Matrix Matrix.eye(int n)

Construct the identity matrix of size \(n\).

Parameters

n (int) – The dimension of the matrix.

Return

(Matrix)

Matrix.get
double get(int i, int j)

Get a single entry.

Parameters
  • i (int) – Row index.

  • j (int) – Column index.

Return

(double)

Matrix.getDataAsArray
double[] getDataAsArray()

Return the matrix elements as a dense array in row-major format.

Return

(double[])

Matrix.getDataAsTriplets
void getDataAsTriplets(int[] subi, int[] subj, double[] val)

Return the matrix data in sparse triplet format. Data is copied to the arrays subi, subj and val which must be pre-allocated to hold at least the number of non-zeros in the matrix.

The data returned must be ordered with subi as primary key and subj as secondary key.

Parameters
  • subi (int[]) – Row subscripts are returned in this array.

  • subj (int[]) – Column subscripts are returned in this array.

  • val (double[]) – Coefficient values are returned in this array.

Matrix.isSparse
boolean isSparse()

Returns true if the matrix is sparse.

Return

(boolean)

Matrix.numColumns
int numColumns()

Returns the number of columns in the matrix.

Return

(int)

Matrix.numNonzeros
long numNonzeros()

Returns the number of non-zeros in the matrix.

Return

(long)

Matrix.numRows
int numRows()

Returns the number of rows in the matrix.

Return

(int)

Matrix.ones
Matrix Matrix.ones(int n, int m)

Construct a matrix filled with ones.

Parameters
  • n (int) – Number of rows.

  • m (int) – Number of columns.

Return

(Matrix)

Matrix.sparse
Matrix Matrix.sparse(int nrow, int ncol, int[] subi, int[] subj, double[] val)
Matrix Matrix.sparse(int[] subi, int[] subj, double[] val)
Matrix Matrix.sparse(int[] subi, int[] subj, double val)
Matrix Matrix.sparse(int nrow, int ncol, int[] subi, int[] subj, double val)
Matrix Matrix.sparse(int nrow, int ncol)
Matrix Matrix.sparse(double[][] data)
Matrix Matrix.sparse(Matrix[][] blocks)
Matrix Matrix.sparse(Matrix mx)

Create a sparse matrix from the given data.

Parameters
  • nrow (int) – Number of rows.

  • ncol (int) – Number of columns.

  • subi (int[]) – Row subscripts of non-zero elements.

  • subj (int[]) – Column subscripts of non-zero elements.

  • val (double[]) – Coefficients of non-zero elements.

  • val (double) – Coefficients of non-zero elements.

  • data (double[][]) – Dense data array.

  • blocks (Matrix[][]) – The matrix data in block format. All elements in a row must have the same height, and all elements in a column must have the same width. Entries that are null will be interpreted as a block of zeros whose height and width are deduced from the other elements in the same row and column. Any row that contains only null entries will have height 0, and any column that contains only null entries will have width 0.

  • mx (Matrix) – A Matrix object.

Return

(Matrix)

Matrix.toString
String toString()

Get a string representation of the matrix.

Return

(String)

Matrix.transpose
Matrix transpose()

Transpose the matrix.

Return

(Matrix)