public class DenseMatrix extends java.lang.Object implements Matrix
1.0 2.0
3.0 4.0
5.0 6.0
is stored as [1.0, 3.0, 5.0, 2.0, 4.0, 6.0].
param: numRows number of rows
param: numCols number of columns
param: values matrix entries in column major if not transposed or in row major otherwise
param: isTransposed whether the matrix is transposed. If true, values stores the matrix in
row major.
| Constructor and Description |
|---|
DenseMatrix(int numRows,
int numCols,
double[] values)
Column-major dense matrix.
|
DenseMatrix(int numRows,
int numCols,
double[] values,
boolean isTransposed) |
| Modifier and Type | Method and Description |
|---|---|
double |
apply(int i,
int j)
Gets the (i, j)-th element.
|
scala.collection.Iterator<Vector> |
colIter()
Returns an iterator of column vectors.
|
DenseMatrix |
copy()
Get a deep copy of the matrix.
|
static DenseMatrix |
diag(Vector vector)
Generate a diagonal matrix in
DenseMatrix format from the supplied values. |
boolean |
equals(java.lang.Object o) |
static DenseMatrix |
eye(int n)
Generate an Identity Matrix in
DenseMatrix format. |
int |
hashCode() |
boolean |
isTransposed()
Flag that keeps track whether the matrix is transposed or not.
|
static DenseMatrix |
multiply(DenseMatrix y) |
static DenseVector |
multiply(DenseVector y) |
static DenseVector |
multiply(Vector y) |
int |
numActives()
Find the number of values stored explicitly.
|
int |
numCols()
Number of columns.
|
int |
numNonzeros()
Find the number of non-zero active values.
|
int |
numRows()
Number of rows.
|
static DenseMatrix |
ones(int numRows,
int numCols)
Generate a
DenseMatrix consisting of ones. |
static DenseMatrix |
rand(int numRows,
int numCols,
java.util.Random rng)
Generate a
DenseMatrix consisting of i.i.d. uniform random numbers. |
static DenseMatrix |
randn(int numRows,
int numCols,
java.util.Random rng)
Generate a
DenseMatrix consisting of i.i.d. gaussian random numbers. |
static scala.collection.Iterator<Vector> |
rowIter() |
static double[] |
toArray() |
SparseMatrix |
toSparse()
Generate a
SparseMatrix from the given DenseMatrix. |
static java.lang.String |
toString() |
static java.lang.String |
toString(int maxLines,
int maxLineWidth) |
DenseMatrix |
transpose()
Transpose the Matrix.
|
double[] |
values() |
static DenseMatrix |
zeros(int numRows,
int numCols)
Generate a
DenseMatrix consisting of zeros. |
public DenseMatrix(int numRows,
int numCols,
double[] values,
boolean isTransposed)
public DenseMatrix(int numRows,
int numCols,
double[] values)
1.0 2.0
3.0 4.0
5.0 6.0
is stored as [1.0, 3.0, 5.0, 2.0, 4.0, 6.0].
numRows - number of rowsnumCols - number of columnsvalues - matrix entries in column majorpublic static DenseMatrix zeros(int numRows, int numCols)
DenseMatrix consisting of zeros.numRows - number of rows of the matrixnumCols - number of columns of the matrixDenseMatrix with size numRows x numCols and values of zerospublic static DenseMatrix ones(int numRows, int numCols)
DenseMatrix consisting of ones.numRows - number of rows of the matrixnumCols - number of columns of the matrixDenseMatrix with size numRows x numCols and values of onespublic static DenseMatrix eye(int n)
DenseMatrix format.n - number of rows and columns of the matrixDenseMatrix with size n x n and values of ones on the diagonalpublic static DenseMatrix rand(int numRows, int numCols, java.util.Random rng)
DenseMatrix consisting of i.i.d. uniform random numbers.numRows - number of rows of the matrixnumCols - number of columns of the matrixrng - a random number generatorDenseMatrix with size numRows x numCols and values in U(0, 1)public static DenseMatrix randn(int numRows, int numCols, java.util.Random rng)
DenseMatrix consisting of i.i.d. gaussian random numbers.numRows - number of rows of the matrixnumCols - number of columns of the matrixrng - a random number generatorDenseMatrix with size numRows x numCols and values in N(0, 1)public static DenseMatrix diag(Vector vector)
DenseMatrix format from the supplied values.vector - a Vector that will form the values on the diagonal of the matrixDenseMatrix with size values.length x values.length and values
on the diagonalpublic static double[] toArray()
public static scala.collection.Iterator<Vector> rowIter()
public static DenseMatrix multiply(DenseMatrix y)
public static DenseVector multiply(DenseVector y)
public static DenseVector multiply(Vector y)
public static java.lang.String toString()
public static java.lang.String toString(int maxLines,
int maxLineWidth)
public int numRows()
Matrixpublic int numCols()
Matrixpublic double[] values()
public boolean isTransposed()
MatrixisTransposed in interface Matrixpublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic double apply(int i,
int j)
Matrixpublic DenseMatrix copy()
Matrixpublic DenseMatrix transpose()
Matrixpublic int numNonzeros()
MatrixnumNonzeros in interface Matrixpublic int numActives()
MatrixnumActives in interface Matrixpublic SparseMatrix toSparse()
SparseMatrix from the given DenseMatrix. The new matrix will have isTransposed
set to false.