public class DenseMatrix extends Object implements Matrix, Densifiable
double based matrix
representation. There are two additional methods to change the matrix
content:
| Modifier | Constructor and Description |
|---|---|
|
DenseMatrix(DenseMatrix A)
Copy constructor performing a deep copy.
|
protected |
DenseMatrix(DenseMatrix A,
boolean copy)
This constructor is useful for subclass to pass in computed value.
|
|
DenseMatrix(double[][] data)
Constructs a matrix from a 2D
double[][] array. |
|
DenseMatrix(double[] data,
int nRows,
int nCols)
Constructs a matrix from a 1D
double[]. |
|
DenseMatrix(int nRows,
int nCols)
Constructs a 0 matrix of dimension nRows * nCols.
|
|
DenseMatrix(Matrix A)
Converts any matrix to the standard matrix representation.
|
|
DenseMatrix(Vector v)
Constructs a column matrix from a vector.
|
| Modifier and Type | Method and Description |
|---|---|
Matrix |
add(Matrix that)
this + that
|
DenseMatrix |
deepCopy()
The implementation returns an instance created from
this by the copy
constructor of the class, or just this if the instance itself is
immutable. |
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 |
getColumn(int j,
int beginRow,
int endRow)
Gets a sub-column of the j-th column, from
beginRow row to
endRow row, inclusively. |
Vector |
getRow(int i)
Get the specified row in the matrix as a vector.
|
Vector |
getRow(int i,
int beginCol,
int endCol)
Gets a sub-row of the i-th row, from
beginCol column to
endCol column, inclusively. |
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.
|
DenseMatrix |
ONE()
Get an identity matrix that has the same dimension as this matrix.
|
Matrix |
opposite()
Get the opposite of this matrix.
|
DenseMatrix |
scaled(double c)
Scale this matrix, A, by a constant.
|
void |
set(int i,
int j,
double value)
Set the matrix entry at [i,j] to a value.
|
void |
setColumn(int j,
Vector v)
Changes the matrix column values to a vector value.
|
void |
setRow(int i,
Vector v)
Changes the matrix row values to a vector value.
|
DenseMatrix |
t()
Get the transpose of this matrix.
|
DenseMatrix |
toDense()
Densify a matrix, i.e., convert a matrix implementation to the standard dense matrix,
DenseMatrix. |
String |
toString() |
DenseMatrix |
ZERO()
Get a zero matrix that has the same dimension as this matrix.
|
public DenseMatrix(int nRows,
int nCols)
nRows - the number of rowsnCols - the number of columnspublic DenseMatrix(double[][] data)
double[][] array.data - a 2D array inputIllegalArgumentException - when data is a jagged arraypublic DenseMatrix(double[] data,
int nRows,
int nCols)
double[]. The array is a
concatenation of the matrix rows. A sample usage is to convert a vector
to a matrix. For example, to construct a column vector, we do
DenseMatrix V = new DenseMatrix(v.toArray(), v.length, 1);
To construct a row vector, we do
DenseMatrix V = new DenseMatrix(v.toArray(), 1, v.length);
data - the 1D array inputnRows - the number or rowsnCols - the number of columnsIllegalArgumentException - when the length of data does not
equal to nRows * nColspublic DenseMatrix(Vector v)
v - a vectorpublic DenseMatrix(Matrix A)
toDense() if A is Densifiable.A - a matrixpublic DenseMatrix(DenseMatrix A)
A - a DenseMatrixprotected DenseMatrix(DenseMatrix A, boolean copy)
A - a DenseMatrixcopy - true if a deep copy of A is neededpublic DenseMatrix deepCopy()
DeepCopyablethis by the copy
constructor of the class, or just this if the instance itself is
immutable.deepCopy in interface MatrixdeepCopy in interface DeepCopyablepublic DenseMatrix toDense()
DensifiableDenseMatrix.toDense in interface DensifiableDenseMatrixpublic int nRows()
Tablepublic int nCols()
Tablepublic void set(int i,
int j,
double value)
throws MatrixAccessException
MatrixAccessset in interface MatrixAccessi - the row indexj - the column indexvalue - the value to set A[i,j] toMatrixAccessException - if i or j is out of rangepublic void setRow(int i,
Vector v)
i - the i-th row to changev - the values to change the row topublic void setColumn(int j,
Vector v)
j - the j-th column to changev - the values to change the column topublic 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)
Matrixpublic Vector getRow(int i, int beginCol, int endCol)
beginCol column to
endCol column, inclusively.i - the row to extractbeginCol - the beginning column of the sub-rowendCol - the ending column of the sub-rowpublic Vector getColumn(int j)
Matrixpublic Vector getColumn(int j, int beginRow, int endRow)
beginRow row to
endRow row, inclusively.j - the column to extractbeginRow - the beginning row of the sub-columnendRow - the ending row of the sub-columnpublic 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 DenseMatrix ZERO()
MatrixRingZERO in interface MatrixRingZERO in interface AbelianGroup<Matrix>public DenseMatrix ONE()
MatrixRingONE in interface MatrixRingONE in interface Monoid<Matrix>public DenseMatrix t()
MatrixRingt in interface MatrixRingpublic Vector multiply(Vector v)
Matrixpublic DenseMatrix scaled(double c)
Matrixpublic Matrix opposite()
MatrixRingopposite in interface MatrixRingopposite in interface AbelianGroup<Matrix>Copyright © 2010-2020 NM FinTech Ltd.. All Rights Reserved.