1use std::error;
4use std::fmt;
5
6pub use std::error::Error as StdError;
8
9#[derive(Debug)]
11pub enum NeuralError {
12 InvalidArchitecture(String),
14 TrainingError(String),
16 InferenceError(String),
18 SerializationError(String),
20 DeserializationError(String),
22 ValidationError(String),
24 NotImplementedError(String),
26 IOError(String),
28 InvalidArgument(String),
30 ShapeMismatch(String),
32 ComputationError(String),
34 DimensionMismatch(String),
36 DistributedError(String),
38 Other(String),
40}
41
42impl fmt::Display for NeuralError {
43 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
44 match self {
45 NeuralError::InvalidArchitecture(msg) => write!(f, "Invalid architecture: {}", msg),
46 NeuralError::TrainingError(msg) => write!(f, "Training error: {}", msg),
47 NeuralError::InferenceError(msg) => write!(f, "Inference error: {}", msg),
48 NeuralError::SerializationError(msg) => write!(f, "Serialization error: {}", msg),
49 NeuralError::DeserializationError(msg) => write!(f, "Deserialization error: {}", msg),
50 NeuralError::ValidationError(msg) => write!(f, "Validation error: {}", msg),
51 NeuralError::NotImplementedError(msg) => write!(f, "Not implemented: {}", msg),
52 NeuralError::IOError(msg) => write!(f, "IO error: {}", msg),
53 NeuralError::InvalidArgument(msg) => write!(f, "Invalid argument: {}", msg),
54 NeuralError::ShapeMismatch(msg) => write!(f, "Shape mismatch: {}", msg),
55 NeuralError::ComputationError(msg) => write!(f, "Computation error: {}", msg),
56 NeuralError::DimensionMismatch(msg) => write!(f, "Dimension mismatch: {}", msg),
57 NeuralError::DistributedError(msg) => write!(f, "Distributed training error: {}", msg),
58 NeuralError::Other(msg) => write!(f, "Error: {}", msg),
59 }
60 }
61}
62
63impl error::Error for NeuralError {}
64
65pub type Error = NeuralError;
67
68pub type Result<T> = std::result::Result<T, Error>;
70
71#[cfg(not(feature = "gpu"))]
73pub struct DummyGpuBackend;
74
75impl From<std::io::Error> for NeuralError {
77 fn from(error: std::io::Error) -> Self {
78 NeuralError::IOError(error.to_string())
79 }
80}
81
82impl From<ndarray::ShapeError> for NeuralError {
84 fn from(error: ndarray::ShapeError) -> Self {
85 NeuralError::InferenceError(format!("Shape error: {}", error))
86 }
87}