uncertain_numerics/
bayesian_quadrature_error.rs1use core::fmt;
2
3use crate::{ConditioningError, PosteriorError};
4
5#[derive(Debug, Clone, Copy, PartialEq)]
7pub enum BayesianQuadratureError {
8 EmptyObservations,
10 ObservationLengthMismatch,
12 NonFiniteObservationNode,
14 NonFiniteObservationValue,
16 Conditioning(ConditioningError),
18 Posterior(PosteriorError),
20 MateriallyNegativePosteriorVariance {
22 value: f64,
24 tolerance: f64,
26 },
27}
28
29impl fmt::Display for BayesianQuadratureError {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 match self {
32 Self::EmptyObservations => write!(f, "at least one observation is required"),
33 Self::ObservationLengthMismatch => {
34 write!(f, "observation nodes and values must have equal lengths")
35 }
36 Self::NonFiniteObservationNode => {
37 write!(f, "observation nodes must be finite")
38 }
39 Self::NonFiniteObservationValue => {
40 write!(f, "observed function values must be finite")
41 }
42 Self::Conditioning(error) => write!(f, "Gaussian conditioning failed: {error}"),
43 Self::Posterior(error) => write!(f, "posterior construction failed: {error}"),
44 Self::MateriallyNegativePosteriorVariance { value, tolerance } => write!(
45 f,
46 "posterior variance {value:.16e} is negative beyond roundoff tolerance {tolerance:.16e}"
47 ),
48 }
49 }
50}
51
52impl std::error::Error for BayesianQuadratureError {
53 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
54 match self {
55 Self::Conditioning(error) => Some(error),
56 Self::Posterior(error) => Some(error),
57 _ => None,
58 }
59 }
60}
61
62impl From<ConditioningError> for BayesianQuadratureError {
63 fn from(error: ConditioningError) -> Self {
64 Self::Conditioning(error)
65 }
66}
67
68impl From<PosteriorError> for BayesianQuadratureError {
69 fn from(error: PosteriorError) -> Self {
70 Self::Posterior(error)
71 }
72}