diffsol_la/lib.rs
1//! # diffsol-la
2//!
3//! Linear algebra traits and backends for [diffsol](https://github.com/martinjrobins/diffsol).
4//!
5//! This crate provides the vector, matrix, and linear-solver abstractions used by
6//! diffsol, together with concrete implementations backed by
7//! [nalgebra](https://nalgebra.org), [faer](https://github.com/sarah-ek/faer-rs),
8//! suitesparse (KLU), and CUDA.
9
10/// Context objects for managing device resources for vectors and matrices (e.g. device streams, threading pools, etc.).
11///
12/// This module provides context types that encapsulate information about where data is stored and computed
13/// (CPU, GPU, etc.). Different backends like nalgebra and faer may require different context implementations.
14/// The [Context] trait defines the interface that must be implemented.
15pub mod context;
16
17/// Error types and handling.
18///
19/// This module defines the [LaError] enum and specialized error variants for
20/// the linear algebra layer, including matrix, linear-solver, and (optional)
21/// CUDA errors.
22pub mod error;
23
24/// The [LinearOp] trait describing a linear operator `A` for use with [LinearSolver].
25pub mod linear_op;
26
27/// Linear solver implementations and traits.
28///
29/// This module defines the [LinearSolver] trait for solving linear systems and provides implementations:
30/// - Direct solvers: [NalgebraLU], [FaerLU], [FaerSparseLU]
31/// - Optional sparse solvers: `KLU` (requires `suitesparse` feature)
32/// - GPU solvers: `CudaLU` (requires `cuda` feature)
33///
34/// The linear solver is a critical component used internally by nonlinear solvers to solve Newton systems.
35pub mod linear_solver;
36
37/// Matrix types and operations.
38///
39/// This module defines the [Matrix] trait and related traits for matrix operations:
40/// - [DenseMatrix] for dense column-major matrices
41/// - [MatrixView] and [MatrixViewMut] for borrowed views
42/// - Sparsity detection and handling
43///
44/// Implementations are provided for:
45/// - Dense matrices: [NalgebraMat], [FaerMat]
46/// - Sparse matrices: [FaerSparseMat]
47/// - GPU matrices: `CudaMat` (requires `cuda` feature)
48pub mod matrix;
49
50/// Scalar types and traits.
51///
52/// This module defines the [Scalar] trait that all floating-point types used in DiffSol must implement.
53/// It aggregates requirements from nalgebra, faer, and num_traits to ensure compatibility with linear algebra operations.
54///
55/// Implementations are provided for `f32` and `f64`.
56/// GPU scalar types are available via `ScalarCuda` (requires `cuda` feature).
57pub mod scalar;
58
59/// Vector types and traits.
60///
61/// This module defines the [Vector] trait and related traits for vector operations:
62/// - [VectorView] and [VectorViewMut] for borrowed views
63/// - [VectorIndex] for index collections
64/// - [VectorHost] for CPU-resident vectors with direct access
65///
66/// Implementations are provided for:
67/// - [NalgebraVec] using nalgebra vectors
68/// - [FaerVec] using faer vectors
69/// - `CudaVec` for GPU computation (requires `cuda` feature)
70pub mod vector;
71
72pub use error::LaError;
73
74pub use context::{faer::FaerContext, nalgebra::NalgebraContext, Context};
75
76pub use linear_op::LinearOp;
77pub use linear_solver::LinearSolver;
78pub use linear_solver::{faer::sparse_lu::FaerSparseLU, FaerLU, NalgebraLU};
79
80#[cfg(feature = "suitesparse")]
81pub use linear_solver::suitesparse::klu::KLU;
82
83pub use matrix::{
84 default_solver::DefaultSolver, dense_faer_serial::FaerMat, dense_nalgebra_serial::NalgebraMat,
85 sparse_faer::FaerSparseMat, DenseMatrix, Matrix, MatrixCommon,
86};
87
88pub(crate) use matrix::extract_block::ColMajBlock;
89pub use matrix::{
90 sparsity::Dense, sparsity::DenseRef, sparsity::MatrixSparsity, sparsity::MatrixSparsityRef,
91 MatrixHost, MatrixRef, MatrixView, MatrixViewMut,
92};
93
94pub use scalar::{scale, FaerScalar, IndexType, NalgebraScalar, Scalar, Scale};
95
96pub use vector::DefaultDenseMatrix;
97pub use vector::{
98 faer_serial::{FaerVec, FaerVecIndex, FaerVecMut, FaerVecRef},
99 nalgebra_serial::{NalgebraVec, NalgebraVecMut, NalgebraVecRef},
100 Vector, VectorCommon, VectorHost, VectorIndex, VectorRef, VectorView, VectorViewMut,
101};
102
103#[cfg(feature = "cuda")]
104pub use context::cuda::CudaContext;
105#[cfg(feature = "cuda")]
106pub use linear_solver::cuda::lu::CudaLU;
107#[cfg(feature = "cuda")]
108pub use matrix::cuda::{CudaMat, CudaMatMut, CudaMatRef};
109#[cfg(feature = "cuda")]
110pub use scalar::cuda::{CudaType, ScalarCuda};
111#[cfg(feature = "cuda")]
112pub use vector::cuda::{CudaIndex, CudaVec, CudaVecMut, CudaVecRef};