koblas

SparseBlas

The sparse matrix routines, the seam a host sparse BLAS plugs into.

Thin next to its dense sibling, and honestly so: gemv is the one sparse matrix operation koblas has callers for. Sparse gemm fills in — the product of two sparse matrices is denser than either, often dramatically — so it is a different algorithm with a different output type, not a flag on this one, and it goes here when something needs it rather than before.

The SparseMatrix backing crosses to a host library without repacking: its CSC layout is what UMFPACK, KLU and CHOLMOD all consume, and MKL's inspector-executor takes CSC with an index-base flag. See SparseMatrix for the verified details and the two remaining mismatches.

Inheritors

Properties

Link copied to clipboard
abstract val name: String

A short backend identifier for diagnostics (e.g. "reference").

Link copied to clipboard
open val priority: Int

Relative preference among simultaneously available backends: automatic selection through registerBackend — JVM classpath discovery, native startup registration — picks the highest per half. The portable reference is 0; native-accelerated backends rank above it (koblas-openblas 100, koblas-cblas 90).

Functions

gemv

open fun gemv(alpha: Double, a: SparseMatrix, x: DoubleArray, beta: Double, y: DoubleArray, transpose: Boolean = false)(source)

In-place y = alpha · op(A) · x + beta · y, where op(A) is Aᵀ when transpose — the sparse dgemv. Per BLAS convention beta == 0.0 overwrites y without reading it, so it may arrive uninitialized, and alpha == 0.0 reduces to the beta scale.

Both directions walk the columns, which is what CSC stores. The non-transposed form accumulates x_j times column j into y; the transposed form dots column j with x to make y_j. Neither touches a structural zero.


open fun gemv(a: SparseMatrix, x: DoubleArray, transpose: Boolean = false): DoubleArray(source)

A · x, or Aᵀ · x when transpose, into a fresh result — the restricted gemv with alpha = 1, beta = 0.

trsv

open fun trsv(a: SparseMatrix, x: DoubleArray, lower: Boolean, transpose: Boolean = false)(source)

Solve op(T) · x = b in place, where T is the lower or upper triangle of the square a and op transposes when transpose — the sparse dtrsv. x holds the right-hand side on entry and the solution on return.

The solve existed inside SparseLu and nowhere else, so a caller holding a triangular SparseMatrix of their own had no way to solve against it. This is that routine, on the seam a host sparse BLAS would replace (MKL has mkl_sparse_d_trsv; it is one of the routines an inspector-executor interface covers).

Every direction walks columns, which is what CSC stores, and only the selected triangle is read — so the other one may hold anything. The two non-transposed forms push a finished unknown down or up its column; the transposed forms pull, dotting the column against the already-solved entries. That is the same four-way structure the dense cores have, for the same reason: a column of T is a row of Tᵀ.

Unlike the dense cores, this validates the diagonal. Triangular.kt leaves a singular dense triangle to produce infinities on the grounds that the caller knows what it passed; here a structurally missing diagonal entry is detectable for free while walking the column, so reporting it costs nothing and a silent NaN would be a worse trade.

Throws

if a diagonal entry is missing or zero, naming its position.