public class ImmutableMatrix extends Object implements Matrix
Matrix instance.
It keeps a reference to the matrix instance,
delegates all operations to the instance except for set(int, int, double) which
will always result in an MatrixAccessException.
Note that the returned values of all operations (e.g., add()) have the same types as the
original matrix.
Popular usages of this class include, e.g., the final member of a class, the return value
of a method.
Note that the 'immutability' can be broken if the original matrix is modified.
To avoid this, make a copy of the original matrix before passing it to the constructor. For
example,
ImmutableMatrix immutable = new ImmutableMatrix(m.deepCopy());
| Constructor and Description |
|---|
ImmutableMatrix(Matrix A)
Construct a read-only version of a matrix.
|
| Modifier and Type | Method and Description |
|---|---|
Matrix |
add(Matrix that)
this + that
|
Matrix |
deepCopy()
Make a deep copy of the underlying matrix.
|
boolean |
equals(Object obj) |
double |
get(int i,
int j)
Get the matrix entry at [i,j].
|
Vector |
getColumn(int j)
Get the specified column in the matrix as a vector.
|
Vector |
getRow(int i)
Get the specified row in the matrix as a vector.
|
int |
hashCode() |
Matrix |
minus(Matrix that)
this - that
|
Matrix |
multiply(Matrix that)
this * that
|
Vector |
multiply(Vector v)
Right multiply this matrix, A, by a vector.
|
int |
nCols()
Gets the number of columns.
|
int |
nRows()
Gets the number of rows.
|
Matrix |
ONE()
Get an identity matrix that has the same dimension as this matrix.
|
Matrix |
opposite()
Get the opposite of this matrix.
|
Matrix |
scaled(double c)
Scale this matrix, A, by a constant.
|
void |
set(int row,
int col,
double value)
Set the matrix entry at [i,j] to a value.
|
Matrix |
t()
Get the transpose of this matrix.
|
String |
toString() |
Matrix |
ZERO()
Get a zero matrix that has the same dimension as this matrix.
|
public ImmutableMatrix(Matrix A)
A - a matrixpublic void set(int row,
int col,
double value)
throws MatrixAccessException
MatrixAccessset in interface MatrixAccessrow - the row indexcol - the column indexvalue - the value to set A[i,j] toMatrixAccessException - if i or j is out of rangepublic int nRows()
Tablepublic int nCols()
Tablepublic double get(int i,
int j)
throws MatrixAccessException
MatrixAccessget in interface MatrixAccessi - the row indexj - the column indexMatrixAccessException - if i or j is out of rangepublic Vector getRow(int i) throws MatrixAccessException
MatrixgetRow in interface Matrixi - the row indexMatrixAccessException - when i < 1, or when i > the number of rowspublic Vector getColumn(int j) throws MatrixAccessException
MatrixgetColumn in interface Matrixj - the column indexMatrixAccessException - when j < 1, or when j > the number of columnspublic Matrix add(Matrix that)
MatrixRingadd in interface MatrixRingadd in interface AbelianGroup<Matrix>that - a matrixthis and thatpublic Matrix minus(Matrix that)
MatrixRingminus in interface MatrixRingminus in interface AbelianGroup<Matrix>that - a matrixthis and thatpublic Matrix multiply(Matrix that)
MatrixRingmultiply in interface MatrixRingmultiply in interface Monoid<Matrix>that - a matrixthis and thatpublic Vector multiply(Vector v)
Matrixpublic Matrix scaled(double c)
Matrixpublic Matrix opposite()
MatrixRingopposite in interface MatrixRingopposite in interface AbelianGroup<Matrix>public Matrix ZERO()
MatrixRingZERO in interface MatrixRingZERO in interface AbelianGroup<Matrix>public Matrix ONE()
MatrixRingONE in interface MatrixRingONE in interface Monoid<Matrix>public Matrix t()
MatrixRingt in interface MatrixRingpublic Matrix deepCopy()
ImmutableMatrix and may be mutable.deepCopy in interface MatrixdeepCopy in interface DeepCopyableCopyright © 2010-2020 NM FinTech Ltd.. All Rights Reserved.