Class: SparseMatrix

LinearAlgebra. SparseMatrix


new SparseMatrix()

This class represents a m by n real matrix where only nonzero entries
are stored explicitly. Do not create a SparseMatrix from its constructor,
instead use static factory methods such as fromTriplet, identity and diag.

Example
let T = new Triplet(100, 100);
T.addEntry(3.4, 11, 43);
T.addEntry(6.4, 99, 99);
let A = SparseMatrix.fromTriplet(T);

let B = SparseMatrix.identity(10, 10);

let d = DenseMatrix.ones(100, 1);
let C = SparseMatrix.diag(d);

Methods


<static> fromTriplet(T)

Initializes a sparse matrix from a Triplet object.

Parameters:
Name Type Description
T module:LinearAlgebra.Triplet

A triplet object containing only the nonzero entries that
need to be stored in this sparse matrix.

Returns:
Type
module:LinearAlgebra.SparseMatrix

<static> identity(m, n)

Initializes a m by n sparse identity matrix.

Parameters:
Name Type Description
m number

The number of rows in this sparse matrix.

n number

The number of columns in this sparse matrix.

Returns:
Type
module:LinearAlgebra.SparseMatrix

<static> diag(d)

Initializes a sparse diagonal matrix.

Parameters:
Name Type Description
d module:LinearAlgebra.DenseMatrix

The dense vector (d.nCols() == 1) used to initialize
this sparse diagonal matrix.

Returns:
Type
module:LinearAlgebra.SparseMatrix

transpose()

Returns the transpose of this sparse matrix.

Returns:
Type
module:LinearAlgebra.SparseMatrix

invertDiagonal()

Returns the inverse of this diagonal sparse matrix.

Returns:
Type
module:LinearAlgebra.SparseMatrix

nRows()

Returns the number of rows in this sparse matrix.

Returns:
Type
number

nCols()

Returns the number of columns in this sparse matrix.

Returns:
Type
number

nnz()

Returns the number of nonzero entries in this sparse matrix.

Returns:
Type
number

frobeniusNorm()

Computes the frobenius norm of this sparse matrix.

Returns:
Type
number

subMatrix(r0, r1, c0, c1)

Extracts a sparse sub-matrix in the range [r0, r1) x [c0, c1), i.e., a matrix
of size (r1 - r0) x (c1 - c0) starting at indices (r0, c0).

Parameters:
Name Type Description
r0 number

The start row index.

r1 number

The end row index (not included).

c0 number

The start column index.

c1 number

The end column index (not included).

Returns:
Type
module:LinearAlgebra.SparseMatrix

chol()

Returns a sparse Cholesky factorization of this sparse matrix.

Returns:
Type
module:LinearAlgebra.Cholesky

lu()

Returns a sparse LU factorization of this sparse matrix.

Returns:
Type
module:LinearAlgebra.LU

qr()

Returns a sparse QR factorization of this sparse matrix.

Returns:
Type
module:LinearAlgebra.QR

toDense()

Returns a dense copy of this sparse matrix.

Returns:
Type
module:LinearAlgebra.DenseMatrix

incrementBy(B)

A += B

Parameters:
Name Type Description
B module:LinearAlgebra.SparseMatrix

The sparse matrix added to this sparse matrix.


decrementBy(B)

A -= B

Parameters:
Name Type Description
B module:LinearAlgebra.SparseMatrix

The sparse matrix subtracted from this sparse matrix.


scaleBy(s)

A *= s

Parameters:
Name Type Description
s number

The number this sparse matrix is scaled by.


plus(B)

Returns A + B

Parameters:
Name Type Description
B module:LinearAlgebra.SparseMatrix

The sparse matrix added to this sparse matrix.

Returns:
Type
module:LinearAlgebra.SparseMatrix

minus(B)

Returns A - B

Parameters:
Name Type Description
B module:LinearAlgebra.SparseMatrix

The sparse matrix subtracted from this sparse matrix.

Returns:
Type
module:LinearAlgebra.SparseMatrix

timesReal(s)

Returns A * s

Parameters:
Name Type Description
s number

The number this sparse matrix is multiplied by.

Returns:
Type
module:LinearAlgebra.SparseMatrix

timesDense(X)

Returns A * X

Parameters:
Name Type Description
X module:LinearAlgebra.DenseMatrix

The dense matrix this sparse matrix is multiplied by.

Returns:
Type
module:LinearAlgebra.DenseMatrix

timesSparse(B)

Returns A * B

Parameters:
Name Type Description
B module:LinearAlgebra.SparseMatrix

The sparse matrix this sparse matrix is multiplied by.

Returns:
Type
module:LinearAlgebra.SparseMatrix