koblas

Top-level

The containers every part of koblas speaks, and the free-function arithmetic over them. The routines themselves live one package down, split by storage: com.eignex.koblas.dense and com.eignex.koblas.sparse. See the README's "BLAS coverage" table for the routine-by-routine mapping to BLAS/LAPACK and the deliberate deviations.

  • Containers: F64MatrixView / F64DenseMatrix and F64VectorView / F64DenseVector / F64SparseVector, all @Serializable, plus the CSC F64SparseMatrix. The view roots are sealed, which is what gives the concrete storage a closed set and lets a snapshot round-trip with its type preserved — and is why the containers stay in one package rather than splitting with the operations that consume them.

  • Free-function arithmetic over the views, dispatching dense or sparse by operand type: dot, axpy, scale, norm2, asum, iamax, copy, swap, ger, times, transpose, forEachStored, and the matrix 1-norm norm1.

  • Shared machinery: Backend (what every backend of every tier reports about itself), the Workspace buffer pool, and the mathBackend identifier. None of these is per element type.

  • The element type in the names, and the unqualified aliases for the double-precision ones, are collected in Precision.kt; the dense and sparse packages each have the same file for their own names.

Types

Link copied to clipboard
interface Backend

What every backend reports about itself.

Link copied to clipboard

Double-precision F64DenseMatrix, the dense matrix an unqualified DenseMatrix means.

Link copied to clipboard

Double-precision F64DenseVector, the dense vector an unqualified DenseVector means.

Link copied to clipboard

Operands whose shapes do not fit the routine.

Link copied to clipboard
class F64Context(val kernels: F64Kernels, val blas: F64Blas, val decompositions: F64Decompositions, val sparseKernels: F64SparseKernels, val sparseBlas: F64SparseBlas, val sparseLu: F64SparseLu) : F64LinearAlgebra, F64Blas, F64Decompositions, F64SparseLinearAlgebra, F64SparseBlas, F64SparseLu

Every backend koblas will use for a piece of work, in one object you can hold. Immutable, and itself a F64LinearAlgebra and a F64SparseLinearAlgebra by delegation.

Link copied to clipboard
class F64Givens
Link copied to clipboard
typealias Givens = F64Givens

Double-precision F64Givens, the rotation an unqualified Givens means.

Link copied to clipboard

The double-precision F64Context, the context an unqualified KoblasContext means.

Link copied to clipboard

What koblas throws when a routine cannot do what was asked. Every one is an IllegalArgumentException.

Link copied to clipboard

Double-precision F64MatrixLike, the matrix contract an unqualified MatrixLike means.

Link copied to clipboard

Double-precision F64MatrixView, the sealed matrix storage an unqualified MatrixView means.

Link copied to clipboard
class NotPositiveDefinite(val position: Int, val pivot: Double, message: String) : KoblasException

A Cholesky or a strict L·D·Lᵀ met a pivot that was zero, negative or NaN.

Link copied to clipboard
class SingularMatrix(val position: Int, message: String) : KoblasException

A factorization met an exactly zero pivot, so the matrix it came from has no inverse.

Link copied to clipboard

Double-precision F64SparseMatrix, the CSC matrix an unqualified SparseMatrix means.

Link copied to clipboard

Double-precision F64SparseVector, the sparse vector an unqualified SparseVector means.

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

Double-precision F64VectorLike, the vector contract an unqualified VectorLike means.

Link copied to clipboard

Double-precision F64VectorView, the sealed vector storage an unqualified VectorView means.

Link copied to clipboard
class Workspace

Reusable scratch buffers, pooled by width. Every borrow outstanding at the same time gets a different buffer, so nesting is safe. Not thread-safe, deliberately: sharing one across threads corrupts results.

Properties

Link copied to clipboard
const val HOST_BACKEND_PRIORITY: Int = 100

The priority every host binding koblas ships registers at. A third-party backend is unprobed, and an ILP64 OpenBLAS exports identical symbols while computing wrong answers, caught by reading openblas_get_config.

Link copied to clipboard

The process-wide default context: an installBackends override when set, else registered backends, else the portable reference implementations. Every free function in koblas uses this.

Link copied to clipboard

What this runtime resolved, for startup logging (e.g. "backend=openblas, kernels=simd(8 lanes)").

Link copied to clipboard

Short identifier for the vector kernels the current process resolved, as named by F64PlatformKernels: "scalar", "simd(8 lanes)", or a "+openblas" suffix for a host backend.

Link copied to clipboard
const val NOT_SINGULAR: Int

The failedAt value of a factorization that succeeded, dense or sparse.

Link copied to clipboard

The slots still running koblas's own portable implementation, in declaration order.

Link copied to clipboard

A failedAt meaning "singular, but this backend cannot say where". Exists so a host solver like UMFPACK, which counts zero pivots without locating them, need not invent a position or report NOT_SINGULAR.

Functions

Link copied to clipboard

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

Link copied to clipboard

y = y + alpha * x. A sparse x touches only the positions it stores.

Link copied to clipboard

The backend installed in slot.

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

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

Link copied to clipboard

dst = src (BLAS dcopy). A sparse source zero-fills the destination first, so nothing survives.

Link copied to clipboard

Runs automatic platform discovery once, registering whatever host backends are available.

Link copied to clipboard

aT * b. Any sparse operand goes through F64SparseKernels, walking the stored entries only.

Link copied to clipboard
inline fun F64VectorLike.forEachStored(block: (i: Int, v: Double) -> Unit)

Visit each stored entry as (index, value), in ascending index order for any storage. A F64SparseVector may present numerical zeros as stored, and any other F64VectorLike has every index visited.

Link copied to clipboard

Rank-one update A = A + alpha * x * yT (BLAS dger) in place. Subtract by passing alpha = -1.0.

Link copied to clipboard

Index of the entry with maximal absolute value (BLAS idamax), -1 for a zero-length vector. Ties resolve to the lowest index, and a vector with no stored entries returns 0.

Link copied to clipboard

Overrides the context koblas returns; null restores automatic selection.

Link copied to clipboard

Whether slot is filled by something other than koblas's own portable implementation.

Link copied to clipboard
fun lapackFailedAt(info: Int): Int

Translates a LAPACK info return into a failedAt position. A positive info is the 1-based pivot index; a negative one is an illegal-argument report and maps to NOT_SINGULAR.

Link copied to clipboard

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

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

Link copied to clipboard

Matrix 1-norm, the maximum absolute column sum (LAPACK dlange with norm 1). This is the anorm rcond expects, computed before the matrix is factored.

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

Frobenius norm (LAPACK dlange with norm F). Rescales like norm2 against overflow and underflow.

Link copied to clipboard
fun F64DenseMatrix.normInf(workspace: Workspace? = null): Double

Matrix infinity-norm, the maximum absolute row sum (LAPACK dlange with norm I).

Link copied to clipboard

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

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

Link copied to clipboard
fun registerBackend(backend: Backend)

Offers backend as an explicit choice for every half it implements. Explicit registrations outrank automatically discovered ones; among explicit registrations, Backend.priority selects the winner.

Link copied to clipboard

Throws unless every one of slots is filled by an accelerated backend.

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.

Link copied to clipboard

Generate the plane rotation that zeroes b against a (BLAS drotg), rescaling so squares that would overflow or vanish still rotate correctly. Netlib sign convention; the all-zero pair gives the identity.

Link copied to clipboard

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

Link copied to clipboard

v = alpha * v.

Link copied to clipboard

Scale column j by d(j) in place, the product A * D for the diagonal D with entries d(j).

Scale column j by d(j) in place for a CSC matrix. The pattern is untouched.

Link copied to clipboard

Scale row i by d(i) in place, the product D * A for the diagonal D with entries d(i).

Link copied to clipboard

Exchange the contents of a and b (BLAS dswap).

Link copied to clipboard
fun F64DenseMatrix.syr(alpha: Double, x: F64VectorLike, uplo: Uplo = Uplo.FULL)

Symmetric rank-1 update A += alpha * x * xT (BLAS dsyr) in place. See F64Blas.syr.

Link copied to clipboard
fun F64DenseMatrix.syr2(alpha: Double, x: F64VectorLike, y: F64VectorLike, uplo: Uplo = Uplo.FULL)

Symmetric rank-2 update A += alpha * (x * yT + y * xT) (BLAS dsyr2) in place. See F64Blas.syr2.

Link copied to clipboard

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

alpha * A, allocating. scale multiplies in place.

alpha * x, allocating. scale multiplies in place.

Matrix-vector product into a fresh dense result for any F64MatrixLike against any F64VectorLike. gemv provide transpose and destination-buffer variants.

Link copied to clipboard

Fresh transposed matrix. For products, prefer the transpose flags on gemv and gemm, which read the original storage without copying.

Fresh transposed matrix, still CSC, which makes this the CSC-to-CSR conversion as well. Explicitly stored zeros survive.

Link copied to clipboard

-A, allocating.

-x, allocating.

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.