1use crate::{DType, Shape};
2
3#[derive(Debug, thiserror::Error)]
16pub enum Error {
17 #[error("shape mismatch: expected {expected}, got {actual}")]
18 ShapeMismatch { expected: Shape, actual: Shape },
19
20 #[error("shapes {left} and {right} cannot be broadcast together")]
21 NotBroadcastable { left: Shape, right: Shape },
22
23 #[error("dtype mismatch: expected {expected}, got {actual}")]
24 DTypeMismatch { expected: DType, actual: DType },
25
26 #[error("operation {op} does not support dtype {dtype}")]
27 UnsupportedDType { op: &'static str, dtype: DType },
28
29 #[error(
30 "cannot index a {dtype} tensor elementwise: it packs {block_size} elements per quantized block"
31 )]
32 QuantizedElementAccess { dtype: DType, block_size: usize },
33
34 #[error("storage holds {actual} bytes but shape {shape} of {dtype} needs {expected}")]
35 StorageTooSmall {
36 shape: Shape,
37 dtype: DType,
38 expected: usize,
39 actual: usize,
40 },
41
42 #[error("{count} elements is not a whole number of {dtype} blocks ({block_size} per block)")]
43 PartialQuantizedBlock {
44 dtype: DType,
45 count: usize,
46 block_size: usize,
47 },
48
49 #[error("index {index} is out of bounds for dimension {dim} of length {len}")]
50 IndexOutOfBounds { dim: usize, index: usize, len: usize },
51
52 #[error("malformed {format} model file: {reason}")]
53 MalformedModel {
54 format: &'static str,
55 reason: String,
56 },
57
58 #[error("{format} model uses unsupported feature: {feature}")]
59 UnsupportedModelFeature {
60 format: &'static str,
61 feature: String,
62 },
63
64 #[error("model is missing required tensor {name:?}")]
65 MissingTensor { name: String },
66
67 #[error("io error: {0}")]
68 Io(#[from] std::io::Error),
69}
70
71pub type Result<T> = std::result::Result<T, Error>;