def get_input(self, node): input_nodes = [] for name in node.input: name = get_real_name(name) if name in self.node_dict: input_nodes.append(self.get_node(name)) return input_nodes
def emit(self): # Decompose DAG into chains chains = [] for node in self.graph.topologically_sorted(): attach_to_chain = None if len(node.input) == 1: parent = get_real_name(node.input[0]) for chain in chains: if chain[ -1].name == parent: # Node is part of an existing chain. attach_to_chain = chain break if attach_to_chain is None: # Start a new chain for this node. attach_to_chain = [] chains.append(attach_to_chain) attach_to_chain.append(node) # Generate Python code line by line source = self.emit_imports() source += self.emit_class_def(self.graph.name) self.indent() source += self.emit_setup_def() self.indent() blocks = [] for chain in chains: b = '' for node in chain: b += self.emit_node(node) blocks.append(b[:-1]) source += '\n\n'.join(blocks) return source
def emit(self): # Decompose DAG into chains chains = [] for node in self.graph.topologically_sorted(): attach_to_chain = None if len(node.input) == 1: parent = get_real_name(node.input[0]) for chain in chains: if chain[-1].name == parent: # Node is part of an existing chain. attach_to_chain = chain break if attach_to_chain is None: # Start a new chain for this node. attach_to_chain = [] chains.append(attach_to_chain) attach_to_chain.append(node) # Generate Python code line by line source = self.emit_imports() source += self.emit_class_def(self.graph.name) self.indent() source += self.emit_setup_def() self.indent() blocks = [] for chain in chains: b = '' for node in chain: b += self.emit_node(node) blocks.append(b[:-1]) source += '\n\n'.join(blocks) return source