pub struct Graph {
pub vars: HashMap<String, VarDecl>,
pub blocks: HashMap<String, Block>,
/* private fields */
}Expand description
Graph structure containing blocks and variable declarations.
Fields§
§vars: HashMap<String, VarDecl>§blocks: HashMap<String, Block>Implementations§
Source§impl Graph
impl Graph
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an empty graph with no blocks or variables.
§Example
let mut g = Graph::new();
g.add_block("entry");
g.add_var(MemoryKind::Dynamic, "x", DType::F32, vec!["B".into()], None, None, vec![], None, false, vec![], vec![]);
g.add_node("entry", NodeKind::Return)?;Sourcepub fn add_var(
&mut self,
kind: MemoryKind,
name: impl Into<String>,
dtype: DType,
dims: Vec<String>,
init: Option<ScalarValue>,
ref_name: Option<String>,
table_indices: Vec<String>,
pattern: Option<String>,
table: bool,
auto_dim: Vec<String>,
fixed: Vec<(String, usize)>,
)
pub fn add_var( &mut self, kind: MemoryKind, name: impl Into<String>, dtype: DType, dims: Vec<String>, init: Option<ScalarValue>, ref_name: Option<String>, table_indices: Vec<String>, pattern: Option<String>, table: bool, auto_dim: Vec<String>, fixed: Vec<(String, usize)>, )
Add a variable declaration to the graph.
Sourcepub fn add_block(&mut self, name: impl Into<String>)
pub fn add_block(&mut self, name: impl Into<String>)
Ensure a block exists, creating it if missing.
Sourcepub fn add_node(&mut self, block: &str, kind: NodeKind) -> Result<()>
pub fn add_node(&mut self, block: &str, kind: NodeKind) -> Result<()>
Append a node to a block by name.
Sourcepub fn add_prebuilt_node(&mut self, block: &str, node: Node) -> Result<()>
pub fn add_prebuilt_node(&mut self, block: &str, node: Node) -> Result<()>
Append a prebuilt node to a block by name.
Sourcepub fn make_node(&mut self, kind: NodeKind) -> Node
pub fn make_node(&mut self, kind: NodeKind) -> Node
Allocate a node with a fresh index and UUID.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Graph
impl<'de> Deserialize<'de> for Graph
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. 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 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
Mutably borrows from an owned value. Read more
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>
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 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>
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