Skip to content
Snippets Groups Projects

Resolve "Operation Replacement in a SFG"

Closed Kevin Scott requested to merge 17-operation-replacement-in-a-sfg into develop
5 unresolved threads
2 files
+ 30
22
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 25
17
@@ -406,7 +406,7 @@ class SFG(AbstractOperation):
@@ -406,7 +406,7 @@ class SFG(AbstractOperation):
return self()
return self()
def replace_operations(self, operation_ids: Sequence[GraphID], operation: Operation):
def replace_operations(self, operation_ids: Sequence[GraphID], operation: Operation):
"""Replace multiple operations in the sfg with a operation of equivalent functionallity with the same number of inputs and outputs.
"""Replace multiple operations in the sfg with a operation with the same amount of inputs and outputs.
Then return a new deepcopy of the sfg with the replaced operations.
Then return a new deepcopy of the sfg with the replaced operations.
Arguments:
Arguments:
@@ -414,28 +414,36 @@ class SFG(AbstractOperation):
@@ -414,28 +414,36 @@ class SFG(AbstractOperation):
operation: The operation used for replacement.
operation: The operation used for replacement.
"""
"""
operations = [self.find_by_id(_id) for _id in operation_ids]
inputs = []
 
outputs = []
assert sum(o.input_count + o.output_count for o in operations) == operation.input_count + operation.output_count, \
for _operation in self.operations:
"The input and output count must match"
if _operation.graph_id not in operation_ids:
continue
# Create a copy of the sfg for manipulating
_sfg = self()
# Retrive input operations
 
for _signal in _operation.input_signals:
 
if _signal.source.operation.graph_id not in operation_ids:
 
inputs.append(_signal.source.operation)
for operation in operations:
# Retrive output operations
operation
for _signal in _operation.output_signals:
 
if _signal.destination.operation.graph_id not in operation_ids:
 
outputs.append(_signal.destination.operation)
 
assert len(inputs) + len(outputs) == \
 
operation.input_count + operation.output_count, "The input and output count must match"
for _index, _inp in enumerate(inputs):
for index_in, _input in enumerate(inputs):
for _signal in _inp.output_signals:
for _signal in _input.output_signals:
_signal.remove_destination()
_signal.remove_destination()
_signal.set_destination(operation.input(_index))
_signal.set_destination(operation.input(index_in))
for _index, _out in enumerate(outputs):
for index_out, _output in enumerate(outputs):
for _signal in _out.input_signals:
for _signal in _output.input_signals:
_signal.remove_destination()
_signal.remove_source()
_signal.set_source(operation.output(_index))
_signal.set_source(operation.output(index_out))
return self()
return self()
def _evaluate_source(self, src: OutputPort, results: MutableResultMap, registers: MutableRegisterMap, prefix: str) -> Number:
def _evaluate_source(self, src: OutputPort, results: MutableResultMap, registers: MutableRegisterMap, prefix: str) -> Number:
Loading