Skip to main content

tensor4all_tcicore/cached_function/
error.rs

1//! Error types for cache key operations.
2//!
3//! [`CacheKeyError`] is returned when constructing a [`CachedFunction`](crate::CachedFunction)
4//! fails due to an index space that exceeds the key type's capacity.
5
6use thiserror::Error;
7
8/// Errors that can occur during cache key computation.
9#[derive(Debug, Error)]
10pub enum CacheKeyError {
11    /// The index space requires more bits than the key type supports.
12    #[error(
13        "Cache key overflow: {total_bits} bits required, but {key_type} supports only \
14         {max_bits} bits. Use CachedFunction::with_key_type::<LargerType>() to specify \
15         a larger key type."
16    )]
17    Overflow {
18        /// Total bits required by the index space.
19        total_bits: u32,
20        /// Maximum bits the key type supports.
21        max_bits: u32,
22        /// Name of the key type.
23        key_type: &'static str,
24    },
25
26    /// Tensor has wrong number of dimensions for batch evaluation.
27    #[error("Expected 2D tensor for batch evaluation, got {ndim}D")]
28    InvalidTensorDim {
29        /// Actual number of dimensions.
30        ndim: usize,
31    },
32}