From ff2002451afbe762e102a0b6dd5f690d7ee56709 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson <oscar.gustafsson@liu.se> Date: Wed, 12 Apr 2023 16:44:08 +0000 Subject: [PATCH] Fixes --- b_asic/core_operations.py | 42 +++++++--------------------- b_asic/special_operations.py | 21 +++++--------- examples/secondorderdirectformiir.py | 2 -- test/test_schedule.py | 8 +++--- 4 files changed, 21 insertions(+), 52 deletions(-) diff --git a/b_asic/core_operations.py b/b_asic/core_operations.py index 958b3e25..f266afc6 100644 --- a/b_asic/core_operations.py +++ b/b_asic/core_operations.py @@ -34,6 +34,8 @@ class Constant(AbstractOperation): """ _execution_time = 0 + is_linear = True + is_constant = True def __init__(self, value: Num = 0, name: Name = ""): """Construct a Constant operation with the given value.""" @@ -72,14 +74,6 @@ class Constant(AbstractOperation): def __str__(self) -> str: return f"{self.value}" - @property - def is_linear(self) -> bool: - return True - - @property - def is_constant(self) -> bool: - return True - class Addition(AbstractOperation): """ @@ -114,6 +108,8 @@ class Addition(AbstractOperation): """ + is_linear = True + def __init__( self, src0: Optional[SignalSourceProvider] = None, @@ -143,10 +139,6 @@ class Addition(AbstractOperation): def evaluate(self, a, b): return a + b - @property - def is_linear(self) -> bool: - return True - class Subtraction(AbstractOperation): """ @@ -180,6 +172,8 @@ class Subtraction(AbstractOperation): AddSub """ + is_linear = True + def __init__( self, src0: Optional[SignalSourceProvider] = None, @@ -207,10 +201,6 @@ class Subtraction(AbstractOperation): def evaluate(self, a, b): return a - b - @property - def is_linear(self) -> bool: - return True - class AddSub(AbstractOperation): r""" @@ -252,6 +242,7 @@ class AddSub(AbstractOperation): ======== Addition, Subtraction """ + is_linear = True def __init__( self, @@ -292,10 +283,6 @@ class AddSub(AbstractOperation): """Set if operation is an addition.""" self.set_param("is_add", is_add) - @property - def is_linear(self) -> bool: - return True - class Multiplication(AbstractOperation): r""" @@ -615,6 +602,7 @@ class ConstantMultiplication(AbstractOperation): .. math:: y = x_0 \times \text{value} """ + is_linear = True def __init__( self, @@ -654,10 +642,6 @@ class ConstantMultiplication(AbstractOperation): """Set the constant value of this operation.""" self.set_param("value", value) - @property - def is_linear(self) -> bool: - return True - class Butterfly(AbstractOperation): r""" @@ -672,6 +656,7 @@ class Butterfly(AbstractOperation): y_1 & = & x_0 - x_1 \end{eqnarray} """ + is_linear = True def __init__( self, @@ -700,10 +685,6 @@ class Butterfly(AbstractOperation): def evaluate(self, a, b): return a + b, a - b - @property - def is_linear(self) -> bool: - return True - class MAD(AbstractOperation): r""" @@ -761,6 +742,7 @@ class SymmetricTwoportAdaptor(AbstractOperation): y_1 & = & x_0 + \text{value}\times\left(x_1 - x_0\right) \end{eqnarray} """ + is_linear = True def __init__( self, @@ -802,10 +784,6 @@ class SymmetricTwoportAdaptor(AbstractOperation): """Set the constant value of this operation.""" self.set_param("value", value) - @property - def is_linear(self) -> bool: - return True - class Reciprocal(AbstractOperation): r""" diff --git a/b_asic/special_operations.py b/b_asic/special_operations.py index 22bfa70b..c1bc4deb 100644 --- a/b_asic/special_operations.py +++ b/b_asic/special_operations.py @@ -25,7 +25,8 @@ class Input(AbstractOperation): Its value will be updated on each iteration when simulating the SFG. """ - _execution_time = 0 + is_linear = True + is_constant = False def __init__(self, name: Name = ""): """Construct an Input operation.""" @@ -34,6 +35,7 @@ class Input(AbstractOperation): output_count=1, name=name, latency_offsets={"out0": 0}, + execution_time=0, ) self.set_param("value", 0) @@ -89,14 +91,6 @@ class Input(AbstractOperation): # doc-string inherited return ((0, 0.5),) - @property - def is_constant(self) -> bool: - return False - - @property - def is_linear(self) -> bool: - return True - class Output(AbstractOperation): """ @@ -107,7 +101,7 @@ class Output(AbstractOperation): destinations. """ - _execution_time = 0 + is_linear = True def __init__( self, @@ -121,6 +115,7 @@ class Output(AbstractOperation): name=Name(name), input_sources=[src0], latency_offsets={"in0": 0}, + execution_time=0, ) @classmethod @@ -173,6 +168,8 @@ class Delay(AbstractOperation): Name. """ + is_linear = True + def __init__( self, src0: Optional[SignalSourceProvider] = None, @@ -242,7 +239,3 @@ class Delay(AbstractOperation): def initial_value(self, value: Num) -> None: """Set the initial value of this delay.""" self.set_param("initial_value", value) - - @property - def is_linear(self) -> bool: - return True diff --git a/examples/secondorderdirectformiir.py b/examples/secondorderdirectformiir.py index 413bf2da..e78a48f3 100644 --- a/examples/secondorderdirectformiir.py +++ b/examples/secondorderdirectformiir.py @@ -35,8 +35,6 @@ sfg.set_latency_of_type(ConstantMultiplication.type_name(), 2) sfg.set_latency_of_type(Addition.type_name(), 1) sfg.set_execution_time_of_type(ConstantMultiplication.type_name(), 1) sfg.set_execution_time_of_type(Addition.type_name(), 1) -sfg.set_execution_time_of_type(Input.type_name(), 1) -sfg.set_execution_time_of_type(Output.type_name(), 1) # %% # Create schedule diff --git a/test/test_schedule.py b/test/test_schedule.py index 5d22981a..70ab9e9f 100644 --- a/test/test_schedule.py +++ b/test/test_schedule.py @@ -415,14 +415,14 @@ class TestTimeResolution: assert start_times_names == { "C1": (0, 0, None), - "IN1": (0, 0, None), - "IN2": (0, 0, None), + "IN1": (0, 0, 0), + "IN2": (0, 0, 0), "CMUL1": (0, 30, 18), "CMUL2": (30, 24, 6), "ADD1": (0, 42, 12), "CMUL3": (42, 18, 6), - "OUT1": (54, 0, None), - "OUT2": (60, 0, None), + "OUT1": (54, 0, 0), + "OUT2": (60, 0, 0), } assert 6 * old_schedule_time == schedule.schedule_time -- GitLab