Skip to content
Snippets Groups Projects

Initial work on constant propagation

Open Oscar Gustafsson requested to merge constantpropagation into master
+ 31
0
@@ -354,6 +354,8 @@ class Multiplication(AbstractOperation):
) -> None:
if any(c == 0.0 for c in constants):
print("One input is 0!")
if any(c == 1.0 for c in constants):
print("One input is 1!")
print("Can turn into ConstantMultiplication")
@@ -690,6 +692,14 @@ class Butterfly(AbstractOperation):
def evaluate(self, a, b):
return a + b, a - b
def _propagate_some_constants(
self,
constants: Iterable[Optional[Number]],
valid_operations: Optional[Set["Operation"]] = None,
) -> None:
if any(c == 0.0 for c in constants):
print("One input is 0!")
class MAD(AbstractOperation):
r"""
@@ -729,6 +739,19 @@ class MAD(AbstractOperation):
def evaluate(self, a, b, c):
return a * b + c
def _propagate_some_constants(
self,
constants: Iterable[Optional[Number]],
valid_operations: Optional[Set["Operation"]] = None,
) -> None:
a, b, c = constants
if a == 0.0 or b == 0.0:
print("One multiplier input is zero!")
if a == 1.0 or b == 1.0:
print("One multiplier input is one!")
if any(c == 0.0):
print("Adder input is zero!")
class SymmetricTwoportAdaptor(AbstractOperation):
r"""
@@ -780,3 +803,11 @@ class SymmetricTwoportAdaptor(AbstractOperation):
def value(self, value: Number) -> None:
"""Set the constant value of this operation."""
self.set_param("value", value)
def _propagate_some_constants(
self,
constants: Iterable[Optional[Number]],
valid_operations: Optional[Set["Operation"]] = None,
) -> None:
if any(c == 0.0 for c in constants):
print("One input is 0!")
Loading