koblas

DenseVector

sealed interface DenseVector : Vector(source)

A vector that stores every one of its entries, addressed as a buffer, an origin and a step.

Dense is about what is stored, not about how it is spaced: a run of adjacent entries and every second entry of a longer buffer are both dense, and a BLAS call takes either as a pointer and an increment without knowing the difference. That is why this is the operand type the dense matrix routines declare. A vector storing a pattern is a different thing with no increment to hand over, so SparseVector is deliberately not one of these and does not compile where one is wanted.

Sealed because the two shapes are the whole set: entries laid out one after another, or entries a fixed step apart. A caller that must tell them apart can do so exhaustively.

Neither shape implies ownership. of and zero allocate, while wrap and the StridedVector constructor borrow an array the caller keeps; mutations stay visible through every reference either way. So a vector here says how its entries are spaced, and says nothing about who owns them.

Inheritors

Types

Link copied to clipboard
object Companion

Factories for dense vectors.

Properties

offset

abstract val offset: Int(source)

First physical entry of this vector within values.

stride

abstract val stride: Int(source)

Physical distance between adjacent entries, which may be negative but is never zero.

values

abstract val values: DoubleArray(source)

Borrowed or owned backing array.

Link copied to clipboard
abstract val size: Int

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

Functions

set

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

Writes (v) at index (i).

Link copied to clipboard

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

Link copied to clipboard

A borrowed view over this whole vector, keeping whatever origin and spacing it already has.

Link copied to clipboard
fun DenseVector.axpy(alpha: Double, x: Vector)

y = y + alpha * x. A sparse x touches only the positions it stores. A dense x with an identical mapping is read directly; other dense overlaps, or sparse values sharing the destination buffer, are snapshotted before writing. Custom Vector implementations are also snapshotted, since their backing storage is opaque.

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

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
@JvmName(name = "subtract")
operator fun DenseVector.minus(other: DenseVector): DenseVector

a - b, allocating. axpy with alpha = -1.0 accumulates into an existing operand.

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

Whether these vectors address at least one common buffer entry.

Link copied to clipboard
@JvmName(name = "add")
operator fun DenseVector.plus(other: DenseVector): DenseVector

a + b, allocating. axpy accumulates into an existing operand.

Link copied to clipboard

v = alpha * v.

Link copied to clipboard

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

Link copied to clipboard
@JvmName(name = "multiply")
operator fun DenseVector.times(alpha: Double): DenseVector

alpha * x, allocating. scale multiplies in place.

Link copied to clipboard
abstract fun toDoubleArray(): DoubleArray

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

Link copied to clipboard
@JvmName(name = "negate")
operator fun DenseVector.unaryMinus(): DenseVector

-x, allocating.

Link copied to clipboard
fun DenseVector.view(offset: Int, size: Int, stride: Int = 1): StridedVector

A borrowed strided slice, addressed in this vector's logical indices rather than its buffer's positions.