|
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<T>
com.numericalmethod.suanshu.matrix.doubles.matrixtype.dense.diagonal.DiagonalMatrix
public class DiagonalMatrix
This class represents a matrix with non-zero entries only on the main diagonal.
| Constructor Summary | |
|---|---|
DiagonalMatrix(DiagonalMatrix that)
Copy constructor. |
|
DiagonalMatrix(double[] data)
Construct a diagonal matrix from a double[] array. |
|
DiagonalMatrix(int dim)
Construct a diagonal matrix of dimension dim * dim. |
|
| Method Summary | |
|---|---|
DiagonalMatrix |
add(DiagonalMatrix that)
this + that
Add with a DiagonalMatrix. |
DiagonalMatrix |
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. |
DenseVector |
diagonal()
Get a copy of the diagonal of the matrix. |
boolean |
equals(java.lang.Object obj)
Check if two matrices (of different implementations) are equal. |
DenseVector |
getColumn(int col)
Get a specified column as a vector. |
DenseVector |
getRow(int row)
Get a specified row as a vector. |
int |
hashCode()
|
DiagonalMatrix |
minus(DiagonalMatrix that)
this - that
Subtract a DiagonalMatrix. |
DiagonalMatrix |
multiply(DiagonalMatrix that)
this %*% that
Multiply by a DiagonalMatrix. |
Vector |
multiply(Vector v)
Right multiply this matrix, A by a vector. |
DiagonalMatrix |
ONE()
Get an identity matrix that has the same dimension as this matrix. |
DiagonalMatrix |
scaled(double scalar)
scalar * this |
DenseVector |
subDiagonal()
Get a copy of the sub-diagonal of the matrix. |
DenseVector |
superDiagonal()
Get a copy of the super-diagonal of the matrix. |
DiagonalMatrix |
t()
The transpose of a diagonal matrix is the same as itself. |
DenseMatrix |
toDense()
Densify a matrix, i.e., convert a matrix implementation to a standard dense matrix, DenseMatrix. |
java.lang.String |
toString()
|
DiagonalMatrix |
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 |
|---|
get, getMatrixData, set, setMatrixData |
| Methods inherited from class com.numericalmethod.suanshu.matrix.doubles.matrixtype.MatrixMathImpl |
|---|
add, call, getSample, minus, multiply, nCols, nRows, opposite, setColumn, setColumn, setRow, setRow |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public DiagonalMatrix(double[] data)
For example,
new double[][]{
{1, 2, 3, 4, 5},
}
is
| 1 0 0 0 0 |
| 0 2 0 0 0 |
| 0 0 3 0 0 |
| 0 0 0 4 0 |
| 0 0 0 0 5 |
data - the 1D array inputpublic DiagonalMatrix(int dim)
dim * dim.
dim - dimension; for a square matrix, it is the number of rows or columnspublic DiagonalMatrix(DiagonalMatrix that)
that - a DiagonalMatrix| Method Detail |
|---|
public DiagonalMatrix deepCopy()
Matrixthis by the copy
constructor of the class, or just this if the instance itself is
immutable.
Override the return type.
Matrix instancepublic DiagonalMatrix add(DiagonalMatrix that)
this + that
Add with a DiagonalMatrix.
that - another matrix
this and thatpublic DiagonalMatrix minus(DiagonalMatrix that)
this - that
Subtract a DiagonalMatrix.
that - another matrix
this and thatpublic DiagonalMatrix multiply(DiagonalMatrix that)
this %*% that
Multiply by a DiagonalMatrix.
that - another matrix
this and thatpublic Vector multiply(Vector v)
MatrixA by a vector.
multiply in interface Matrixmultiply in class MatrixMathImpl<DiagonalMatrix>v - a vector
A %*% vpublic DiagonalMatrix scaled(double scalar)
Matrixscalar * this
scaled in interface Matrixscaled in class MatrixMathImpl<DiagonalMatrix>scalar - a double
scalar * thispublic DiagonalMatrix t()
t in interface MatrixRingt in class MatrixMathImpl<DiagonalMatrix>public DiagonalMatrix ZERO()
AbelianGroupa in the group,
the equation 0 + a = a + 0 = a holds.
0public DiagonalMatrix ONE()
MatrixRingFor a non-square matrix, it zeros out the rows (columns) with index > nCols (nRows).
public 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 DensifiableDenseMatrixpublic DenseVector diagonal()
public DenseVector superDiagonal()
public DenseVector subDiagonal()
public DenseVector getRow(int row)
MatrixAccessor
getRow in interface MatrixAccessorgetRow in class MatrixMathImpl<T extends com.numericalmethod.suanshu.matrix.doubles.matrixtype.dense.diagonal.DiagonalDataMatrix>row - the row index
A[row, ]public DenseVector getColumn(int col)
MatrixAccessor
getColumn in interface MatrixAccessorgetColumn in class MatrixMathImpl<T extends com.numericalmethod.suanshu.matrix.doubles.matrixtype.dense.diagonal.DiagonalDataMatrix>col - the column index
A[, col]public java.lang.String toString()
toString in class MatrixMathImpl<T extends com.numericalmethod.suanshu.matrix.doubles.matrixtype.dense.diagonal.DiagonalDataMatrix>public boolean equals(java.lang.Object obj)
MatrixStorageImpl
equals in class MatrixStorageImpl<T extends com.numericalmethod.suanshu.matrix.doubles.matrixtype.dense.diagonal.DiagonalDataMatrix>true iff two matrices have the same values, entry-by-entrypublic int hashCode()
hashCode in class MatrixStorageImpl<T extends com.numericalmethod.suanshu.matrix.doubles.matrixtype.dense.diagonal.DiagonalDataMatrix>
|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||