public class CellMaskedMatrix extends Object implements Matrix
Matrix
decorator allows every row and column index to be
remapped to new indices. The size of this matrix will depend on the number
of mapped rows and columns. Write-through access is allowed for each cell in
the underlying matrix through the set
method. Array based accessors
and getters are disabled when using this decorator.Matrix.Type
Modifier and Type | Field and Description |
---|---|
protected int[] |
colMaskMap
The mapping for columns from new indices to old indices.
|
protected int[] |
rowMaskMap
The mapping for rows from new indices to old indices.
|
Constructor and Description |
---|
CellMaskedMatrix(Matrix matrix,
int[] rowMaskMap,
int[] colMaskMap)
Creates a new
CellMaskedMatrix from a given Matrix and
maps, one for the row indices and one for the column indices. |
Modifier and Type | Method and Description |
---|---|
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 |
getIndexFromMap(int[] maskMap,
int index)
Returns the new index value for a given index from a given mapping.
|
double[] |
getRow(int row)
Returns the entire row.
|
DoubleVector |
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 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. |
protected final int[] rowMaskMap
protected final int[] colMaskMap
public CellMaskedMatrix(Matrix matrix, int[] rowMaskMap, int[] colMaskMap)
CellMaskedMatrix
from a given Matrix
and
maps, one for the row indices and one for the column indices. Only valid
mappings should be included.matrix
- The underlying matrix to decoraterowMaskMap
- A mapping from new indices to old indices in the
original map for rows.colMaskMap
- A mapping from new indices to old indices in the
original map for columns.protected int getIndexFromMap(int[] maskMap, int index)
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.Copyright © 2012. All Rights Reserved.