Class SparseMatrix
- java.lang.Object
-
- smile.math.matrix.Matrix
-
- smile.math.matrix.SparseMatrix
-
- All Implemented Interfaces:
- java.io.Serializable, MatrixMultiplication<SparseMatrix,SparseMatrix>
public class SparseMatrix extends Matrix implements MatrixMultiplication<SparseMatrix,SparseMatrix>
A sparse matrix is a matrix populated primarily with zeros. Conceptually, sparsity corresponds to systems which are loosely coupled. Huge sparse matrices often appear when solving partial differential equations.Operations using standard dense matrix structures and algorithms are slow and consume large amounts of memory when applied to large sparse matrices. Indeed, some very large sparse matrices are infeasible to manipulate with the standard dense algorithms. Sparse data is by nature easily compressed, and this compression almost always results in significantly less computer data storage usage.
This class employs Harwell-Boeing column-compressed sparse matrix format. Nonzero values are stored in an array (top-to-bottom, then left-to-right-bottom). The row indices corresponding to the values are also stored. Besides, a list of pointers are indexes where each column starts. This format is efficient for arithmetic operations, column slicing, and matrix-vector products. One typically uses SparseDataset for construction of SparseMatrix.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description SparseMatrix(double[][] D)Constructor.SparseMatrix(double[][] D, double tol)Constructor.SparseMatrix(int nrows, int ncols, double[] x, int[] rowIndex, int[] colIndex)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description SparseMatrixaat()Returns A * A'SparseMatrixabmm(SparseMatrix B)Returns the matrix multiplication C = A * B.SparseMatrixabtmm(SparseMatrix B)Returns the result of matrix multiplication A * B'.SparseMatrixata()Returns A' * ASparseMatrixatbmm(SparseMatrix B)Returns the result of matrix multiplication A' * B.double[]atx(double[] x, double[] y)y = A' * xdouble[]atxpy(double[] x, double[] y)y = A' * x + ydouble[]atxpy(double[] x, double[] y, double b)y = A' * x + b * ydouble[]ax(double[] x, double[] y)y = A * xdouble[]axpy(double[] x, double[] y)y = A * x + ydouble[]axpy(double[] x, double[] y, double b)y = A * x + b * ydouble[]diag()Returns the diagonal elements.doubleget(int i, int j)Returns the entry value at row i and column j.intncols()Returns the number of columns.intnrows()Returns the number of rows.intsize()Returns the number of nonzero values.SparseMatrixtranspose()Returns the matrix transpose.double[]values()Returns all nonzero values.-
Methods inherited from class smile.math.matrix.Matrix
apply, diag, eigen, eigen, eye, eye, isSymmetric, newInstance, newInstance, newInstance, ones, randn, randn, setSymmetric, svd, svd, toString, toString, trace, zeros
-
-
-
-
Constructor Detail
-
SparseMatrix
public SparseMatrix(int nrows, int ncols, double[] x, int[] rowIndex, int[] colIndex)Constructor.- Parameters:
nrows- the number of rows in the matrix.ncols- the number of columns in the matrix.rowIndex- the row indices of nonzero values.colIndex- the index of the start of columns.x- the array of nonzero values stored column by column.
-
SparseMatrix
public SparseMatrix(double[][] D)
Constructor.- Parameters:
D- a dense matrix to converted into sparse matrix format.
-
SparseMatrix
public SparseMatrix(double[][] D, double tol)Constructor.- Parameters:
D- a dense matrix to converted into sparse matrix format.tol- the tolerance to regard a value as zero if |x| < tol.
-
-
Method Detail
-
nrows
public int nrows()
Description copied from class:MatrixReturns the number of rows.
-
ncols
public int ncols()
Description copied from class:MatrixReturns the number of columns.
-
size
public int size()
Returns the number of nonzero values.
-
values
public double[] values()
Returns all nonzero values.- Returns:
- all nonzero values
-
get
public double get(int i, int j)Description copied from class:MatrixReturns the entry value at row i and column j.
-
ax
public double[] ax(double[] x, double[] y)Description copied from class:Matrixy = A * x
-
axpy
public double[] axpy(double[] x, double[] y)Description copied from class:Matrixy = A * x + y
-
axpy
public double[] axpy(double[] x, double[] y, double b)Description copied from class:Matrixy = A * x + b * y
-
atx
public double[] atx(double[] x, double[] y)Description copied from class:Matrixy = A' * x
-
atxpy
public double[] atxpy(double[] x, double[] y)Description copied from class:Matrixy = A' * x + y
-
atxpy
public double[] atxpy(double[] x, double[] y, double b)Description copied from class:Matrixy = A' * x + b * y
-
transpose
public SparseMatrix transpose()
Description copied from class:MatrixReturns the matrix transpose.
-
abmm
public SparseMatrix abmm(SparseMatrix B)
Returns the matrix multiplication C = A * B.- Specified by:
abmmin interfaceMatrixMultiplication<SparseMatrix,SparseMatrix>
-
abtmm
public SparseMatrix abtmm(SparseMatrix B)
Description copied from interface:MatrixMultiplicationReturns the result of matrix multiplication A * B'.- Specified by:
abtmmin interfaceMatrixMultiplication<SparseMatrix,SparseMatrix>
-
atbmm
public SparseMatrix atbmm(SparseMatrix B)
Description copied from interface:MatrixMultiplicationReturns the result of matrix multiplication A' * B.- Specified by:
atbmmin interfaceMatrixMultiplication<SparseMatrix,SparseMatrix>
-
ata
public SparseMatrix ata()
Description copied from class:MatrixReturns A' * A
-
aat
public SparseMatrix aat()
Description copied from class:MatrixReturns A * A'
-
-
DataMelt 3.0 © DataMelt by jWork.ORG