mir-blas — BLAS Bindings for D
mir-blas provides BLAS (Basic Linear Algebra Subprograms) bindings for D that accept ndslice directly, enabling high-performance matrix and vector operations without manual pointer management.
📖 Full API reference → mir-blas.libmir.org — every module and symbol of
mir-blas, regenerated from current source.
mir-blas provides D bindings to BLAS (Basic Linear Algebra Subprograms) with native ndslice support. Instead of managing raw pointers and leading dimensions manually, you pass ndslice directly and the library handles the translation.
GitHub: libmir/mir-blas
Install
// dub.sdl
dependency "mir-blas" version="~>1.0"
dependency "mir-algorithm" version="~>3.0"You also need a BLAS implementation at link time. Common choices:
# Ubuntu / Debian
sudo apt-get install libopenblas-dev
# macOS (Accelerate is built in, or via Homebrew)
brew install openblasLevel 1 — vector operations
import mir.blas;
import mir.ndslice;
auto x = [1.0, 2.0, 3.0].sliced;
auto y = [4.0, 5.0, 6.0].sliced;
// dot product
double d = dot(x, y); // 1*4 + 2*5 + 3*6 = 32
// y = alpha*x + y (DAXPY)
axpy(2.0, x, y); // y is now [6, 9, 12]
// Euclidean norm
double n = nrm2(x); // sqrt(14) ≈ 3.742Level 2 — matrix-vector
auto A = slice!double(3, 4);
auto x = slice!double(4);
auto y = slice!double(3);
// Fill A, x ...
// y = alpha*A*x + beta*y (DGEMV)
gemv(1.0, A, x, 0.0, y);Level 3 — matrix-matrix
auto A = slice!double(3, 4);
auto B = slice!double(4, 5);
auto C = slice!double(3, 5);
// C = alpha*A*B + beta*C (DGEMM)
gemm(1.0, A, B, 0.0, C);ndslice integration
The key advantage over raw BLAS bindings: mir-blas reads the shape and stride from the Slice automatically.
// Transposed matrix — no copy, just different strides
auto At = A.transposed; // Universal slice (stride-aware)
gemm(1.0, At, B, 0.0, C); // mir-blas reads At.strides correctlyRelationship to lubeck
mir-blas provides low-level BLAS wrappers. lubeck (under kaleidicassociates) builds a higher-level API on top:
| Operation | mir-blas | lubeck |
|---|---|---|
| Matrix multiply | gemm(1.0, A, B, 0.0, C) | mtimes(A, B) |
| Solve Ax=b | manual gesv | solve(A, b) |
| SVD | manual gesvd | svd(A) |
| Inverse | manual getri after getrf | inv(A) |
Use lubeck for high-level work; use mir-blas when you need fine control over alpha/beta, transposes, or symmetric storage.
Related guides
mir-ion
Fast ION binary and JSON serialization for D. Zero-copy parsing, automatic struct serialization via mir-core reflection, BetterC compatible read path.
mir-lapack — LAPACK Bindings for D
mir-lapack provides LAPACK (Linear Algebra PACKage) bindings for D with ndslice integration — eigenvalues, SVD, LU factorization, Cholesky, and linear system solvers.