Skip to main content

sim_lib_discrete_algebra/
error.rs

1//! Error type for the discrete algebra spine.
2
3/// Errors raised by semiring construction and matrix operations.
4#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
5pub enum AlgebraError {
6    /// Operand shapes are incompatible for the requested operation.
7    #[error("shape mismatch: {0}")]
8    ShapeMismatch(String),
9    /// A `from_rows` input had rows of unequal length.
10    #[error("ragged matrix input: rows have unequal length")]
11    Ragged,
12    /// Closure is undefined: a diagonal entry's Kleene star does not converge
13    /// (either the semiring defines no `star`, or the series diverges here, as
14    /// with a negative cycle in min-plus or a directed cycle in counting).
15    #[error("closure undefined: a diagonal entry has no convergent star")]
16    NoStar,
17    /// An explicit size or iteration limit was exceeded.
18    #[error("limit exceeded: {0}")]
19    LimitExceeded(String),
20    /// An index was out of bounds.
21    #[error("index out of bounds: index {index}, len {len}")]
22    IndexOutOfBounds {
23        /// The offending index.
24        index: usize,
25        /// The valid length.
26        len: usize,
27    },
28}