Skip to main content

uncertain_numerics/
active_error.rs

1use core::fmt;
2
3use crate::BayesianQuadratureError;
4
5/// Errors raised while selecting active Bayesian-quadrature candidates.
6#[derive(Debug, Clone, Copy, PartialEq)]
7pub enum ActiveSelectionError {
8    /// No candidate points were supplied.
9    EmptyCandidates,
10    /// At least one candidate is not finite.
11    NonFiniteCandidate,
12    /// Acquisition evaluation failed for the current design.
13    Acquisition(BayesianQuadratureError),
14}
15
16impl fmt::Display for ActiveSelectionError {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        match self {
19            Self::EmptyCandidates => write!(f, "at least one candidate is required"),
20            Self::NonFiniteCandidate => write!(f, "candidate points must be finite"),
21            Self::Acquisition(error) => write!(f, "acquisition evaluation failed: {error}"),
22        }
23    }
24}
25
26impl std::error::Error for ActiveSelectionError {
27    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
28        match self {
29            Self::Acquisition(error) => Some(error),
30            _ => None,
31        }
32    }
33}
34
35impl From<BayesianQuadratureError> for ActiveSelectionError {
36    fn from(error: BayesianQuadratureError) -> Self {
37        Self::Acquisition(error)
38    }
39}