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
// SPDX-License-Identifier: AGPL-3.0-or-later
//! Linear algebra operations for scientific computing
//!
//! This module provides f64 linear algebra operations dispatched to GPU
//! shaders. All production math uses GPU (no CPU-only paths).
//!
//! # Available Operations
//!
//! ## Dense Decompositions
//!
//! - [`lu_decompose`] - LU decomposition with partial pivoting (PA = LU)
//! - [`qr_decompose`] - QR decomposition via Householder reflections
//! - [`svd_decompose`] - Singular value decomposition (A = `UΣVᵀ`)
//! - [`cholesky_f64`] - Cholesky decomposition for SPD matrices (A = `LLᵀ`)
//! - [`eigh_f64`] - Eigendecomposition for symmetric matrices (A = `VDVᵀ`)
//! - [`gen_eigh_f64`] - Generalized eigenvalue problem Ax = λBx
//!
//! ## Dense Solvers
//!
//! - [`solve_f64`] - General linear solve via Gauss-Jordan (GPU)
//! - [`solve_f64_cpu`] - CPU fallback for small matrices (no GPU required)
//! - [`lu_solve`] - Linear solve via LU decomposition
//! - [`qr_least_squares`] - Least squares via QR
//! - [`tridiagonal_solve_f64`] - Thomas algorithm for tridiagonal systems
//!
//! ## Sparse Operations ([`sparse`] module)
//!
//! For large-scale problems (HFB basis sets, finite elements):
//!
//! - [`sparse::CsrMatrix`] - Compressed sparse row format
//! - [`sparse::CooMatrix`] - Coordinate format (for construction)
//! - [`sparse::cg_solve`] - Conjugate gradient (SPD matrices)
//! - [`sparse::bicgstab_solve`] - `BiCGSTAB` (general matrices)
//! - [`sparse::jacobi_solve`] - Jacobi iteration
//!
//! ## Utilities
//!
//! - [`lu_det`] - Determinant via LU
//! - [`lu_inverse`] - Matrix inverse via LU
//! - [`svd_pinv`] - Pseudoinverse via SVD
//!
//! # Examples
//!
//! ```no_run
//! use barracuda::linalg::{solve_f64, lu_decompose, qr_decompose};
//! use barracuda::prelude::WgpuDevice;
//! use std::sync::Arc;
//!
//! # async fn example() -> barracuda::error::Result<()> {
//! let device = Arc::new(WgpuDevice::new().await?);
//! let a = vec![2.0, 1.0, 1.0, 3.0];
//! let b = vec![5.0, 8.0];
//! let x = solve_f64(device.clone(), &a, &b, 2)?;
//! // LU decomposition for multiple solves
//! let lu = lu_decompose(&a, 2)?;
//! let _det = lu.det();
//! let _x2 = lu.solve(&b)?;
//! // QR for least squares
//! let a_overdetermined = vec![1.0, 1.0, 1.0, 2.0, 1.0, 3.0];
//! let _qr = qr_decompose(&a_overdetermined, 3, 2)?;
//! # Ok(())
//! # }
//! ```
// CPU-only linear algebra (always available)
pub use ;
pub use ;
pub use ;
// GPU-dependent linear algebra (requires "gpu" feature)
pub use cratetridiagonal_solve;
pub use cratetridiagonal_solve as tridiagonal_solve_f64;
pub use crate;
pub use crate;
pub use crate;
pub use cholesky_f64;
pub use eigh_f64;
pub use ;
pub use ;
pub use ;