1use std::fmt;
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Clone, Debug, PartialEq, Eq)]
7pub enum Error {
8 InvalidDescriptor(String),
9 InvalidExpression(String),
10 InvalidOperation(String),
11 IncompatibleExtent { mode: i32, left: usize, right: usize },
12 UnsupportedDType(String),
13 Overflow,
14 InputCount { expected: usize, actual: usize },
15 ScalarCount { expected: usize, actual: usize },
16 TensorMismatch { input: usize },
17 OutputMismatch,
18 DeviceMismatch,
19 SharedOutput,
20 BufferTooSmall,
21 UnsupportedDevice(String),
22}
23
24impl fmt::Display for Error {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 match self {
27 Self::InvalidDescriptor(s) => write!(f, "invalid tensor descriptor: {s}"),
28 Self::InvalidExpression(s) => write!(f, "invalid einsum expression: {s}"),
29 Self::InvalidOperation(s) => write!(f, "invalid tensor operation: {s}"),
30 Self::IncompatibleExtent { mode, left, right } =>
31 write!(f, "mode {mode} has incompatible extents {left} and {right}"),
32 Self::UnsupportedDType(s) => write!(f, "unsupported data type: {s}"),
33 Self::Overflow => f.write_str("tensor size or address exceeds usize"),
34 Self::InputCount { expected, actual } => write!(f, "expected {expected} inputs, got {actual}"),
35 Self::ScalarCount { expected, actual } => write!(f, "expected {expected} coefficients, got {actual}"),
36 Self::TensorMismatch { input } => write!(f, "input {input} does not match its descriptor"),
37 Self::OutputMismatch => f.write_str("output does not match its descriptor"),
38 Self::DeviceMismatch => f.write_str("all tensors must be on the same device"),
39 Self::SharedOutput => f.write_str("execute_into requires an exclusively owned output buffer"),
40 Self::BufferTooSmall => f.write_str("tensor layout exceeds its backing buffer"),
41 Self::UnsupportedDevice(s) => write!(f, "unsupported device configuration: {s}"),
42 }
43 }
44}
45
46impl std::error::Error for Error {}