use core::fmt;
use numra_core::NumraError;
#[derive(Clone, Debug, PartialEq)]
pub enum InterpError {
TooFewPoints { got: usize, min: usize },
UnsortedData,
DimensionMismatch { x_len: usize, y_len: usize },
InvalidInput(String),
}
impl fmt::Display for InterpError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
InterpError::TooFewPoints { got, min } => {
write!(f, "Too few data points: got {}, need at least {}", got, min)
}
InterpError::UnsortedData => {
write!(f, "Data x-coordinates must be strictly increasing")
}
InterpError::DimensionMismatch { x_len, y_len } => {
write!(
f,
"Dimension mismatch: x has {} elements, y has {}",
x_len, y_len
)
}
InterpError::InvalidInput(msg) => {
write!(f, "Invalid input: {}", msg)
}
}
}
}
impl From<InterpError> for NumraError {
fn from(e: InterpError) -> Self {
NumraError::Interp(e.to_string())
}
}