Class ImmutableMatrix
java.lang.Object
dev.nm.algebra.linear.matrix.doubles.ImmutableMatrix
- All Implemented Interfaces:
Matrix
,MatrixAccess
,MatrixRing
,MatrixTable
,AbelianGroup<Matrix>
,Monoid<Matrix>
,Ring<Matrix>
,Table
,DeepCopyable
This is a read-only view of a
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 Summary
ConstructorsConstructorDescriptionfor serializationConstruct a read-only version of a matrix. -
Method Summary
Modifier and TypeMethodDescriptionthis + thatdeepCopy()
Make a deep copy of the underlying matrix.boolean
double
get
(int i, int j) Get the matrix entry at [i,j].getColumn
(int j) Get the specified column in the matrix as a vector.getRow
(int i) Get the specified row in the matrix as a vector.int
hashCode()
this - thatthis * thatRight multiply this matrix, A, by a vector.int
nCols()
Gets the number of columns.int
nRows()
Gets the number of rows.ONE()
Get an identity matrix that has the same dimension as this matrix.opposite()
Get the opposite of this 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.t()
Get the transpose of this matrix.toString()
ZERO()
Get a zero matrix that has the same dimension as this matrix.
-
Constructor Details
-
ImmutableMatrix
public ImmutableMatrix()for serialization -
ImmutableMatrix
Construct a read-only version of a matrix. Note that changing the original matrix changes the "immutable" version as well.- Parameters:
A
- a matrix
-
-
Method Details
-
set
Description copied from interface:MatrixAccess
Set the matrix entry at [i,j] to a value. This is the only method that may change a matrix.- Specified by:
set
in interfaceMatrixAccess
- Parameters:
row
- the row indexcol
- the column indexvalue
- the value to set A[i,j] to- Throws:
MatrixAccessException
- if i or j is out of range
-
nRows
public int nRows()Description copied from interface:Table
Gets the number of rows. Rows count from 1. -
nCols
public int nCols()Description copied from interface:Table
Gets the number of columns. Columns count from 1. -
get
Description copied from interface:MatrixAccess
Get the matrix entry at [i,j].- Specified by:
get
in interfaceMatrixAccess
- Parameters:
i
- the row indexj
- the column index- Returns:
- A[i,j]
- Throws:
MatrixAccessException
- if i or j is out of range
-
getRow
Description copied from interface:Matrix
Get the specified row in the matrix as a vector.- Specified by:
getRow
in interfaceMatrix
- Parameters:
i
- the row index- Returns:
- the vector A[i, ]
- Throws:
MatrixAccessException
- when i < 1, or when i > the number of rows
-
getColumn
Description copied from interface:Matrix
Get the specified column in the matrix as a vector.- Specified by:
getColumn
in interfaceMatrix
- Parameters:
j
- the column index- Returns:
- a vector A[, j]
- Throws:
MatrixAccessException
- when j < 1, or when j > the number of columns
-
add
Description copied from interface:MatrixRing
this + that- Specified by:
add
in interfaceAbelianGroup<Matrix>
- Specified by:
add
in interfaceMatrixRing
- Parameters:
that
- a matrix- Returns:
- the sum of
this
andthat
-
minus
Description copied from interface:MatrixRing
this - that- Specified by:
minus
in interfaceAbelianGroup<Matrix>
- Specified by:
minus
in interfaceMatrixRing
- Parameters:
that
- a matrix- Returns:
- the difference between
this
andthat
-
multiply
Description copied from interface:MatrixRing
this * that- Specified by:
multiply
in interfaceMatrixRing
- Specified by:
multiply
in interfaceMonoid<Matrix>
- Parameters:
that
- a matrix- Returns:
- the product of
this
andthat
-
multiply
Description copied from interface:Matrix
Right multiply this matrix, A, by a vector. -
scaled
Description copied from interface:Matrix
Scale this matrix, A, by a constant. -
opposite
Description copied from interface:MatrixRing
Get the opposite of this matrix.- Specified by:
opposite
in interfaceAbelianGroup<Matrix>
- Specified by:
opposite
in interfaceMatrixRing
- Returns:
- -this
- See Also:
-
ZERO
Description copied from interface:MatrixRing
Get a zero matrix that has the same dimension as this matrix.- Specified by:
ZERO
in interfaceAbelianGroup<Matrix>
- Specified by:
ZERO
in interfaceMatrixRing
- Returns:
- the 0 matrix
-
ONE
Description copied from interface:MatrixRing
Get an identity matrix that has the same dimension as this matrix. For a non-square matrix, it zeros out the rows (columns) with index > nCols (nRows).- Specified by:
ONE
in interfaceMatrixRing
- Specified by:
ONE
in interfaceMonoid<Matrix>
- Returns:
- an identity matrix
-
t
Description copied from interface:MatrixRing
Get the transpose of this matrix. This is the involution on the matrix ring.- Specified by:
t
in interfaceMatrixRing
- Returns:
- the transpose of this matrix
-
deepCopy
Make a deep copy of the underlying matrix. The copy is no longer anImmutableMatrix
and may be mutable.- Specified by:
deepCopy
in interfaceDeepCopyable
- Specified by:
deepCopy
in interfaceMatrix
- Returns:
- a deep copy of the underlying matrix
-
toString
-
equals
-
hashCode
public int hashCode()
-