koblas

DenseVector

@Serializable(with = DenseVectorSerializer::class)
@SerialName(value = "DenseVector")
class DenseVector : VectorStorage(source)

Mutable dense vector, including borrowed slices with positive or negative strides. Entry x(i) is at offset + i * stride in values. Factories allocate or borrow storage; view shares it. Equality and hashing compare logical entries, including signed zeros and NaNs. Serialization writes logical entries in order and decodes independent contiguous storage. Do not use the vector as a hash-map key while mutating its entries.

Types

Link copied to clipboard
object Companion

Factories for allocated or borrowed dense vector storage.

Properties

offset

size

open override val size: Int(source)

stride

values

Functions

equals

open operator override fun equals(other: Any?): Boolean(source)

get

open operator override fun get(i: Int): Double(source)

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

hashCode

open override fun hashCode(): Int(source)

set

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

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

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)

view

fun view(offset: Int, size: Int, stride: Int = 1): DenseVector(source)

Borrows a slice addressed in this vector's logical indices. The offset and stride compose with the existing layout, and both endpoints must remain within this vector. An empty slice may start at size. A composed stride outside the Int range is rejected.

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.