8.5.2. MDOMatrix

MDOMatrix

Represents a matrix class with a double value. Typically used to interact with matrix attributes

Methods

coo

Construct a sparse matrix with indexes and values

coo

Construct a sparse matrix containing row indexes, column indexes, and values

csc

Construct a matrix in the format of compressed sparse columns (CSC)

csr

Construct a compressed sparse row (CSR) formatting matrix

dense

Construct a dense matrix

full

Construct a matrix whose internal elements are all value

identity

Construct a square matrix where the main diagonal elements are all 1

zero

Construct a matrix containing only zeros

cols

The number of columns contained in this matrix

data

Retrieve the ith value in this matrix

index

Retrieve the index of the ith non-zero element in this matrix

nzs

The number of non-zero elements in a matrix

rows

The number of rows contained in this matrix

toString

Converts the current matrix into String format

static MDOMatrix coo(int rows, int cols, int[] indices, double[] data)

Construct a sparse matrix with indexes and values

Parameters
  • int rows – The number of rows

  • int cols – The number of columns

  • int[] indices – Indexes of all non-zero elements

  • double[] data – Values of all non-zero elements

Returns

Newly created matrix

static MDOMatrix coo(int rows, int cols, int[] rowIndices, int[] colIndices, double[] data)

Construct a sparse matrix containing row indexes, column indexes, and values

Parameters
  • int rows – The Number of rows

  • int cols – The Number of columns

  • int[] rowIndices – Row indexes of all non-zero elements

  • int[] colIndices – Column indexes of all non-zero elements

  • double[] data – Values of all non-zero elements

Returns

Newly created matrix

static MDOMatrix csc(int rows, int cols, int[] ptr, int[] ind, double[] data)

Construct a matrix in the format of compressed sparse columns (CSC)

Parameters
  • int rows – The number of rows

  • int cols – The number of columns

  • int[] ptr – The begin indices in ind of columns contained in matrix.

  • int[] ind – Row indices of all non-zero elements

  • double[] data – Values of all non-zero elements

Returns

Newly created matrix

static MDOMatrix csr(int rows, int cols, int[] ptr, int[] ind, double[] data)

Construct a compressed sparse row (CSR) formatting matrix

Parameters
  • int rows – The number of rows

  • int cols – The number of columns

  • int[] ptr – The begin indices in ind of rows contained in matrix

  • int[] ind – Column indices of all non-zero elements

  • double[] data – Values of all non-zero elements

Returns

Newly created matrix

static MDOMatrix dense(int rows, int cols, double[] data)

Construct a dense matrix

Parameters
  • int rows – The number of rows

  • int cols – The number of columns

  • double[] data – Values for all elements. It should have at least rows * cols elements.

Returns

The newly created matrix

static MDOMatrix full(int rows, int cols, double value)

Construct a matrix whose internal elements are all value .

Parameters
  • int rows – The number of rows

  • int cols – The number of columns

  • double value – The value of all matrix elements.

Returns

The newly created matrix.

static MDOMatrix identity(int n)

Construct a square matrix where the main diagonal elements are all 1

Parameters

int n – The dimension of the new matrix, that is, the number of rows and columns of the square matrix.

Returns

The newly created matrix

static MDOMatrix zero(int rows, int cols)

Construct a matrix containing only zeros.

Parameters
  • int rows – Number of rows

  • int cols – Number of columns

Returns

The newly created matrix

int cols()

The number of columns contained in this matrix

Returns

The number of columns contained in this matrix

double data(int i)

Retrieve the ith value in this matrix

Parameters

int i – Index i to query

Returns

The ith value in this matrix

int index(int i)

Retrieve the index of the ith non-zero element in this matrix

Parameters

int i – The number of orders of this non-zero element in the matrix

Returns

The index position of the ith non-zero element in this matrix

int nzs()

The number of non-zero elements in a matrix

Returns

The number of non-zero elements in a matrix

int rows()

The number of rows contained in this matrix

Returns

The number of rows contained in this matrix

String toString()

Converts the current matrix into String format.

Returns

The string format of the matrix.