quad-rs 0.5.0

Adaptive Gauss-Kronrod Integration in Rust
Documentation
use super::policy::RangeSplitError;
use crate::storage::SegmentHeapError;

#[derive(thiserror::Error, Debug, PartialEq)]
/// Error type for integrator
pub enum IntegratorError<T, E> {
    #[error("exceeded the maximum number of function evaluations before convergence")]
    ExceededMaxFunctionEvaluations,
    #[error("non-finite error estimate")]
    NonFiniteErrorEstimate,
    #[error("no segments found")]
    NoSegments,
    #[error("empty integration segment")]
    EmptySegment,
    #[error("non-finite integrand at {point:?}")]
    NonFiniteIntegrand { point: T },
    #[error("possible singularity at {singularity:?}")]
    PossibleSingularity { singularity: T },
    #[error("refined contour piece smaller than minimum")]
    PieceTooSmall,
    #[error("error in user code")]
    User(E),
}

impl<T, E> From<SegmentHeapError> for IntegratorError<T, E> {
    fn from(value: SegmentHeapError) -> Self {
        match value {
            SegmentHeapError::NonFiniteErrorEstimate => Self::NonFiniteErrorEstimate,
        }
    }
}

impl<T: nalgebra::ComplexField, E> From<RangeSplitError<T>> for IntegratorError<T, E> {
    fn from(value: RangeSplitError<T>) -> Self {
        match value {
            RangeSplitError::SegmentTooSmall { center, .. } => Self::PossibleSingularity {
                singularity: center,
            },
        }
    }
}