adaptif 0.1.0

Adaptive filters for digital signal processing.
use std::error;
use std::fmt::Display;
use std::result;

pub type Result<T> = result::Result<T, Error>;

#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
/// Error type used by the `adaptif` crate.
pub enum Error {
    EmptyInputArr,
    WindowSizeZero,
    BlockSizeZero,
    NoiseRefTooShort {
        input_len: usize,
        noise_len: usize,
    },
    NonPositiveStepSize,
    NonPositiveEpsilon,
    InvalidForgettingFactorRange,
    NonPositivePInitScale,
    WeightsDontMatchWindowSize {
        n_weights: usize,
        window_size: usize,
    },
}
impl Display for Error {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match *self {
            Self::EmptyInputArr => write!(f, "empty input array."),
            Self::WindowSizeZero => write!(f, "window size must be greater than zero."),
            Self::BlockSizeZero => write!(f, "block size must be greater than zero."),
            Self::NoiseRefTooShort {
                input_len,
                noise_len,
            } => write!(
                f,
                "length of the noise reference ({noise_len}) must be equal to or greater than that of the input signal ({input_len})."
            ),
            Self::NonPositiveStepSize => write!(f, "step size must be greater than 0.0"),
            Self::NonPositiveEpsilon => write!(f, "epsilon value must be greater than 0.0"),
            Self::InvalidForgettingFactorRange => {
                write!(f, "forgetting factor (lambda) must be > 0.0 and <= 1.0")
            }
            Self::NonPositivePInitScale => write!(
                f,
                "scalar value (delta) used in initializing the inverse correlation matrix must be greater than 0.0"
            ),
            Self::WeightsDontMatchWindowSize {
                n_weights,
                window_size,
            } => write!(
                f,
                "number of weights ({n_weights}) must match the window size ({window_size})"
            ),
        }
    }
}
impl error::Error for Error {}