8.7.2. MDOMatrix

MDOMatrix

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

Properties

Cols

The number of columns contained in this matrix

Nzs

The number of non-zero elements in a matrix

Rows

The number of rows contained in this matrix

Cols

The number of columns contained in this matrix

Nzs

The number of non-zero elements in a matrix

Rows

The number of rows contained in this matrix

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

Data

Retrieve the ith value in this matrix

Index

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

ToString

Convert 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

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

string ToString()

Convert the current matrix into string format.

Returns

The string format of the matrix.