|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.numericalmethod.suanshu.matrix.doubles.matrixtype.sparse.CSRSparseMatrix
public class CSRSparseMatrix
The Compressed Sparse Row (CSR) format for sparse matrix has this
representation: (value, col_ind, row_ptr). Three arrays are used to
represent a sparse matrix:
value stores all the non-zero entries of the matrix from left to
right, top to bottom.
col_ind is the column indices corresponding to the values.
row_ptr is the list of values indices where each row starts.
For example:
\[
\begin{bmatrix}
1 & 2 & 0 & 0\\
0 & 3 & 9 & 0\\
0 & 1 & 4 & 0
\end{bmatrix}
\]
Note:value = [ 1 2 3 9 1 4 ] col_ind = [ 0 1 1 2 1 2 ] row_ptr = [ 0 2 4 6 ]
(row_ptr[i] - row_ptr[i - 1]) is the number of non-zero entries
in row i.
This format is very inefficient for incremental construction or changes using
set(int, int, double),
but efficient for matrix computation.
| Constructor Summary | |
|---|---|
CSRSparseMatrix(CSRSparseMatrix that)
Copy constructor. |
|
CSRSparseMatrix(int nRows,
int nCols)
Construct a sparse matrix in CSR format. |
|
CSRSparseMatrix(int nRows,
int nCols,
int[] rowIndices,
int[] columnIndices,
double[] value)
Construct a sparse matrix in CSR format. |
|
CSRSparseMatrix(int nRows,
int nCols,
java.util.List<SparseEntry> entries)
Construct a sparse matrix in CSR format by a list of non-zero entries. |
|
| Method Summary | |
|---|---|
Matrix |
add(Matrix that)
this + that |
CSRSparseMatrix |
deepCopy()
The implementation returns an instance created from this by the copy
constructor of the class, or just this if the instance itself is
immutable. |
boolean |
equals(java.lang.Object obj)
|
double |
get(int i,
int j)
Get the matrix entry at [i,j]. |
SparseVector |
getColumn(int j)
Get the specified column in the matrix as a vector. |
java.util.List<SparseEntry> |
getEntrytList()
Export the non-zero values in the matrix as a list of SparseEntrys. |
SparseVector |
getRow(int i)
Get the specified row in the matrix as a vector. |
int |
hashCode()
|
Matrix |
minus(Matrix that)
this - that |
Matrix |
multiply(Matrix that)
this * that |
Vector |
multiply(Vector v)
Right multiply this matrix, A, by a vector. |
int |
nCols()
Get the number of columns. |
int |
nNonZeros()
Get the number of non-zero entries in the structure. |
int |
nRows()
Get the number of rows. |
CSRSparseMatrix |
ONE()
Get an identity matrix that has the same dimension as this matrix. |
CSRSparseMatrix |
opposite()
Get the opposite of this matrix. |
CSRSparseMatrix |
scaled(double c)
Scale this matrix, A, by a constant. |
void |
set(int row,
int col,
double value)
Set the matrix entry at [i,j] to a value. |
CSRSparseMatrix |
t()
Get the transpose of this matrix. |
DenseMatrix |
toDense()
Densify a matrix, i.e., convert a matrix implementation to the standard dense matrix, DenseMatrix. |
java.lang.String |
toString()
|
CSRSparseMatrix |
ZERO()
Get a zero matrix that has the same dimension as this matrix. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public CSRSparseMatrix(int nRows,
int nCols)
nRows - the number of rowsnCols - the number of columns
public CSRSparseMatrix(int nRows,
int nCols,
int[] rowIndices,
int[] columnIndices,
double[] value)
nRows - the number of rowsnCols - the number of columnsrowIndices - the row indices of the non-zeros valuescolumnIndices - the column indices of the non-zeros valuesvalue - the non-zero values
public CSRSparseMatrix(int nRows,
int nCols,
java.util.List<SparseEntry> entries)
nRows - the number of rowsnCols - the number of columnsentries - the list of entriespublic CSRSparseMatrix(CSRSparseMatrix that)
that - the matrix to be copied| Method Detail |
|---|
public int nRows()
Table
nRows in interface Tablepublic int nCols()
Table
nCols in interface Tablepublic java.util.List<SparseEntry> getEntrytList()
SparseMatrixSparseEntrys.
This is useful for converting between the different formats of SparseMatrix.
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.getEntrytList());
getEntrytList in interface SparseMatrix
public void set(int row,
int col,
double value)
MatrixAccess
set in interface MatrixAccessrow - the row indexcol - the column indexvalue - the value to set A[i,j] to
public double get(int i,
int j)
MatrixAccess
get in interface MatrixAccessi - the row indexj - the column index
public SparseVector getRow(int i)
throws MatrixAccessException
Matrix
getRow in interface Matrixi - the row index
MatrixAccessException - when i < 1, or when i > the number of rows
public SparseVector getColumn(int j)
throws MatrixAccessException
Matrix
getColumn in interface Matrixj - the column index
MatrixAccessException - when j < 1, or when j > the number of columnspublic Matrix add(Matrix that)
MatrixRing
add in interface AbelianGroup<Matrix>add in interface MatrixRingthat - a matrix
this and thatpublic Matrix minus(Matrix that)
MatrixRing
minus in interface AbelianGroup<Matrix>minus in interface MatrixRingthat - a matrix
this and thatpublic Matrix multiply(Matrix that)
MatrixRing
multiply in interface Monoid<Matrix>multiply in interface MatrixRingthat - a matrix
this and thatpublic Vector multiply(Vector v)
Matrix
multiply in interface Matrixv - a vector
public CSRSparseMatrix scaled(double c)
Matrix
scaled in interface Matrixc - a double
public CSRSparseMatrix opposite()
MatrixRing
opposite in interface AbelianGroup<Matrix>opposite in interface MatrixRingpublic CSRSparseMatrix t()
MatrixRing
t in interface MatrixRingpublic DenseMatrix toDense()
DensifiableDenseMatrix.
toDense in interface DensifiableDenseMatrixpublic CSRSparseMatrix ZERO()
MatrixRing
ZERO in interface AbelianGroup<Matrix>ZERO in interface MatrixRingpublic CSRSparseMatrix ONE()
MatrixRing
ONE in interface Monoid<Matrix>ONE in interface MatrixRingpublic CSRSparseMatrix deepCopy()
DeepCopyablethis by the copy
constructor of the class, or just this if the instance itself is
immutable.
deepCopy in interface DeepCopyabledeepCopy in interface Matrixpublic int nNonZeros()
SparseStructure
nNonZeros in interface SparseStructurepublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Object
|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||