#simd #lapack #blas-lapack #blas

no-std oxiblas

OxiBLAS - Pure Rust BLAS/LAPACK implementation for the scirs2 ecosystem

6 releases

Uses new Rust 2024

0.2.4 Nov 18, 2026
0.2.3 Nov 11, 2026
0.2.2 Aug 6, 2026
0.2.1 Mar 16, 2026
0.1.2 Dec 29, 2025

#2175 in Math

Download history 72/week @ 2026-08-05 91/week @ 2026-08-12 130/week @ 2026-08-19 89/week @ 2026-08-26 162/week @ 2026-09-02 251/week @ 2026-09-09 376/week @ 2026-09-16 390/week @ 2026-09-23 870/week @ 2026-09-30 908/week @ 2026-10-07 834/week @ 2026-10-14 994/week @ 2026-10-21 1370/week @ 2026-10-28 1196/week @ 2026-11-04 2003/week @ 2026-11-11 544/week @ 2026-11-18

5,305 downloads per month
Used in 21 crates (5 directly)

Apache-2.0

12MB
237K SLoC

oxiblas

Unified API for OxiBLAS - Pure Rust BLAS/LAPACK implementation

Crates.io Documentation License

Overview

oxiblas is the meta-crate that re-exports all OxiBLAS functionality through a unified, convenient API. This is the recommended way to use OxiBLAS for most users.

Features

  • Complete BLAS - Level 1, 2, 3 operations
  • Extensive LAPACK - LU, QR, SVD, Cholesky, EVD, and more
  • Sparse matrices - 9 formats with iterative solvers
  • Tensor operations - Einstein summation, batched operations
  • Extended precision - f16, f128 support
  • High performance - BLIS-style blocked algorithms and SIMD kernels; see Performance
  • Opt-in SME2 backend - GEMM and GEMV on AArch64 CPUs with SME2 (Apple M4 and later) with the sme2 feature; as released it has run only under emulation (QEMU), and an early state of its kernels passed its unit tests on an Apple M4 Pro except the floating-point status flag tests (a known limit on macOS, see the CHANGELOG); see Feature Flags
  • Pure Rust - No C, C++ or Fortran in the libraries or their normal dependencies, easy cross-compilation

Quick Start

[dependencies]
oxiblas = "0.2"

# With all features
oxiblas = { version = "0.2", features = ["full"] }

Usage

Matrix Operations

use oxiblas::prelude::*;

// Create matrices
let a = Mat::from_rows(&[
    &[1.0, 2.0, 3.0],
    &[4.0, 5.0, 6.0],
]);

let b = Mat::from_rows(&[
    &[7.0, 8.0],
    &[9.0, 10.0],
    &[11.0, 12.0],
]);

// Matrix multiplication
let mut c = Mat::zeros(2, 2);
gemm(1.0, a.as_ref(), b.as_ref(), 0.0, c.as_mut());
// c = [[58, 64], [139, 154]]

Builders and Lazy Evaluation

use oxiblas::prelude::*;

let a = MatBuilder::<f64>::identity(3);
let b = MatBuilder::<f64>::ones(3, 3);

// Expressions are only evaluated when `.eval()` is called
let c = (a.as_ref().lazy() + b.as_ref().lazy()).scale(2.0).eval();

Parallel GEMM

With the parallel feature, the Rayon path is opt-in per call. Plain gemm always runs sequentially; pass Par::Rayon to gemm_with_par to parallelize:

use oxiblas::prelude::*;

let a = Mat::<f64>::filled(256, 256, 1.0);
let b = Mat::<f64>::filled(256, 256, 2.0);
let mut c = Mat::<f64>::zeros(256, 256);

// Requires the `parallel` feature
gemm_with_par(1.0, a.as_ref(), b.as_ref(), 0.0, c.as_mut(), Par::Rayon);

Linear Algebra

use oxiblas::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let a = Mat::from_rows(&[
        &[2.0, 1.0, 1.0],
        &[4.0, 3.0, 3.0],
        &[8.0, 7.0, 9.0],
    ]);

    // LU decomposition
    let lu = Lu::compute(a.as_ref())?;
    let det = lu.determinant();
    let inv = lu.inverse()?;

    // QR decomposition
    let qr = Qr::compute(a.as_ref())?;
    let q = qr.q();
    let r = qr.r();

    // SVD
    let svd = Svd::compute(a.as_ref())?;
    let singular_values = svd.singular_values();

    // Solve Ax = b (b is an n x 1 matrix, i.e. a column vector)
    let b = Mat::from_rows(&[&[4.0], &[10.0], &[24.0]]);
    let x = lu.solve(b.as_ref())?;
    Ok(())
}

Sparse Matrices

use oxiblas::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a 1000 x 1000 sparse matrix (tridiagonal)
    let n = 1000;
    let mut coo = CooMatrix::<f64>::new_empty(n, n);
    for i in 0..n {
        coo.push(i, i, 4.0);
        if i + 1 < n {
            coo.push(i, i + 1, -1.0);
            coo.push(i + 1, i, -1.0);
        }
    }

    let csr = coo.to_csr();

    // Solve sparse system with GMRES
    let b = vec![1.0; n];
    let x0 = vec![0.0; n]; // initial guess
    let result = gmres(&csr, &b, &x0, 30, 1e-10, 100)?;
    let x = result.x;
    Ok(())
}

Tensor Operations

// Tensor operations live in `oxiblas-blas`'s `tensor` module and are not
// part of `oxiblas::prelude` - import them from `oxiblas::blas::tensor`.
use oxiblas::blas::tensor::{Tensor3, batched_matmul, einsum};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Einstein summation: matrix multiplication (A: 2x3, B: 3x2)
    let a = vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0];
    let b = vec![7.0, 8.0, 9.0, 10.0, 11.0, 12.0];
    let c = einsum("ij,jk->ik", &a, &[2, 3], Some((&b, &[3, 2])))?;

    // Batched matrix multiplication
    let (batch, m, k, n) = (4, 2, 3, 2);
    let data_a = vec![1.0; batch * m * k];
    let data_b = vec![1.0; batch * k * n];
    let a_batch = Tensor3::from_data(data_a, batch, m, k);
    let b_batch = Tensor3::from_data(data_b, batch, k, n);
    let c_batch = batched_matmul(&a_batch, &b_batch)?;
    Ok(())
}

Module Structure

The oxiblas crate re-exports from these sub-crates:

Module Re-exported from Description
oxiblas::core oxiblas-core Core traits, SIMD, scalar types
oxiblas::matrix oxiblas-matrix Matrix types and views
oxiblas::blas oxiblas-blas BLAS operations
oxiblas::lapack oxiblas-lapack LAPACK decompositions
oxiblas::sparse oxiblas-sparse Sparse matrices and solvers (sparse feature, on by default)
oxiblas::ndarray oxiblas-ndarray ndarray integration (ndarray feature)
oxiblas-ffi RETIRED (v0.2.0) - C FFI bindings

The crate also defines oxiblas::builder (MatBuilder), oxiblas::fluent (method-chaining traits such as MatrixOps), oxiblas::auto (size- and structure-based algorithm selection, e.g. auto_matmul) and oxiblas::features (compile-time constants such as HAS_PARALLEL).

Prelude

The oxiblas::prelude module provides convenient imports:

use oxiblas::prelude::*;

// Now you have access to:
// - Mat, MatRef, MatMut (matrix types)
// - gemm, gemv, dot, axpy, etc. (BLAS operations)
// - Lu, Qr, Svd, Cholesky, etc. (LAPACK decompositions)
// - solve, inv, det, lstsq, etc. (LAPACK solvers and utilities)
// - CsrMatrix, CooMatrix, etc. (sparse matrices)
// - gmres, cg, pcg, bicgstab (sparse solvers; the others are in oxiblas::sparse::linalg)

Feature Flags

Feature Description Default
default std and sparse (f32, f64 and complex are always available) ✓
std Standard library support (forwarded to oxiblas-core and oxiblas-matrix) ✓
parallel Rayon-based parallelization, opt-in per call with Par::Rayon (see Parallel GEMM); implies std
f16 Half-precision (16-bit) floating point
f128 Quad precision with the double-double QuadFloat: about 31 digits for the arithmetic and sqrt, fewer for exp, ln and the other elementary functions
sparse Sparse matrix operations ✓
ndarray ndarray integration
serde Serialization support for matrix types
mmap Memory-mapped matrices for large datasets
nalgebra nalgebra type conversions
full parallel, f16, f128, ndarray, sparse, serde, mmap and nalgebra (not the SIMD flags and not sme2 below)
force-scalar Use the portable scalar GEMM kernel and report no SIMD level; on aarch64 also the portable DOT, NRM2, GEMV and TRSM/TRMM code
max-simd-128 Cap the GEMM kernel at 128-bit SIMD (SSE4.2/NEON)
max-simd-256 Cap the GEMM kernel at 256-bit SIMD (AVX2)
sme2 Opt-in SME2 backend for GEMM and GEMV on AArch64 CPUs with SME2 and a 512-bit streaming vector length (Apple M4 and later), forwarded to oxiblas-blas; not part of full; as released it has run only under emulation (QEMU), and an early state of its kernels passed its unit tests on an Apple M4 Pro except the floating-point status flag tests (a known limit on macOS)

The three SIMD flags are forwarded to oxiblas-core, oxiblas-blas and oxiblas-lapack. They take effect in the capability detection and in GEMM kernel selection. On aarch64, force-scalar also keeps the generic dot, nrm2 and cnrm2, gemv, the unit-stride cblas_?gemv and the TRSM/TRMM tile kernels on portable code, and the GEMM routes of 0.2.3 by default; the typed *_f64/*_f32 Level-1 kernels and the x86_64 Level-1 and gemv kernels pick AVX2 or NEON on their own and ignore the flags. All three SIMD flags keep the sme2 backend off at run time.

With sme2 the backend is used only when the operating system reports SME2 with a 512-bit streaming vector length and the first-use checks of its kernels pass; OXIBLAS_DISABLE_SME2 set to anything other than an empty string or 0 turns it off. features::HAS_SME2 says whether the backend is compiled in (the feature on AArch64), and oxiblas::blas::level3::sme2_active() whether the backend is active for the calling thread. See the CHANGELOG for what was verified and for the known limit about the floating-point status flags on macOS.

Note: oxiblas-ffi (C FFI bindings) was retired in v0.2.0 and is no longer a feature of this crate - see the Module Structure table above.

Examples

# Minimal (dense matrices only, no sparse support)
oxiblas = { version = "0.2", default-features = false, features = ["std"] }

# With parallelization
oxiblas = { version = "0.2", features = ["parallel"] }

# With extended precision
oxiblas = { version = "0.2", features = ["f16", "f128"] }

# With ndarray support
oxiblas = { version = "0.2", features = ["ndarray"] }

# All features
oxiblas = { version = "0.2", features = ["full"] }

# Opt-in SME2 backend (AArch64; not part of "full")
oxiblas = { version = "0.2", features = ["sme2"] }

Examples

The repository includes comprehensive examples (in crates/oxiblas/examples/):

# Basic BLAS operations
cargo run -p oxiblas --example basic_blas

# LAPACK decompositions
cargo run -p oxiblas --example lapack_decompositions

# Extended precision
cargo run -p oxiblas --example extended_precision --features f128

# Tensor operations
cargo run -p oxiblas --example tensor_operations

# Sparse matrices
cargo run -p oxiblas --example sparse_matrices

The timing examples (lu_bench, cholesky_bench, trmm_trsm_bench, syrk_syr2k_bench, symm_hemm_bench, complex_gemm_bench, evd_svd_bench, and parallel_bench with --features parallel) are meant to run with --release, for example cargo run --release -p oxiblas --example evd_svd_bench -- --reps 3 500 1000.

Performance

OxiBLAS uses BLIS-style blocked algorithms and hand-tuned SIMD micro-kernels. On an Apple M3 on one thread, f64 GEMM runs at 92-99% of OpenBLAS and f32 GEMM at 101-120%; Par::Rayon GEMM is level with OpenBLAS on 4 threads (95-103%) and ahead on 8 (115-169%). DOT, NRM2, GEMV, TRSM and SYRK were reworked in 0.2.3 (NEON Level-1/2 kernels on aarch64, a blocked TRSM, a triangle-only SYRK) and now run at 99% of OpenBLAS or faster on one thread, except GEMV at 5000×5000 (97%). These figures were measured on 0.2.3 and not again for 0.2.4. See Performance in the root README for the figures.

Actual performance depends heavily on operation, matrix size, and hardware (SIMD width, cache hierarchy, core count), so no single ratio is representative. Run the benchmark suite yourself for numbers reproducible on your own hardware:

# OxiBLAS-only benchmarks
cargo bench --package oxiblas-benchmarks

# Direct comparison against OpenBLAS (requires OpenBLAS installed)
cargo bench --package oxiblas-benchmarks --bench comparison --features compare-openblas

See the oxiblas-benchmarks README for details on the available benchmark suites.

Documentation

Sub-Crate Documentation

For more detailed documentation on specific components:

Ecosystem

OxiBLAS is part of the SciRS2 scientific computing ecosystem:

Requirements

  • Rust: 1.89+ (Edition 2024)
  • No C, C++ or Fortran in the normal or default dependencies; only the criterion (through alloca) and faer (through psm and generator) dev-dependencies of the benches and tests compile C or assembly
  • Supported platforms: x86_64, AArch64 (Linux, macOS, Windows)

License

Licensed under the Apache License, Version 2.0. See LICENSE for details.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Citation

If you use OxiBLAS in your research, please cite:

@software{oxiblas2026,
  author = {OxiBLAS Contributors},
  title = {OxiBLAS: Pure Rust BLAS/LAPACK Implementation},
  year = {2026},
  url = {https://github.com/cool-japan/oxiblas}
}

Dependencies