pub struct Graph { /* private fields */ }Expand description
Main computation graph structure
Implementations§
Source§impl Graph
impl Graph
Sourcepub fn compute_topological_order(&mut self) -> Result<&[NodeId], TensorError>
pub fn compute_topological_order(&mut self) -> Result<&[NodeId], TensorError>
Compute and cache the topological order of nodes
Sourcepub fn validate(&self) -> Result<(), TensorError>
pub fn validate(&self) -> Result<(), TensorError>
Validate the graph structure
Sourcepub fn input_nodes(&self) -> Vec<NodeId> ⓘ
pub fn input_nodes(&self) -> Vec<NodeId> ⓘ
Find all input nodes (nodes with no incoming data edges)
Sourcepub fn output_nodes(&self) -> Vec<NodeId> ⓘ
pub fn output_nodes(&self) -> Vec<NodeId> ⓘ
Find all output nodes (nodes with no outgoing data edges)
Source§impl Graph
impl Graph
Sourcepub fn add_control_dependency(
&mut self,
from_node: NodeId,
to_node: NodeId,
) -> Result<EdgeId, TensorError>
pub fn add_control_dependency( &mut self, from_node: NodeId, to_node: NodeId, ) -> Result<EdgeId, TensorError>
Add a control dependency between two nodes
Sourcepub fn add_control_dependencies(
&mut self,
from_node: NodeId,
to_nodes: &[NodeId],
) -> Result<Vec<EdgeId>, TensorError>
pub fn add_control_dependencies( &mut self, from_node: NodeId, to_nodes: &[NodeId], ) -> Result<Vec<EdgeId>, TensorError>
Add control dependencies from one node to multiple nodes
Sourcepub fn get_control_dependencies(&self, node_id: NodeId) -> Vec<NodeId> ⓘ
pub fn get_control_dependencies(&self, node_id: NodeId) -> Vec<NodeId> ⓘ
Get all nodes that this node has control dependencies on
Sourcepub fn get_control_dependents(&self, node_id: NodeId) -> Vec<NodeId> ⓘ
pub fn get_control_dependents(&self, node_id: NodeId) -> Vec<NodeId> ⓘ
Get all nodes that depend on this node via control dependencies
Sourcepub fn has_control_dependency(&self, from_node: NodeId, to_node: NodeId) -> bool
pub fn has_control_dependency(&self, from_node: NodeId, to_node: NodeId) -> bool
Check if there’s a control dependency between two nodes
Sourcepub fn remove_control_dependencies(
&mut self,
node_id: NodeId,
) -> Result<usize, TensorError>
pub fn remove_control_dependencies( &mut self, node_id: NodeId, ) -> Result<usize, TensorError>
Remove all control dependencies for a node (both incoming and outgoing)
Sourcepub fn create_control_context(
&mut self,
context_nodes: &[NodeId],
) -> Result<(), TensorError>
pub fn create_control_context( &mut self, context_nodes: &[NodeId], ) -> Result<(), TensorError>
Create a control context - ensure all nodes in the list execute in order
Source§impl Graph
impl Graph
Sourcepub fn add_node(
&mut self,
name: String,
op_type: NodeType,
device: Device,
attributes: HashMap<String, AttributeValue>,
) -> Result<NodeId, TensorError>
pub fn add_node( &mut self, name: String, op_type: NodeType, device: Device, attributes: HashMap<String, AttributeValue>, ) -> Result<NodeId, TensorError>
Add a new node to the graph
Sourcepub fn add_edge(
&mut self,
from_node: NodeId,
to_node: NodeId,
from_output: usize,
to_input: usize,
dtype: DType,
shape: Shape,
is_control: bool,
) -> Result<EdgeId, TensorError>
pub fn add_edge( &mut self, from_node: NodeId, to_node: NodeId, from_output: usize, to_input: usize, dtype: DType, shape: Shape, is_control: bool, ) -> Result<EdgeId, TensorError>
Add a new edge to the graph
Sourcepub fn get_node_by_name(&self, name: &str) -> Option<&GraphNode>
pub fn get_node_by_name(&self, name: &str) -> Option<&GraphNode>
Get a node by name
Sourcepub fn get_node_mut(&mut self, node_id: NodeId) -> Option<&mut GraphNode>
pub fn get_node_mut(&mut self, node_id: NodeId) -> Option<&mut GraphNode>
Get a mutable reference to a node
Sourcepub fn get_edge_mut(&mut self, edge_id: EdgeId) -> Option<&mut GraphEdge>
pub fn get_edge_mut(&mut self, edge_id: EdgeId) -> Option<&mut GraphEdge>
Get a mutable reference to an edge
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Get the number of nodes
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Get the number of edges
Source§impl Graph
impl Graph
Sourcepub fn extend_with_graph(
&mut self,
other: &Graph,
node_prefix: Option<&str>,
) -> Result<HashMap<NodeId, NodeId>, TensorError>
pub fn extend_with_graph( &mut self, other: &Graph, node_prefix: Option<&str>, ) -> Result<HashMap<NodeId, NodeId>, TensorError>
Extend this graph with another graph
Sourcepub fn integrate_subgraph(
&mut self,
subgraph: &Graph,
input_connections: &[(NodeId, usize, NodeId, usize)],
output_connections: &[(NodeId, usize, NodeId, usize)],
node_prefix: Option<&str>,
) -> Result<HashMap<NodeId, NodeId>, TensorError>
pub fn integrate_subgraph( &mut self, subgraph: &Graph, input_connections: &[(NodeId, usize, NodeId, usize)], output_connections: &[(NodeId, usize, NodeId, usize)], node_prefix: Option<&str>, ) -> Result<HashMap<NodeId, NodeId>, TensorError>
Integrate a subgraph into this graph at specific connection points
Sourcepub fn merge_graphs(graphs: &[&Graph]) -> Result<Graph, TensorError>
pub fn merge_graphs(graphs: &[&Graph]) -> Result<Graph, TensorError>
Merge multiple graphs into a single graph
Sourcepub fn add_node_auto_name(
&mut self,
base_name: &str,
op_type: NodeType,
device: Device,
attributes: HashMap<String, AttributeValue>,
) -> Result<NodeId, TensorError>
pub fn add_node_auto_name( &mut self, base_name: &str, op_type: NodeType, device: Device, attributes: HashMap<String, AttributeValue>, ) -> Result<NodeId, TensorError>
Add a node with automatically generated unique name
Sourcepub fn add_operation_subgraph(
&mut self,
op_name: &str,
inputs: &[NodeId],
output_shapes: &[Shape],
output_dtypes: &[DType],
device: Device,
attributes: HashMap<String, AttributeValue>,
) -> Result<Vec<NodeId>, TensorError>
pub fn add_operation_subgraph( &mut self, op_name: &str, inputs: &[NodeId], output_shapes: &[Shape], output_dtypes: &[DType], device: Device, attributes: HashMap<String, AttributeValue>, ) -> Result<Vec<NodeId>, TensorError>
Add a complete operation subgraph (operation with inputs and outputs)
Sourcepub fn insert_node_between(
&mut self,
from_node: NodeId,
to_node: NodeId,
new_node_name: String,
new_node_type: NodeType,
device: Device,
attributes: HashMap<String, AttributeValue>,
) -> Result<NodeId, TensorError>
pub fn insert_node_between( &mut self, from_node: NodeId, to_node: NodeId, new_node_name: String, new_node_type: NodeType, device: Device, attributes: HashMap<String, AttributeValue>, ) -> Result<NodeId, TensorError>
Insert a new node between two existing connected nodes
Source§impl Graph
impl Graph
Sourcepub fn remove_node(&mut self, node_id: NodeId) -> Result<(), TensorError>
pub fn remove_node(&mut self, node_id: NodeId) -> Result<(), TensorError>
Remove a node and all its associated edges
Sourcepub fn remove_edge(&mut self, edge_id: EdgeId) -> Result<(), TensorError>
pub fn remove_edge(&mut self, edge_id: EdgeId) -> Result<(), TensorError>
Remove an edge
Sourcepub fn replace_with_constant(
&mut self,
node_id: NodeId,
constant_value: Tensor<f32>,
) -> Result<(), TensorError>
pub fn replace_with_constant( &mut self, node_id: NodeId, constant_value: Tensor<f32>, ) -> Result<(), TensorError>
Replace a node with a constant value
Sourcepub fn redirect_node_outputs(
&mut self,
from_node: NodeId,
to_node: NodeId,
) -> Result<usize, TensorError>
pub fn redirect_node_outputs( &mut self, from_node: NodeId, to_node: NodeId, ) -> Result<usize, TensorError>
Redirect all outputs from one node to another
Source§impl Graph
impl Graph
Sourcepub fn to_graph_def(&self) -> GraphDef
pub fn to_graph_def(&self) -> GraphDef
Convert graph to serializable format
Sourcepub fn from_graph_def(graph_def: &GraphDef) -> Result<Self, TensorError>
pub fn from_graph_def(graph_def: &GraphDef) -> Result<Self, TensorError>
Create graph from serializable format
Source§impl Graph
impl Graph
Sourcepub fn subgraph(&self, node_ids: &[NodeId]) -> Result<Graph, TensorError>
pub fn subgraph(&self, node_ids: &[NodeId]) -> Result<Graph, TensorError>
Create a subgraph containing only the specified nodes
Sourcepub fn subgraph_by_op_types(
&self,
op_types: &[&str],
) -> Result<Graph, TensorError>
pub fn subgraph_by_op_types( &self, op_types: &[&str], ) -> Result<Graph, TensorError>
Create a subgraph containing nodes of specific operation types
Sourcepub fn subgraph_by_device(&self, device: Device) -> Result<Graph, TensorError>
pub fn subgraph_by_device(&self, device: Device) -> Result<Graph, TensorError>
Create a subgraph containing nodes on a specific device
Sourcepub fn subgraph_with_dependencies(
&self,
root_nodes: &[NodeId],
include_control_deps: bool,
) -> Result<Graph, TensorError>
pub fn subgraph_with_dependencies( &self, root_nodes: &[NodeId], include_control_deps: bool, ) -> Result<Graph, TensorError>
Create a subgraph with all dependencies of the specified nodes
Sourcepub fn connected_component(
&self,
start_node: NodeId,
) -> Result<Graph, TensorError>
pub fn connected_component( &self, start_node: NodeId, ) -> Result<Graph, TensorError>
Find the connected component containing the specified node
Sourcepub fn forward_slice(
&self,
start_nodes: &[NodeId],
include_control_deps: bool,
) -> Result<Graph, TensorError>
pub fn forward_slice( &self, start_nodes: &[NodeId], include_control_deps: bool, ) -> Result<Graph, TensorError>
Create a forward slice from the given nodes (includes all nodes reachable forward)
Sourcepub fn subgraph_by_predicate<F>(
&self,
predicate: F,
) -> Result<Graph, TensorError>
pub fn subgraph_by_predicate<F>( &self, predicate: F, ) -> Result<Graph, TensorError>
Create a subgraph based on a custom predicate function
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
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