ariadnetor_core/contraction_error.rs
1//! Error types for tensor contraction operations
2
3/// Error raised while parsing or validating an Einstein-notation contraction.
4///
5/// Every variant fully describes its own failure; none wraps a structured
6/// inner error. `ContractionError` is therefore a leaf in the error chain —
7/// its `source()` is always `None`.
8#[derive(Debug, Clone, PartialEq, thiserror::Error)]
9pub enum ContractionError {
10 /// The notation string could not be parsed as valid Einstein notation.
11 #[error("Invalid Einstein notation: {0}")]
12 InvalidNotation(String),
13 /// A tensor's label count does not match its rank.
14 #[error("{tensor} tensor: expected {expected} labels, got {actual}")]
15 LabelMismatch {
16 /// Number of labels expected (the tensor's rank).
17 expected: usize,
18 /// Number of labels actually supplied.
19 actual: usize,
20 /// Which operand the mismatch occurred on.
21 tensor: String,
22 },
23 /// A shared label is bound to different extents on the two operands.
24 #[error("Dimension mismatch for '{label}': lhs={lhs_dim}, rhs={rhs_dim}")]
25 DimensionMismatch {
26 /// The label whose extents disagree.
27 label: String,
28 /// Extent of the label on the left operand.
29 lhs_dim: usize,
30 /// Extent of the label on the right operand.
31 rhs_dim: usize,
32 },
33 /// A referenced label is absent from the named tensor.
34 #[error("Label '{label}' not found in {tensor} tensor")]
35 LabelNotFound {
36 /// The label that was not found.
37 label: String,
38 /// Which operand was searched.
39 tensor: String,
40 },
41 /// The output specification repeats a label.
42 #[error("Duplicate label '{label}' in output")]
43 DuplicateOutputLabel {
44 /// The label that appears more than once in the output.
45 label: String,
46 },
47}