Skip to main content

EinsumGraph

Struct EinsumGraph 

Source
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

Source

pub fn extract_subgraph( &self, node_indices: &[usize], ) -> Result<EinsumGraph, IrError>

Extract a subgraph containing only the specified nodes and their dependencies.

Source

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.

Source

pub fn visit<V: GraphVisitor>(&self, visitor: &mut V)

Visit all nodes in the graph using a visitor.

Source

pub fn visit_mut<V: GraphMutVisitor>( &mut self, visitor: &mut V, ) -> Result<(), IrError>

Visit all nodes mutably using a mutable visitor.

Source

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.

Source

pub fn tensor_consumers(&self, tensor_idx: usize) -> Vec<usize>

Get all nodes that depend on a specific tensor (consume it as input).

Source

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.

Source

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.

Source

pub fn dependencies(&self, node_idx: usize) -> HashSet<usize>

Get dependency chain for a node (all nodes it depends on).

Source

pub fn node_count(&self) -> usize

Get number of nodes.

Source

pub fn tensor_count(&self) -> usize

Get number of tensors.

Source§

impl EinsumGraph

Source

pub fn new() -> Self

Source

pub fn with_capacity(tensor_cap: usize, node_cap: usize) -> Self

Source

pub fn add_tensor(&mut self, name: impl Into<String>) -> usize

Source

pub fn add_node(&mut self, node: EinsumNode) -> Result<usize, IrError>

Source

pub fn add_input(&mut self, tensor_idx: usize) -> Result<(), IrError>

Source

pub fn add_output(&mut self, tensor_idx: usize) -> Result<(), IrError>

Source

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

Source

pub fn is_empty(&self) -> bool

Source

pub fn add_tensor_metadata(&mut self, tensor_idx: usize, metadata: Metadata)

Add metadata for a tensor.

Source

pub fn get_tensor_metadata(&self, tensor_idx: usize) -> Option<&Metadata>

Get metadata for a tensor if it exists.

Source

pub fn add_tensor_with_metadata( &mut self, name: impl Into<String>, metadata: Metadata, ) -> usize

Add a tensor with metadata.

Trait Implementations§

Source§

impl Clone for EinsumGraph

Source§

fn clone(&self) -> EinsumGraph

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 EinsumGraph

Source§

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

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

impl Default for EinsumGraph

Source§

fn default() -> EinsumGraph

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

impl<'de> Deserialize<'de> for EinsumGraph

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for EinsumGraph

Source§

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

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

impl PartialEq for EinsumGraph

Source§

fn eq(&self, other: &EinsumGraph) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for EinsumGraph

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for EinsumGraph

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,