Crate ndarray_rblas [−] [src]
Experimental rblas
and BLAS (Basic Linear Algebra Subprograms) integration
Note: This crate is for explicitly integrating with the rblas
crate and its API. ndarray can use BLAS by itself too.
Depends on crate rblas
, (docs).
extern crate ndarray; extern crate ndarray_rblas; extern crate rblas; use rblas::Gemv; use rblas::attribute::Transpose; use ndarray::{arr1, arr2}; use ndarray_rblas::AsBlas; fn main() { // Gemv is the operation y = α a x + β y let alpha = 1.; let mut a = arr2(&[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]]); let x = [1., 0., 1.]; let beta = 1.; let mut y = arr1(&[0., 0., 0.]); Gemv::gemv(Transpose::NoTrans, &alpha, &a.blas(), &x[..], &beta, &mut y.blas()); assert_eq!(y, arr1(&[4., 10., 16.])); }
Use the methods in trait AsBlas
to convert an array into a view that
implements rblas’ Vector
or Matrix
traits.
Blas supports strided vectors and matrices; Matrices need to be contiguous
in their lowest dimension, so they will be copied into c-contiguous layout
automatically if needed. You should be able to use blocks sliced out
from a larger matrix without copying. Use the transpose flags in blas
instead of transposing with ndarray
.
Blas has its own error reporting system and will not panic on errors (that I know), instead output its own error conditions, for example on dimension mismatch in a matrix multiplication.
Structs
BlasArrayView |
Requires crate feature |
BlasArrayViewMut |
Requires crate feature |
Traits
AsBlas |
Convert an array into a blas friendly wrapper. |