1use thiserror::Error;
4
5#[derive(Error, Debug)]
6pub enum Error {
7 #[error("Shape mismatch: expected {expected:?}, got {got:?}")]
8 ShapeMismatch { expected: Vec<usize>, got: Vec<usize> },
9
10 #[error("Invalid gradient: {0}")]
11 InvalidGradient(String),
12
13 #[error("Backward operation failed: {0}")]
14 BackwardFailed(String),
15
16 #[error("Configuration error: {0}")]
17 ConfigError(String),
18
19 #[error("I/O error: {0}")]
20 Io(String),
21
22 #[error("Serialization error: {0}")]
23 Serialization(String),
24
25 #[error("Invalid parameter: {0}")]
26 InvalidParameter(String),
27
28 #[error("Parse error: {0}")]
29 Parse(String),
30
31 #[error("Validation error: {0}")]
32 Validation(String),
33}
34
35impl From<std::io::Error> for Error {
36 fn from(err: std::io::Error) -> Self {
37 Error::Io(err.to_string())
38 }
39}
40
41pub type Result<T> = std::result::Result<T, Error>;