ReferenceBackend
Portable pure-Kotlin backend — correct on every target, no native dependency, and the semantic reference a native backend is validated against. Textbook Doolittle LU with partial pivoting and naive (SIMD-assisted where the vector kernels kick in) level-2/3 loops.
A class rather than an object because its inner loops need vector kernels, and which kernels those are is a property of the KoblasContext it belongs to. Passing null — which ReferenceLinearAlgebra, the shared instance, does — follows the process default instead, so the singleton stays a stable identity while still picking up a registered host BLAS for long runs.
Parameters
the vector kernels the inner loops use, or null to follow the process default.
Constructors
ReferenceBackend
Parameters
the vector kernels the inner loops use, or null to follow the process default.
Properties
name
Relative preference among simultaneously available backends: automatic selection through registerBackend — JVM classpath discovery, native startup registration — picks the highest per half. The portable reference is 0; native-accelerated backends rank above it (koblas-openblas 100, koblas-cblas 90).
Functions
applyQInto
Apply Q (or Qᵀ when transpose) from qr to y into out, which is returned. out may be y.
factor
LU factorization with partial pivoting of a square a (LAPACK dgetrf); a is not modified. Allocates the factor buffers; factorInto refactorizes into existing ones.
factorInto
Refactorize a into out's existing buffers, returning out. A periodic refactorization — the simplex rebuilding its basis, a filter re-decomposing a covariance — otherwise allocates an n² copy and a pivot array each time; this reuses both. out must have the same dimension as a, and its previous contents are discarded.
ldl
Symmetric indefinite factorization A = L·D·Lᵀ with Bunch–Kaufman partial pivoting (LAPACK dsytrf, lower). As with Blas.symv, only the lower triangle of a is read — the strictly upper triangle may hold anything — and a is not modified. Use this where the matrix is symmetric but not positive definite (KKT systems); for SPD matrices cholesky is cheaper.
qr
QR factorization A = Q·R of an m×n a via Householder reflections (LAPACK dgeqrf); a is not modified and any shape is accepted. Rank deficiency is not detected — zero diagonal entries of R surface in solveLeastSquares as infinities/NaNs, following the triangular-solve convention.
symm
In-place symmetric matrix-matrix accumulate C = alpha · A · B + beta · C, or C = alpha · B · A + beta · C when right (BLAS dsymm). As with symv, only the triangle of the symmetric a selected by lower is read. Shapes: b and c agree, and a is square with dimension B.rows (left) or B.cols (right). Per BLAS convention, beta == 0.0 overwrites c without reading it, and alpha == 0.0 reduces to the beta scale.
symv
In-place symmetric matrix-vector accumulate y = alpha · A · x + beta · y for a symmetric a (BLAS dsymv). Only the triangle selected by lower (diagonal included) is read; the opposite strict triangle may hold anything. Exploits symmetry for roughly half the memory traffic of gemv. Per BLAS convention, beta == 0.0 overwrites y without reading it, and alpha == 0.0 reduces to the beta scale.
syrk
In-place symmetric rank-k accumulate C = alpha · A·Aᵀ + beta · C, or alpha · Aᵀ·A + beta · C when transpose (BLAS dsyrk). With the default Uplo.FULL the full symmetric result is produced (the alpha term is applied to both triangles, and beta scales all of c); with Uplo.LOWER / Uplo.UPPER the standard dsyrk semantics apply — only the selected triangle is written and beta-scaled, the opposite strict triangle untouched. c must be square with dimension op(A).rows. Per BLAS convention, beta == 0.0 overwrites without reading (within the written region), and alpha == 0.0 reduces to the beta scale.
Apply Q (or Qᵀ when transpose) from qr to a length-m y, into a fresh result (LAPACK dormqr restricted to a single column). Allocates; applyQInto does not.
Lower-triangular Cholesky decomposition A = L * LT, returned as a fresh matrix.
Matrix-matrix product A · B into a fresh matrix (restricted gemm with alpha = 1, beta = 0); A.cols must equal B.rows.
In-place matrix-matrix accumulate C = alpha · op(A) · op(B) + beta · C (full BLAS dgemm), where op transposes its operand when transposeA / transposeB is set. Shapes must satisfy op(A): m×k, op(B): k×n, C: m×n. Per BLAS convention, beta == 0.0 overwrites c without reading it, and alpha == 0.0 reduces to the beta scale.
Matrix-vector product A · x, or Aᵀ · x when transpose, into a fresh result (restricted gemv with alpha = 1, beta = 0).
Rank-one update A = A + alpha · x · yᵀ (BLAS dger).
Invert a general matrix from its LU factorization: returns A⁻¹ given P·A = L·U (LAPACK dgetri).
Invert an SPD matrix from its Cholesky factor: returns A^-1 given L = chol(A).
Reciprocal condition number estimate 1 / (anorm · est(‖A⁻¹‖₁)) from a factorization (LAPACK dgecon). anorm is the 1-norm of the original, unfactored matrix (see norm1), which the caller computes before factoring. Returns 1.0 for the empty factorization and exactly 0.0 when lu is singular or anorm is zero.
Solve A · X = B for the b.cols right-hand-side columns of b at once against a symmetric indefinite factorization (LAPACK dsytrs with nrhs); returns a fresh X. Backends may substitute a native block solve.
Solve A · x = b for a symmetric indefinite factorization ldl (LAPACK dsytrs); returns a fresh x. Symmetry makes the transposed solve identical, so there is no transpose flag. Allocates the result; solveInto writes into a caller-owned destination instead.
Solve A · X = B (or Aᵀ · X = B when transpose) into out, which is returned. out may be b. The transposed direction stages a block before scattering its rows through the permutation, so pass a workspace to lend that n·nrhs buffer.
Least-squares solve min ‖A·x − b‖₂ from the factorization (the dgels shape): requires m ≥ n and full column rank, returns the length-n solution x = R⁻¹·(Qᵀb)[0..n). This is the kernel square-root/array filters build on; it composes with cholesky rank-one updates for sliding-window problems.
Minimum-norm solution of the underdetermined consistent system A · x = b for a wide m×n A with m <= n and full row rank (LAPACK dgels's underdetermined shape, via QR of the transpose instead of LQ): pass the factorization qr(Aᵀ). With Aᵀ = Q·R we have A = Rᵀ·Qᵀ, so a forward solve Rᵀ·w = b followed by x = Q·(w padded with zeros) gives the solution of smallest 2-norm. b has length m; the result has length n. Rank deficiency is not detected and surfaces as infinities/NaNs, following the triangular-solve convention.
Solve A * x = b for x, given L = chol(A) (lower-triangular, A = L * LT). Allocates a fresh result vector; b is not modified.
Symmetric rank-1 update A += alpha · x · xᵀ (BLAS dsyr), writing the triangle(s) uplo selects.
Symmetric rank-2 update A += alpha · (x · yᵀ + y · xᵀ) (BLAS dsyr2), writing the triangle(s) uplo selects.
Symmetric rank-2k update C = alpha · (op(A) · op(B)ᵀ + op(B) · op(A)ᵀ) + beta · C (BLAS dsyr2k), where op transposes when transpose.
Multiply x = op(T) · x in place (BLAS dtrmv), the product counterpart of trsv.
Solve op(T) · x = b in place (BLAS dtrsv), where T is the lower or upper triangle of the square a, op transposes when transpose, and unitDiag takes the diagonal as 1 without reading it. x holds the right-hand side on entry and the solution on return. Only the selected triangle is read, so the rest of a may hold anything.
gemm
In-place matrix-matrix accumulate C = alpha · op(A) · op(B) + beta · C (full BLAS dgemm), where op transposes its operand when transposeA / transposeB is set. Shapes must satisfy op(A): m×k, op(B): k×n, C: m×n. Per BLAS convention, beta == 0.0 overwrites c without reading it, and alpha == 0.0 reduces to the beta scale.
gemv
In-place matrix-vector accumulate y = alpha · op(A) · x + beta · y (full BLAS dgemv), where op(A) is Aᵀ when transpose. Per BLAS convention, beta == 0.0 overwrites y without reading it (it may be uninitialized), and alpha == 0.0 reduces to the beta scale.
solveInto
Solve A · x = b into out, which is returned; allocates nothing. out may be b.
Solve A · x = b (or Aᵀ · x = b when transpose) into out, which is returned. Nothing is allocated, so a loop that owns its destination — a simplex FTRAN/BTRAN against a factored basis, a filter update — runs without touching the collector. out may be the same array as b.
The transposed direction has to stage the solved vector before scattering it through the permutation, so pass a workspace to make that staging buffer reusable as well; without one it is the single allocation this routine still makes.