1use core::fmt;
7use numra_core::NumraError;
8
9#[derive(Clone, Debug, PartialEq)]
11pub enum InterpError {
12 TooFewPoints { got: usize, min: usize },
14 UnsortedData,
16 DimensionMismatch { x_len: usize, y_len: usize },
18 InvalidInput(String),
20}
21
22impl fmt::Display for InterpError {
23 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24 match self {
25 InterpError::TooFewPoints { got, min } => {
26 write!(f, "Too few data points: got {}, need at least {}", got, min)
27 }
28 InterpError::UnsortedData => {
29 write!(f, "Data x-coordinates must be strictly increasing")
30 }
31 InterpError::DimensionMismatch { x_len, y_len } => {
32 write!(
33 f,
34 "Dimension mismatch: x has {} elements, y has {}",
35 x_len, y_len
36 )
37 }
38 InterpError::InvalidInput(msg) => {
39 write!(f, "Invalid input: {}", msg)
40 }
41 }
42 }
43}
44
45impl From<InterpError> for NumraError {
46 fn from(e: InterpError) -> Self {
47 NumraError::Interp(e.to_string())
48 }
49}