kumulant

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.

get is a linear scan rather than a binary search on purpose. Typical nnz is small (handful to a few hundred for sparse feature vectors from nominal-heavy CSPs), and at that scale a tight IntArray loop beats binary search's mispredicted branches and indirect indexing. Internal ops iterate via forEachStored and skip get entirely.

Indices are not required to be sorted; the constructor only checks the parallel- array invariant.

Types

Link copied to clipboard
object Companion

Factory entrypoints for SparseVector.

Properties

Link copied to clipboard
open override val size: Int

Number of entries (including stored zeros for sparse).

Functions

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open operator override fun get(i: Int): Double

Read entry at i. O(1) for DenseVector, O(nnz) linear scan for SparseVector. Use the internal forEachStored extension when you want to walk the populated entries without per-index lookup cost.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open override fun toDoubleArray(): DoubleArray

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.

Link copied to clipboard
open override fun toString(): String

equals

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

get

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

Read entry at i. O(1) for DenseVector, O(nnz) linear scan for SparseVector. Use the internal forEachStored extension when you want to walk the populated entries without per-index lookup cost.

hashCode

open override fun hashCode(): Int(source)

size

open override val size: Int(source)

Number of entries (including stored zeros for sparse).

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)