Package de.labathome.trustconstr.sparse
Class CSRMatrix.Builder
java.lang.Object
de.labathome.trustconstr.sparse.CSRMatrix.Builder
- Enclosing class:
- CSRMatrix
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 Summary
Modifier and TypeMethodDescriptionbuild()Compress the DOK contents into a canonical CSR representation (column indices sorted within each row, no duplicates, no explicit zeros).intcols()doubleget(int i, int j) Read back the value at(i, j); defaults to0.0.intnnz()introws()set(int i, int j, double v) Storevat(i, j).
-
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
Storevat(i, j). Setting to0.0removes the entry. Repeated calls overwrite (this is set, not add).- Parameters:
i- 0-based row indexj- 0-based column indexv- value to store- Returns:
- this builder, for chaining
-
get
public double get(int i, int j) Read back the value at(i, j); defaults to0.0.- Parameters:
i- 0-based row indexj- 0-based column index- Returns:
- current value at
(i, j), or0.0
-
nnz
public int nnz()- Returns:
- current number of stored non-zero entries
-
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
-