#[cfg(not(feature = "std"))]
use alloc::string::String;
use core::fmt::{Display, Formatter, Result};
#[cfg(feature = "std")]
use std::error::Error;
#[cfg(feature = "std")]
use std::string::String;
#[derive(Debug, Clone, PartialEq)]
pub enum LowessError {
EmptyInput,
InvalidInput(String),
MismatchedInputs {
x_len: usize,
y_len: usize,
},
InvalidNumericValue(String),
TooFewPoints {
got: usize,
min: usize,
},
InvalidFraction(f64),
InvalidDelta(f64),
InvalidIterations(usize),
InvalidIntervals(f64),
InvalidTolerance(f64),
InvalidChunkSize {
got: usize,
min: usize,
},
InvalidOverlap {
overlap: usize,
chunk_size: usize,
},
InvalidWindowCapacity {
got: usize,
min: usize,
},
InvalidMinPoints {
got: usize,
window_capacity: usize,
},
UnsupportedFeature {
adapter: &'static str,
feature: &'static str,
},
DuplicateParameter {
parameter: &'static str,
},
RuntimeError(String),
}
impl Display for LowessError {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match self {
Self::EmptyInput => write!(f, "Input arrays are empty"),
Self::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
Self::MismatchedInputs { x_len, y_len } => {
write!(f, "Length mismatch: x has {x_len} points, y has {y_len}")
}
Self::InvalidNumericValue(s) => write!(f, "Invalid numeric value: {s}"),
Self::TooFewPoints { got, min } => {
write!(f, "Too few points: got {got}, need at least {min}")
}
Self::InvalidFraction(frac) => {
write!(f, "Invalid fraction: {frac} (must be > 0 and <= 1)")
}
Self::InvalidDelta(delta) => write!(f, "Invalid delta: {delta} (must be >= 0)"),
Self::InvalidIterations(iter) => {
write!(f, "Invalid iterations: {iter} (must be in [0, 1000])")
}
Self::InvalidIntervals(level) => {
write!(f, "Invalid interval level: {level} (must be > 0 and < 1)")
}
Self::InvalidTolerance(tol) => {
write!(f, "Invalid tolerance: {tol} (must be > 0 and finite)")
}
Self::InvalidChunkSize { got, min } => {
write!(f, "Invalid chunk_size: {got} (must be at least {min})")
}
Self::InvalidOverlap {
overlap,
chunk_size,
} => {
write!(
f,
"Invalid overlap: {overlap} (must be less than chunk_size {chunk_size})"
)
}
Self::InvalidWindowCapacity { got, min } => {
write!(f, "Invalid window_capacity: {got} (must be at least {min})")
}
Self::InvalidMinPoints {
got,
window_capacity,
} => {
write!(
f,
"Invalid min_points: {got} (must be between 2 and window_capacity {window_capacity})"
)
}
Self::UnsupportedFeature { adapter, feature } => {
write!(f, "Adapter '{adapter}' does not support feature: {feature}")
}
Self::DuplicateParameter { parameter } => {
write!(
f,
"Parameter '{parameter}' was set multiple times. Each parameter can only be configured once."
)
}
Self::RuntimeError(msg) => write!(f, "Runtime error: {}", msg),
}
}
}
#[cfg(feature = "std")]
impl Error for LowessError {}