MCPcopy Create free account
hub / github.com/ciphermodelabs/ciphercore / set_graph_name

Method set_graph_name

ciphercore-base/src/graphs.rs:4103–4126  ·  view source on GitHub ↗

Sets the name of a graph. A given name should be unique. # Arguments `graph` - graph `name` - name of the graph # Returns This context # Example ``` # use ciphercore_base::graphs::create_context; let c = create_context().unwrap(); let g = c.create_graph().unwrap(); g.set_name("relu").unwrap(); ```

(&self, graph: Graph, name: &str)

Source from the content-addressed store, hash-verified

4101 /// g.set_name("relu").unwrap();
4102 /// ```
4103 pub fn set_graph_name(&self, graph: Graph, name: &str) -> Result<Context> {
4104 if graph.get_context() != *self {
4105 return Err(runtime_error!(
4106 "The graph to be named is in a different context"
4107 ));
4108 }
4109 if self.is_finalized() {
4110 return Err(runtime_error!(
4111 "Can't set a graph name in a finalized context"
4112 ));
4113 }
4114 let id = graph.get_id();
4115 let name_owned = name.to_owned();
4116 let mut cell = self.body.borrow_mut();
4117 if cell.graphs_names.get(&id).is_some() {
4118 return Err(runtime_error!("Can't set the graph name twice"));
4119 }
4120 if cell.graphs_names_inverse.get(name).is_some() {
4121 return Err(runtime_error!("Graph names must be unique"));
4122 }
4123 cell.graphs_names.insert(id, name_owned.clone());
4124 cell.graphs_names_inverse.insert(name_owned, id);
4125 Ok(self.clone())
4126 }
4127
4128 /// Returns the name of a graph.
4129 ///

Callers 5

set_nameMethod · 0.45
context_generatorsFunction · 0.45
test_named_contextsFunction · 0.45

Calls 6

is_finalizedMethod · 0.80
cloneMethod · 0.80
get_contextMethod · 0.45
get_idMethod · 0.45
getMethod · 0.45
insertMethod · 0.45

Tested by 1

test_named_contextsFunction · 0.36