Libmir Archive

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.

📖 Full API reference → mir-lapack.libmir.org — every module and symbol of mir-lapack, regenerated from current source.

mir-lapack provides D bindings to LAPACK routines with ndslice integration. Use it for decompositions (LU, QR, Cholesky, SVD), eigenvalue problems, and linear system solvers.

GitHub: libmir/mir-lapack

Install

// dub.sdl
dependency "mir-lapack" version="~>1.0"
dependency "mir-blas" version="~>1.0"
dependency "mir-algorithm" version="~>3.0"

Requires a LAPACK implementation (OpenBLAS, MKL, or system LAPACK):

sudo apt-get install libopenblas-dev   # includes LAPACK

LU factorization and linear solve

import mir.lapack;
import mir.ndslice;

// Solve A * x = b
auto A = slice!double(3, 3);
auto b = slice!double(3);
// Fill A and b ...

// LU factorization (in-place)
auto ipiv = slice!int(3);
int info = getrf(A, ipiv);   // A is now LU-factored in-place

// Solve using factored A
getrs('N', A, ipiv, b);      // b is now the solution x

Cholesky factorization

For symmetric positive-definite matrices:

// Cholesky: A = L * L^T
int info = potrf('L', A);    // A lower triangle holds L

// Solve A * x = b using Cholesky factor
potrs('L', A, b);

Eigenvalues (symmetric matrix)

// All eigenvalues of symmetric A
auto w = slice!double(n);    // output eigenvalues
auto work = slice!double(3 * n);
int info = dsyev('N', 'U', A, w, work);
// w now contains eigenvalues in ascending order

SVD — Singular Value Decomposition

auto A = slice!double(m, n);
auto s = slice!double(min(m, n));   // singular values
auto U = slice!double(m, m);
auto Vt = slice!double(n, n);
auto work = slice!double(max(1, 5 * min(m, n)));

int info = dgesv('A', 'A', A, s, U, Vt, work);

Relationship to lubeck

mir-lapack is the low-level binding layer. lubeck wraps it with a simpler API:

Taskmir-lapack (low-level)lubeck (high-level)
Solve Ax=bgetrf + getrssolve(A, b)
Eigenvaluesdsyeveigvals(A)
SVDdgesvsvd(A)
Inversegetrf + getriinv(A)
Least squaresdgelsmldivide(A, b)

For most use cases, lubeck is the better entry point. Use mir-lapack directly when you need workspace control, specific storage layouts, or routines not exposed by lubeck.

On this page