nabled_core/errors.rs
1//! Shared error types for ndarray-native kernels.
2
3use thiserror::Error;
4
5/// Common shape and dimensional validation errors.
6#[derive(Debug, Error, Clone, Copy, PartialEq, Eq)]
7pub enum ShapeError {
8 /// Matrix or vector input is empty.
9 #[error("input cannot be empty")]
10 EmptyInput,
11 /// Matrix is expected to be square.
12 #[error("matrix must be square")]
13 NotSquare,
14 /// Matrix and vector dimensions do not match.
15 #[error("dimension mismatch")]
16 DimensionMismatch,
17}
18
19/// Cross-domain top-level error taxonomy for `nabled` crates.
20#[derive(Debug, Error, Clone, PartialEq)]
21pub enum NabledError {
22 /// Shape or dimensional validation failure.
23 #[error(transparent)]
24 Shape(#[from] ShapeError),
25 /// Matrix/vector is singular.
26 #[error("matrix is singular")]
27 SingularMatrix,
28 /// Matrix symmetry requirement failed.
29 #[error("matrix must be symmetric")]
30 NotSymmetric,
31 /// Matrix positive-definiteness requirement failed.
32 #[error("matrix must be positive definite")]
33 NotPositiveDefinite,
34 /// Numerical method failed to converge.
35 #[error("algorithm failed to converge")]
36 ConvergenceFailed,
37 /// Non-finite or unstable numerical state observed.
38 #[error("numerical instability detected")]
39 NumericalInstability,
40 /// Invalid user input.
41 #[error("invalid input: {0}")]
42 InvalidInput(String),
43 /// Domain-specific catch-all.
44 #[error("{0}")]
45 Other(String),
46}
47
48/// Trait for domain errors that can be normalized into [`NabledError`].
49pub trait IntoNabledError {
50 /// Convert domain-specific error into shared taxonomy.
51 fn into_nabled_error(self) -> NabledError;
52}