1use std::fmt;
2
3#[derive(Debug)]
5pub enum SheafError {
6 DimensionMismatch {
8 edge: (usize, usize),
9 expected_rows: usize,
10 expected_cols: usize,
11 got_rows: usize,
12 got_cols: usize,
13 },
14 InvalidNode(usize),
16 InvalidEdge(usize, usize),
18 BeliefDimensionMismatch {
20 agent: String,
21 expected: usize,
22 got: usize,
23 },
24 EmptySheaf,
26 SingularMatrix,
28}
29
30impl fmt::Display for SheafError {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 match self {
33 Self::DimensionMismatch { edge, expected_rows, expected_cols, got_rows, got_cols } => {
34 write!(f, "restriction map on edge {:?}: expected {}x{}, got {}x{}", edge, expected_rows, expected_cols, got_rows, got_cols)
35 }
36 Self::InvalidNode(i) => write!(f, "invalid node index {i}"),
37 Self::InvalidEdge(i, j) => write!(f, "invalid edge ({i}, {j})"),
38 Self::BeliefDimensionMismatch { agent, expected, got } => {
39 write!(f, "agent '{agent}': belief vector length {got}, expected {expected}")
40 }
41 Self::EmptySheaf => write!(f, "sheaf has no nodes"),
42 Self::SingularMatrix => write!(f, "singular matrix encountered"),
43 }
44 }
45}
46
47impl std::error::Error for SheafError {}