Skip to content

Commit

Permalink
Improve AssertEqual simplification
Browse files Browse the repository at this point in the history
This patch improves AssertEqual._simplified by composing a list of unique items
that are compared in the AssertEqual tree, and composing a new tree (if any)
from the results. This allows `AssertEqual(a, AssertEqual(a, b))` to be
simplified to `AssertEqual(a, b)`, which was not formerly the case.
  • Loading branch information
gertjanvanzwieten committed Oct 22, 2024
1 parent 8bce381 commit 8d3334f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions nutils/evaluable.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,15 @@ def _intbounds_impl(self):
return max(lowera, lowerb), min(uppera, upperb)

def _simplified(self):
if self.a == self.b:
return self.a
unique = []
queue = [self.a, self.b]
for item in queue:
if isinstance(item, AssertEqual):
queue.append(item.a)
queue.append(item.b)
elif item not in unique:
unique.append(item)
return functools.reduce(AssertEqual, unique)

@property
def dependencies(self):
Expand Down

0 comments on commit 8d3334f

Please sign in to comment.