koblas

SparseVector

@Serializable(with = SparseVectorSerializer::class)
@SerialName(value = "SparseVector")
class SparseVector : VectorStorage(source)

Stored indices are strictly ascending and in range within this vector's window. Factories validate the structure; of sorts and sums instead.

Use copyIndices or com.eignex.koblas.forEachStored for safe structural access. indices is a live zero-copy escape hatch for specialized kernels and requires UnsafeKoblasApi; mutating it can invalidate the sparse structure. values remains live so coefficients can be updated without changing the sparse pattern. Column views borrow their owner's arrays: only the nnz entries beginning at offset belong to the vector. A view follows its matrix after structural changes; serialization and copies contain only its stored entries. Inserting an entry through set or changing the pattern through Vector.copyFrom or KoblasEngine.axpy replaces the buffers; obtain current arrays from the accessors after structural writes.

Types

Link copied to clipboard
object Companion

Factories for sparse vectors.

Properties

indices

Live stored positions; structural writes may replace this buffer. Do not mutate it.

nnz

val nnz: Int(source)

Number of stored entries, beginning at offset in the backing arrays.

offset

Start of this vector's stored entries in indices and values. Owning vectors start at zero.

size

open override val size: Int(source)

values

Live stored values; structural writes may replace this buffer.

Functions

copyIndices

A copy of this vector's stored positions, in strictly ascending order.

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 where nothing is stored.

hashCode

open override fun hashCode(): Int(source)

set

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

Writes an entry, inserting its position when absent. Explicitly written zeros remain stored.

toDoubleArray

open override fun toDoubleArray(): DoubleArray(source)

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

toString

open override fun toString(): String(source)
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.