Class CSRMatrix.Builder

java.lang.Object
de.labathome.trustconstr.sparse.CSRMatrix.Builder
Enclosing class:
CSRMatrix

public static final class CSRMatrix.Builder extends Object
Incremental builder for CSRMatrix using a Dictionary-of-Keys (DOK) representation under the hood. Cheap O(1) amortised set(int, int, double); build() compresses to canonical CSR (column indices sorted within each row, no duplicates).

Storing a value of exactly 0.0 via set(i, j, 0.0) removes any previously-stored entry at (i, j) so the resulting CSR contains no explicit zeros.

  • Method Details

    • rows

      public int rows()
      Returns:
      number of rows the resulting CSR will have
    • cols

      public int cols()
      Returns:
      number of columns the resulting CSR will have
    • set

      public CSRMatrix.Builder set(int i, int j, double v)
      Store v at (i, j). Setting to 0.0 removes the entry. Repeated calls overwrite (this is set, not add).
      Parameters:
      i - 0-based row index
      j - 0-based column index
      v - value to store
      Returns:
      this builder, for chaining
    • get

      public double get(int i, int j)
      Read back the value at (i, j); defaults to 0.0.
      Parameters:
      i - 0-based row index
      j - 0-based column index
      Returns:
      current value at (i, j), or 0.0
    • nnz

      public int nnz()
      Returns:
      current number of stored non-zero entries
    • build

      public CSRMatrix build()
      Compress the DOK contents into a canonical CSR representation (column indices sorted within each row, no duplicates, no explicit zeros).
      Returns:
      the compressed CSRMatrix