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 DenseMatrix
protected DenseMatrix(DenseMatrix A, boolean copy)
A
- a DenseMatrix
copy
- true
if a deep copy of A
is neededpublic DenseMatrix deepCopy()
DeepCopyable
this
by the copy
constructor of the class, or just this
if the instance itself is
immutable.deepCopy
in interface Matrix
deepCopy
in interface DeepCopyable
public DenseMatrix toDense()
Densifiable
DenseMatrix
.toDense
in interface Densifiable
DenseMatrix
public int nRows()
Table
public int nCols()
Table
public void set(int i, int j, double value) throws MatrixAccessException
MatrixAccess
set
in interface MatrixAccess
i
- 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
MatrixAccess
get
in interface MatrixAccess
i
- the row indexj
- the column indexMatrixAccessException
- if i or j is out of rangepublic Vector getRow(int i)
Matrix
public 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)
Matrix
public 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)
MatrixRing
add
in interface MatrixRing
add
in interface AbelianGroup<Matrix>
that
- a matrixthis
and that
public Matrix minus(Matrix that)
MatrixRing
minus
in interface MatrixRing
minus
in interface AbelianGroup<Matrix>
that
- a matrixthis
and that
public Matrix multiply(Matrix that)
MatrixRing
multiply
in interface MatrixRing
multiply
in interface Monoid<Matrix>
that
- a matrixthis
and that
public DenseMatrix ZERO()
MatrixRing
ZERO
in interface MatrixRing
ZERO
in interface AbelianGroup<Matrix>
public DenseMatrix ONE()
MatrixRing
ONE
in interface MatrixRing
ONE
in interface Monoid<Matrix>
public DenseMatrix t()
MatrixRing
t
in interface MatrixRing
public Vector multiply(Vector v)
Matrix
public DenseMatrix scaled(double c)
Matrix
public Matrix opposite()
MatrixRing
opposite
in interface MatrixRing
opposite
in interface AbelianGroup<Matrix>
Copyright © 2010-2020 NM FinTech Ltd.. All Rights Reserved.