tenferro_runtime/
error.rs1use tenferro_tensor::DType;
13
14#[derive(Debug, thiserror::Error)]
24pub enum Error {
25 #[error("invalid subscripts: {0}")]
27 InvalidSubscripts(String),
28
29 #[error("contraction error: {0}")]
31 ContractionError(String),
32
33 #[error("missing input: {0}")]
35 MissingInput(String),
36
37 #[error("grad requires a scalar output, got shape {shape:?}")]
39 NonScalarGrad { shape: Vec<usize> },
40
41 #[error(transparent)]
43 TensorRuntime(#[from] tenferro_tensor::Error),
44
45 #[error(
48 "binding #{binding_index} is not a placeholder; \
49 only tensors built via input_concrete_shape / input_symbolic_shape \
50 can be bound"
51 )]
52 UnexpectedBinding { binding_index: usize },
53
54 #[error("placeholder {input_key} has no runtime input binding")]
56 UnboundPlaceholder { input_key: String },
57
58 #[error("placeholder {input_key} was bound more than once")]
60 DuplicateBinding { input_key: String },
61
62 #[error("binding dtype mismatch for placeholder: expected {expected:?}, got {actual:?}")]
64 PlaceholderDtypeMismatch { expected: DType, actual: DType },
65
66 #[error(
69 "binding shape mismatch for concrete-shape placeholder: \
70 expected {expected:?}, got {actual:?}"
71 )]
72 PlaceholderShapeMismatch {
73 expected: Vec<usize>,
74 actual: Vec<usize>,
75 },
76
77 #[error(
80 "binding rank mismatch for symbolic-shape placeholder: \
81 expected rank {expected}, got rank {actual}"
82 )]
83 PlaceholderRankMismatch { expected: usize, actual: usize },
84
85 #[error(
87 "tensors belong to different eager AD contexts ({lhs} vs {rhs}); \
88 detach into the target context before combining them"
89 )]
90 ContextMismatch { lhs: ContextId, rhs: ContextId },
91
92 #[error("{op}: invalid traced graph build: {message}")]
94 InvalidGraphBuild {
95 op: &'static str,
97 message: String,
99 },
100
101 #[error("invalid compiled graph: {message}")]
103 InvalidCompiledGraph {
104 message: String,
106 },
107
108 #[error("internal error: {0}")]
110 Internal(String),
111}
112
113#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
115pub struct ContextId(usize);
116
117impl ContextId {
118 #[doc(hidden)]
119 pub fn from_ptr<T>(ptr: *const T) -> Self {
120 Self(ptr as usize)
121 }
122}
123
124impl std::fmt::Display for ContextId {
125 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
126 write!(f, "ctx@{:x}", self.0)
127 }
128}
129
130pub type Result<T> = std::result::Result<T, Error>;