public class SparseOnDiskMatrix extends OnDiskMatrix implements SparseMatrix
SparseMatrix
implementation that uses a binary file to read and
write. The matrix is still stored in a dense row-column order on disk, so
in-order column accesses to elments in a row will perform much better than
sequential row accesses to the same column. However calls to getRowVector
and getColumnVector
will return SparseVector
instances. This class is
intended for large matrices that need to be on disk due to their dimensions,
but whose data is mostly sparse
The DoubleVector
representations returned reflect a snapshot of the state
of the matrix at the time of access. Subsequent updates to the matrix will
not be reflected in these vectors, nor will changes to the vector be
propagated to the matrix.
If a IOException
is ever raised as a part of executing an the methods
of an instance, the exception is rethrown as a IOError
.
Matrix.Type
Constructor and Description |
---|
SparseOnDiskMatrix(int rows,
int cols)
Create a matrix of the provided size using a temporary file.
|
Modifier and Type | Method and Description |
---|---|
SparseDoubleVector |
getColumnVector(int column)
Returns the column as a vector.
|
SparseDoubleVector |
getRowVector(int row)
Returns a
DoubleVector for an entire row. |
void |
set(int row,
int col,
double val)
Sets the location at the row and column to the provided value.
|
void |
setColumn(int column,
double[] values)
Sets the values for the column of this
Matrix using the provided
array. |
void |
setColumn(int column,
DoubleVector values)
Sets the values for the column of this
Matrix using the provided
DoubleVector . |
void |
setRow(int row,
double[] vals)
Sets the values for the row of this
Matrix using the provided
array. |
void |
setRow(int row,
DoubleVector values)
Sets the values for the row of this
Matrix using the provided
DoubleVector . |
columns, finalize, get, getColumn, getRow, rows, toDenseArray
public SparseOnDiskMatrix(int rows, int cols)
IOError
- if the backing file for this matrix cannot be createdpublic SparseDoubleVector getColumnVector(int column)
SparseVector
instance.getColumnVector
in interface Matrix
getColumnVector
in interface SparseMatrix
getColumnVector
in class OnDiskMatrix
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 OnDiskMatrix
row
- the index of the row to return.DoubleVector
representing the row at row
.public void set(int row, int col, double val)
set
in interface Matrix
set
in class OnDiskMatrix
row
- The row of the cell to update.col
- The column of the cell to update.val
- The new value of the specified cell.public void setColumn(int column, double[] values)
Matrix
using the provided
array. Note that the array itself is not made internal to the instance
itself.setColumn
in interface Matrix
setColumn
in class OnDiskMatrix
column
- The column to update.values
- The values to update into column
.public void setColumn(int column, DoubleVector values)
Matrix
using the provided
DoubleVector
. Note that the DoubleVector
itself is not
made internal to the instance itself.setColumn
in interface Matrix
setColumn
in class OnDiskMatrix
column
- The column to update.values
- The values to update into column
.public void setRow(int row, double[] vals)
Matrix
using the provided
array. Note that the array itself is not made internal to the instance
itself.setRow
in interface Matrix
setRow
in class OnDiskMatrix
row
- The row to update.vals
- The values to update into row
.public void setRow(int row, DoubleVector values)
Matrix
using the provided
DoubleVector
. Note that the DoubleVector
itself is not
made internal to the instance itself.setRow
in interface Matrix
setRow
in class OnDiskMatrix
row
- The row to update.values
- The values to update into row
.Copyright © 2012. All Rights Reserved.