Skip to main content

tensorlogic_train/augmentation/
error.rs

1/// Errors that can occur during augmentation operations.
2#[derive(Debug, Clone)]
3pub enum AugmentationError {
4    /// Probability value is outside [0, 1].
5    InvalidProbability(f64),
6    /// Alpha parameter is non-positive.
7    InvalidAlpha(f64),
8    /// Two arrays have incompatible shapes.
9    ShapeMismatch {
10        expected: Vec<usize>,
11        got: Vec<usize>,
12    },
13    /// Input array has zero elements.
14    EmptyInput,
15    /// Noise std is negative.
16    InvalidNoise { std: f64 },
17    /// Crop size exceeds input size along that dimension.
18    InvalidCrop { crop_size: usize, input_size: usize },
19}
20
21impl std::fmt::Display for AugmentationError {
22    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23        match self {
24            AugmentationError::InvalidProbability(p) => {
25                write!(f, "probability {p} is outside [0, 1]")
26            }
27            AugmentationError::InvalidAlpha(a) => {
28                write!(f, "alpha {a} must be positive")
29            }
30            AugmentationError::ShapeMismatch { expected, got } => {
31                write!(f, "shape mismatch: expected {expected:?}, got {got:?}")
32            }
33            AugmentationError::EmptyInput => write!(f, "input array is empty"),
34            AugmentationError::InvalidNoise { std } => {
35                write!(f, "noise std {std} must be non-negative")
36            }
37            AugmentationError::InvalidCrop {
38                crop_size,
39                input_size,
40            } => {
41                write!(f, "crop size {crop_size} exceeds input size {input_size}")
42            }
43        }
44    }
45}
46
47impl std::error::Error for AugmentationError {}