mdarray_linalg_blas/lib.rs
1//! Don’t forget to include a BLAS implementation:
2//! ```toml
3//! [dependencies]
4//! mdarray = "0.7.1"
5//! mdarray-linalg = "0.1"
6//! mdarray-linalg-blas = "0.1"
7//! openblas-src = { version = "0.10", features = ["system"] }
8//! ```
9//! The following example demonstrates the core functionality of BLAS:
10//! ```rust
11//! use mdarray::tensor;
12//! use mdarray_linalg::prelude::*; // Imports only traits
13//!
14//! use mdarray_linalg_blas::Blas;
15//!
16//! // Declare two vectors
17//! let x = tensor![1., 2.];
18//! let y = tensor![2., 4.];
19//!
20//! // Declare two matrices
21//! let a = tensor![[1., 2.], [3., 4.]];
22//! let b = tensor![[5., 6.], [7., 8.]];
23//!
24//! // ----- Vector operations -----
25//! let dot_result = Blas.dot(&x, &y);
26//! println!("dot(x, y) = {}", dot_result);
27//!
28//! let y_result = Blas.matvec(&a, &x).scale(2.).eval();
29//! println!("A * x * 2 = {:?}", y_result);
30//!
31//! // ----- Matrix multiplication -----
32//! let c = Blas.matmul(&a, &b).eval();
33//! println!("A * B = {:?}", c);
34//!
35//!
36//! // ----- Contract: full contraction between two 3D tensors -----
37//! let a = tensor![
38//! [[1., 2.], [3., 4.]],
39//! [[5., 6.], [7., 8.]]
40//! ].into_dyn();
41//!
42//! let b = tensor![
43//! [[9., 10.], [11., 12.]],
44//! [[13., 14.], [15., 16.]]
45//! ].into_dyn();
46//!
47//! let result = Blas.contract_all(&a, &b).eval();
48//! println!("Full contraction result (tensordot over all axes): {:?}", result);
49//! ```
50
51pub mod matmul;
52pub use matmul::{gemm, gemm_uninit};
53pub mod matvec;
54
55#[derive(Default)]
56pub struct Blas;