pub enum GraphError {
ShapeMismatch,
InvalidNodeId,
IdCollision,
CycleDetected,
}Expand description
Error types for Graph construction and validation.
These errors are returned by graph-building APIs when an operation cannot be represented safely in the current graph.
§Examples
let mut g = Graph::new();
let a = g.input_node(vec![2, 3]);
let b = g.input_node(vec![2, 4]);
// add() requires identical shapes
assert!(matches!(g.add(a, b).unwrap_err(), GraphError::ShapeMismatch));Variants§
ShapeMismatch
Raised when connecting nodes whose tensor shapes are incompatible for the requested op.
§Examples
add(A, B)requiresshape(A) == shape(B).matmul(L, R)requiresLandRbe 2-D andL.shape[1] == R.shape[0].
This error indicates the graph is not well-typed under the op’s shape rules.
InvalidNodeId
Raised when an operation references a NodeId that does not exist in the graph.
This typically happens when:
- A
NodeIdwas produced by a differentGraphinstance, or - A stale/invalid
NodeIdwas stored and reused.
§Example
let mut g1 = Graph::new();
let foreign = g1.input_node(vec![1, 1]);
let mut g2 = Graph::new();
assert!(matches!(g2.relu(foreign).unwrap_err(), GraphError::InvalidNodeId));IdCollision
Raised when inserting a node whose ID already exists in the graph.
In this implementation, node IDs are expected to be monotonically increasing and unique. A collision indicates a serious invariant failure (e.g. ID overflow or a bug in node allocation), and should be treated as unrecoverable at the application level.
CycleDetected
Raised when the graph contains a cycle and no valid execution order exists.
Trait Implementations§
Source§impl Clone for GraphError
impl Clone for GraphError
Source§fn clone(&self) -> GraphError
fn clone(&self) -> GraphError
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more