ghostflow_core/
error.rs

1//! Error types for GhostFlow
2
3use thiserror::Error;
4
5/// Main error type for GhostFlow operations
6#[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("Invalid operation: {0}")]
39    InvalidOperation(String),
40}
41
42/// Result type alias for GhostFlow operations
43pub type Result<T> = std::result::Result<T, GhostError>;