use crate::config::*;
use snafu::prelude::*;
use std::fmt::{Display, Formatter};
use strum::IntoEnumIterator;
use strum_macros::{Display, EnumIter, EnumMessage};
#[cfg_attr(
feature = "python-bindings",
gen_stub_pyclass_complex_enum,
pyclass(from_py_object)
)]
#[derive(Debug, Snafu, Clone, PartialEq)]
#[snafu(visibility(pub))]
#[allow(missing_docs)]
pub enum FreqSmoothError {
#[snafu(display("Invalid frequency vector length {length}. Must be >= 2"))]
FreqTooShort {
length: usize,
},
#[snafu(display(
"Frequency vector length ({freq_len}) does not match spectrum vector length ({x_len})"
))]
SizeMismatch {
freq_len: usize,
x_len: usize,
},
#[snafu(display(
"Minimum non-DC frequency ({freq_min}) must be strictly positive for log-scale interpolation"
))]
InvalidFreqMin {
freq_min: Flt,
},
#[snafu(display("Interpolation failed: {msg}"))]
InterpolationFailed {
msg: String,
},
#[snafu(display("Power spectrum contains negative values (minimum: {min_value})"))]
NegativePower {
min_value: Flt,
},
#[snafu(display("Decibel (levels) input must be real-valued, not complex"))]
ComplexLevels {},
}
#[cfg(feature = "python-bindings")]
#[gen_stub_pymethods]
#[pymethods]
impl FreqSmoothError {
fn __str__(&self) -> String {
self.to_string()
}
}
cfg_select! {
any(feature = "python-bindings") => {
use pyo3::exceptions::PyException;
#[gen_stub_pyclass]
#[pyclass(extends = PyException, str, from_py_object)]
#[derive(Debug, Clone)]
pub struct PyFreqSmoothError {
#[pyo3(get)]
pub inner: FreqSmoothError,
}
impl Display for PyFreqSmoothError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.inner)
}
}
#[gen_stub_pymethods]
#[pymethods]
impl PyFreqSmoothError {
#[new]
fn new(inner: FreqSmoothError) -> Self {
PyFreqSmoothError { inner }
}
}
impl From<FreqSmoothError> for PyErr {
fn from(value: FreqSmoothError) -> Self {
PyErr::new::<PyFreqSmoothError, _>(value)
}
}
}
_ => {}
}