|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectedu.northwestern.at.utils.math.matrix.AbstractMatrix
public abstract class AbstractMatrix
Abstract class which implements Matrix interface.
Provides concrete implementations of all the Matrix interface methods except two: get and set. All the Matrix interface methods can be written in terms of get anc set. To implement a new concrete matrix subclass all that is needed is to override the get and set methods with concrete versions.
See the DenseMatrix and SparseMatrix
classes of two concrete subclasses derived by extending
AbstractMatrix.
| Field Summary | |
|---|---|
protected int |
columns
Number of columns in matrix. |
protected int |
rows
Number of rows in matrix. |
| Constructor Summary | |
|---|---|
protected |
AbstractMatrix()
Don't allow instantiation without size specification. |
|
AbstractMatrix(int rows,
int columns)
Create a matrix of the specified size. |
| Method Summary | |
|---|---|
int |
columns()
Get number of columns in the matrix. |
double[][] |
get()
Get all matrix elements as a two-dimensional double array. |
abstract double |
get(int row,
int column)
Gets value of element at given row and column. |
Matrix |
getColumn(int column)
Get entire column as a matrix. |
double[] |
getColumnData(int column)
Get entire column as an array of doubles. |
Matrix |
getColumns(int[] columns)
Extract columns. |
Matrix |
getColumns(int firstColumn,
int lastColumn)
Extract columns. |
Matrix |
getCopy()
Get all elements as a new matrix. |
Matrix |
getRow(int row)
Get entire row as a matrix. |
double[] |
getRowData(int row)
Get entire row as an array of doubles . |
Matrix |
getRows(int[] rows)
Extract rows. |
Matrix |
getRows(int firstRow,
int lastRow)
Extract rows. |
Matrix |
getSubMatrix(int[] rows,
int[] columns)
Extract a submatrix. |
Matrix |
getSubMatrix(int[] rows,
int firstColumn,
int lastColumn)
Extract a submatrix. |
Matrix |
getSubMatrix(int firstRow,
int lastRow,
int[] columns)
Extract a submatrix. |
Matrix |
getSubMatrix(int firstRow,
int firstColumn,
int lastRow,
int lastColumn)
Extract a submatrix. |
int |
rows()
Get number of rows in the matrix. |
void |
set(double[][] values)
Set all elements of a matrix from a double array. |
abstract void |
set(int row,
int column,
double value)
Set an element at the given position to a new value. |
void |
set(Matrix matrix)
Set all elements from another matrix. |
void |
setColumn(int column,
Matrix columnMatrix)
Set entire column of values from a column matrix. |
void |
setColumnData(int column,
double[] columnData)
Set entire column from an array of doubles . |
void |
setColumnData(int column,
int[] columnData)
Set entire column from an array of ints . |
void |
setRow(int row,
Matrix rowMatrix)
Set entire row of values from a row matrix. |
void |
setRowData(int row,
double[] rowData)
Set entire row from an array of doubles . |
java.lang.String |
toString()
Return matrix contents as a string. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected int rows
protected int columns
| Constructor Detail |
|---|
protected AbstractMatrix()
public AbstractMatrix(int rows,
int columns)
rows - Number of rows.columns - Number of columns.
A subclass constructor should call this constructor and then create the matrix storage for the specified number of rows and columns.
| Method Detail |
|---|
public int rows()
rows in interface Matrixpublic int columns()
columns in interface Matrix
public abstract void set(int row,
int column,
double value)
set in interface Matrixrow - Row in which the element occurs.column - Column in which the element occurs.value - The new value to be set.
Must be overridden by a subclass.
public void set(Matrix matrix)
throws MatrixMismatchedSizeException
set in interface Matrixmatrix - Matrix whose value to copy to this matrix.
MatrixMismatchedSizeException - If the source matrix and this one don't have
the same number of rows and columns. public Matrix getCopy()
getCopy in interface MatrixEssentially creates a deep clone of the current matrix as another AbstractMatrix .
public void set(double[][] values)
set in interface Matrixvalues - The double[][] from which values should be set.
If there are fewer values entries than the size of the matrix, the other elements are set to zero. If there are more values entries than the size of the matrix, the extra values are ignored.
public abstract double get(int row,
int column)
get in interface Matrixrow - Row in which the element occurs.column - Column in which the element occurs.
Must be overridden by a subclass.
public Matrix getRow(int row)
getRow in interface Matrixrow - Row to retrieve.
public double[] getRowData(int row)
getRowData in interface Matrixrow - Row to retrieve.
public void setRow(int row,
Matrix rowMatrix)
setRow in interface Matrixrow - Row to set.rowMatrix - Matrix containing row data.
If the length of the first row in rowMatrix exceeds the number of columns in this matrix, the extra values are ignored. If rowMatrix's first row is shorter than the number of columns in this matrix, the remaining row elements are set to zero.
public void setRowData(int row,
double[] rowData)
setRowData in interface Matrixrow - Row to set.rowData - Array of doubles containing row data.
If the length of rowData exceeds the number of columns in the matrix, the extra values are ignored. If rowData is shorter than the number of columns in the matrix, the remaining row elements are set to zero.
public Matrix getColumn(int column)
getColumn in interface Matrixcolumn - Column to retrieve.
public double[] getColumnData(int column)
getColumnData in interface Matrixcolumn - Column to retrieve.
public void setColumn(int column,
Matrix columnMatrix)
setColumn in interface Matrixcolumn - Column to set.columnMatrix - Matrix containing column data.
If the length of the first column in columnMatrix exceeds the number of rows in this matrix, the extra values are ignored. If columnMatrix's first column is shorter than the number of rows in this matrix, the remaining column elements are set to zero.
public void setColumnData(int column,
double[] columnData)
setColumnData in interface Matrixcolumn - Column to set.columnData - Array of doubles containing column data.
If the length of columnData exceeds the number of rows in the matrix, the extra values are ignored. If columnData is shorter than the number of rows in this matrix, the remaining column elements are set to zero.
public void setColumnData(int column,
int[] columnData)
setColumnData in interface Matrixcolumn - Column to set.columnData - Array of ints containing column data.
If the length of columnData exceeds the number of rows in the matrix, the extra values are ignored. If columnData is shorter than the number of rows in this matrix, the remaining column elements are set to zero.
public double[][] get()
get in interface Matrix
public Matrix getSubMatrix(int firstRow,
int firstColumn,
int lastRow,
int lastColumn)
getSubMatrix in interface MatrixfirstRow - First row index.firstColumn - First column index.lastRow - Last row index.lastColumn - Last column index.
MatrixMismatchedSizeException - If requested matrix indices are bad.
public Matrix getSubMatrix(int[] rows,
int[] columns)
getSubMatrix in interface Matrixrows - Array of row indices.columns - Array of column indices.
MatrixMismatchedSizeException - If requested matrix indices are bad.
public Matrix getSubMatrix(int firstRow,
int lastRow,
int[] columns)
getSubMatrix in interface MatrixfirstRow - First row index.lastRow - Last row indexcolumns - Array of column indices.
MismatchedSizeException - If requested matrix indices are bad.
public Matrix getSubMatrix(int[] rows,
int firstColumn,
int lastColumn)
getSubMatrix in interface Matrixrows - Array of row indices.firstColumn - First column index.lastColumn - Last column index.
MismatchedSizeException - If requested matrix indices are bad.
public Matrix getColumns(int firstColumn,
int lastColumn)
getColumns in interface MatrixfirstColumn - First column index.lastColumn - Last column index.
MismatchedSizeException - If requested matrix indices are bad. public Matrix getColumns(int[] columns)
getColumns in interface Matrixcolumns - Indices of columns to extract.
MismatchedSizeException - If requested matrix indices are bad.
public Matrix getRows(int firstRow,
int lastRow)
getRows in interface MatrixfirstRow - First row index.lastRow - Last row index.
MismatchedSizeException - If requested matrix indices are bad. public Matrix getRows(int[] rows)
getRows in interface Matrixrows - Indices of rows to extract.
MismatchedSizeException - If requested matrix indices are bad. public java.lang.String toString()
toString in interface MatrixtoString in class java.lang.Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||