Skip to main content

Graph

Struct Graph 

Source
pub struct Graph { /* private fields */ }
Expand description

Main computation graph structure

Implementations§

Source§

impl Graph

Source

pub fn compute_topological_order(&mut self) -> Result<&[NodeId], TensorError>

Compute and cache the topological order of nodes

Source

pub fn validate(&self) -> Result<(), TensorError>

Validate the graph structure

Source

pub fn input_nodes(&self) -> Vec<NodeId>

Find all input nodes (nodes with no incoming data edges)

Source

pub fn output_nodes(&self) -> Vec<NodeId>

Find all output nodes (nodes with no outgoing data edges)

Source§

impl Graph

Source

pub fn add_control_dependency( &mut self, from_node: NodeId, to_node: NodeId, ) -> Result<EdgeId, TensorError>

Add a control dependency between two nodes

Source

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

Source

pub fn get_control_dependencies(&self, node_id: NodeId) -> Vec<NodeId>

Get all nodes that this node has control dependencies on

Source

pub fn get_control_dependents(&self, node_id: NodeId) -> Vec<NodeId>

Get all nodes that depend on this node via control dependencies

Source

pub fn has_control_dependency(&self, from_node: NodeId, to_node: NodeId) -> bool

Check if there’s a control dependency between two nodes

Source

pub fn remove_control_dependencies( &mut self, node_id: NodeId, ) -> Result<usize, TensorError>

Remove all control dependencies for a node (both incoming and outgoing)

Source

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

Source

pub fn new() -> Self

Create a new empty graph

Source

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

Source

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

Source

pub fn get_node(&self, node_id: NodeId) -> Option<&GraphNode>

Get a node by ID

Source

pub fn get_node_by_name(&self, name: &str) -> Option<&GraphNode>

Get a node by name

Source

pub fn get_edge(&self, edge_id: EdgeId) -> Option<&GraphEdge>

Get an edge by ID

Source

pub fn nodes(&self) -> impl Iterator<Item = &GraphNode>

Iterate over all nodes

Source

pub fn edges(&self) -> impl Iterator<Item = &GraphEdge>

Iterate over all edges

Source

pub fn get_node_mut(&mut self, node_id: NodeId) -> Option<&mut GraphNode>

Get a mutable reference to a node

Source

pub fn get_edge_mut(&mut self, edge_id: EdgeId) -> Option<&mut GraphEdge>

Get a mutable reference to an edge

Source

pub fn node_count(&self) -> usize

Get the number of nodes

Source

pub fn edge_count(&self) -> usize

Get the number of edges

Source§

impl Graph

Source

pub fn extend_with_graph( &mut self, other: &Graph, node_prefix: Option<&str>, ) -> Result<HashMap<NodeId, NodeId>, TensorError>

Extend this graph with another graph

Source

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

Source

pub fn merge_graphs(graphs: &[&Graph]) -> Result<Graph, TensorError>

Merge multiple graphs into a single graph

Source

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

Source

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)

Source

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

pub fn replace_node_with_subgraph( &mut self, node_to_replace: NodeId, replacement_graph: &Graph, input_mapping: &HashMap<usize, NodeId>, output_mapping: &HashMap<usize, NodeId>, ) -> Result<HashMap<NodeId, NodeId>, TensorError>

Replace a node with a subgraph

Source§

impl Graph

Source

pub fn remove_node(&mut self, node_id: NodeId) -> Result<(), TensorError>

Remove a node and all its associated edges

Source

pub fn remove_edge(&mut self, edge_id: EdgeId) -> Result<(), TensorError>

Remove an edge

Source

pub fn replace_with_constant( &mut self, node_id: NodeId, constant_value: Tensor<f32>, ) -> Result<(), TensorError>

Replace a node with a constant value

Source

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

Source

pub fn to_graph_def(&self) -> GraphDef

Convert graph to serializable format

Source

pub fn from_graph_def(graph_def: &GraphDef) -> Result<Self, TensorError>

Create graph from serializable format

Source§

impl Graph

Source

pub fn subgraph(&self, node_ids: &[NodeId]) -> Result<Graph, TensorError>

Create a subgraph containing only the specified nodes

Source

pub fn subgraph_by_op_types( &self, op_types: &[&str], ) -> Result<Graph, TensorError>

Create a subgraph containing nodes of specific operation types

Source

pub fn subgraph_by_device(&self, device: Device) -> Result<Graph, TensorError>

Create a subgraph containing nodes on a specific device

Source

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

Source

pub fn connected_component( &self, start_node: NodeId, ) -> Result<Graph, TensorError>

Find the connected component containing the specified node

Source

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)

Source

pub fn subgraph_by_predicate<F>( &self, predicate: F, ) -> Result<Graph, TensorError>
where F: Fn(&GraphNode) -> bool,

Create a subgraph based on a custom predicate function

Trait Implementations§

Source§

impl Clone for Graph

Source§

fn clone(&self) -> Graph

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Graph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Graph

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V