Skip to content
Snippets Groups Projects

Add matrix inversion sfg generator

Merged Simon Bjurek requested to merge add-matrix-inversion-sfg-generator into master
2 unresolved threads
Files
4
+ 71
3
@@ -1102,6 +1102,7 @@ class MAD(AbstractOperation):
class MADS(AbstractOperation):
__slots__ = (
"_is_add",
"_override_zero_on_src0",
"_src0",
"_src1",
"_src2",
@@ -1111,6 +1112,7 @@ class MADS(AbstractOperation):
"_execution_time",
)
_is_add: Optional[bool]
_override_zero_on_src0: Optional[bool]
_src0: Optional[SignalSourceProvider]
_src1: Optional[SignalSourceProvider]
_src2: Optional[SignalSourceProvider]
@@ -1124,6 +1126,7 @@ class MADS(AbstractOperation):
def __init__(
self,
is_add: Optional[bool] = True,
override_zero_on_src0: Optional[bool] = False,
src0: Optional[SignalSourceProvider] = None,
src1: Optional[SignalSourceProvider] = None,
src2: Optional[SignalSourceProvider] = None,
@@ -1143,13 +1146,23 @@ class MADS(AbstractOperation):
execution_time=execution_time,
)
self.set_param("is_add", is_add)
self.set_param("override_zero_on_src0", override_zero_on_src0)
@classmethod
def type_name(cls) -> TypeName:
return TypeName("mads")
def evaluate(self, a, b, c):
return a + b * c if self.is_add else a - b * c
if self.is_add:
if self.override_zero_on_src0:
return b * c
else:
return a + b * c
else:
if self.override_zero_on_src0:
return -b * c
else:
return a - b * c
@property
def is_add(self) -> bool:
@@ -1161,11 +1174,21 @@ class MADS(AbstractOperation):
"""Set if operation is an addition."""
self.set_param("is_add", is_add)
@property
def override_zero_on_src0(self) -> bool:
"""Get if operation is overriding a zero on port src0."""
return self.param("override_zero_on_src0")
@override_zero_on_src0.setter
def override_zero_on_src0(self, override_zero_on_src0: bool) -> None:
"""Set if operation is overriding a zero on port src0."""
self.set_param("override_zero_on_src0", override_zero_on_src0)
@property
def is_linear(self) -> bool:
return (
self.input(0).connected_source.operation.is_constant
or self.input(1).connected_source.operation.is_constant
self.input(1).connected_source.operation.is_constant
or self.input(2).connected_source.operation.is_constant
)
def swap_io(self) -> None:
@@ -1598,6 +1621,51 @@ class Shift(AbstractOperation):
self.set_param("value", value)
class DontCare(AbstractOperation):
r"""
Dont-care operation
Used for ignoring the input to another operation and thus avoiding dangling input nodes.
Parameters
----------
name : Name, optional
Operation name.
"""
__slots__ = "_name"
_name: Name
is_linear = True
def __init__(self, name: Name = ""):
"""Construct a DontCare operation."""
super().__init__(
input_count=0,
output_count=1,
name=name,
latency_offsets={"out0": 0},
)
@classmethod
def type_name(cls) -> TypeName:
return TypeName("dontcare")
def evaluate(self):
return 0
@property
def latency(self) -> int:
return self.latency_offsets["out0"]
def __repr__(self) -> str:
return "DontCare()"
def __str__(self) -> str:
return "dontcare"
class Sink(AbstractOperation):
r"""
Sink operation.
Loading