public class SparseSymmetricMatrix extends AbstractMatrix implements SparseMatrix, Serializable
SparseMatrix
that keeps only the upper
triangular values while providing a symmetric view of the data. This class
only records changes values where row > col. For all other values, the
row and column values are swapped and then the backing matrix is updated.
Note, that if the provided backing matrix has existing values for indices row
< col, these values will be ignored and never returned from any method.
Note the original perfomance characteristics of the backing matrix are
retained by this class.
The primary benfit of this class is for storing large symmetric sparse matrices in half of the memory.
Matrix.Type
Constructor and Description |
---|
SparseSymmetricMatrix(SparseMatrix backing)
Constructs a sparse matrix with the specified dimensions.
|
Modifier and Type | Method and Description |
---|---|
int |
columns()
Returns the number of columns in this
Matrix . |
double |
get(int row,
int column)
Returns the value of the
Matrix at the provided row and column. |
SparseDoubleVector |
getColumnVector(int column)
Returns the column as a vector.
|
SparseDoubleVector |
getRowVector(int row)
Returns a
DoubleVector for an entire row. |
int |
rows()
Returns the number of rows in this
Matrix . |
void |
set(int row,
int column,
double val)
Throws an
UnsupportedOperationException if called (matrix is
unmodifiable). |
equals, getColumn, getRow, hashCode, setColumn, setColumn, setRow, setRow, toDenseArray
public SparseSymmetricMatrix(SparseMatrix backing)
public int columns()
Matrix
.columns
in interface Matrix
columns
in class AbstractMatrix
Matrix
.public double get(int row, int column)
Matrix
at the provided row and column.get
in interface Matrix
get
in class AbstractMatrix
row
- The row values of the cell to return.column
- The column value of the cell to return.row
and col
.public SparseDoubleVector getColumnVector(int column)
SparseVector
instance.getColumnVector
in interface Matrix
getColumnVector
in interface SparseMatrix
getColumnVector
in class AbstractMatrix
column
- The column to return a DoubleVector
for.DoubleVector
representing the column at column
.public SparseDoubleVector getRowVector(int row)
DoubleVector
for an entire row. Implementations should
return an approriately typed DoubleVector. Whether updates to the vector
are written through to the backing matrix is left open to the specific
implementation. Implementations that maintain their data in a sparse
format are encouraged to return a SparseVector
instance.getRowVector
in interface Matrix
getRowVector
in interface SparseMatrix
getRowVector
in class AbstractMatrix
row
- the index of the row to return.DoubleVector
representing the row at row
.public int rows()
Matrix
.rows
in interface Matrix
rows
in class AbstractMatrix
Matrix
.public void set(int row, int column, double val)
UnsupportedOperationException
if called (matrix is
unmodifiable).set
in interface Matrix
set
in class AbstractMatrix
row
- The row of the cell to update.column
- The column of the cell to update.val
- The new value of the specified cell.Copyright © 2012. All Rights Reserved.