1use core::fmt;
8
9#[derive(Clone, Debug, PartialEq)]
11pub enum StatsError {
12 EmptyData,
14 LengthMismatch { expected: usize, got: usize },
16 InvalidParameter(String),
18 DimensionMismatch(String),
20 SingularMatrix,
22 ConvergenceFailure(String),
24}
25
26impl fmt::Display for StatsError {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 match self {
29 StatsError::EmptyData => write!(f, "empty data set"),
30 StatsError::LengthMismatch { expected, got } => {
31 write!(f, "length mismatch: expected {}, got {}", expected, got)
32 }
33 StatsError::InvalidParameter(msg) => write!(f, "invalid parameter: {}", msg),
34 StatsError::DimensionMismatch(msg) => write!(f, "dimension mismatch: {}", msg),
35 StatsError::SingularMatrix => write!(f, "singular matrix"),
36 StatsError::ConvergenceFailure(msg) => write!(f, "convergence failure: {}", msg),
37 }
38 }
39}
40
41impl From<StatsError> for numra_core::NumraError {
42 fn from(e: StatsError) -> Self {
43 numra_core::NumraError::Stats(e.to_string())
44 }
45}