diff --git a/b_asic/operation.py b/b_asic/operation.py index 36bad20e8911d8c62547d40299e847950b21d01a..79ad9ce6a766ebe4884374f7508737c82b5d2c00 100644 --- a/b_asic/operation.py +++ b/b_asic/operation.py @@ -180,11 +180,6 @@ 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. TODO: More info. diff --git a/b_asic/signal_flow_graph.py b/b_asic/signal_flow_graph.py index be6862c49578df197b8b536c34254852ee0a54ee..19675e33943e2470c52a864ed2badc7ca00ae862 100644 --- a/b_asic/signal_flow_graph.py +++ b/b_asic/signal_flow_graph.py @@ -410,13 +410,22 @@ class SFG(AbstractOperation): Then return a new deepcopy of the sfg with the replaced operations. Arguments: - inputs: The inputs of the operations we are replacing. - outputs: The outputs of the operations we are replacing. + operation_ids: The id's of the operations we are replacing operation: The operation used for replacement. """ operations = [self.find_by_id(_id) for _id in operation_ids] + assert sum(o.input_count + o.output_count for o in operations) == operation.input_count + operation.output_count, \ + "The input and output count must match" + + # Create a copy of the sfg for manipulating + _sfg = self() + + for operation in operations: + operation + + for _index, _inp in enumerate(inputs): for _signal in _inp.output_signals: _signal.remove_destination() diff --git a/test/test_core_operations.py b/test/test_core_operations.py index 1482938ef989da53203c8d211c1643946af95383..7549570769ed39856d47fd5efd642c813a66782d 100644 --- a/test/test_core_operations.py +++ b/test/test_core_operations.py @@ -168,9 +168,3 @@ class TestButterfly: but1 = Butterfly() split = but1.split() assert len(split) == 2 - -class TestMad: - def test_split_mad(self): - mad1 = MAD() - res = mad1.split() - assert len(res) == 2 diff --git a/test/test_sfg.py b/test/test_sfg.py index de9b65ac19f3373f7d590f8fab151b1bdc8006af..8c00cd73d4bfb35c978b2aa83131f8b87f1a3b57 100644 --- a/test/test_sfg.py +++ b/test/test_sfg.py @@ -274,20 +274,20 @@ class TestReplaceOperations: def test_replace_neg_add_with_sub(self): in1 = Input() in2 = Input() - neg = ConstantMultiplication(-1, in1) - add1 = neg + in2 + neg1 = ConstantMultiplication(-1, in1) + add1 = neg1 + in2 out1 = Output(add1) sfg = SFG(inputs=[in1, in2], outputs=[out1]) sub1 = Subtraction() - sfg.replace_operations([in1, in2], [out1], sub1) + sfg.replace_operations(['add1, neg1'], sub1) assert sub1 in sfg.operations - assert {add1, neg} not in sfg.operations + assert {add1, neg1} not in sfg.operations - def test_not_equal_functionallity(self, operation_tree): + def test_different_input_output_count(self, operation_tree): sfg = SFG(outputs=[Output(operation_tree)]) - mul1 = Multiplication() + constmul1 = ConstantMultiplication() with pytest.raises(AssertionError): - sfg.replace_operations([sfg.inputs(0), sfg.inputs(1)], [sfg.outputs(0)], mul1) + sfg.replace_operations(['add1'], constmul1)