public interface Matrix
Matrix represents a 2-dimensional matrix.
Matrices provide a fixed number of rows and columns, with values
for each row and column.
An optional operation setValue(int,int,double) allows
values to be set.
Two matrices should be equal if they have the same number of
rows and columns and every value is equal. Their hash codes should
be defined as specified in the documentation for hashCode().
| Modifier and Type | Method and Description |
|---|---|
Vector |
columnVector(int column)
Returns the vector of values in the specified column.
|
boolean |
equals(Object that)
Returns
true if the specified object is a matrix
with the same number of rows and columns and the same value in
every cell as this matrix. |
int |
hashCode()
Return the hash code for the matrix.
|
int |
numColumns()
Returns the number of columns in the matrix.
|
int |
numRows()
Returns the number of rows in the matrix.
|
Vector |
rowVector(int row)
Returns the vector of values in the specified row.
|
void |
setValue(int row,
int column,
double value)
Sets the value for the specified row and column to be
the specified value.
|
double |
value(int row,
int column)
Returns the value in the matrix at the specified row and
column.
|
int numRows()
int numColumns()
double value(int row,
int column)
row - The specified row.column - The specified column.IndexOutOfBoundsException - If the row or column index
are out of bounds for this matrix.void setValue(int row,
int column,
double value)
This operation is optional. Implementations may throw unsupported operation exceptions.
row - Specified row.column - Specified column.value - New value for specified row and column.UnsupportedOperationException - If this operation is not
supported.IndexOutOfBoundsException - If the row or column index
are out of bounds for this matrix.Vector rowVector(int row)
Changes to the returned vector will affect this matrix and vice-versa. To circumvent this dependency, clone the result.
row - Index of row whose vector is returned.IndexOutOfBoundsException - If the row index is
out of bounds for this matrix.Vector columnVector(int column)
Changes to the returned vector will affect this matrix and vice-versa. To circumvent this dependency, clone the result.
column - Index of column whose vector is returned.IndexOutOfBoundsException - If the column index is
out of bounds for this matrix.boolean equals(Object that)
true if the specified object is a matrix
with the same number of rows and columns and the same value in
every cell as this matrix.int hashCode()
java.util.List of java.lang.Double values
ordered row by row:
int hashCode = 1;
for (int i = 0; i < numRows(); ++i) {
for (int j = 0; j < numColumns(); ++j) {
int v = Double.doubleToLongBits(value(i,j));
int valHash = (int) (v^(v>>>32));
hashCode = 31*hashCode + valHash;
}
}
Note that this definition is consistent with equals(Object).Copyright © 2019 Alias-i, Inc.. All rights reserved.