public class RowMaskedMatrix extends Object implements Matrix
Matrix
instance where selected rows of the instance
a represented as a single, contiguous matrix. This effectively creates a
Matrix
out of a possibly non-contiguous selection of the rows of the
original. This class is intended to be use when a large matrix has been
created and submatrices of the large matrix need to be treated as full Matrix
instances; rather than copy the data, this class provides a way of
representing the original data as a partial view.
All methods are write-through to the original backing matrix.
This matrix recomputes the mapping if the Matrix
being masked is also
a RowMaskedMatrix
, thus preventing a recursive call to row lookups.Matrix.Type
Constructor and Description |
---|
RowMaskedMatrix(Matrix matrix,
BitSet included)
Creates a partial view of the provided matrix using the bits set to
true as the rows that should be included |
RowMaskedMatrix(Matrix matrix,
int[] reordering)
Creates a partial view of the provided matrix using the integers in the
array of indices.
|
RowMaskedMatrix(Matrix matrix,
LinkedHashSet<Integer> included)
Creates a partial view of the provided matrix using the integers in the
ordered set.
|
RowMaskedMatrix(Matrix matrix,
Set<Integer> included)
Creates a partial view of the provided matrix using the integers in the
set to specify which rows should be included in the matrix.
|
Modifier and Type | Method and Description |
---|---|
Matrix |
backingMatrix()
Returns the
backingMatrix that is being masked. |
int |
columns()
Returns the number of columns in this
Matrix . |
double |
get(int row,
int col)
Returns the value of the
Matrix at the provided row and column. |
double[] |
getColumn(int column)
Returns the entire column.
|
DoubleVector |
getColumnVector(int column)
Returns the column as a vector.
|
protected int |
getRealRow(int virtualRow)
Returns the row in the backing matrix that the
virtualRow value
is mapped to in the row-masked matrix. |
double[] |
getRow(int row)
Returns the entire row.
|
DoubleVector |
getRowVector(int row)
Returns a
DoubleVector for an entire row. |
int[] |
reordering()
Returns the mapping from indices in this
RowMaskedMatrix to the
real indices in the backingMatrix . |
int |
rows()
Returns the number of rows in this
Matrix . |
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[] columns)
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 . |
double[][] |
toDenseArray()
Converts the
Matrix to a two dimensional array. |
public RowMaskedMatrix(Matrix matrix, BitSet included)
true
as the rows that should be includedIllegalArgumentException
- if included
has a bit set whose
index is greater than the number of rows present in matrix
public RowMaskedMatrix(Matrix matrix, Set<Integer> included)
IllegalArgumentException
- if included
specifies a value
that is less than 0 or greater than the number of rows present in
matrix
public RowMaskedMatrix(Matrix matrix, LinkedHashSet<Integer> included)
IllegalArgumentException
- if included
specifies a value
that is less than 0 or greater than the number of rows present in
matrix
public RowMaskedMatrix(Matrix matrix, int[] reordering)
IllegalArgumentException
- if included
specifies a value
that is less than 0 or greater than the number of rows present in
matrix
protected int getRealRow(int virtualRow)
virtualRow
value
is mapped to in the row-masked matrix.public double get(int row, int col)
Matrix
at the provided row and column.public double[] getColumn(int column)
public DoubleVector getColumnVector(int column)
SparseVector
instance.getColumnVector
in interface Matrix
column
- The column to return a DoubleVector
for.DoubleVector
representing the column at column
.public double[] getRow(int row)
public DoubleVector 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
row
- the index of the row to return.DoubleVector
representing the row at row
.public int columns()
Matrix
.public double[][] toDenseArray()
Matrix
to a two dimensional array. Note that for
large matrices, this may exhaust all available memory.toDenseArray
in interface Matrix
Matrix
.public int rows()
Matrix
.public void set(int row, int col, double val)
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.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.public void setRow(int row, double[] columns)
Matrix
using the provided
array. Note that the array itself is not made internal to the instance
itself.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.public Matrix backingMatrix()
backingMatrix
that is being masked.public int[] reordering()
RowMaskedMatrix
to the
real indices in the backingMatrix
.Copyright © 2012. All Rights Reserved.