Skip to main content

differential_equations/linalg/
error.rs

1//! Linear algebra error types.
2
3/// Errors that can occur during linear algebra operations.
4#[derive(Debug, Clone, PartialEq)]
5pub enum LinalgError {
6    /// Input validation error (e.g., non-square matrix, mismatched dimensions)
7    BadInput { message: String },
8    /// Matrix is singular at the given step (1-indexed)
9    Singular { step: usize },
10    /// Pivot vector has incorrect size
11    PivotSizeMismatch { expected: usize, actual: usize },
12}
13
14impl std::fmt::Display for LinalgError {
15    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16        match self {
17            LinalgError::BadInput { message } => {
18                write!(f, "Linear algebra input error: {}", message)
19            }
20            LinalgError::Singular { step } => write!(f, "Matrix is singular at step {}", step),
21            LinalgError::PivotSizeMismatch { expected, actual } => {
22                write!(
23                    f,
24                    "Pivot vector size mismatch: expected {}, got {}",
25                    expected, actual
26                )
27            }
28        }
29    }
30}
31
32impl std::error::Error for LinalgError {}