Skip to main content

axonml_quant/
error.rs

1//! Quantization Error Types
2//!
3//! # File
4//! `crates/axonml-quant/src/error.rs`
5//!
6//! # Author
7//! Andrew Jewell Sr - AutomataNexus
8//!
9//! # Updated
10//! March 8, 2026
11//!
12//! # Disclaimer
13//! Use at own risk. This software is provided "as is", without warranty of any
14//! kind, express or implied. The author and AutomataNexus shall not be held
15//! liable for any damages arising from the use of this software.
16
17use thiserror::Error;
18
19/// Result type for quantization operations.
20pub type QuantResult<T> = Result<T, QuantError>;
21
22/// Errors that can occur during quantization.
23#[derive(Error, Debug)]
24pub enum QuantError {
25    /// Invalid block size.
26    #[error("Invalid block size: {0}")]
27    InvalidBlockSize(usize),
28
29    /// Invalid quantization type.
30    #[error("Invalid quantization type: {0}")]
31    InvalidQuantType(String),
32
33    /// Shape mismatch during quantization.
34    #[error("Shape mismatch: expected {expected:?}, got {actual:?}")]
35    ShapeMismatch {
36        /// Expected shape.
37        expected: Vec<usize>,
38        /// Actual shape.
39        actual: Vec<usize>,
40    },
41
42    /// Data length mismatch.
43    #[error("Data length mismatch: expected {expected}, got {actual}")]
44    DataLengthMismatch {
45        /// Expected length.
46        expected: usize,
47        /// Actual length.
48        actual: usize,
49    },
50
51    /// Calibration error.
52    #[error("Calibration error: {0}")]
53    CalibrationError(String),
54
55    /// Numerical overflow during quantization.
56    #[error("Numerical overflow during quantization")]
57    Overflow,
58
59    /// Invalid quantized data.
60    #[error("Invalid quantized data: {0}")]
61    InvalidData(String),
62
63    /// Tensor conversion error.
64    #[error("Tensor conversion error: {0}")]
65    TensorConversion(String),
66}