pub struct EinsumGraph {
pub tensors: Vec<String>,
pub nodes: Vec<EinsumNode>,
pub inputs: Vec<usize>,
pub outputs: Vec<usize>,
pub tensor_metadata: HashMap<usize, Metadata>,
}Fields§
§tensors: Vec<String>§nodes: Vec<EinsumNode>§inputs: Vec<usize>§outputs: Vec<usize>§tensor_metadata: HashMap<usize, Metadata>Metadata for tensors (indexed by tensor index)
Implementations§
Source§impl EinsumGraph
impl EinsumGraph
Sourcepub fn extract_subgraph(
&self,
node_indices: &[usize],
) -> Result<EinsumGraph, IrError>
pub fn extract_subgraph( &self, node_indices: &[usize], ) -> Result<EinsumGraph, IrError>
Extract a subgraph containing only the specified nodes and their dependencies.
Sourcepub fn merge(
&mut self,
other: &EinsumGraph,
) -> Result<HashMap<usize, usize>, IrError>
pub fn merge( &mut self, other: &EinsumGraph, ) -> Result<HashMap<usize, usize>, IrError>
Merge another graph into this one.
Returns a mapping from old tensor indices to new tensor indices.
Sourcepub fn visit<V: GraphVisitor>(&self, visitor: &mut V)
pub fn visit<V: GraphVisitor>(&self, visitor: &mut V)
Visit all nodes in the graph using a visitor.
Sourcepub fn visit_mut<V: GraphMutVisitor>(
&mut self,
visitor: &mut V,
) -> Result<(), IrError>
pub fn visit_mut<V: GraphMutVisitor>( &mut self, visitor: &mut V, ) -> Result<(), IrError>
Visit all nodes mutably using a mutable visitor.
Sourcepub fn apply_rewrite<F>(&mut self, rule: F) -> Result<usize, IrError>
pub fn apply_rewrite<F>(&mut self, rule: F) -> Result<usize, IrError>
Apply a rewrite rule to all nodes in the graph.
The rule function takes a node and returns an optional replacement node.
Sourcepub fn tensor_consumers(&self, tensor_idx: usize) -> Vec<usize>
pub fn tensor_consumers(&self, tensor_idx: usize) -> Vec<usize>
Get all nodes that depend on a specific tensor (consume it as input).
Sourcepub fn tensor_producer(&self, tensor_idx: usize) -> Option<usize>
pub fn tensor_producer(&self, tensor_idx: usize) -> Option<usize>
Get the node that produces a specific tensor.
Note: In the current graph model, tensors can be produced by at most one node or be external inputs. This returns nodes that might output to this tensor based on graph topology.
Sourcepub fn has_path(&self, node_from: usize, node_to: usize) -> bool
pub fn has_path(&self, node_from: usize, node_to: usize) -> bool
Check if there’s a path from node_from to node_to based on node ordering.
Sourcepub fn dependencies(&self, node_idx: usize) -> HashSet<usize>
pub fn dependencies(&self, node_idx: usize) -> HashSet<usize>
Get dependency chain for a node (all nodes it depends on).
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Get number of nodes.
Sourcepub fn tensor_count(&self) -> usize
pub fn tensor_count(&self) -> usize
Get number of tensors.
Source§impl EinsumGraph
impl EinsumGraph
pub fn new() -> Self
pub fn with_capacity(tensor_cap: usize, node_cap: usize) -> Self
pub fn add_tensor(&mut self, name: impl Into<String>) -> usize
pub fn add_node(&mut self, node: EinsumNode) -> Result<usize, IrError>
pub fn add_input(&mut self, tensor_idx: usize) -> Result<(), IrError>
pub fn add_output(&mut self, tensor_idx: usize) -> Result<(), IrError>
pub fn validate(&self) -> Result<(), IrError>
pub fn is_empty(&self) -> bool
Sourcepub fn add_tensor_metadata(&mut self, tensor_idx: usize, metadata: Metadata)
pub fn add_tensor_metadata(&mut self, tensor_idx: usize, metadata: Metadata)
Add metadata for a tensor.
Sourcepub fn get_tensor_metadata(&self, tensor_idx: usize) -> Option<&Metadata>
pub fn get_tensor_metadata(&self, tensor_idx: usize) -> Option<&Metadata>
Get metadata for a tensor if it exists.
Trait Implementations§
Source§impl Clone for EinsumGraph
impl Clone for EinsumGraph
Source§fn clone(&self) -> EinsumGraph
fn clone(&self) -> EinsumGraph
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more