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 /// A matrix dimension product overflowed `usize`.
21 #[error("matrix dimensions overflow: {rows}x{cols}")]
22 DimensionOverflow {
23 /// The requested row count.
24 rows: usize,
25 /// The requested column count.
26 cols: usize,
27 },
28 /// A public matrix value violated `data.len() == rows * cols`.
29 #[error(
30 "matrix invariant violation: {rows}x{cols} requires {expected} entries, found {actual}"
31 )]
32 InvalidMatrix {
33 /// The declared row count.
34 rows: usize,
35 /// The declared column count.
36 cols: usize,
37 /// The expected row-major entry count.
38 expected: usize,
39 /// The actual row-major entry count.
40 actual: usize,
41 },
42 /// An index was out of bounds.
43 #[error("index out of bounds: index {index}, len {len}")]
44 IndexOutOfBounds {
45 /// The offending index.
46 index: usize,
47 /// The valid length.
48 len: usize,
49 },
50}