koblas

SparseVector

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

Indices are strictly ascending and in range, validated by the constructor; 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.

Types

Link copied to clipboard
object Companion

Factories for sparse vectors.

Properties

indices

nnz

val nnz: Int(source)

Number of stored entries, counted as SparseMatrix.nnz counts a matrix's.

size

open override val size: Int(source)

values

Functions

copyIndices

A copy of the 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)

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

Zero-based logical index of the maximum absolute value (BLAS idamax), or -1 when empty. Dense vectors use DenseVectorKernels.iamax; sparse vectors visit only their stored entries. All-zero nonempty inputs return 0, as do sparse inputs whose maximum is an implicit zero. Strided views report their logical index rather than a backing-array offset.

Link copied to clipboard

Euclidean norm (BLAS dnrm2). Rescales when the sum of squares would overflow or underflow, so any finite input gives the correct norm.

Link copied to clipboard

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