|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.numericalmethod.suanshu.matrix.doubles.matrixtype.MatrixMathImpl<T>
com.numericalmethod.suanshu.matrix.doubles.matrixtype.MatrixStorageImpl<DenseMatrix>
com.numericalmethod.suanshu.matrix.doubles.matrixtype.dense.DenseMatrix
public class DenseMatrix
This class implements the standard double dense matrix representation.
| Constructor Summary | |
|---|---|
DenseMatrix(DenseMatrix A)
Copy constructor performing a deep copy. |
|
DenseMatrix(double[][] data)
Construct a matrix from a 2D double[][] array. |
|
DenseMatrix(double[] data,
int nRows,
int nCols)
Construct a matrix from a 1D double[] array. |
|
DenseMatrix(int nRows,
int nCols)
Construct a matrix of dimension nRows * nCols. |
|
DenseMatrix(Matrix A)
Copy constructor performing a deep copy. |
|
DenseMatrix(Vector v)
Construct a column matrix from a vector. |
|
| Method Summary | |
|---|---|
DenseMatrix |
add(DenseMatrix that)
|
DenseMatrix |
deepCopy()
The implementation can return an instance created from this by the copy
constructor of the class, or just this if the instance itself is
immutable. |
Vector |
getColumn(int col)
Get a specified column as a vector. |
Vector |
getColumn(int col,
int beginRow,
int endRow)
Return a sub-column of the col-th column, from beginRow row to endRow row, inclusively. |
protected DenseData |
getMatrixData()
|
Vector |
getRow(int row)
Get a specified row as a vector. |
Vector |
getRow(int row,
int beginCol,
int endCol)
Return a sub-row of the row-th row, from beginCol column to endCol column, inclusively. |
protected DenseMatrix |
getSample()
|
DenseMatrix |
minus(DenseMatrix that)
|
DenseMatrix |
multiply(DenseMatrix that)
|
Vector |
multiply(Vector v)
Compute A %*% v, where v is a vector. |
DenseMatrix |
ONE()
Get an identity matrix that has the same dimension as this matrix. |
protected void |
overwrite(Matrix A)
This method is provided so that extended classes can overwrite itself efficiently. |
DenseMatrix |
scaled(double scalar)
scalar * this |
DenseMatrix |
t()
t(this)
Compute the transpose of this matrix. |
DenseMatrix |
toDense()
Densify a matrix, i.e., convert a matrix implementation to a standard dense matrix, DenseMatrix. |
DenseMatrix |
ZERO()
The additive element 0 in the group, such that for all elements a in the group,
the equation 0 + a = a + 0 = a holds. |
| Methods inherited from class com.numericalmethod.suanshu.matrix.doubles.matrixtype.MatrixStorageImpl |
|---|
equals, get, hashCode, set, setMatrixData |
| Methods inherited from class com.numericalmethod.suanshu.matrix.doubles.matrixtype.MatrixMathImpl |
|---|
add, call, minus, multiply, nCols, nRows, opposite, setColumn, setColumn, setRow, setRow, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public DenseMatrix(int nRows,
int nCols)
nRows * nCols.
Space for the matrix data is not yet allocated.
nRows - number of rowsnCols - number of columnspublic DenseMatrix(double[][] data)
data - the 2D array input
java.lang.IllegalArgumentException - when data is a jagged array
public DenseMatrix(double[] data,
int nRows,
int nCols)
This can be used to convert a vector to a matrix.
E.g., to form a column vector, we do
DenseMatrix V = new DenseMatrix(v.toArray(), v.length, 1)
E.g., to form a row vector, we do
DenseMatrix V = new DenseMatrix(v.toArray(), 1, v.length)
data - the 1D array inputnRows - number or rowsnCols - number of columns
java.lang.IllegalArgumentException - when the length of data is not equal to nRows * nColspublic DenseMatrix(Vector v)
v - a vector
java.lang.IllegalArgumentException - when row < 1, or when row > number of rowspublic DenseMatrix(Matrix A)
This method is in general very inefficient especially for large sparse matrices.
Use toDense() whenever available.
A - a matrixpublic DenseMatrix(DenseMatrix A)
A - a DenseMatrix| Method Detail |
|---|
protected DenseData getMatrixData()
getMatrixData in class MatrixStorageImpl<DenseMatrix>protected void overwrite(Matrix A)
MatrixStorageImpl.set(int, int, double) repeatedly.
A - a matrixpublic DenseMatrix deepCopy()
Matrixthis by the copy
constructor of the class, or just this if the instance itself is
immutable.
Override the return type.
deepCopy in interface DeepCopyabledeepCopy in interface MatrixMatrix instancepublic DenseMatrix toDense()
DensifiableDenseMatrix.
This is equivalent to
new DenseMatrix(Matrix A)
Individual matrix implementation may optimize the conversion
by taking advantage of having access to the class' private members.
In other words, toDense() is in general more efficient than explicit copy construction.
As an example, for some long matrix computations, we may not be sure about the return type. We can always cast it to the standard matrix. That is,
DenseMatrix A = B.multiply(C).add(D).minus(E).toDense();
This statement always works regardless of the types of B, C, D, and E.
toDense in interface DensifiableDenseMatrixprotected DenseMatrix getSample()
getSample in class MatrixMathImpl<DenseMatrix>public Vector getRow(int row)
MatrixAccessor
getRow in interface MatrixAccessorgetRow in class MatrixMathImpl<DenseMatrix>row - the row index
A[row, ]
public Vector getRow(int row,
int beginCol,
int endCol)
row-th row, from beginCol column to endCol column, inclusively.
row - the row to extractbeginCol - the beginning column of the sub-rowendCol - the ending column of the sub-row
public Vector getColumn(int col)
MatrixAccessor
getColumn in interface MatrixAccessorgetColumn in class MatrixMathImpl<DenseMatrix>col - the column index
A[, col]
public Vector getColumn(int col,
int beginRow,
int endRow)
col-th column, from beginRow row to endRow row, inclusively.
col - the column to extractbeginRow - the beginning row of the sub-columnendRow - the ending row of the sub-column
public DenseMatrix add(DenseMatrix that)
public DenseMatrix minus(DenseMatrix that)
public DenseMatrix multiply(DenseMatrix that)
public DenseMatrix ZERO()
AbelianGroupa in the group,
the equation 0 + a = a + 0 = a holds.
ZERO in interface AbelianGroup<Matrix>ZERO in interface MatrixRing0public DenseMatrix ONE()
MatrixRingFor a non-square matrix, it zeros out the rows (columns) with index > nCols (nRows).
ONE in interface Monoid<Matrix>ONE in interface MatrixRingpublic DenseMatrix t()
MatrixRingt(this)
Compute the transpose of this matrix. The original matrix does not change. The returned value is independent and can be modified anyhow.
This is the involution on the matrix ring.
t in interface MatrixRingt in class MatrixMathImpl<DenseMatrix>public Vector multiply(Vector v)
A %*% v, where v is a vector.
multiply in interface Matrixmultiply in class MatrixMathImpl<DenseMatrix>v - a vector
A %*% vpublic DenseMatrix scaled(double scalar)
Matrixscalar * this
scaled in interface Matrixscaled in class MatrixMathImpl<DenseMatrix>scalar - a double
scalar * this
|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||