Package de.labathome.trustconstr.matrix
Class Matrix.Factory
java.lang.Object
de.labathome.trustconstr.matrix.Matrix.Factory
- Enclosing class:
- Matrix
Static constructors. All paths now produce
DenseMatrix instances
(column-major double[]) -- kept under Matrix.Factory.* so
existing call sites compile unchanged during the staged migration.-
Method Summary
Modifier and TypeMethodDescriptionstatic Matrixstatic DenseMatrixeye(long rows, long cols) static DenseMatrixfill(double v, long rows, long cols) static DenseMatriximportFromArray(double[] rowVec) Wrap a 1-D array as a1 x nrow matrix (the row-vector counterpart oflinkToArray(double[])).static DenseMatriximportFromArray(double[][] arr) Alias forlinkToArray(double[][]).static DenseMatrixlinkToArray(double[] colVec) Wrap a 1-D array as ann x 1column vector.static DenseMatrixlinkToArray(double[][] arr) static DenseMatrixlinkToArray(int[][] arr) int[][]input -- promoted todoublefor test fixtures.static DenseMatrixones(long[] size) static DenseMatrixones(long rows, long cols) static DenseMatrixrandn(long rows, long cols) Random normal matrix with mean 0 and stddev 1.static voidsetRandSeed(long seed) Set the seed of the RNG underlyingrandn(long, long)so results become reproducible.static DenseMatrixVertical concatenation: stack the input matrices on top of each other.static DenseMatrixzeros(long[] size) static DenseMatrixzeros(long rows, long cols)
-
Method Details
-
zeros
- Parameters:
rows- number of rowscols- number of columns- Returns:
- a fresh
rows x colszero matrix
-
zeros
- Parameters:
size- length-2 shape array[rows, cols](length-1 interpreted as a column vector)- Returns:
- a fresh zero matrix of the requested shape
-
eye
- Parameters:
rows- number of rowscols- number of columns- Returns:
- a fresh
rows x colsidentity-like matrix (1.0on the leading diagonal,0.0elsewhere)
-
ones
- Parameters:
rows- number of rowscols- number of columns- Returns:
- a fresh matrix filled with
1.0
-
ones
- Parameters:
size- length-2 shape array[rows, cols]- Returns:
- a fresh matrix filled with
1.0
-
fill
- Parameters:
v- value to fill every entry withrows- number of rowscols- number of columns- Returns:
- a fresh
rows x colsmatrix with all entries equal tov
-
linkToArray
- Parameters:
arr- row-major source (arr[i][j]= entry at(i, j))- Returns:
- a fresh dense matrix with the same shape and content
-
linkToArray
Wrap a 1-D array as ann x 1column vector. For example,linkToArray(new double[] {a, b})produces a 2×1 vector indexed viagetAsDouble(i, 0).- Parameters:
colVec- entries of the resulting column vector- Returns:
- an
n x 1column vector
-
importFromArray
Alias forlinkToArray(double[][]).- Parameters:
arr- row-major source- Returns:
- a fresh dense matrix
-
importFromArray
Wrap a 1-D array as a1 x nrow matrix (the row-vector counterpart oflinkToArray(double[])). Test fixtures that need a column then call.transpose().- Parameters:
rowVec- entries of the resulting row vector- Returns:
- a
1 x nrow vector
-
linkToArray
int[][]input -- promoted todoublefor test fixtures.- Parameters:
arr- row-major integer source- Returns:
- a fresh dense matrix with the same shape and content
-
randn
Random normal matrix with mean 0 and stddev 1. The underlyingRandomis seedable viasetRandSeed(long).- Parameters:
rows- number of rowscols- number of columns- Returns:
- a fresh
rows x colsmatrix populated with i.i.d. standard-normal samples
-
setRandSeed
public static void setRandSeed(long seed) Set the seed of the RNG underlyingrandn(long, long)so results become reproducible.- Parameters:
seed- RNG seed
-
copyFromMatrix
- Parameters:
m- source matrix- Returns:
- a deep copy of
m
-
vertCat
Vertical concatenation: stack the input matrices on top of each other. All inputs must have the same column count.- Parameters:
parts- matrices to stack (in order, from top to bottom)- Returns:
- a fresh
DenseMatrixcontaining the stacked rows - Throws:
IllegalArgumentException- if column counts differ
-