Skip to main content

axonml_quant/
error.rs

1//! Quantization Error Types — Block, Shape, and Calibration Failures
2//!
3//! Defines `QuantError`, the `thiserror`-derived error enum for the
4//! `axonml-quant` crate. Variants cover invalid block sizes, unknown
5//! quantization-type strings, shape mismatch (expected/actual `Vec<usize>`),
6//! data-length mismatch (expected/actual byte counts), calibration errors,
7//! numerical overflow during quantization, invalid encoded data, and
8//! tensor-conversion errors. `QuantResult<T>` is the corresponding `Result`
9//! alias used throughout the quantization pipeline.
10//!
11//! # File
12//! `crates/axonml-quant/src/error.rs`
13//!
14//! # Author
15//! Andrew Jewell Sr. — AutomataNexus LLC
16//! ORCID: 0009-0005-2158-7060
17//!
18//! # Updated
19//! April 16, 2026 11:15 PM EST
20//!
21//! # Disclaimer
22//! Use at own risk. This software is provided "as is", without warranty of any
23//! kind, express or implied. The author and AutomataNexus shall not be held
24//! liable for any damages arising from the use of this software.
25
26// =============================================================================
27// Error Types
28// =============================================================================
29
30use thiserror::Error;
31
32/// Result type for quantization operations.
33pub type QuantResult<T> = Result<T, QuantError>;
34
35/// Errors that can occur during quantization.
36#[derive(Error, Debug)]
37pub enum QuantError {
38    /// Invalid block size.
39    #[error("Invalid block size: {0}")]
40    InvalidBlockSize(usize),
41
42    /// Invalid quantization type.
43    #[error("Invalid quantization type: {0}")]
44    InvalidQuantType(String),
45
46    /// Shape mismatch during quantization.
47    #[error("Shape mismatch: expected {expected:?}, got {actual:?}")]
48    ShapeMismatch {
49        /// Expected shape.
50        expected: Vec<usize>,
51        /// Actual shape.
52        actual: Vec<usize>,
53    },
54
55    /// Data length mismatch.
56    #[error("Data length mismatch: expected {expected}, got {actual}")]
57    DataLengthMismatch {
58        /// Expected length.
59        expected: usize,
60        /// Actual length.
61        actual: usize,
62    },
63
64    /// Calibration error.
65    #[error("Calibration error: {0}")]
66    CalibrationError(String),
67
68    /// Numerical overflow during quantization.
69    #[error("Numerical overflow during quantization")]
70    Overflow,
71
72    /// Invalid quantized data.
73    #[error("Invalid quantized data: {0}")]
74    InvalidData(String),
75
76    /// Tensor conversion error.
77    #[error("Tensor conversion error: {0}")]
78    TensorConversion(String),
79}