Skip to content
Snippets Groups Projects
Commit 5e5056c6 authored by Kevin's avatar Kevin
Browse files

Added MAD operation to core_operations.py and function definition for replacing operations

parent 7d53d11f
No related branches found
No related tags found
2 merge requests!44Resolve "Operation Replacement in a SFG",!42Resolve "Operation to SFG Conversion"
Pipeline #14015 failed
...@@ -229,3 +229,18 @@ class Butterfly(AbstractOperation): ...@@ -229,3 +229,18 @@ class Butterfly(AbstractOperation):
def evaluate(self, a, b): def evaluate(self, a, b):
return a + b, a - b return a + b, a - b
class MAD(AbstractOperation):
"""Multiply-and-add operation.
TODO: More info.
"""
def __init__(self, src0: Optional[SignalSourceProvider] = None, src1: Optional[SignalSourceProvider] = None, name: Name = ""):
super().__init__(input_count = 3, output_count = 1, name = name, input_sources = [src0, src1])
@property
def type_name(self) -> TypeName:
return "mad"
def evaluate(self, a, b, c):
return a * b + c
...@@ -405,6 +405,16 @@ class SFG(AbstractOperation): ...@@ -405,6 +405,16 @@ class SFG(AbstractOperation):
# The old SFG will be deleted by Python GC # The old SFG will be deleted by Python GC
return self() 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.
Arguments:
inputs: The inputs for the operations we are replacing.
outputs: The outputs for the operations we are replacing.
operation: The replacing operation.
"""
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:
src_prefix = prefix src_prefix = prefix
if src_prefix: if src_prefix:
......
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