koblas

Companion

Factories for sparse matrices.

Functions

ofColumns

fun ofColumns(rows: Int, cols: Int, columns: List<List<Pair<Int, Double>>>): F64SparseMatrix(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, rowIdx: IntArray, colIdx: IntArray, values: DoubleArray): F64SparseMatrix(source)

Builds a CSC matrix from parallel coordinate (triplet) arrays, where entry k is values(k) at (rowIdx(k), colIdx(k)). Any order, duplicate positions summed, inputs copied. O(nnz + rows + cols).

wrap

fun wrap(rows: Int, cols: Int, colPtr: IntArray, rowIdx: IntArray, values: DoubleArray): F64SparseMatrix(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.