MCPcopy
hub / github.com/OpenPPL/ppq / replace_var

Method replace_var

ppq/IR/morph.py:53–73  ·  view source on GitHub ↗
(self, var_name: str, replace_to: Variable)

Source from the content-addressed store, hash-verified

51 self._graph.operations[op_name] = replace_to
52
53 def replace_var(self, var_name: str, replace_to: Variable):
54 if var_name not in self._graph.variables:
55 raise KeyError(f'Variable {var_name} is not in current graph')
56 variable = self._graph.variables[var_name]
57
58 replace_to.dest_ops.clear()
59 replace_to.dest_ops.extend(variable.dest_ops)
60 for dest_op in replace_to.dest_ops:
61 dest_idx = dest_op.inputs.index(variable)
62 dest_op.inputs[dest_idx] = replace_to
63
64 replace_to.source_op = variable.source_op
65 if variable.source_op is not None:
66 source_idx = variable.source_op.outputs.index(variable)
67 variable.source_op.outputs[source_idx] = replace_to
68
69 self._graph.variables[var_name] = replace_to
70 if var_name in self._graph.inputs:
71 self._graph.inputs[var_name] = replace_to
72 if var_name in self._graph.outputs:
73 self._graph.outputs[var_name] = replace_to
74
75 def _acceptable_command_types(self) -> List[GraphCommandType]:
76 return [

Callers 1

processMethod · 0.95

Calls 1

clearMethod · 0.45

Tested by

no test coverage detected