linear-algebra/backends/openblas
API baseline for Luna-Flow/linear-algebra/backends/openblas in the current 0.4.7 repository state.
Purpose
backends/openblas provides owned native-only matrix and vector backend wrappers. Matrix multiplication delegates to OpenBLAS GEMM, while vector and matrix-vector helpers delegate to the matching BLAS kernels.
This package is separate from @immut.Matrix. There is no runtime backend selector in immut; backend choice is now expressed by the concrete matrix type you use and the compilation target you build for.
Platform Constraint
- Supported target:
native - Unsupported targets:
js,wasm,wasm-gc - Current repository link configuration searches both
/opt/homebrew/opt/openblas/includeand/opt/homebrew/opt/openblas/libfor Homebrew on macOS, and/usr/include/x86_64-linux-gnu/openblas-pthread,/usr/include/openblas,/usr/lib/x86_64-linux-gnu/openblas-pthread, and/usr/lib/x86_64-linux-gnufor the default Ubuntu OpenBLAS package layout
BLASInnerType
BLASInnerType is a backend-local trait implemented only for Float and Double.
It owns the scalar-specific pieces required by the backend:
tolerance()returns the comparison tolerance used by backend tests and result checks.dot(length, left, right)dispatches tocblas_sdotorcblas_ddot.scal(length, alpha, data)dispatches tocblas_sscalorcblas_dscal.axpy(length, alpha, x, y)dispatches tocblas_saxpyorcblas_daxpy.gemm(m, n, k, left, right)dispatches matrix multiplication to the matching OpenBLAS kernel:cblas_sgemmforFloatandcblas_dgemmforDouble.gemv(row, col, matrix, vector)dispatches matrix-vector multiplication tocblas_sgemvorcblas_dgemv.
BlasMatrix[T] and BlasVector[T] public construction and conversion APIs require T : BLASInnerType, so the backend does not expose a half-open “constructible for any T but only operable for some T” surface.
BlasVector[T]
Owned native vector wrapper for the OpenBLAS backend.
Constructors, Conversions, And Accessors
BlasVector::from_immut(inner : @immut.Vector[T]) -> BlasVector[T]BlasVector::from_default(inner : @default.ImmutableDenseVector[T]) -> BlasVector[T]BlasVector::from_array(data : Array[T]) -> BlasVector[T]BlasVector::make(length : Int, value : T) -> BlasVector[T]to_immut(self) -> @immut.Vector[T]to_default(self) -> @default.ImmutableDenseVector[T]to_array(self) -> Array[T]length(self) -> Intop_get(self, index : Int) -> T
Trait Coverage
BlasVector[T] currently implements:
@algebra.VectorShape@algebra.AdditiveVectorAdd,Neg,SubShow
It does not implement @algebra.VecMulVector. BLAS-style scale, dot, and axpy are exposed as backend methods rather than new structure traits.
Backend Methods
BlasVector::scale(self, scalar : T) -> BlasVector[T]BlasVector::dot(self, other : BlasVector[T]) -> TBlasVector::axpy(self, alpha : T, other : BlasVector[T]) -> BlasVector[T]
BlasMatrix[T]
///|
test "BlasMatrix stores shape and values" {
let matrix = @openblas.BlasMatrix::from_2d_array([[1.0F, 2.0F], [3.0F, 4.0F]])
inspect(matrix.row(), content="2")
inspect(matrix.col(), content="2")
}BlasMatrix[T] is the owned concrete backend matrix type for this package. Internally it stores:
row : Intcol : Int- a contiguous
FixedArray[T]buffer
The public mental model stays row-major. Layout details needed by OpenBLAS stay inside the backend implementation.
Constructors And Conversions
BlasMatrix::from_immut(inner : @immut.Matrix[T]) -> BlasMatrix[T]BlasMatrix::from_default(inner : @default.ImmutableDenseMatrix[T]) -> BlasMatrix[T]BlasMatrix::from_2d_array(data : Array[Array[T]]) -> BlasMatrix[T]BlasMatrix::new(row : Int, col : Int, value : T) -> BlasMatrix[T]to_immut(self) -> @immut.Matrix[T]to_default(self) -> @default.ImmutableDenseMatrix[T]to_2d_array(self) -> Array[Array[T]]
Accessors
row(self) -> Intcol(self) -> Intto_array(self) -> Array[T]
Backend Methods
BlasMatrix::matvec(self, vector : BlasVector[T]) -> BlasVector[T]multiplies the matrix by an OpenBLAS backend vector through GEMV.
Trait Implementations
BlasMatrix[T] currently implements:
@algebra.MatrixShape@algebra.TransposeMatrix@algebra.AdditiveMatrix@algebra.MatMulMatrixAdd,Neg,Sub,MulShow
Behavior is split intentionally:
Muluses OpenBLAS GEMM throughBLASInnerType::gemm.matvecuses OpenBLAS GEMV throughBLASInnerType::gemv.shape,transpose,+,-, and unary-are implemented locally in MoonBit inside this backend package.
Boundary
This package exposes an owned trait-compatible backend wrapper. It does not:
- add a runtime backend enum
- retrofit traits directly onto third-party OpenBLAS binding types
- expose raw OpenBLAS handle types in the public API