pub struct Graph {
pub nodes: Vec<GraphNode>,
pub names: BTreeMap<usize, String>,
}Expand description
The traced computational graph: a list of GraphNodes plus optional node names.
Fields§
§nodes: Vec<GraphNode>The graph’s nodes, in the order they were recorded.
names: BTreeMap<usize, String>Node index → dotted name captured from [crate::name_scope] at recording time.
Implementations§
Source§impl Graph
impl Graph
Sourcepub fn add_node(
&mut self,
op: Op,
inputs: Vec<usize>,
dtype: DtypeRepr,
shape: Shape,
) -> usize
pub fn add_node( &mut self, op: Op, inputs: Vec<usize>, dtype: DtypeRepr, shape: Shape, ) -> usize
Appends a new node to the graph, returning its index.
Sourcepub fn topological_sort(&self) -> Vec<usize>
pub fn topological_sort(&self) -> Vec<usize>
Returns node indices in topological order (producers before consumers) using Kahn’s algorithm. Panics if the graph contains a cycle.
Sourcepub fn optimise(&self) -> Graph
pub fn optimise(&self) -> Graph
Rewrite the graph by fusing compatible op sequences into single fused ops.
Currently recognises: Conv2d(no bias) → BatchNorm2d → Silu
and replaces the triple with a single Conv2dBnSilu node.
Nodes that are absorbed into a fused node are removed from the output graph; remaining node indices are renumbered contiguously.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Graph
impl !RefUnwindSafe for Graph
impl Send for Graph
impl Sync for Graph
impl Unpin for Graph
impl UnsafeUnpin for Graph
impl !UnwindSafe for Graph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more