koblas

SparseVectorKernels

The sparse level-1 kernels: a sparse vector against a dense one, or against another sparse one.

The sparse counterpart of VectorKernels, and a real standard rather than an invention — the BLAS Technical Forum's Sparse BLAS defines this tier (usdot, usaxpy, gather and scatter), and it is the shape a revised simplex prices in: one sparse column against a dense reduced-cost vector.

Unlike VectorKernels there is no length threshold, and the difference is structural rather than an oversight. Dense level-1 kernels are compiled per target, so consulting a backend has to beat a compiled-in primitive and only pays above a length. These have no compile-time leaf to protect: the default is an object either way, so dispatch is unconditional and the koblas.sparseVectorKernels accessor never returns null.

Defaults implement every routine over the ascending index arrays, so a backend overrides only what it accelerates.

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

asum

Sum |x_i| over the stored entries.

axpy

open fun axpy(y: DoubleArray, alpha: Double, x: SparseVector)(source)

y += alpha·x for a sparse x into a dense y (Sparse BLAS usaxpy); touches only x's positions, which is the reason to pass a sparse operand at all.

dot

xᵀ·y for a sparse x against a dense y (Sparse BLAS usdot); walks only the stored entries.


xᵀ·y for two sparse vectors, merging their index lists in one pass — O(nnz_x + nnz_y).

Gathering instead, looking each stored position of one up in the other, would be O(nnz_x · log nnz_y). Both operands are strictly ascending, which is what makes the merge possible; SparseVector validates that.

nrm2

Euclidean norm over the stored entries.

The unstored entries are zero and contribute nothing to a sum of squares, so this is the dense euclideanNorm of the value array — the same kernel, rescaling included, because a stored entry near 1e±150 is no less likely for being sparse.

scatter

Write x's stored entries into out at their positions, leaving the rest of out alone (Sparse BLAS ussc). Zero-fill out first for a plain densification.