public class DiagonalMatrix extends Object implements SparseMatrix
Matrix
implementation for diagonal matrices. This
class provides a memory efficient representation and additional bounds
checking to ensure non-diagonal elements cannot be set.Matrix.Type
Constructor and Description |
---|
DiagonalMatrix(double[] newValues)
Creates a new
DiagonalMatrix with newValues as the
diagonal values. |
DiagonalMatrix(int numValues)
Creates a new
DiagonalMatrix with numValues rows and
columns. |
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.
|
SparseDoubleVector |
getColumnVector(int column)
Returns the column as a sparse vector.
|
double[] |
getRow(int row)
Returns the entire row.
|
SparseDoubleVector |
getRowVector(int row)
Returns the row as a sparse vector.
|
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 vector)
Sets the values for the column of this
Matrix using the provided
DoubleVector . |
void |
setRow(int row,
double[] values)
Sets the values for the row of this
Matrix using the provided
array. |
void |
setRow(int row,
DoubleVector vector)
Sets the values for the row of this
Matrix using the provided
DoubleVector . |
double[][] |
toDenseArray()
Converts the
Matrix to a two dimensional array. |
public DiagonalMatrix(int numValues)
DiagonalMatrix
with numValues
rows and
columns.numValues
- The number of rows, columns, and diagonals in this
DiagonalMatrix
.public DiagonalMatrix(double[] newValues)
DiagonalMatrix
with newValues
as the
diagonal values.newValues
- The values to use as the diagonals of this Matrix
.public double get(int row, int col)
Matrix
at the provided row and column.public double[] getColumn(int column)
public SparseDoubleVector getColumnVector(int column)
getColumnVector
in interface Matrix
getColumnVector
in interface SparseMatrix
column
- The column to return a DoubleVector
forDoubleVector
representing the column at column
public double[] getRow(int row)
public SparseDoubleVector getRowVector(int row)
getRowVector
in interface Matrix
getRowVector
in interface SparseMatrix
row
- the index of row to returnSparseDoubleVector
of the row's datapublic int columns()
Matrix
.public void set(int row, int col, double val)
set
in interface Matrix
row
- The row of the cell to update.col
- The column of the cell to update.val
- The new value of the specified cell.IllegalArgumentException
- if row != col
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.
Note that any values are not on the diagonal are ignored.public void setColumn(int column, DoubleVector vector)
Matrix
using the provided
DoubleVector
. Note that the DoubleVector
itself is not
made internal to the instance itself.
Note that any values are not on the diagonal are ignored.public void setRow(int row, double[] values)
Matrix
using the provided
array. Note that the array itself is not made internal to the instance
itself.
Note that any values are not on the diagonal are ignored.public void setRow(int row, DoubleVector vector)
Matrix
using the provided
DoubleVector
. Note that the DoubleVector
itself is not
made internal to the instance itself.
Note that any values are not on the diagonal are ignored.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
.Copyright © 2012. All Rights Reserved.