Interface SparseMatrix
-
- All Superinterfaces:
AbelianGroup<Matrix>
,DeepCopyable
,Densifiable
,Matrix
,MatrixAccess
,MatrixRing
,MatrixTable
,Monoid<Matrix>
,Ring<Matrix>
,SparseStructure
,Table
- All Known Implementing Classes:
CSRSparseMatrix
,DOKSparseMatrix
,LILSparseMatrix
public interface SparseMatrix extends Matrix, Densifiable, SparseStructure
A sparse matrix stores only non-zero values. When there are only a few non-zeros in a matrix, sparse matrix saves memory space for storing the matrix. In addition, the matrix operations based on sparse matrix are usually more efficient. The time complexities are proportional to the number of non-zero values instead of the dimension-squared of dense matrix.- See Also:
- Wikipedia: Sparse matrix
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
SparseMatrix.Entry
This is a (non-zero) entry in a sparse matrix.static class
SparseMatrix.ValueArray
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description List<SparseMatrix.Entry>
getEntryList()
Exports the non-zero values in the matrix as a list ofSparseMatrix.Entry
s.SparseMatrix.ValueArray
getValueArray()
Exports the non-zero values in the matrix as arrays of row/column indices and values.SparseMatrix
subMatrix(int rowFrom, int rowTo, int colFrom, int colTo)
Extracts a sub-matrix given the bounds of row and column indices (inclusive).-
Methods inherited from interface dev.nm.algebra.linear.matrix.doubles.matrixtype.dense.Densifiable
toDense
-
Methods inherited from interface dev.nm.algebra.linear.matrix.doubles.Matrix
deepCopy, getColumn, getRow, multiply, scaled, toCSV
-
Methods inherited from interface dev.nm.algebra.linear.matrix.doubles.MatrixAccess
get, set
-
Methods inherited from interface dev.nm.algebra.linear.matrix.doubles.MatrixRing
add, minus, multiply, ONE, opposite, t, ZERO
-
Methods inherited from interface dev.nm.algebra.linear.matrix.doubles.matrixtype.sparse.SparseStructure
nNonZeros
-
-
-
-
Method Detail
-
getEntryList
List<SparseMatrix.Entry> getEntryList()
Exports the non-zero values in the matrix as a list ofSparseMatrix.Entry
s. This is useful for converting between the different formats ofSparseMatrix.Entry
. For example,// construct matrix using DOK DOKSparseMatrix dok = new DOKSparseMatrix(5, 5); // ... insert some values to DOK matrix // convert to CSR matrix for efficient matrix operations CSRSparseMatrix csr = new CSRSparseMatrix(5, 5, dok.getEntryList());
- Returns:
- the sparse entries
-
getValueArray
SparseMatrix.ValueArray getValueArray()
Exports the non-zero values in the matrix as arrays of row/column indices and values.- Returns:
- the arrays of indices and values
- See Also:
SparseMatrix.ValueArray
-
subMatrix
SparseMatrix subMatrix(int rowFrom, int rowTo, int colFrom, int colTo)
Extracts a sub-matrix given the bounds of row and column indices (inclusive).- Parameters:
rowFrom
- the beginning row indexrowTo
- the ending row indexcolFrom
- the beginning column indexcolTo
- the ending column index- Returns:
- A[rowFrom:rowTo, colFrom:colTo]
-
-