Skip to content

Fix removal of nodes ingested by multiple downstream nodes #544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions hls4ml/model/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,14 @@ def remove_node(self, node, rewire=True):
if len(node.inputs) > 1 or len(node.outputs) > 1:
raise Exception('Cannot rewire a node with multiple inputs/outputs')
prev_node = self.graph.get(node.inputs[0])
next_node = next((x for x in self.graph.values() if node.outputs[0] in x.inputs), None)
next_nodes = [x for x in self.graph.values() if node.outputs[0] in x.inputs]
if prev_node is not None:
if next_node is not None:
for i,_ in enumerate(next_node.inputs):
if node.outputs[0] == next_node.inputs[i]:
next_node.inputs[i] = prev_node.outputs[0]
break
if len(next_nodes) > 0:
for next_node in next_nodes:
for i,_ in enumerate(next_node.inputs):
if node.outputs[0] == next_node.inputs[i]:
next_node.inputs[i] = prev_node.outputs[0]
break
else:
if not node.outputs[0] in self.outputs:
raise Exception('Cannot rewire a node without child')
Expand Down