Skip to main content

antecedent_prob/
error.rs

1//! Probability / inference errors.
2//!
3//! SPDX-License-Identifier: MIT OR Apache-2.0
4
5use core::fmt;
6
7/// Errors from prior construction, posterior storage, or inference backends.
8#[derive(Clone, Debug, Eq, PartialEq)]
9pub enum ProbError {
10    /// Shape / dimension mismatch.
11    Shape {
12        /// Context.
13        message: &'static str,
14    },
15    /// Invalid prior or configuration.
16    InvalidPrior {
17        /// Context.
18        message: &'static str,
19    },
20    /// Inference failed to converge or produce a usable approximation.
21    Inference {
22        /// Context.
23        message: &'static str,
24    },
25    /// Numerical failure (singular Hessian, separation, etc.).
26    Numerical {
27        /// Context.
28        message: String,
29    },
30    /// Missing required diagnostics for a reported posterior.
31    MissingDiagnostics {
32        /// Context.
33        message: String,
34    },
35}
36
37impl fmt::Display for ProbError {
38    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39        match self {
40            Self::Shape { message } => write!(f, "shape error: {message}"),
41            Self::InvalidPrior { message } => write!(f, "invalid prior: {message}"),
42            Self::Inference { message } => write!(f, "inference error: {message}"),
43            Self::Numerical { message } => write!(f, "numerical error: {message}"),
44            Self::MissingDiagnostics { message } => {
45                write!(f, "missing diagnostics: {message}")
46            }
47        }
48    }
49}
50
51impl std::error::Error for ProbError {}