Skip to content
Snippets Groups Projects
Commit 521e5598 authored by Oscar Gustafsson's avatar Oscar Gustafsson :bicyclist:
Browse files

Fix code and add helper method to SFG

parent fcec0280
No related branches found
No related tags found
No related merge requests found
Pipeline #96096 failed
...@@ -288,10 +288,6 @@ class AddSub(AbstractOperation): ...@@ -288,10 +288,6 @@ class AddSub(AbstractOperation):
def is_swappable(self) -> bool: def is_swappable(self) -> bool:
return self.is_add return self.is_add
def swap_io(self) -> None:
if self.is_add:
super().swap_io()
class Multiplication(AbstractOperation): class Multiplication(AbstractOperation):
r""" r"""
......
...@@ -748,6 +748,21 @@ class SFG(AbstractOperation): ...@@ -748,6 +748,21 @@ class SFG(AbstractOperation):
Signal(output_port, new_operation) Signal(output_port, new_operation)
signal.set_source(new_operation) signal.set_source(new_operation)
def swap_io_of_operation(self, operation_id: GraphID) -> None:
"""
Swap the inputs (and outputs) of operation.
Parameters
----------
graph_id : GraphID
The GraphID of the operation to swap.
"""
operation = cast(Operation, self.find_by_id(operation_id))
if operation is None:
return None
operation.swap_io()
def remove_operation(self, operation_id: GraphID) -> Union["SFG", None]: def remove_operation(self, operation_id: GraphID) -> Union["SFG", None]:
""" """
Returns a version of the SFG where the operation with the specified GraphID Returns a version of the SFG where the operation with the specified GraphID
...@@ -1399,7 +1414,8 @@ class SFG(AbstractOperation): ...@@ -1399,7 +1414,8 @@ class SFG(AbstractOperation):
branch_node : bool, default: False branch_node : bool, default: False
Add a branch node in case the fan-out of a signal is two or more. Add a branch node in case the fan-out of a signal is two or more.
port_numbering : bool, default: True port_numbering : bool, default: True
Show the port number in case the number of ports (input or output) is two or more. Show the port number in case the number of ports (input or output) is two or
more.
splines : {"spline", "line", "ortho", "polyline", "curved"}, default: "spline" splines : {"spline", "line", "ortho", "polyline", "curved"}, default: "spline"
Spline style, see https://graphviz.org/docs/attrs/splines/ for more info. Spline style, see https://graphviz.org/docs/attrs/splines/ for more info.
...@@ -1503,7 +1519,8 @@ class SFG(AbstractOperation): ...@@ -1503,7 +1519,8 @@ class SFG(AbstractOperation):
branch_node : bool, default: False branch_node : bool, default: False
Add a branch node in case the fan-out of a signal is two or more. Add a branch node in case the fan-out of a signal is two or more.
port_numbering : bool, default: True port_numbering : bool, default: True
Show the port number in case the number of ports (input or output) is two or more. Show the port number in case the number of ports (input or output) is two or
more.
splines : {"spline", "line", "ortho", "polyline", "curved"}, default: "spline" splines : {"spline", "line", "ortho", "polyline", "curved"}, default: "spline"
Spline style, see https://graphviz.org/docs/attrs/splines/ for more info. Spline style, see https://graphviz.org/docs/attrs/splines/ for more info.
...@@ -1599,8 +1616,8 @@ class SFG(AbstractOperation): ...@@ -1599,8 +1616,8 @@ class SFG(AbstractOperation):
new_source_op = new_ops[layer][source_op_idx] new_source_op = new_ops[layer][source_op_idx]
source_op_output = new_source_op.outputs[source_op_output_index] source_op_output = new_source_op.outputs[source_op_output_index]
# If this is the last layer, we need to create a new delay element and connect it instead # If this is the last layer, we need to create a new delay element
# of the copied port # and connect it instead of the copied port
if layer == factor - 1: if layer == factor - 1:
delay = Delay(name=op.name) delay = Delay(name=op.name)
delay.graph_id = op.graph_id delay.graph_id = op.graph_id
...@@ -1630,14 +1647,14 @@ class SFG(AbstractOperation): ...@@ -1630,14 +1647,14 @@ class SFG(AbstractOperation):
new_destination = new_dest_op.inputs[sink_op_output_index] new_destination = new_dest_op.inputs[sink_op_output_index]
new_destination.connect(new_source_port) new_destination.connect(new_source_port)
else: else:
# Other opreations need to be re-targeted to the corresponding output in the # Other opreations need to be re-targeted to the corresponding
# current layer, as long as that output is not a delay, as that has been solved # output in the current layer, as long as that output is not a
# above. # delay, as that has been solved above.
# To avoid double connections, we'll only re-connect inputs # To avoid double connections, we'll only re-connect inputs
for input_num, original_input in enumerate(op.inputs): for input_num, original_input in enumerate(op.inputs):
original_source = original_input.connected_source original_source = original_input.connected_source
# We may not always have something connected to the input, if we don't # We may not always have something connected to the input, if we
# we can abort # don't we can abort
if original_source is None: if original_source is None:
continue continue
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment