r"""Replaces operators in the graph. Args: repl_dict: the map {old_opr: new_opr} that specifies how to replace the operators.
(self, repl_dict: Dict[OpNode, OpNode])
| 399 | self._compile() |
| 400 | |
| 401 | def replace_oprs(self, repl_dict: Dict[OpNode, OpNode]): |
| 402 | r"""Replaces operators in the graph. |
| 403 | |
| 404 | Args: |
| 405 | repl_dict: the map {old_opr: new_opr} that specifies how to replace the operators. |
| 406 | """ |
| 407 | for opr in self.all_oprs: |
| 408 | if opr in repl_dict: |
| 409 | assert len(opr.outputs) == len( |
| 410 | repl_dict[opr].outputs |
| 411 | ), "can not replace {} with {}".format(type(opr), type(repl_dict[opr])) |
| 412 | for ind, var in enumerate(opr.outputs): |
| 413 | var.owner = repl_dict[opr] |
| 414 | var.__dict__.update(repl_dict[opr].outputs[ind].__dict__) |
| 415 | var._reset_var(repl_dict[opr].outputs[ind].var) |
| 416 | repl_dict[opr].outputs = opr.outputs |
| 417 | self._compile() |
| 418 | |
| 419 | def get_opr_by_type(self, oprcls, unique=True): |
| 420 | assert issubclass(oprcls, OpNode) |