public class SparseMatrix extends Object implements IMatrix
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.
| 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.
|
| Modifier and Type | Method and Description |
|---|---|
static SparseMatrix |
AAT(SparseMatrix A,
SparseMatrix AT)
Returns A * AT.
|
void |
asolve(double[] b,
double[] x)
Solve Ad * x = b for the preconditioner matrix Ad.
|
void |
atx(double[] x,
double[] y)
y = A' * x
|
void |
atxpy(double[] x,
double[] y)
y = A' * x + y
|
void |
atxpy(double[] x,
double[] y,
double b)
y = A' * x + b * y
|
void |
ax(double[] x,
double[] y)
y = A * x
|
void |
axpy(double[] x,
double[] y)
y = A * x + y
|
void |
axpy(double[] x,
double[] y,
double b)
y = A * x + b * y
|
double |
eigen(double[] v)
Returns the largest eigen pair of matrix with the power iteration
under the assumptions A has an eigenvalue that is strictly greater
in magnitude than its other its other eigenvalues and the starting
vectorhas a nonzero component in the direction of an eigenvector
associated with the dominant eigenvalue.
|
EigenValueDecomposition |
eigen(int k)
Returns the k largest eigen pairs.
|
double |
get(int i,
int j)
Returns the entry value at row i and column j.
|
int |
ncols()
Returns the number of columns.
|
int |
nrows()
Returns the number of rows.
|
SparseMatrix |
set(int i,
int j,
double x)
Set the entry value at row i and column j.
|
int |
size()
Returns the number of nonzero values.
|
SparseMatrix |
times(SparseMatrix B)
Returns the matrix multiplication C = A * B.
|
SparseMatrix |
transpose()
Returns the matrix transpose.
|
double[] |
values()
Returns all nonzero values.
|
public SparseMatrix(int nrows,
int ncols,
double[] x,
int[] rowIndex,
int[] colIndex)
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.public SparseMatrix(double[][] D)
D - a dense matrix to converted into sparse matrix format.public SparseMatrix(double[][] D,
double tol)
D - a dense matrix to converted into sparse matrix format.tol - the tolerance to regard a value as zero if |x| < tol.public int nrows()
IMatrixpublic int ncols()
IMatrixpublic int size()
public double[] values()
public double get(int i,
int j)
IMatrixpublic SparseMatrix set(int i, int j, double x)
IMatrixpublic void ax(double[] x,
double[] y)
IMatrixpublic void axpy(double[] x,
double[] y)
IMatrixpublic void axpy(double[] x,
double[] y,
double b)
IMatrixpublic void atx(double[] x,
double[] y)
IMatrixpublic void atxpy(double[] x,
double[] y)
IMatrixpublic void atxpy(double[] x,
double[] y,
double b)
IMatrixpublic SparseMatrix transpose()
public SparseMatrix times(SparseMatrix B)
public static SparseMatrix AAT(SparseMatrix A, SparseMatrix AT)
public double eigen(double[] v)
v - on input, it is the non-zero initial guess of the eigen vector.
On output, it is the eigen vector corresponding largest eigen value.public EigenValueDecomposition eigen(int k)
public void asolve(double[] b,
double[] x)
IMatrixCopyright © 2015. All rights reserved.