public class DenseMatrix extends 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(Object o) |
static DenseMatrix |
eye(int n)
Generate an Identity Matrix in
DenseMatrix format. |
void |
foreachActive(scala.Function3<Object,Object,Object,scala.runtime.BoxedUnit> f)
Applies a function
f to all the active elements of dense and sparse matrix. |
int |
hashCode() |
boolean |
isTransposed()
Flag that keeps track whether the matrix is transposed or not.
|
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. |
DenseMatrix |
transpose()
Transpose the Matrix.
|
double[] |
values() |
static DenseMatrix |
zeros(int numRows,
int numCols)
Generate a
DenseMatrix consisting of zeros. |
compressed, compressedColMajor, compressedRowMajor, getDenseSizeInBytes, getSparseSizeInBytes, isColMajor, isRowMajor, multiply, multiply, multiply, rowIter, toArray, toDense, toDenseColMajor, toDenseRowMajor, toSparse, toSparseColMajor, toSparseRowMajor, toString, toStringpublic 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 int numRows()
Matrixpublic int numCols()
Matrixpublic double[] values()
public boolean isTransposed()
MatrixisTransposed in interface Matrixpublic boolean equals(Object o)
equals in class Objectpublic int hashCode()
hashCode in class Objectpublic double apply(int i,
int j)
Matrixpublic DenseMatrix copy()
Matrixpublic DenseMatrix transpose()
MatrixMatrix instance sharing the same underlying data.public void foreachActive(scala.Function3<Object,Object,Object,scala.runtime.BoxedUnit> f)
Matrixf to all the active elements of dense and sparse matrix. The ordering
of the elements are not defined.
foreachActive in interface Matrixf - the function takes three parameters where the first two parameters are the row
and column indices respectively with the type Int, and the final parameter is the
corresponding value in the matrix with type Double.public int numNonzeros()
MatrixnumNonzeros in interface Matrixpublic int numActives()
MatrixnumActives in interface Matrix