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]
.
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) |
double |
apply(int i,
int j)
Gets the (i, j)-th element.
|
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 |
index(int i,
int j)
Return the index for the (i, j)-th element in the backing array.
|
boolean |
isTransposed()
Flag that keeps track whether the matrix is transposed or not.
|
DenseMatrix |
map(scala.Function1<Object,Object> f)
Map the values of this matrix using a function.
|
int |
numCols()
Number of columns.
|
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. |
breeze.linalg.Matrix<Object> |
toBreeze()
Converts to a breeze matrix.
|
SparseMatrix |
toSparse()
Generate a
SparseMatrix from the given DenseMatrix . |
DenseMatrix |
transpose()
Transpose the Matrix.
|
DenseMatrix |
update(scala.Function1<Object,Object> f)
Update all the values of this matrix using the function f.
|
void |
update(int i,
int j,
double v)
Update element at (i, j)
|
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 int numRows()
Matrix
public int numCols()
Matrix
public double[] values()
public boolean isTransposed()
Matrix
isTransposed
in interface Matrix
public boolean equals(Object o)
equals
in class Object
public breeze.linalg.Matrix<Object> toBreeze()
Matrix
public double apply(int i)
public double apply(int i, int j)
Matrix
public int index(int i, int j)
Matrix
public void update(int i, int j, double v)
Matrix
public DenseMatrix copy()
Matrix
public DenseMatrix map(scala.Function1<Object,Object> f)
Matrix
SparseMatrix
.public DenseMatrix update(scala.Function1<Object,Object> f)
Matrix
SparseMatrix
.public DenseMatrix transpose()
Matrix
public void foreachActive(scala.Function3<Object,Object,Object,scala.runtime.BoxedUnit> f)
Matrix
f
to all the active elements of dense and sparse matrix. The ordering
of the elements are not defined.
foreachActive
in interface Matrix
f
- 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 SparseMatrix toSparse()
SparseMatrix
from the given DenseMatrix
. The new matrix will have isTransposed
set to false.