1use thiserror::Error;
4
5#[derive(Error, Debug)]
7pub enum GhostError {
8 #[error("Shape mismatch: expected {expected:?}, got {got:?}")]
9 ShapeMismatch { expected: Vec<usize>, got: Vec<usize> },
10
11 #[error("Invalid shape: {0}")]
12 InvalidShape(String),
13
14 #[error("Dimension out of bounds: dim {dim} for tensor with {ndim} dimensions")]
15 DimOutOfBounds { dim: usize, ndim: usize },
16
17 #[error("Index out of bounds: index {index} for dimension of size {size}")]
18 IndexOutOfBounds { index: usize, size: usize },
19
20 #[error("Data type mismatch: expected {expected:?}, got {got:?}")]
21 DTypeMismatch { expected: String, got: String },
22
23 #[error("Device mismatch: tensors on different devices")]
24 DeviceMismatch,
25
26 #[error("Cannot broadcast shapes {a:?} and {b:?}")]
27 BroadcastError { a: Vec<usize>, b: Vec<usize> },
28
29 #[error("Operation requires gradient tracking")]
30 NoGradient,
31
32 #[error("Memory allocation failed: {0}")]
33 AllocationError(String),
34
35 #[error("CUDA error: {0}")]
36 CudaError(String),
37
38 #[error("Device error: {0}")]
39 DeviceError(String),
40
41 #[error("Invalid operation: {0}")]
42 InvalidOperation(String),
43
44 #[error("IO error: {0}")]
45 IOError(String),
46
47 #[error("Invalid format: {0}")]
48 InvalidFormat(String),
49
50 #[error("Not implemented: {0}")]
51 NotImplemented(String),
52}
53
54pub type Result<T> = std::result::Result<T, GhostError>;