koblas

Companion

Factories for sparse matrices.

Functions

ofColumns

fun ofColumns(rows: Int, cols: Int, columns: List<List<Pair<Int, Double>>>): SparseMatrix(source)

Builds a CSC matrix from column-major (row, value) entries, where columns(j) lists column j's nonzeros in any order. Entries are sorted by row and duplicate positions are summed.

ofTriplets

fun ofTriplets(rows: Int, cols: Int, rowIndices: IntArray, colIndices: IntArray, values: DoubleArray): SparseMatrix(source)

Builds a CSC matrix from parallel coordinate (triplet) arrays, where entry k is values(k) at (rowIndices(k), colIndices(k)). Any order, duplicate positions summed in input order, inputs copied. Uses O(nnz + cols) storage. Construction is O(nnz + rows + cols) when rows <= nnz, otherwise O(nnz log nnz + cols) without scanning the row domain.

wrap

fun wrap(rows: Int, cols: Int, colPointers: IntArray, rowIndices: IntArray, values: DoubleArray): SparseMatrix(source)

Wraps arrays already in CSC form without copying; the caller relinquishes ownership. Validates the invariants rather than repairing them, so use ofColumns or ofTriplets when they do not hold. The structural arrays cannot be recovered for mutation afterwards.