differential_equations/linalg/
error.rs1use crate::{
4 error,
5 traits::{Real, State},
6};
7
8#[derive(Debug, Clone, PartialEq)]
10pub enum LinalgError {
11 BadInput { message: String },
13 Singular { step: usize },
15 PivotSizeMismatch { expected: usize, actual: usize },
17}
18
19impl std::fmt::Display for LinalgError {
20 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21 match self {
22 LinalgError::BadInput { message } => {
23 write!(f, "Linear algebra input error: {}", message)
24 }
25 LinalgError::Singular { step } => write!(f, "Matrix is singular at step {}", step),
26 LinalgError::PivotSizeMismatch { expected, actual } => {
27 write!(
28 f,
29 "Pivot vector size mismatch: expected {}, got {}",
30 expected, actual
31 )
32 }
33 }
34 }
35}
36
37impl std::error::Error for LinalgError {}
38
39impl<T, Y> From<LinalgError> for error::Error<T, Y>
41where
42 T: Real,
43 Y: State<T>,
44{
45 fn from(err: LinalgError) -> Self {
46 error::Error::LinearAlgebra {
48 msg: err.to_string(),
49 }
50 }
51}