|
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.LilSparseMatrix
public class LilSparseMatrix
The list of lists (LIL) format for sparse matrix. Non-zero values in each row are stored in a list.
| Field Summary | |
|---|---|
protected int |
nCols
|
protected int |
nRows
|
| Constructor Summary | |
|---|---|
LilSparseMatrix(int nRows,
int nCols)
Create an instance of LIL sparse matrix with the matrix dimension. |
|
LilSparseMatrix(int nRows,
int nCols,
int[] rowIndices,
int[] columnIndices,
double[] values)
Create an instance of LIL sparse matrix with non-zero values. |
|
LilSparseMatrix(int nRows,
int nCols,
java.util.List<SparseElement> elementList)
Create an instance of LIL sparse matrix with a list of non-zero SparseElements. |
|
LilSparseMatrix(LilSparseMatrix that)
Copy constructor. |
|
| Method Summary | |
|---|---|
Matrix |
add(Matrix that)
this + that |
LilSparseMatrix |
deepCopy()
The implementation can return an instance created from this by the copy
constructor of the class, or just this if the instance itself is
immutable. |
int |
dropTolerance(double tolerance)
Remove non-zero entries x whose magnitude is less than or equal to the tolerance, i.e., ( |x| <= tolerance). |
boolean |
equals(java.lang.Object obj)
|
double |
get(int row,
int col)
Get the matrix entry at [row, col]. |
Vector |
getColumn(int col)
Get a specified column as a vector. |
Vector |
getRow(int row)
Get a specified row 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 |
nnz()
Get the number of non-zero entries in the matrix. |
int |
nRows()
Get the number of rows. |
Matrix |
ONE()
Get an identity matrix that has the same dimension as this matrix. |
Matrix |
opposite()
Get the opposite of this matrix. |
Matrix |
scaled(double scalar)
scalar * this |
void |
set(int row,
int col,
double value)
Set the matrix entry at [row, col] to value. |
Matrix |
t()
t(this)
Compute the transpose of this matrix. |
DenseMatrix |
toDense()
Densify a matrix, i.e., convert a matrix implementation to a standard dense matrix, DenseMatrix. |
java.util.List<SparseElement> |
toElementList()
Export the non-zero values in the matrix as a list of SparseElements. |
java.lang.String |
toString()
|
Matrix |
ZERO()
The additive element 0 in the group, such that for all elements a in the group,
the equation 0 + a = a + 0 = a holds. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected final int nRows
protected final int nCols
| Constructor Detail |
|---|
public LilSparseMatrix(int nRows,
int nCols)
nRows - the number of rows of the matrixnCols - the number of columns of the matrix
public LilSparseMatrix(int nRows,
int nCols,
int[] rowIndices,
int[] columnIndices,
double[] values)
nRows - the number of rows of the matrixnCols - the number of columns of the matrixrowIndices - the row indices of the input non-zeroscolumnIndices - the column indices of the input non-zerosvalues - the non-zero values
public LilSparseMatrix(int nRows,
int nCols,
java.util.List<SparseElement> elementList)
SparseElements.
nRows - the number of rows of the matrixnCols - the number of columns of the matrixelementList - the element listpublic LilSparseMatrix(LilSparseMatrix that)
that - the matrix to be copied| Method Detail |
|---|
public java.util.List<SparseElement> toElementList()
SparseMatrixSparseElements.
This is useful for converting between SparseMatrix of different
formats. 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.toElementList());
public double get(int row,
int col)
MatrixAccessor[row, col].
row - the row indexcol - the column index
A[row, col]
public void set(int row,
int col,
double value)
MatrixAccessor[row, col] to value.
This is the only method that may change the entries of a matrix.
row - the row indexcol - the column indexvalue - the value to set A[row, col] topublic Vector getRow(int row)
MatrixAccessor
row - the row index
A[row, ]public Vector getColumn(int col)
MatrixAccessor
col - the column index
A[, col]public Matrix add(Matrix that)
MatrixRingthis + that
add in interface AbelianGroup<Matrix>add in interface MatrixRingthat - another matrix
this and thatpublic Matrix minus(Matrix that)
MatrixRingthis - that
minus in interface AbelianGroup<Matrix>minus in interface MatrixRingthat - another matrix
this and thatpublic Matrix multiply(Matrix that)
MatrixRingthis %*% that
multiply in interface Monoid<Matrix>multiply in interface MatrixRingthat - another matrix
this and thatpublic Vector multiply(Vector v)
MatrixA by a vector.
multiply in interface Matrixv - a vector
A %*% vpublic Matrix scaled(double scalar)
Matrixscalar * this
scaled in interface Matrixscalar - a double
scalar * thispublic Matrix t()
MatrixRingt(this)
Compute the transpose of this matrix. The original matrix does not change. The returned value is independent and can be modified anyhow.
This is the involution on the matrix ring.
t in interface MatrixRingpublic Matrix ZERO()
AbelianGroupa in the group,
the equation 0 + a = a + 0 = a holds.
0public Matrix ONE()
MatrixRingFor a non-square matrix, it zeros out the rows (columns) with index > nCols (nRows).
public LilSparseMatrix deepCopy()
DeepCopyablethis by the copy
constructor of the class, or just this if the instance itself is
immutable.
public DenseMatrix toDense()
DensifiableDenseMatrix.
This is equivalent to
new DenseMatrix(Matrix A)
Individual matrix implementation may optimize the conversion
by taking advantage of having access to the class' private members.
In other words, toDense() is in general more efficient than explicit copy construction.
As an example, for some long matrix computations, we may not be sure about the return type. We can always cast it to the standard matrix. That is,
DenseMatrix A = B.multiply(C).add(D).minus(E).toDense();
This statement always works regardless of the types of B, C, D, and E.
DenseMatrixpublic int nnz()
SparseStructure
public int dropTolerance(double tolerance)
SparseStructure|x| <= tolerance).
tolerance - the tolerance for non-zeros
public int nRows()
MatrixDimension
nRows in interface MatrixDimensionpublic int nCols()
MatrixDimension
nCols in interface MatrixDimensionpublic java.lang.String toString()
toString in class java.lang.Objectpublic Matrix opposite()
MatrixRing
opposite in interface AbelianGroup<Matrix>opposite in interface MatrixRing-thispublic 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 | |||||||