1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
//! # mdarray_linalg_lapack
//!
//! LAPACK backend for [`mdarray_linalg`].
//!
//! This crate provides the [`Lapack`] struct that implements the decomposition and
//! solver traits defined by [`mdarray_linalg`], delegating computations to a LAPACK
//! implementation (e.g. OpenBLAS) via the `lapack-sys` and `cblas-sys` crates.
//!
//! Backend implementation modules are private. Use [`Lapack`] together with the
//! operation traits from `mdarray_linalg::prelude::*`.
//!
//! ## Scope
//!
//! The LAPACK backend covers:
//!
//! - **Eigenvalue decomposition** — `eig`, `eig_full`, `eig_values`, `eigh`
//! - **Schur decomposition** — `schur`, `schur_complex`
//! - **SVD** — `svd`, `svd_thin`, `svd_s`
//! - **LU decomposition** — `lu`, `det`, `inv`
//! - **Cholesky decomposition** — `cholesky`
//! - **QR decomposition** — `qr`
//! - **Linear system solving** — `solve`
//!
//! For basic matrix/vector operations (Level 1–3 BLAS) and tensor contractions,
//! use the [`mdarray_linalg_blas`] or [`mdarray_linalg_faer`] backends instead.
//!
//! ## Setup
//!
//! This crate binds to the LAPACK/BLAS ABI but does not choose a native library to link against.
//! This is left to the user. For example, to use a system OpenBLAS installation:
//!
//! ```bash
//! cargo add mdarray mdarray-linalg mdarray-linalg-lapack
//! cargo add lapack-src --features openblas
//! cargo add openblas-src --features system
//! ```
//!
//! In one of your Rust crates, reference the provider so its link directives are
//! included:
//!
//! ```rust
//! extern crate lapack_src as _;
//! ```
//!
//! Other LAPACK providers may be used if they expose the symbols required by
//! `lapack-sys` and `cblas-sys`.
//!
//! ## Example
//!
//! All operations are accessed through the [`Lapack`] backend via the traits from
//! `mdarray_linalg::prelude::*`:
//!
//! ```rust
//! # extern crate lapack_src as _;
//! use mdarray::array;
//! use mdarray_linalg::prelude::*;
//! use mdarray_linalg::eig::EigDecomp;
//! use mdarray_linalg::solve::Solve;
//! use mdarray_linalg::svd::SVDDecomp;
//! use mdarray_linalg_lapack::Lapack;
//!
//! // ----- Eigenvalue decomposition -----
//! let mut a = array![[1., 2.], [3., 4.]];
//! let EigDecomp {
//! eigenvalues: lambda,
//! right_eigenvectors,
//! ..
//! } = Lapack::new().eig(&mut a.clone()).expect("Eigenvalue decomposition failed");
//!
//! println!("Eigenvalues: {:?}", lambda);
//! if let Some(v) = right_eigenvectors {
//! println!("Right eigenvectors: {:?}", v);
//! }
//!
//! // ----- SVD -----
//! let mut a = array![[1., 2.], [3., 4.]];
//! let SVDDecomp { s, u, vt } = Lapack::new().svd_thin(&mut a).expect("SVD failed");
//! println!("Singular values: {:?}", s);
//!
//! // ----- QR decomposition -----
//! let mut a = array![[12., -51., 4.], [6., 167., -68.], [-4., 24., -41.]];
//! let (q, r) = Lapack::new().qr(&mut a);
//! println!("Q: {:?}", q);
//! println!("R: {:?}", r);
//!
//! // ----- Solve linear system Ax = b -----
//! let mut a = array![[2., 1., 0.], [1., 3., 1.], [0., 1., 2.]];
//! let b = array![[1., 0., 0.], [2., 0., 0.], [1., 0., 0.]];
//! let x = Lapack::new().solve(&mut a, &b).expect("Solve failed");
//! println!("x = {:?}", x);
//! ```
//!
//! > **Note:** Decomposition routines (eig, svd, lu, etc.) **destroy the input matrix**.
//! > Always pass a clone if you need the original data.
//!
//! ## Currently supported types
//!
//! `f32`, `f64`, `Complex<f32>`, `Complex<f64>`.
//!
//! ## Troubleshooting
//!
//! Linking errors usually mean that no LAPACK/BLAS implementation was linked
//! into the final binary, or that the selected libraries are not in the
//! linker/runtime search path. Add a source crate such as `lapack-src`,
//! reference it from Rust code, or provide equivalent link flags from your
//! application `build.rs`.
//!
// Keep the doc-comment blank line above: these reference definitions must start
// a separate Markdown block from the preceding paragraph.
extern crate lapack_src as _;
/// Configuration for the SVD algorithm.
///
/// This is hidden while backend configuration is being reconsidered.
/// Configuration for the QR decomposition.
///
/// This is hidden while backend configuration is being reconsidered.
/// LAPACK backend.
///
/// Implements the decomposition and solver traits from [`mdarray_linalg`] by
/// delegating to LAPACK routines.