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)
| 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 | /// |