Skip to content
Snippets Groups Projects
Commit 4672f718 authored by Kevin's avatar Kevin
Browse files

changed some tests and desc. of replace operations

parent 5e5056c6
No related branches found
No related tags found
2 merge requests!44Resolve "Operation Replacement in a SFG",!42Resolve "Operation to SFG Conversion"
Pipeline #14053 failed
......@@ -406,14 +406,15 @@ class SFG(AbstractOperation):
return self()
def replace_operations(self, inputs: Sequence[Input], outputs: Sequence[Output], operation: Operation):
"""Replace one or more operations in the sfg with a operation that have same number of inputs and outputs.
Then return a new deepcopy of the sfg.
"""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.
Arguments:
inputs: The inputs for the operations we are replacing.
outputs: The outputs for the operations we are replacing.
operation: The replacing operation.
inputs: The inputs of the operations we are replacing.
outputs: The outputs of the operations we are replacing.
operation: The operation used for replacement.
"""
return self()
def _evaluate_source(self, src: OutputPort, results: MutableResultMap, registers: MutableRegisterMap, prefix: str) -> Number:
src_prefix = prefix
......
import pytest
from b_asic import SFG, Signal, Input, Output, Constant, Addition, Multiplication, MAD
from b_asic import SFG, Signal, Input, Output, Constant, Addition, Subtraction, Multiplication, MAD, ConstantMultiplication, Butterfly
class TestInit:
......@@ -256,20 +256,38 @@ class TestReplaceComponents:
assert False
class TestReplaceOperations:
def test_replace_mul_add_with_MAD(self):
def test_replace_mul_add_with_mad(self):
in1 = Input()
in2 = Input()
in3 = Input()
mul1 = in1 * in2
add1 = mul1 + in3
out1 = Output(add1)
sfg = SFG(inputs=[in1, in2, in3], outputs=[out1])
assert len(sfg.operations) == 6
mad1 = MAD()
sfg.replace_operations([in1, in2, in3], [out1], mad1)
assert len(sfg.operations) == 5
assert mad1 in sfg.operations
assert {add1, mul1} not in sfg.operations
\ No newline at end of file
def test_replace_neg_add_with_sub(self):
in1 = Input()
in2 = Input()
neg = ConstantMultiplication(-1, in1)
add1 = neg + in2
out1 = Output(add1)
sfg = SFG(inputs=[in1, in2], outputs=[out1])
sub1 = Subtraction()
sfg.replace_operations([in1, in2], [out1], sub1)
assert sub1 in sfg.operations
assert {add1, neg} not in sfg.operations
def test_not_equal_functionallity(self, operation_tree):
sfg = SFG(outputs=[Output(operation_tree)])
mul1 = Multiplication()
with pytest.raises(AssertionError):
sfg.replace_operations([sfg.inputs(0), sfg.inputs(1)], [sfg.outputs(0)], mul1)
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