Skip to main content

uncertain_numerics/
conditioning_error.rs

1use core::fmt;
2
3/// Errors raised while constructing or using a Gaussian conditioning system.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum ConditioningError {
6    /// The requested matrix dimension is zero.
7    ZeroDimension,
8    /// The flattened matrix length does not equal `dimension * dimension`.
9    MatrixDimensionMismatch,
10    /// At least one matrix entry is not finite.
11    NonFiniteMatrixEntry,
12    /// The jitter value is not finite.
13    NonFiniteJitter,
14    /// The jitter value is negative.
15    NegativeJitter,
16    /// Cholesky factorization failed because the regularized matrix is not positive definite.
17    NotPositiveDefinite,
18    /// The right-hand-side length does not equal the matrix dimension.
19    RightHandSideDimensionMismatch,
20    /// At least one right-hand-side entry is not finite.
21    NonFiniteRightHandSideEntry,
22}
23
24impl fmt::Display for ConditioningError {
25    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26        match self {
27            Self::ZeroDimension => write!(f, "conditioning matrix dimension must be positive"),
28            Self::MatrixDimensionMismatch => write!(
29                f,
30                "flattened conditioning matrix length must equal dimension squared"
31            ),
32            Self::NonFiniteMatrixEntry => {
33                write!(f, "conditioning matrix entries must be finite")
34            }
35            Self::NonFiniteJitter => write!(f, "conditioning jitter must be finite"),
36            Self::NegativeJitter => {
37                write!(f, "conditioning jitter must be non-negative")
38            }
39            Self::NotPositiveDefinite => write!(
40                f,
41                "conditioning matrix is not positive definite after applying jitter"
42            ),
43            Self::RightHandSideDimensionMismatch => write!(
44                f,
45                "right-hand-side length must equal conditioning matrix dimension"
46            ),
47            Self::NonFiniteRightHandSideEntry => {
48                write!(f, "right-hand-side entries must be finite")
49            }
50        }
51    }
52}
53
54impl std::error::Error for ConditioningError {}