| 36 | |
| 37 | |
| 38 | class SimpleNode: |
| 39 | def __init__( |
| 40 | self, |
| 41 | name: str = "", |
| 42 | op: str = "", |
| 43 | inputs: List[str] = [], |
| 44 | output_nodes: List[str] = [], |
| 45 | tensors: Dict[str, List[str]] = {}, |
| 46 | ): |
| 47 | self.name = name |
| 48 | self.op = op |
| 49 | self.inputs = inputs |
| 50 | # Input tensors. |
| 51 | self.inputs_tensors = [get_canonical_tensor_name(n) for n in inputs] |
| 52 | # Output nodes. |
| 53 | self.output_nodes = output_nodes.copy() |
| 54 | # Mapping from output tensor name to list of nodes that consume this tensor. |
| 55 | self.tensors = tensors.copy() |
| 56 | |
| 57 | @property |
| 58 | def num_inputs(self) -> int: |
| 59 | return len(self.inputs_tensors) |
| 60 | |
| 61 | @property |
| 62 | def num_outputs(self) -> int: |
| 63 | return len(self.output_nodes) |
| 64 | |
| 65 | @property |
| 66 | def num_tensors(self) -> int: |
| 67 | return len(self.tensors) |
| 68 | |
| 69 | @property |
| 70 | def input_nodes(self) -> List[str]: |
| 71 | return [tensor_name_to_node_name(inp) for inp in self.inputs_tensors] |
| 72 | |
| 73 | def __eq__(self, o: object) -> bool: |
| 74 | if not isinstance(o, SimpleNode): |
| 75 | return False |
| 76 | return ( |
| 77 | self.name == o.name |
| 78 | and self.op == o.op |
| 79 | and self.inputs_tensors == o.inputs_tensors |
| 80 | and self.output_nodes == o.output_nodes |
| 81 | and self.tensors == o.tensors |
| 82 | ) |
| 83 | |
| 84 | def __str__(self) -> str: |
| 85 | s = "" |
| 86 | s += "name : {}\n".format(self.name) |
| 87 | s += "op : {}\n".format(self.op) |
| 88 | s += "inputs_tensors: {}\n".format(self.inputs_tensors) |
| 89 | s += "ouput_nodes : {}\n".format(self.output_nodes) |
| 90 | s += "tensors : {}\n".format(self.tensors) |
| 91 | return s |
| 92 | |
| 93 | |
| 94 | class SimpleGraph: |
no outgoing calls
no test coverage detected