oxiblas-ndarray
ndarray integration for OxiBLAS
Overview
oxiblas-ndarray provides seamless integration between OxiBLAS and the ndarray crate, enabling you to use high-performance BLAS/LAPACK operations on ndarray arrays.
Features
- Zero-copy conversions between
ndarray::Arrayandoxiblas_matrix::Mat - BLAS operations on ndarray arrays
- LAPACK decompositions (LU, QR, SVD, Cholesky, etc.)
- Type-safe API leveraging Rust's type system
- Compatible with existing ndarray code
Installation
[]
= "0.1"
Usage
BLAS Operations
use Array2;
use NdarrayExt;
// Create ndarray matrices
let a = from_shape_vec.unwrap;
let b = from_shape_vec.unwrap;
// Matrix multiplication using OxiBLAS
let c = a.gemm?;
// c = [[58, 64], [139, 154]]
// Or use method syntax
let c = a.matmul?;
Decompositions
use Array2;
use NdarrayExt;
let a = from_shape_vec.unwrap;
// LU decomposition
let lu = a.lu?;
let det = lu.determinant;
let inv = lu.inverse?;
// Solve Ax = b
let b = from_vec;
let x = lu.solve?;
// QR decomposition
let qr = a.qr?;
let q = qr.q;
let r = qr.r;
// SVD
let svd = a.svd?;
let singular_values = svd.singular_values;
let u = svd.u;
let vt = svd.vt;
// Cholesky (for SPD matrices)
let chol = a.cholesky?;
let l = chol.l;
Linear Solvers
use ;
use NdarrayExt;
let a = from_shape_vec.unwrap;
let b = from_vec;
// Solve linear system
let x = a.solve?;
// x = [1.0, 3.0]
// Multiple right-hand sides
let b_multi = from_shape_vec.unwrap;
let x_multi = a.solve_multiple?;
Conversions
use Array2;
use Mat;
use ;
// ndarray -> oxiblas
let nd = zeros;
let ox = from_ndarray;
// oxiblas -> ndarray
let ox = zeros;
let nd = ox.to_ndarray;
// Zero-copy views (when possible)
let nd = zeros;
let ox_view = from_ndarray_view;
Performance
All operations use OxiBLAS's optimized SIMD kernels:
- GEMM: 80-172% of OpenBLAS performance
- Zero-copy when data layout permits
- Column-major conversion handled automatically
API Reference
Extension Trait
The NdarrayExt trait extends Array2<T> with BLAS/LAPACK methods:
Conversion Traits
Examples
Comparison with ndarray-linalg
| Feature | oxiblas-ndarray | ndarray-linalg |
|---|---|---|
| Pure Rust | ✓ | |
| No C dependencies | ✓ | |
| BLAS/LAPACK | ✓ | ✓ |
| OpenBLAS backend | ✓ | |
| Intel MKL backend | ✓ | |
| Custom backend | ✓ (OxiBLAS) | |
| Performance | 80-172% OpenBLAS | 100% (uses OpenBLAS) |
| Cross-compilation | Easy | Difficult |
Related Crates
ndarray- N-dimensional arraysoxiblas- Core BLAS/LAPACK implementationoxiblas-matrix- Matrix types
License
Licensed under MIT or Apache-2.0 at your option.