Skip to content
Snippets Groups Projects
Commit 676a6e96 authored by Kevin's avatar Kevin
Browse files

Added some defintions, need to implement operation to SFG conversion in another issue

parent 033f9ee1
No related branches found
No related tags found
2 merge requests!44Resolve "Operation Replacement in a SFG",!42Resolve "Operation to SFG Conversion"
Pipeline #14319 failed
......@@ -180,6 +180,10 @@ class Operation(GraphComponent, SignalSourceProvider):
"""
raise NotImplementedError
@abstractmethod
def to_sfg(self) -> self:
"""Convert a operation to its correspnding
"""
class AbstractOperation(Operation, AbstractGraphComponent):
"""Generic abstract operation class which most implementations will derive from.
......
......@@ -405,7 +405,7 @@ class SFG(AbstractOperation):
# The old SFG will be deleted by Python GC
return self()
def replace_operations(self, inputs: Sequence[Input], outputs: Sequence[Output], 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.
Then return a new deepcopy of the sfg with the replaced operations.
......@@ -414,6 +414,19 @@ class SFG(AbstractOperation):
outputs: The outputs of the operations we are replacing.
operation: The operation used for replacement.
"""
operations = [self.find_by_id(_id) for _id in operation_ids]
for _index, _inp in enumerate(inputs):
for _signal in _inp.output_signals:
_signal.remove_destination()
_signal.set_destination(operation.input(_index))
for _index, _out in enumerate(outputs):
for _signal in _out.input_signals:
_signal.remove_destination()
_signal.set_source(operation.output(_index))
return self()
def _evaluate_source(self, src: OutputPort, results: MutableResultMap, registers: MutableRegisterMap, prefix: str) -> Number:
......
......@@ -266,10 +266,10 @@ class TestReplaceOperations:
sfg = SFG(inputs=[in1, in2, in3], outputs=[out1])
mad1 = MAD()
sfg.replace_operations([in1, in2, in3], [out1], mad1)
_sfg = sfg.replace_operations(['add1', 'mul1'], mad1)
assert mad1 in sfg.operations
assert {add1, mul1} not in sfg.operations
assert mad1 in _sfg.operations
assert {add1, mul1} not in _sfg.operations
def test_replace_neg_add_with_sub(self):
in1 = Input()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment