1use thiserror::Error;
6
7#[derive(Error, Debug)]
9pub enum SparseError {
10 #[error("Computation error: {0}")]
12 ComputationError(String),
13
14 #[error("Dimension mismatch: expected {expected}, found {found}")]
16 DimensionMismatch { expected: usize, found: usize },
17
18 #[error("Index {index:?} out of bounds for array with shape {shape:?}")]
20 IndexOutOfBounds {
21 index: (usize, usize),
22 shape: (usize, usize),
23 },
24
25 #[error("Invalid axis specified")]
27 InvalidAxis,
28
29 #[error("Invalid slice range specified")]
31 InvalidSliceRange,
32
33 #[error("Inconsistent data: {reason}")]
35 InconsistentData { reason: String },
36
37 #[error("Feature not implemented: {0}")]
39 NotImplemented(String),
40
41 #[error("Singular matrix error: {0}")]
43 SingularMatrix(String),
44
45 #[error("Value error: {0}")]
47 ValueError(String),
48
49 #[error("Conversion error: {0}")]
51 ConversionError(String),
52
53 #[error("Operation not supported: {0}")]
55 OperationNotSupported(String),
56
57 #[error("Shape mismatch: expected {expected:?}, found {found:?}")]
59 ShapeMismatch {
60 expected: (usize, usize),
61 found: (usize, usize),
62 },
63
64 #[error("Iterative solver failure: {0}")]
66 IterativeSolverFailure(String),
67
68 #[error("Index value {value} cannot be represented in the target type {target_type}")]
70 IndexCastOverflow {
71 value: usize,
72 target_type: &'static str,
73 },
74}
75
76pub type SparseResult<T> = Result<T, SparseError>;