Skip to content
Snippets Groups Projects

Reduction Support

Open Richard Angersbach requested to merge rangersbach/reductions into v2.0-dev
Viewing commit 9a8e6f9b
Show latest version
1 file
+ 0
12
Preferences
Compare changes
@@ -9,8 +9,6 @@ import pystencils
from ..assignment import Assignment
from .simplifications import (sort_assignments_topologically, transform_lhs_and_rhs, transform_rhs)
from ..sympyextensions import count_operations, fast_subs
from ..sympyextensions import reduced_assign
from ..sympyextensions.reduction import ReducedAssignment
class AssignmentCollection:
@@ -58,13 +56,8 @@ class AssignmentCollection:
subexpressions = list(itertools.chain.from_iterable(
[(a if isinstance(a, Iterable) else [a]) for a in subexpressions]))
# filter out reduced assignments
reduced_assignments = [a for a in main_assignments if isinstance(a, ReducedAssignment)]
main_assignments = [a for a in main_assignments if (a not in reduced_assignments)]
self.main_assignments = main_assignments
self.subexpressions = subexpressions
self.reductions = reduced_assignments
if simplification_hints is None:
simplification_hints = {}
@@ -79,11 +72,6 @@ class AssignmentCollection:
else:
self.subexpression_symbol_generator = subexpression_symbol_generator
def add_reduction(self, lhs: sp.Symbol, op: str, rhs: sp.Expr) -> None:
"""Adds an entry to the simplification_hints dictionary and checks that is does not exist yet."""
assert lhs not in self.reductions, f"Reduction for lhs {lhs} exists"
self.reductions.append(reduced_assign(lhs, op, rhs))
def add_simplification_hint(self, key: str, value: Any) -> None:
"""Adds an entry to the simplification_hints dictionary and checks that is does not exist yet."""
assert key not in self.simplification_hints, "This hint already exists"