Skip to content

Latest commit

 

History

History
411 lines (180 loc) · 5.6 KB

File metadata and controls

411 lines (180 loc) · 5.6 KB

Home > @josh-brown/vector > SparseMatrix

SparseMatrix class

Implements Matrix with a map of indices to nonzero values.

Signature:

export declare abstract class SparseMatrix<S = number> implements Matrix<S> 

Implements: Matrix<S>

Remarks

Subclasses must specify the usual scalar operations on their contents.

The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the SparseMatrix class.

Methods

Method

Modifiers

Description

add(other)

Implements matrix addition

adjoint()

Returns the adjoint of the matrix

apply(vector)

Applies the matrix as a linear transformation to the given vector. Implements matrix-vector multiplication.

builder()

abstract

Returns a MatrixBuilder which will build new matrices of the same type

combine(other, combineEntries)

Builds a matrix by combining element-wise the values of this matrix with the values of another matrix.

equals(other)

Tests if two matrices are equal

forEach(cb)

Executes the callback function for each entry in the matrix.

getColumn(j)

Returns a vector corresponding to the column at index columnIndex

getColumnVectors()

An array of vectors corresponding to the columns of the matrix

getDiagonal()

Returns a vector containing the elements of the main diagonal of the matrix

getEntry(i, j)

Returns the entry of the matrix at the specified indices i and j

getNumberOfColumns()

Returns the number of columns in the matrix

getNumberOfRows()

Returns the number of rows in the matrix

getRow(i)

Returns a vector corresponding to the row at index rowIndex

getRowVectors()

Returns an array of vectors corresponding to the rows of the matrix

getShape()

Returns a tuple representing the dimensions of the matrix. The first entry is the number of rows, and the second entry is the number of columns.

getSparseData()

Returns the contents of the matrix as a nested map of rowIndex to columnIndex to nonzero value

map(entryFunction)

Builds a matrix by transforming the values of the current matrix.

multiply(other)

Implements matrix multiplication

ops()

abstract

Returns a ScalarOperations object which will allow consumers to work generically with the scalars contained in the vector.

scalarMultiply(scalar)

Implements multiplication of a matrix by a scalar

set(i, j, value)

Returns a new matrix equal to the old one, except with the entry at (i, j) replaced with value

toArray()

Returns the contents of the matrix as a 2-D array.

trace()

Returns the trace of the matrix

transpose()

Returns the transpose of the matrix

vectorBuilder()

abstract

Returns a VectorBuilder which will build new vectors of a compatible type