koblas

Vector

interface Vector(source)

Mutable vector contract with a fixed logical size.

Inheritors

Properties

size

abstract val size: Int(source)

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

Functions

get

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

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

set

abstract operator fun set(i: Int, v: Double)(source)

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

toDoubleArray

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

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

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