public class DOKSparseMatrix extends Object implements SparseMatrix
SparseMatrix.Entry, SparseMatrix.ValueArray
Constructor and Description |
---|
DOKSparseMatrix(DOKSparseMatrix that)
Copy constructor.
|
DOKSparseMatrix(int nRows,
int nCols)
Construct a sparse matrix in DOK format.
|
DOKSparseMatrix(int nRows,
int nCols,
int[] rowIndices,
int[] columnIndices,
double[] value)
Construct a sparse matrix in DOK format.
|
DOKSparseMatrix(int nRows,
int nCols,
List<SparseMatrix.Entry> entries)
Construct a sparse matrix in DOK format by a list of non-zero entries.
|
Modifier and Type | Method and Description |
---|---|
Matrix |
add(Matrix that)
this + that
|
DOKSparseMatrix |
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(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.
|
List<SparseMatrix.Entry> |
getEntryList()
Exports the non-zero values in the matrix as a list of
SparseMatrix.Entry s. |
SparseVector |
getRow(int i)
Get the specified row in the matrix as a vector.
|
SparseMatrix.ValueArray |
getValueArray()
Exports the non-zero values in the matrix as arrays of row/column indices
and values.
|
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()
Gets the number of columns.
|
int |
nNonZeros()
Get the number of non-zero entries in the structure.
|
int |
nRows()
Gets the number of rows.
|
DOKSparseMatrix |
ONE()
Get an identity matrix that has the same dimension as this matrix.
|
DOKSparseMatrix |
opposite()
Get the opposite of this matrix.
|
DOKSparseMatrix |
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.
|
DOKSparseMatrix |
t()
Get the transpose of this matrix.
|
DenseMatrix |
toDense()
Densify a matrix, i.e., convert a matrix implementation to the standard dense matrix,
DenseMatrix . |
String |
toString() |
DOKSparseMatrix |
ZERO()
Get a zero matrix that has the same dimension as this matrix.
|
public DOKSparseMatrix(int nRows, int nCols)
nRows
- the number of rowsnCols
- the number of columnspublic DOKSparseMatrix(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 valuespublic DOKSparseMatrix(int nRows, int nCols, List<SparseMatrix.Entry> entries)
nRows
- the number of rowsnCols
- the number of columnsentries
- the entry listpublic DOKSparseMatrix(DOKSparseMatrix that)
that
- the matrix to be copiedpublic int nRows()
Table
public int nCols()
Table
public List<SparseMatrix.Entry> getEntryList()
SparseMatrix
SparseMatrix.Entry
s. This is useful
for converting between the different formats of SparseMatrix.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());
getEntryList
in interface SparseMatrix
public SparseMatrix.ValueArray getValueArray()
SparseMatrix
getValueArray
in interface SparseMatrix
SparseMatrix.ValueArray
public void set(int row, int col, double value)
MatrixAccess
set
in interface MatrixAccess
row
- the row indexcol
- the column indexvalue
- the value to set A[i,j] topublic double get(int i, int j)
MatrixAccess
get
in interface MatrixAccess
i
- the row indexj
- the column indexpublic SparseVector getRow(int i) throws MatrixAccessException
Matrix
getRow
in interface Matrix
i
- the row indexMatrixAccessException
- when i < 1, or when i > the number of rowspublic SparseVector getColumn(int j) throws MatrixAccessException
Matrix
getColumn
in interface Matrix
j
- the column indexMatrixAccessException
- when j < 1, or when j > the number of columnspublic Matrix add(Matrix that)
MatrixRing
add
in interface MatrixRing
add
in interface AbelianGroup<Matrix>
that
- a matrixthis
and that
public Matrix minus(Matrix that)
MatrixRing
minus
in interface MatrixRing
minus
in interface AbelianGroup<Matrix>
that
- a matrixthis
and that
public Matrix multiply(Matrix that)
MatrixRing
multiply
in interface MatrixRing
multiply
in interface Monoid<Matrix>
that
- a matrixthis
and that
public Vector multiply(Vector v)
Matrix
public DOKSparseMatrix scaled(double c)
Matrix
public DOKSparseMatrix opposite()
MatrixRing
opposite
in interface MatrixRing
opposite
in interface AbelianGroup<Matrix>
public DOKSparseMatrix t()
MatrixRing
t
in interface MatrixRing
public DOKSparseMatrix ZERO()
MatrixRing
ZERO
in interface MatrixRing
ZERO
in interface AbelianGroup<Matrix>
public DOKSparseMatrix ONE()
MatrixRing
ONE
in interface MatrixRing
ONE
in interface Monoid<Matrix>
public DOKSparseMatrix deepCopy()
DeepCopyable
this
by the copy
constructor of the class, or just this
if the instance itself is
immutable.deepCopy
in interface Matrix
deepCopy
in interface DeepCopyable
public DenseMatrix toDense()
Densifiable
DenseMatrix
.toDense
in interface Densifiable
DenseMatrix
public int nNonZeros()
SparseStructure
nNonZeros
in interface SparseStructure
Copyright © 2010-2020 NM FinTech Ltd.. All Rights Reserved.