koblas

VectorStorage

@Serializable
sealed interface VectorStorage : Vector(source)

The vector storages koblas defines and serializes, DenseVector and SparseVector.

This is about which types koblas owns the definition of, not about which own their buffers: either may be wrapped around an array the caller keeps a reference to.

Encoded under the storage's own class name, with the numbers under values and any index array named for the axis it indexes, the same as MatrixStorage. A reader of one payload can then predict the others, and a name in a payload always resolves to the type that wrote it.

Inheritors

Properties

Link copied to clipboard
abstract val size: Int

Number of entries, counting the unstored zeros of a sparse vector.

Functions

Link copied to clipboard

Sum of absolute values (BLAS dasum). Sparse vectors sum over stored entries only.

Link copied to clipboard

An independent copy of the logical entries. Sparse storage keeps its pattern, including stored zeros; dense views and custom vectors produce owning dense storage. No backing arrays are shared.

Link copied to clipboard
fun Vector.copyFrom(source: Vector)

Copies source into this vector, requiring equal sizes before writing. Inputs may share storage; overlapping or opaque sources are snapshotted first. Dense views retain their offsets and strides.

Link copied to clipboard
infix fun Vector.dot(other: Vector): Double

aT * b. Sparse operands walk their stored entries only.

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

Visit each stored entry as (index, value), in ascending index order for any storage. A SparseVector may present numerical zeros as stored, and any other Vector has every index visited.

Link copied to clipboard
abstract operator fun get(i: Int): Double

The entry at index (i). Throws IndexOutOfBoundsException outside 0 until size, whatever the storage.

Link copied to clipboard
fun Vector.norm(type: Norm = Norm.Two): Double

Vector norm of type: Norm.One sums absolute values, Norm.Two is the Euclidean norm, and Norm.Infinity and Norm.MaxAbs select the maximum absolute value. An empty vector has norm zero.

Link copied to clipboard
abstract operator fun set(i: Int, v: Double)

Writes v at index i. Throws IndexOutOfBoundsException outside 0 until size.

Link copied to clipboard

Plain sum of the entries. Distinct from asum, which sums their absolute values.

Link copied to clipboard

Materialise into a fresh dense DoubleArray, independent of the internal storage.