Skip to main content

bitnet_quantize/
error.rs

1//! Error types for bitnet-rs.
2
3use thiserror::Error;
4
5/// Result type alias for bitnet-rs operations.
6pub type Result<T> = std::result::Result<T, BitNetError>;
7
8/// Errors that can occur during BitNet operations.
9#[derive(Debug, Error)]
10pub enum BitNetError {
11    /// Invalid configuration parameter.
12    #[error("invalid configuration: {0}")]
13    InvalidConfig(String),
14
15    /// Shape mismatch in tensor operations.
16    #[error("shape mismatch: expected {expected:?}, got {actual:?}")]
17    ShapeMismatch {
18        /// Expected shape.
19        expected: Vec<usize>,
20        /// Actual shape.
21        actual: Vec<usize>,
22    },
23
24    /// Dimension mismatch.
25    #[error("dimension mismatch: expected {expected}, got {actual}")]
26    DimensionMismatch {
27        /// Expected dimension.
28        expected: usize,
29        /// Actual dimension.
30        actual: usize,
31    },
32
33    /// Quantization error.
34    #[error("quantization error: {0}")]
35    Quantization(String),
36
37    /// Candle tensor operation error.
38    #[error("tensor error: {0}")]
39    Tensor(#[from] candle_core::Error),
40
41    /// Ternary operation error.
42    #[error("ternary error: {0}")]
43    Ternary(#[from] trit_vsa::TernaryError),
44
45    /// I/O error.
46    #[error("I/O error: {0}")]
47    Io(#[from] std::io::Error),
48
49    /// Serialization error.
50    #[error("serialization error: {0}")]
51    Serialization(String),
52
53    /// Feature not available.
54    #[error("feature not available: {0}")]
55    FeatureNotAvailable(String),
56}