koblas

VectorLike

interface VectorLike(source)

Read-only vector contract: length, entry access, materialisation. Anything that only reads a vector should take this.

Open, for the reasons MatrixLike gives: a caller may already have a shape koblas does not define, and copying into a DenseVector to use koblas's routines was a tax on the callers with the most data. koblas recognises its own storages by type and sweeps them directly; a foreign implementation takes the generic path through get.

See also

the closed, serializable subset.

Inheritors

Properties

size

abstract val size: Int(source)

Number of entries (including stored zeros for sparse).

Functions

get

abstract operator fun get(i: Int): Double(source)

Read entry at i. O(1) for DenseVector, O(log nnz) for SparseVector, which binary-searches its ascending indices. Use the forEachStored extension when you want to walk the populated entries without per-index lookup cost.

toDoubleArray

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
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.