pub struct ComputationGraph {
pub inputs: Vec<NodeId>,
pub outputs: Vec<NodeId>,
pub metadata: GraphMetadata,
/* private fields */
}Expand description
Computation graph representing a neural network or computation
Fields§
§inputs: Vec<NodeId>Input nodes
outputs: Vec<NodeId>Output nodes
metadata: GraphMetadataMetadata
Implementations§
Source§impl ComputationGraph
impl ComputationGraph
Sourcepub fn add_output(&mut self, node: NodeId)
pub fn add_output(&mut self, node: NodeId)
Mark a node as output
Sourcepub fn get_node_mut(&mut self, id: NodeId) -> Option<&mut Node>
pub fn get_node_mut(&mut self, id: NodeId) -> Option<&mut Node>
Get mutable node by ID
Sourcepub fn incoming_edges(&self, id: NodeId) -> Vec<(NodeId, NodeId, &Edge)>
pub fn incoming_edges(&self, id: NodeId) -> Vec<(NodeId, NodeId, &Edge)>
Get incoming edges for a node
Sourcepub fn outgoing_edges(&self, id: NodeId) -> Vec<(NodeId, NodeId, &Edge)>
pub fn outgoing_edges(&self, id: NodeId) -> Vec<(NodeId, NodeId, &Edge)>
Get outgoing edges for a node
Sourcepub fn remove_node(&mut self, id: NodeId) -> Option<Node>
pub fn remove_node(&mut self, id: NodeId) -> Option<Node>
Remove a node from the graph
Sourcepub fn remove_edge(&mut self, from: NodeId, to: NodeId) -> bool
pub fn remove_edge(&mut self, from: NodeId, to: NodeId) -> bool
Remove an edge from the graph
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Get number of nodes
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Get number of edges
Sourcepub fn topological_sort(&self) -> JitResult<Vec<NodeId>>
pub fn topological_sort(&self) -> JitResult<Vec<NodeId>>
Get topological ordering of nodes
Sourcepub fn subgraph(&self, node_ids: &[NodeId]) -> JitResult<ComputationGraph>
pub fn subgraph(&self, node_ids: &[NodeId]) -> JitResult<ComputationGraph>
Clone with only specified nodes
Sourcepub fn strongly_connected_components(&self) -> Vec<Vec<NodeId>>
pub fn strongly_connected_components(&self) -> Vec<Vec<NodeId>>
Get strongly connected components
Sourcepub fn memory_estimate(&self) -> usize
pub fn memory_estimate(&self) -> usize
Get memory usage estimate in bytes
Sourcepub fn complexity_estimate(&self) -> usize
pub fn complexity_estimate(&self) -> usize
Get computational complexity estimate (FLOPs)
Sourcepub fn predecessors(&self, node_id: NodeId) -> impl Iterator<Item = NodeId> + '_
pub fn predecessors(&self, node_id: NodeId) -> impl Iterator<Item = NodeId> + '_
Get predecessors of a node (compatibility method)
Sourcepub fn successors(&self, node_id: NodeId) -> impl Iterator<Item = NodeId> + '_
pub fn successors(&self, node_id: NodeId) -> impl Iterator<Item = NodeId> + '_
Get successors of a node (compatibility method)
Sourcepub fn node_mut(&mut self, id: NodeId) -> Option<&mut Node>
pub fn node_mut(&mut self, id: NodeId) -> Option<&mut Node>
Get mutable node by ID (compatibility method)
Sourcepub fn edges_directed(
&self,
node_id: NodeId,
direction: Direction,
) -> impl Iterator<Item = EdgeReference<'_, Edge>>
pub fn edges_directed( &self, node_id: NodeId, direction: Direction, ) -> impl Iterator<Item = EdgeReference<'_, Edge>>
Get directed edges for a node (compatibility method)
Sourcepub fn is_acyclic(&self) -> bool
pub fn is_acyclic(&self) -> bool
Check if the graph is acyclic (compatibility method)
Sourcepub fn replace_node_with_input(
&mut self,
node_id: NodeId,
replacement_id: NodeId,
) -> JitResult<()>
pub fn replace_node_with_input( &mut self, node_id: NodeId, replacement_id: NodeId, ) -> JitResult<()>
Replace a node with one of its inputs (for constant folding and branch elimination)
This operation:
- Redirects all edges coming into
node_idtoreplacement_id - Redirects all edges going out of
node_idto come fromreplacement_id - Removes
node_idfrom the graph
§Arguments
node_id- The node to replacereplacement_id- The input node that will replace it
§Returns
Ok(())if successfulErr(JitError)if the replacement would create an invalid graph
Sourcepub fn replace_node_with_sequence(
&mut self,
node_id: NodeId,
sequence: &[Node],
) -> JitResult<()>
pub fn replace_node_with_sequence( &mut self, node_id: NodeId, sequence: &[Node], ) -> JitResult<()>
Replace a node with a sequence of nodes (for loop unrolling and macro expansion)
This operation:
- Inserts the sequence of nodes into the graph
- Connects the first node in the sequence to the inputs of
node_id - Connects the last node in the sequence to the outputs of
node_id - Removes
node_idfrom the graph
§Arguments
node_id- The node to replacesequence- The sequence of nodes to insert (must not be empty)
§Returns
Ok(())if successfulErr(JitError)if the sequence is empty or would create an invalid graph
Trait Implementations§
Source§impl Clone for ComputationGraph
impl Clone for ComputationGraph
Source§fn clone(&self) -> ComputationGraph
fn clone(&self) -> ComputationGraph
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ComputationGraph
impl Debug for ComputationGraph
Auto Trait Implementations§
impl Freeze for ComputationGraph
impl RefUnwindSafe for ComputationGraph
impl Send for ComputationGraph
impl Sync for ComputationGraph
impl Unpin for ComputationGraph
impl UnsafeUnpin for ComputationGraph
impl UnwindSafe for ComputationGraph
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more