scirs2_sparse/
error.rs

1//! Error types for the SciRS2 sparse module
2//!
3//! This module provides error types for both sparse matrix and sparse array operations.
4
5use thiserror::Error;
6
7/// Sparse matrix/array error type
8#[derive(Error, Debug)]
9pub enum SparseError {
10    /// Computation error (generic error)
11    #[error("Computation error: {0}")]
12    ComputationError(String),
13
14    /// Dimension mismatch error
15    #[error("Dimension mismatch: expected {expected}, found {found}")]
16    DimensionMismatch { expected: usize, found: usize },
17
18    /// Index out of bounds error
19    #[error("Index {index:?} out of bounds for array with shape {shape:?}")]
20    IndexOutOfBounds {
21        index: (usize, usize),
22        shape: (usize, usize),
23    },
24
25    /// Invalid axis error
26    #[error("Invalid axis specified")]
27    InvalidAxis,
28
29    /// Invalid slice range error
30    #[error("Invalid slice range specified")]
31    InvalidSliceRange,
32
33    /// Inconsistent data error
34    #[error("Inconsistent data: {reason}")]
35    InconsistentData { reason: String },
36
37    /// Not implemented error
38    #[error("Feature not implemented: {0}")]
39    NotImplemented(String),
40
41    /// Singular matrix error
42    #[error("Singular matrix error: {0}")]
43    SingularMatrix(String),
44
45    /// Value error (invalid value)
46    #[error("Value error: {0}")]
47    ValueError(String),
48
49    /// Conversion error
50    #[error("Conversion error: {0}")]
51    ConversionError(String),
52
53    /// Operation not supported error
54    #[error("Operation not supported: {0}")]
55    OperationNotSupported(String),
56
57    /// Shape mismatch error
58    #[error("Shape mismatch: expected {expected:?}, found {found:?}")]
59    ShapeMismatch {
60        expected: (usize, usize),
61        found: (usize, usize),
62    },
63
64    /// Iterative solver failure error
65    #[error("Iterative solver failure: {0}")]
66    IterativeSolverFailure(String),
67
68    /// Index cast overflow error
69    #[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
76/// Result type for sparse matrix/array operations
77pub type SparseResult<T> = Result<T, SparseError>;