Skip to main content

antecedent_stats/
error.rs

1//! Stats-layer errors.
2//!
3//! SPDX-License-Identifier: MIT OR Apache-2.0
4
5use core::fmt;
6
7/// Statistical / linear algebra errors.
8#[derive(Clone, Debug, Eq, PartialEq)]
9pub enum StatsError {
10    /// Shape mismatch.
11    Shape {
12        /// Context.
13        message: &'static str,
14    },
15    /// Rank deficiency / singular design.
16    RankDeficient {
17        /// Detected rank.
18        rank: usize,
19        /// Number of columns.
20        ncols: usize,
21    },
22    /// Materially non-positive variance after inclusion–exclusion (not FP noise).
23    NonPositiveVariance {
24        /// Context.
25        message: &'static str,
26    },
27    /// Backend failure.
28    Backend(String),
29}
30
31impl fmt::Display for StatsError {
32    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33        match self {
34            Self::Shape { message } => write!(f, "shape error: {message}"),
35            Self::RankDeficient { rank, ncols } => {
36                write!(f, "rank deficient: rank={rank} ncols={ncols}")
37            }
38            Self::NonPositiveVariance { message } => {
39                write!(f, "non-positive variance: {message}")
40            }
41            Self::Backend(msg) => write!(f, "backend error: {msg}"),
42        }
43    }
44}
45
46impl std::error::Error for StatsError {}