Class Matrix.Factory

java.lang.Object
de.labathome.trustconstr.matrix.Matrix.Factory
Enclosing class:
Matrix

public static final class Matrix.Factory extends Object
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 Details

    • zeros

      public static DenseMatrix zeros(long rows, long cols)
      Parameters:
      rows - number of rows
      cols - number of columns
      Returns:
      a fresh rows x cols zero matrix
    • zeros

      public static DenseMatrix zeros(long[] size)
      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

      public static DenseMatrix eye(long rows, long cols)
      Parameters:
      rows - number of rows
      cols - number of columns
      Returns:
      a fresh rows x cols identity-like matrix (1.0 on the leading diagonal, 0.0 elsewhere)
    • ones

      public static DenseMatrix ones(long rows, long cols)
      Parameters:
      rows - number of rows
      cols - number of columns
      Returns:
      a fresh matrix filled with 1.0
    • ones

      public static DenseMatrix ones(long[] size)
      Parameters:
      size - length-2 shape array [rows, cols]
      Returns:
      a fresh matrix filled with 1.0
    • fill

      public static DenseMatrix fill(double v, long rows, long cols)
      Parameters:
      v - value to fill every entry with
      rows - number of rows
      cols - number of columns
      Returns:
      a fresh rows x cols matrix with all entries equal to v
    • linkToArray

      public static DenseMatrix linkToArray(double[][] arr)
      Parameters:
      arr - row-major source (arr[i][j] = entry at (i, j))
      Returns:
      a fresh dense matrix with the same shape and content
    • linkToArray

      public static DenseMatrix linkToArray(double[] colVec)
      Wrap a 1-D array as an n x 1 column vector. For example, linkToArray(new double[] {a, b}) produces a 2×1 vector indexed via getAsDouble(i, 0).
      Parameters:
      colVec - entries of the resulting column vector
      Returns:
      an n x 1 column vector
    • importFromArray

      public static DenseMatrix importFromArray(double[][] arr)
      Parameters:
      arr - row-major source
      Returns:
      a fresh dense matrix
    • importFromArray

      public static DenseMatrix importFromArray(double[] rowVec)
      Wrap a 1-D array as a 1 x n row matrix (the row-vector counterpart of linkToArray(double[])). Test fixtures that need a column then call .transpose().
      Parameters:
      rowVec - entries of the resulting row vector
      Returns:
      a 1 x n row vector
    • linkToArray

      public static DenseMatrix linkToArray(int[][] arr)
      int[][] input -- promoted to double for test fixtures.
      Parameters:
      arr - row-major integer source
      Returns:
      a fresh dense matrix with the same shape and content
    • randn

      public static DenseMatrix randn(long rows, long cols)
      Random normal matrix with mean 0 and stddev 1. The underlying Random is seedable via setRandSeed(long).
      Parameters:
      rows - number of rows
      cols - number of columns
      Returns:
      a fresh rows x cols matrix populated with i.i.d. standard-normal samples
    • setRandSeed

      public static void setRandSeed(long seed)
      Set the seed of the RNG underlying randn(long, long) so results become reproducible.
      Parameters:
      seed - RNG seed
    • copyFromMatrix

      public static Matrix copyFromMatrix(Matrix m)
      Parameters:
      m - source matrix
      Returns:
      a deep copy of m
    • vertCat

      public static DenseMatrix vertCat(Matrix... parts)
      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 DenseMatrix containing the stacked rows
      Throws:
      IllegalArgumentException - if column counts differ