Skip to main content

trueno_tensor/
error.rs

1//! Tensor error types.
2
3/// Errors from tensor operations.
4#[derive(Debug, thiserror::Error)]
5pub enum TensorError {
6    /// Shape mismatch for an operation.
7    #[error("shape mismatch: expected {expected:?}, got {got:?}")]
8    ShapeMismatch {
9        /// Expected shape.
10        expected: Vec<usize>,
11        /// Actual shape.
12        got: Vec<usize>,
13    },
14
15    /// Data length doesn't match shape.
16    #[error("data length {len} does not match shape {shape:?} (product = {product})")]
17    DataLengthMismatch {
18        /// Data length.
19        len: usize,
20        /// Expected shape.
21        shape: Vec<usize>,
22        /// Product of shape dims.
23        product: usize,
24    },
25
26    /// Invalid einsum subscript string.
27    #[error("invalid einsum subscript: {0}")]
28    InvalidSubscript(String),
29
30    /// Contracted dimensions don't match.
31    #[error(
32        "contracted dimension mismatch: index '{index}' has size {size_a} in A but {size_b} in B"
33    )]
34    ContractionDimensionMismatch {
35        /// Index label.
36        index: char,
37        /// Size in tensor A.
38        size_a: usize,
39        /// Size in tensor B.
40        size_b: usize,
41    },
42}