예제 #1
0
 def __init__(self,
              nodes,
              *,
              duplicate_constants=True,
              duplicate_free_variables=True,
              function_in_node=True,
              tooltip_gen=None,
              class_gen=None,
              extra_style=None):
     super().__init__({'layout': {
         'name': 'dagre',
         'rankDir': 'TB'
     }},
                      tooltip_gen=tooltip_gen,
                      extra_style=extra_style)
     self.duplicate_constants = duplicate_constants
     self.duplicate_free_variables = duplicate_free_variables
     self.function_in_node = function_in_node
     self.labeler = NodeLabeler(function_in_node=function_in_node,
                                relation_symbols=short_relation_symbols)
     self._class_gen = _make_class_gen(class_gen)
     self.todo = set(nodes)
     self.graphs = {node.graph for node in nodes if node.graph}
     self.focus = set()
     # Nodes that are to be colored as return nodes
     self.returns = {
         node
         for node in nodes if node.graph and node is node.graph.return_
     }
     # IDs for duplicated constants
     self.currid = 0
예제 #2
0
 def __init__(self):
     """Initialize."""
     self._prim_graph_cache = {}
     self.make_const = PythonConstantConverter()
     self.graph_to_name = {}
     self.fn_name_to_code = {}
     self.node_labeler = NodeLabeler(
         relation_symbols={"copy": "", "opt": ""}
     )
     self.name_counter = Counter()
예제 #3
0
파일: gprint.py 프로젝트: tor4z/myia
    def __init__(
        self,
        entry_points,
        *,
        duplicate_constants=False,
        duplicate_free_variables=False,
        function_in_node=False,
        follow_references=False,
        tooltip_gen=None,
        class_gen=None,
        extra_style=None,
        beautify=True,
    ):
        """Initialize a MyiaGraphPrinter."""
        super().__init__(
            {"layout": {
                "name": "dagre",
                "rankDir": "TB"
            }},
            tooltip_gen=tooltip_gen,
            extra_style=extra_style,
        )
        # Graphs left to process
        if beautify:
            self.graphs = set()
            self.focus = set()
            for g in entry_points:
                self._import_graph(g)
        else:
            self.graphs = set(entry_points)
            self.focus = set(self.graphs)

        self.beautify = beautify
        self.duplicate_constants = duplicate_constants
        self.duplicate_free_variables = duplicate_free_variables
        self.function_in_node = function_in_node
        self.follow_references = follow_references
        self.labeler = NodeLabeler(
            function_in_node=function_in_node,
            relation_symbols=short_relation_symbols,
        )
        self._class_gen = _make_class_gen(class_gen)
        # Nodes processed
        self.processed = set()
        # Nodes left to process
        self.pool = set()
        # Nodes that are to be colored as return nodes
        self.returns = set()
        # IDs for duplicated constants
        self.currid = 0
예제 #4
0
파일: gprint.py 프로젝트: jangocheng/myia
 def __init__(self,
              entry_points,
              *,
              duplicate_constants=False,
              duplicate_free_variables=False,
              function_in_node=False,
              follow_references=False,
              tooltip_gen=None,
              class_gen=None,
              extra_style=None):
     """Initialize a MyiaGraphPrinter."""
     super().__init__({'layout': {
         'name': 'dagre',
         'rankDir': 'TB'
     }},
                      tooltip_gen=tooltip_gen,
                      extra_style=extra_style)
     # Graphs left to process
     self.graphs = set(entry_points)
     self.duplicate_constants = duplicate_constants
     self.duplicate_free_variables = duplicate_free_variables
     self.function_in_node = function_in_node
     self.follow_references = follow_references
     self.labeler = NodeLabeler(function_in_node=function_in_node,
                                relation_symbols=short_relation_symbols)
     self._class_gen = class_gen
     # Nodes processed
     self.processed = set()
     # Nodes left to process
     self.pool = set()
     # Nodes that are to be colored as return nodes
     self.returns = set()
     # IDs for duplicated constants
     self.currid = 0
     # Custom rules for nodes that represent certain calls
     self.custom_rules = {
         'return': self.process_node_return,
         'getitem': self.process_node_getitem,
         'make_tuple': self.process_node_make_tuple
     }