public abstract class AbstractMatrix extends Object implements Matrix
Matrix class that provides common implementations for
generic matrix operations. This class assumes that all subclasses are
row-based and will therefore call getRowVector for
all operations. At a minimum subclasses must define the following three
operations to be an immutable matrix:
To support modification, implementations need only define
Matrix.Type| Constructor and Description |
|---|
AbstractMatrix() |
| Modifier and Type | Method and Description |
|---|---|
abstract int |
columns()
Returns the number of columns in this
Matrix. |
boolean |
equals(Object o)
Returns
if the object is a Matrix with the same
dimensions as whose values are equivalent. |
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.
|
double[] |
getRow(int row)
Returns the entire row.
|
abstract DoubleVector |
getRowVector(int row)
Returns a
DoubleVector for an entire row. |
int |
hashCode()
Returns the sum of all rows hash codes.
|
abstract int |
rows()
Returns the number of rows in this
Matrix. |
void |
set(int row,
int col,
double val)
Throws an
UnsupportedOperationException if called (matrix is
unmodifiable). |
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 abstract int columns()
Matrix.public boolean equals(Object o)
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 Matrixcolumn - The column to return a DoubleVector for.DoubleVector representing the column at column.public double[] getRow(int row)
public abstract 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 Matrixrow - the index of the row to return.DoubleVector representing the row at row.public int hashCode()
public abstract int rows()
Matrix.public void set(int row,
int col,
double val)
UnsupportedOperationException if called (matrix is
unmodifiable).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 Matrixcolumn - The column to update.values - The values to update into column.IllegalArgumentException - if the length of values is not
equal to the number of rowspublic 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 Matrixcolumn - The column to update.values - The values to update into column.IllegalArgumentException - if the length of values is not
equal to the number of rowspublic void setRow(int row,
double[] columns)
Matrix using the provided
array. Note that the array itself is not made internal to the instance
itself.setRow in interface Matrixrow - The row to update.columns - The values to update into row.IllegalArgumentException - if the length of columns is not
equal to the number of columnspublic 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 Matrixrow - The row to update.values - The values to update into row.IllegalArgumentException - if the length of columns is not
equal to the number of columnspublic double[][] toDenseArray()
Matrix to a two dimensional array. Note that for
large matrices, this may exhaust all available memory.toDenseArray in interface MatrixMatrix.Copyright © 2012. All Rights Reserved.