koblas

Top-level

Owning dense and sparse containers, borrowed vector views, Workspace and high-level arithmetic. Ordinary use needs only com.eignex.koblas.*; Matrix and Vector are read-only contracts custom types can implement. Dense matrices are column-major and sparse matrices are validated CSC.

KoblasEngine.gemm and the * operator dispatch on runtime storage with dense or sparse operands on either side. Two sparse operands produce CSC storage; other built-in pairings produce dense storage. No sparse operand is densified to reach a kernel. Operators use the default engine. Dense operations and mixed CSC products address DenseMatrixRegion directly, including padded views.

Types

Link copied to clipboard
expect object BuiltinEngines

Exact portable and JVM SIMD engines for tests and benchmarks, without changing the default koblas.

actual object BuiltinEngines

JVM built-in engines.

actual object BuiltinEngines

Built-in engines on Kotlin/Native.

Link copied to clipboard
@Serializable
@SerialName(value = "ContiguousVector")
class ContiguousVector : VectorStorage, DenseVector

A dense vector that owns its whole buffer, so its entries are exactly values, in order and complete.

Link copied to clipboard
@Serializable
@SerialName(value = "DenseMatrix")
class DenseMatrix : MatrixStorage, DenseMatrixRegion
Link copied to clipboard
sealed interface DenseMatrixRegion : Matrix

Mutable column-major storage with unit row stride, shared by DenseMatrix and DenseMatrixView. Entry A(i, j) is at offset + i + j * leadingDimension in values.

Link copied to clipboard

A borrowed rectangle of a DoubleArray, with explicit offset and leadingDimension. No entries are copied or owned. The backing buffer can also be mutated by its owner or other views. Unlike DenseMatrix, values need not have exactly rows * cols entries. Views use reference equality.

Link copied to clipboard
sealed interface DenseVector : Vector

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

Link copied to clipboard

Operands whose shapes do not fit the routine.

Link copied to clipboard

Immutable dense and sparse BLAS with portable fallbacks.

Link copied to clipboard
interface Matrix

Read-only matrix contract. Anything that only reads a matrix should take this.

Link copied to clipboard
@Serializable
sealed interface MatrixStorage : Matrix

The matrix storages koblas itself defines, DenseMatrix and SparseMatrix.

Link copied to clipboard

How a call reached its result.

Link copied to clipboard
@Serializable
@SerialName(value = "SparseMatrix")
class SparseMatrix : MatrixStorage

Compressed-sparse-column form: column j occupies colPointers(j) until colPointers(j + 1) of rowIndices and values, rows strictly ascending. A stored zero is preserved, and a 64-bit-index host library needs a widening copy.

Link copied to clipboard
@Serializable
@SerialName(value = "SparseVector")
class SparseVector : VectorStorage

Indices are strictly ascending and in range, validated by the constructor; of sorts and sums instead.

Link copied to clipboard
class StridedVector @JvmOverloads constructor(val values: DoubleArray, val offset: Int, val size: Int, val stride: Int = 1) : DenseVector

A mutable live window of size entries in values, starting at offset and separated by stride.

Link copied to clipboard
@RequiresOptIn(message = "This is live internal storage; mutating it can invalidate the owning object", level = RequiresOptIn.Level.ERROR)
annotation class UnsafeKoblasApi

Marks direct access to live structural or factorization storage. Mutating these buffers can invalidate later operations; access is intended for backend interoperability and specialized kernels.

Link copied to clipboard
interface Vector

Read-only vector contract. Anything that only reads a vector should take this.

Link copied to clipboard
@Serializable
sealed interface VectorStorage : Vector

The vector storages koblas defines and serializes, ContiguousVector and SparseVector.

Link copied to clipboard
class Workspace

Reusable scratch for alias-safe matrix operations.

Properties

Link copied to clipboard
@get:JvmName(name = "getDefault")
val koblas: KoblasEngine

The immutable platform-selected BLAS engine used by top-level convenience operations.

Functions

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
inline fun <T> Workspace?.borrow(size: Int, block: (DoubleArray) -> T): T

Borrows a vector of size for block, allocating one when there is no workspace to lend it.

Link copied to clipboard
inline fun <T> Workspace?.borrowI32(size: Int, block: (IntArray) -> T): T

Index counterpart of borrow.

Link copied to clipboard

Column j as a fresh vector, copied rather than viewed.

Column j as a fresh sparse vector. Runs in O(nnzⱼ) time and allocates copies of its stored indices and values, so later mutations to the returned vector's indices or values cannot affect this matrix. Explicitly stored zeros are preserved.

Link copied to clipboard
fun copy(src: Vector, dst: DenseVector)

dst = src (BLAS dcopy). A sparse source zero-fills the destination first, so nothing survives. Identical dense mappings are a no-op. Overlapping dense slices with unit stride use an overlap-safe block move. Other overlapping sources 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

Read from at x's stored positions into x (Sparse BLAS usga), the inverse of copy from a sparse source. x keeps its pattern, so a nonzero of from at an unstored position is not read.

Link copied to clipboard

gather, and zero in from the positions it read (Sparse BLAS usgz).

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

Makes the stored entries match what structure promises, in place.

Link copied to clipboard
@JvmName(name = "subtract")
operator fun DenseMatrix.minus(other: DenseMatrix): DenseMatrix

A - B, allocating. axpy with alpha = -1.0 accumulates into an existing operand.

@JvmName(name = "subtract")
operator fun DenseVector.minus(other: DenseVector): DenseVector

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

@JvmName(name = "subtract")
operator fun SparseMatrix.minus(other: SparseMatrix): SparseMatrix

A - B, allocating an owned CSC structural union.

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 DenseMatrix.plus(other: DenseMatrix): DenseMatrix

A + B, allocating. axpy accumulates into an existing operand.

@JvmName(name = "add")
operator fun DenseVector.plus(other: DenseVector): DenseVector

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

@JvmName(name = "add")
operator fun SparseMatrix.plus(other: SparseMatrix): SparseMatrix

A + B, allocating an owned CSC structural union.

Link copied to clipboard

Apply a plane rotation (BLAS drot). Each pair (x_i, y_i) becomes (c*x_i + s*y_i, c*y_i - s*x_i), so both x and y are overwritten in place. Dense vectors use the same overlap semantics as the borrowed overload.

rot over borrowed strided storage. Negative strides are supported. If the views overlap, both logical input sequences are snapshotted before writing; at a shared physical entry the final write is from y.

Link copied to clipboard

Row i as a fresh vector, gathered across the backing. Prefer column where the algorithm allows.

Row i as a fresh sparse vector whose stored positions are the source columns. Runs in O(nnz) time, scanning every stored entry in the matrix to gather the ones in this row, and allocates arrays sized to its stored entries. The returned vector is independent of this matrix, and explicitly stored zeros are preserved.

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

Exchange the contents of a and b (BLAS dswap), including rows and columns of a dense matrix.

Link copied to clipboard

Fresh CSC matrix holding A + alpha * x * xT in its lower or upper triangle. The other triangle is copied unchanged. Unlike dense com.eignex.koblas.dense.DenseBlas.syr, this is not in place: a rank update can introduce entries that the source CSC pattern has no room to store.

Link copied to clipboard

Fresh CSC matrix holding A + alpha * (x * yT + y * xT) in its lower or upper triangle. The other triangle is copied unchanged. This structural counterpart of dense com.eignex.koblas.dense.DenseBlas.syr2 never mutates its source, because newly nonzero entries may require CSC fill.

Link copied to clipboard
@JvmName(name = "multiply")
operator fun DenseMatrix.times(other: DenseMatrix): DenseMatrix

A * B (BLAS dgemm), allocating. gemm accumulates into an existing C instead.

@JvmName(name = "multiply")
operator fun DenseMatrix.times(x: DenseVector): DenseVector

Matrix-vector product into a fresh dense result.

@JvmName(name = "multiply")
operator fun DenseMatrix.times(other: SparseMatrix): DenseMatrix

A * B for a dense left operand and sparse right operand, allocating dense storage.

@JvmName(name = "multiply")
operator fun DenseMatrix.times(alpha: Double): DenseMatrix
@JvmName(name = "multiply")
operator fun Double.times(a: DenseMatrix): DenseMatrix

alpha * A, allocating. scale multiplies in place.

@JvmName(name = "multiply")
operator fun DenseVector.times(alpha: Double): DenseVector
@JvmName(name = "multiply")
operator fun Double.times(x: DenseVector): DenseVector

alpha * x, allocating. scale multiplies in place.

@JvmName(name = "multiplyMatrices")
operator fun Matrix.times(other: Matrix): Matrix

Allocating product through koblas: two sparse operands give CSC storage, any other pairing dense.

@JvmName(name = "multiply")
operator fun SparseMatrix.times(other: DenseMatrix): DenseMatrix

A * B for a sparse left operand and dense right operand, allocating dense storage.

@JvmName(name = "multiply")
operator fun SparseMatrix.times(other: SparseMatrix): SparseMatrix

A * B for two sparse matrices, allocating the discovered CSC structure.

Link copied to clipboard

Fresh transposed matrix, with the active backend (koblas). For products, prefer the transpose flags on gemv and gemm, which read the original storage without copying. See DenseBlas.transpose.

Fresh transposed matrix, still CSC, which makes this the CSC-to-CSR conversion as well. Explicitly stored zeros survive, since the transpose is structural rather than arithmetic.

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

-A, allocating.

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

Link copied to clipboard

Fresh matrix with column column replaced by entering, still CSC. The replacement is structural, so an explicitly stored zero in entering survives as one.