1use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum SparseError {
8 #[error("Invalid mask dimensions: expected {expected_heads} heads, {expected_layers} layers, got {actual_heads}x{actual_layers}")]
10 InvalidDimensions {
11 expected_heads: usize,
12 expected_layers: usize,
13 actual_heads: usize,
14 actual_layers: usize,
15 },
16
17 #[error("Head index {index} out of range (max: {max})")]
19 HeadIndexOutOfRange { index: usize, max: usize },
20
21 #[error("Layer index {index} out of range (max: {max})")]
23 LayerIndexOutOfRange { index: usize, max: usize },
24
25 #[error("Sparsity {actual:.2} below minimum required {minimum:.2}")]
27 SparsityTooLow { actual: f32, minimum: f32 },
28
29 #[error("Quality loss {actual:.3} exceeds threshold {threshold:.3}")]
31 QualityLoss { actual: f32, threshold: f32 },
32
33 #[error("Kernel execution failed: {0}")]
35 KernelError(String),
36
37 #[error("Prediction failed: {0}")]
39 PredictionError(String),
40
41 #[error("Analysis failed: {0}")]
43 AnalysisError(String),
44}
45
46pub type Result<T> = std::result::Result<T, SparseError>;