koblas

SparseVector

@Serializable
@SerialName(value = "SparseVector")
class SparseVector : VectorView(source)

Compressed sparse vector: parallel indices/values arrays of equal length, each holding one nonzero entry. Immutable from the caller's perspective; to change the sparsity pattern, rebuild.

Indices are strictly ascending and in range, validated by the constructor. Three things depend on it: get binary-searches rather than scanning, a sparse-against-sparse dot merges the two index lists in one pass instead of looking each position up, and the storage order that forEachStored and iamax expose becomes index order — so a tie in iamax resolves to the lowest index, the same rule the dense vector follows. Strict ascent also rules out duplicate indices, which would otherwise leave get and forEachStored disagreeing about the value at a position.

of is the forgiving entry point: it sorts and sums duplicates, mirroring SparseMatrix.ofColumns.

Types

Link copied to clipboard
object Companion

Factory entrypoints for SparseVector.

Properties

indices

size

open override val size: Int(source)

values

Functions

equals

open operator override fun equals(other: Any?): Boolean(source)

get

open operator override fun get(i: Int): Double(source)

The stored value at i, or 0.0. A binary search over the ascending indices, so O(log nnz).

hashCode

open override fun hashCode(): Int(source)

toDoubleArray

open override fun toDoubleArray(): DoubleArray(source)

Materialise into a fresh dense DoubleArray. Always allocates; the returned array is independent of any internal storage, so the caller is free to mutate it.

toString

open override fun toString(): String(source)
Link copied to clipboard
infix fun VectorLike.dot(other: VectorLike): Double

aT * b. Dense×dense routes through the active com.eignex.koblas.dense.VectorKernels; a mixed pair walks the sparse side and gathers from the dense one; anything else is read entry by entry.

Link copied to clipboard
inline fun VectorLike.forEachStored(block: (i: Int, v: Double) -> Unit)

Visit each stored entry of this as (index, value), in ascending index order for any storage. For DenseVector that's every index in 0 until size; for SparseVector that's the entries present in the parallel index/value arrays (which may include numerical zeros); for any other VectorLike it is every index, read through VectorLike.get.