Adds an operator to current scope. Args: create_node: factory method creating an operator node, taking node id as a parameter. call_operator: operator callback
(
self,
create_node: Callable[[int], O],
call_operator: Callable[[O], T],
*,
special: bool = False,
require_error_log: bool = True,
)
| 130 | return scope |
| 131 | |
| 132 | def add_operator( |
| 133 | self, |
| 134 | create_node: Callable[[int], O], |
| 135 | call_operator: Callable[[O], T], |
| 136 | *, |
| 137 | special: bool = False, |
| 138 | require_error_log: bool = True, |
| 139 | ) -> T: |
| 140 | """Adds an operator to current scope. |
| 141 | |
| 142 | Args: |
| 143 | create_node: factory method creating an operator node, taking node id as a parameter. |
| 144 | call_operator: operator callback |
| 145 | """ |
| 146 | node = create_node(next(self.node_id_sequence)) |
| 147 | node.set_graph(self) |
| 148 | if require_error_log and not self.error_log_stack: |
| 149 | self.add_error_log(global_log=True) # deferred global log creation |
| 150 | node.set_error_log(self.error_log_stack[-1] if require_error_log else None) |
| 151 | result = call_operator(node) |
| 152 | self._current_scope.add_node(node, special=special) |
| 153 | self.unused_operators = True |
| 154 | return result |
| 155 | |
| 156 | def add_iterate( |
| 157 | self, |
no test coverage detected