Skip to main content

Crate oxiblas_ndarray

Crate oxiblas_ndarray 

Source
Expand description

OxiBLAS ndarray Integration

This crate provides seamless integration between OxiBLAS and the ndarray crate, allowing you to use OxiBLAS BLAS and LAPACK operations directly on ndarray types.

§Features

  • Conversions: Efficient conversion between ndarray and OxiBLAS matrix types
  • BLAS Operations: Level 1-3 BLAS operations (dot, gemv, gemm, etc.)
  • LAPACK Operations: Decompositions (LU, QR, SVD, EVD, Cholesky)
  • Linear Solve: Direct and iterative solvers

§Quick Start

use ndarray::{array, Array2};
use oxiblas_ndarray::prelude::*;

// Matrix multiplication
let a = Array2::from_shape_fn((2, 3), |(i, j)| (i * 3 + j + 1) as f64);
let b = Array2::from_shape_fn((3, 2), |(i, j)| (i * 2 + j + 1) as f64);
let c = matmul(&a, &b);
assert_eq!(c.dim(), (2, 2));

// Matrix-vector multiplication
let x = array![1.0f64, 2.0, 3.0];
let y = matvec(&a, &x);
assert_eq!(y.len(), 2);

// Dot product
let v1 = array![1.0f64, 2.0, 3.0];
let v2 = array![4.0f64, 5.0, 6.0];
let d = dot_ndarray(&v1, &v2);
assert!((d - 32.0).abs() < 1e-10);

§LAPACK Operations

use ndarray::array;
use oxiblas_ndarray::prelude::*;

// Solve linear system
let a = array![[2.0f64, 1.0], [1.0, 3.0]];
let b = array![5.0f64, 7.0];
let x = solve_ndarray(&a, &b).unwrap();

// LU decomposition
let lu = lu_ndarray(&a).unwrap();
let det = lu.det();  // Determinant

// QR decomposition
let qr = qr_ndarray(&a).unwrap();

// SVD
let svd = svd_ndarray(&a).unwrap();

// Symmetric eigenvalue decomposition
let evd = eig_symmetric(&a).unwrap();

§Memory Layout

OxiBLAS uses column-major (Fortran) order internally. This crate handles both row-major and column-major ndarray layouts, but be aware of which conversion path a given API uses:

  • The BLAS/LAPACK convenience wrappers in this crate (e.g. matmul, lu_ndarray, qr_ndarray, solve_ndarray, …) internally build an owned oxiblas_matrix::Mat, via conversions::array2_to_mat. That is always a copying conversion - Mat allocates its own cache-line-aligned, potentially padded buffer that cannot adopt ndarray’s Vec-backed storage - so a copy happens whether the source array is row-major, column-major, or otherwise strided.
  • Only the explicit view conversions in conversions - e.g. conversions::array_view_to_mat_ref, conversions::array_view_mut_to_mat_mut, conversions::array_viewd_to_mat_ref - are genuinely zero-copy: they borrow the source array’s existing buffer as a MatRef/MatMut with no allocation, when the array is contiguous along one axis with a non-negative stride (None otherwise). Use these directly if you are writing your own numerical code against MatRef/MatMut and want to avoid a copy.

Column-major arrays remain the preferred layout for interop with other Fortran-order tooling and for the zero-copy view conversions above; the convenience wrappers themselves copy the same way regardless of layout:

use ndarray::{Array2, ShapeBuilder};
use oxiblas_ndarray::prelude::*;

// Create column-major array (preferred)
let a: Array2<f64> = zeros_f(100, 100);
assert!(is_column_major(&a));

// Or convert existing row-major array
let row_major = Array2::<f64>::zeros((100, 100));
let col_major = to_column_major(&row_major);

Modules§

blas
BLAS operations on ndarray types.
conversions
Conversion utilities between ndarray and OxiBLAS types.
lapack
LAPACK decompositions and operations on ndarray types.
parallel
Parallel BLAS operations on ndarray types.
prelude
Prelude module for convenient imports.
sparse
Sparse matrix integration with ndarray types.

Functions§

IxDyn
Create a dynamic-dimensional index

Type Aliases§

Array1
one-dimensional array
Array2
two-dimensional array
ArrayD
dynamic-dimensional array
ArrayView1
one-dimensional array view
ArrayView2
two-dimensional array view
ArrayViewD
dynamic-dimensional array view
ArrayViewMut1
one-dimensional read-write array view
ArrayViewMut2
two-dimensional read-write array view
ArrayViewMutD
dynamic-dimensional read-write array view
Complex32
Alias for a Complex<f32>
Complex64
Alias for a Complex<f64>
IxDyn
dynamic-dimensional