pub mod batched_eigh_gpu;
pub mod cholesky;
pub mod eigh;
pub mod eigh_f64;
pub mod gemm_f64;
pub mod gen_eigh_gpu;
pub mod grid_quadrature_gemm_f64; pub mod inverse_f64;
pub mod linsolve;
pub mod linsolve_f64;
pub mod lu;
pub mod lu_gpu;
pub mod qr;
pub mod qr_gpu;
pub mod svd;
pub mod svd_gpu;
pub mod triangular_solve;
pub mod tridiagonal;
pub use batched_eigh_gpu::BatchedEighGpu;
pub use cholesky::Cholesky;
pub use eigh::Eigh;
pub use eigh_f64::{EighDecompositionF64, eigh_householder_qr};
pub use gemm_f64::{GemmCachedF64, GemmF64};
pub use gen_eigh_gpu::{GenEighDecompositionGpu, GenEighGpu};
pub use grid_quadrature_gemm_f64::GridQuadratureGemm;
pub use inverse_f64::InverseF64;
pub use linsolve::LinSolve;
pub use linsolve_f64::LinSolveF64;
pub use lu::{LuDecomposition, lu_decompose, lu_det, lu_inverse, lu_solve};
pub use lu_gpu::LuGpu;
pub use qr::{QrDecomposition, qr_decompose, qr_least_squares};
pub use qr_gpu::QrGpu;
pub use svd::{SvdDecomposition, svd_decompose, svd_pinv, svd_values};
pub use svd_gpu::SvdGpu;
pub use triangular_solve::{TriangularSolve, TriangularSolveF64};
pub use tridiagonal::{tridiagonal_solve, tridiagonal_solve_batch, tridiagonal_solve_f32};
pub use cholesky::CholeskyF64;
const WGSL_SYMMETRIZE_F64: &str = include_str!("../../shaders/linalg/symmetrize_f64.wgsl");
const WGSL_LAPLACIAN_F64: &str = include_str!("../../shaders/linalg/laplacian_f64.wgsl");
static WGSL_SYMMETRIZE: std::sync::LazyLock<String> =
std::sync::LazyLock::new(|| WGSL_SYMMETRIZE_F64.to_string());
static WGSL_LAPLACIAN: std::sync::LazyLock<String> =
std::sync::LazyLock::new(|| WGSL_LAPLACIAN_F64.to_string());
#[must_use]
pub fn wgsl_symmetrize() -> &'static str {
&WGSL_SYMMETRIZE
}
#[must_use]
pub fn wgsl_laplacian() -> &'static str {
&WGSL_LAPLACIAN
}
pub struct SymmetrizeGpu {
device: std::sync::Arc<crate::device::WgpuDevice>,
}
impl SymmetrizeGpu {
pub fn new(device: std::sync::Arc<crate::device::WgpuDevice>) -> crate::error::Result<Self> {
Ok(Self { device })
}
pub fn execute(&self, matrix: &[f64], n: usize) -> crate::error::Result<Vec<f64>> {
use crate::device::compute_pipeline::ComputeDispatch;
let input_buf = self.device.create_buffer_f64_init("symmetrize:in", matrix);
let output_buf = self.device.create_buffer_f64(n * n)?;
let dim = n as u32;
let params_buf = self.device.create_uniform_buffer("symmetrize:dim", &dim);
let wg = (n as u32).div_ceil(16);
ComputeDispatch::new(&self.device, "symmetrize")
.shader(WGSL_SYMMETRIZE_F64, "symmetrize")
.f64()
.storage_read(0, &input_buf)
.storage_rw(1, &output_buf)
.uniform(2, ¶ms_buf)
.dispatch(wg, wg, 1)
.submit()?;
self.device.read_f64_buffer(&output_buf, n * n)
}
}
pub struct LaplacianGpu {
device: std::sync::Arc<crate::device::WgpuDevice>,
}
impl LaplacianGpu {
pub fn new(device: std::sync::Arc<crate::device::WgpuDevice>) -> crate::error::Result<Self> {
Ok(Self { device })
}
pub fn execute(&self, adjacency: &[f64], n: usize) -> crate::error::Result<Vec<f64>> {
use crate::device::compute_pipeline::ComputeDispatch;
let input_buf = self
.device
.create_buffer_f64_init("laplacian:in", adjacency);
let output_buf = self.device.create_buffer_f64(n * n)?;
let dim = n as u32;
let params_buf = self.device.create_uniform_buffer("laplacian:dim", &dim);
let wg = (n as u32).div_ceil(16);
ComputeDispatch::new(&self.device, "graph_laplacian")
.shader(WGSL_LAPLACIAN_F64, "graph_laplacian")
.f64()
.storage_read(0, &input_buf)
.storage_rw(1, &output_buf)
.uniform(2, ¶ms_buf)
.dispatch(wg, wg, 1)
.submit()?;
self.device.read_f64_buffer(&output_buf, n * n)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn symmetrize_shader_source_valid() {
let source = wgsl_symmetrize();
assert!(!source.is_empty());
assert!(source.contains("fn main") || source.contains("@compute"));
}
#[test]
fn laplacian_shader_source_valid() {
let source = wgsl_laplacian();
assert!(!source.is_empty());
assert!(source.contains("fn main") || source.contains("@compute"));
}
}