Skip to main content

ComputationGraph

Struct ComputationGraph 

Source
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: GraphMetadata

Metadata

Implementations§

Source§

impl ComputationGraph

Source

pub fn new() -> Self

Create a new empty computation graph

Source

pub fn add_node(&mut self, node: Node) -> NodeId

Add a node to the graph

Source

pub fn add_edge(&mut self, from: NodeId, to: NodeId, edge: Edge)

Add an edge between nodes

Source

pub fn add_input(&mut self, node: NodeId)

Mark a node as input

Source

pub fn add_output(&mut self, node: NodeId)

Mark a node as output

Source

pub fn nodes(&self) -> impl Iterator<Item = (NodeId, &Node)>

Get all nodes

Source

pub fn edges(&self) -> impl Iterator<Item = (NodeId, NodeId, &Edge)> + '_

Get all edges

Source

pub fn get_node(&self, id: NodeId) -> Option<&Node>

Get node by ID

Source

pub fn get_node_mut(&mut self, id: NodeId) -> Option<&mut Node>

Get mutable node by ID

Source

pub fn get_node_inputs(&self, id: NodeId) -> Vec<NodeId>

Get node inputs

Source

pub fn get_node_outputs(&self, id: NodeId) -> Vec<NodeId>

Get node outputs

Source

pub fn incoming_edges(&self, id: NodeId) -> Vec<(NodeId, NodeId, &Edge)>

Get incoming edges for a node

Source

pub fn outgoing_edges(&self, id: NodeId) -> Vec<(NodeId, NodeId, &Edge)>

Get outgoing edges for a node

Source

pub fn remove_node(&mut self, id: NodeId) -> Option<Node>

Remove a node from the graph

Source

pub fn remove_edge(&mut self, from: NodeId, to: NodeId) -> bool

Remove an edge from the graph

Source

pub fn node_count(&self) -> usize

Get number of nodes

Source

pub fn edge_count(&self) -> usize

Get number of edges

Source

pub fn is_empty(&self) -> bool

Check if graph is empty

Source

pub fn validate(&self) -> JitResult<()>

Validate the graph structure

Source

pub fn topological_sort(&self) -> JitResult<Vec<NodeId>>

Get topological ordering of nodes

Source

pub fn subgraph(&self, node_ids: &[NodeId]) -> JitResult<ComputationGraph>

Clone with only specified nodes

Source

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

Get strongly connected components

Source

pub fn memory_estimate(&self) -> usize

Get memory usage estimate in bytes

Source

pub fn complexity_estimate(&self) -> usize

Get computational complexity estimate (FLOPs)

Source

pub fn predecessors(&self, node_id: NodeId) -> impl Iterator<Item = NodeId> + '_

Get predecessors of a node (compatibility method)

Source

pub fn successors(&self, node_id: NodeId) -> impl Iterator<Item = NodeId> + '_

Get successors of a node (compatibility method)

Source

pub fn node(&self, id: NodeId) -> Option<&Node>

Get node by ID (compatibility method)

Source

pub fn node_mut(&mut self, id: NodeId) -> Option<&mut Node>

Get mutable node by ID (compatibility method)

Source

pub fn edges_directed( &self, node_id: NodeId, direction: Direction, ) -> impl Iterator<Item = EdgeReference<'_, Edge>>

Get directed edges for a node (compatibility method)

Source

pub fn is_acyclic(&self) -> bool

Check if the graph is acyclic (compatibility method)

Source

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:

  1. Redirects all edges coming into node_id to replacement_id
  2. Redirects all edges going out of node_id to come from replacement_id
  3. Removes node_id from the graph
§Arguments
  • node_id - The node to replace
  • replacement_id - The input node that will replace it
§Returns
  • Ok(()) if successful
  • Err(JitError) if the replacement would create an invalid graph
Source

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:

  1. Inserts the sequence of nodes into the graph
  2. Connects the first node in the sequence to the inputs of node_id
  3. Connects the last node in the sequence to the outputs of node_id
  4. Removes node_id from the graph
§Arguments
  • node_id - The node to replace
  • sequence - The sequence of nodes to insert (must not be empty)
§Returns
  • Ok(()) if successful
  • Err(JitError) if the sequence is empty or would create an invalid graph

Trait Implementations§

Source§

impl Clone for ComputationGraph

Source§

fn clone(&self) -> ComputationGraph

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 ComputationGraph

Source§

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

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

impl Default for ComputationGraph

Source§

fn default() -> Self

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

Auto Trait Implementations§

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