Skip to content

Commit

Permalink
fix map_comparison and map_substitution in IdentityMapper
Browse files Browse the repository at this point in the history
  • Loading branch information
isuruf authored and inducer committed May 4, 2022
1 parent 12923e0 commit 3b361f5
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions pymbolic/mapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,12 @@ def map_bitwise_or(self, expr, *args, **kwargs):
map_logical_and = map_bitwise_or

def map_comparison(self, expr, *args, **kwargs):
return type(expr)(
self.rec(expr.left, *args, **kwargs),
expr.operator,
self.rec(expr.right, *args, **kwargs))
left = self.rec(expr.left, *args, **kwargs)
right = self.rec(expr.right, *args, **kwargs)
if left is expr.left and right is expr.right:
return expr

return type(expr)(left, expr.operator, right)

def map_list(self, expr, *args, **kwargs):
return [self.rec(child, *args, **kwargs) for child in expr]
Expand Down Expand Up @@ -610,10 +612,13 @@ def map_common_subexpression(self, expr, *args, **kwargs):
**expr.get_extra_properties())

def map_substitution(self, expr, *args, **kwargs):
return type(expr)(
self.rec(expr.child, *args, **kwargs),
expr.variables,
tuple([self.rec(v, *args, **kwargs) for v in expr.values]))
child = self.rec(expr.child, *args, **kwargs)
values = tuple([self.rec(v, *args, **kwargs) for v in expr.values])
if child is expr.child and all([val is orig_val
for val, orig_val in zip(values, expr.values)]):
return expr

return type(expr)(child, expr.variables, values)

def map_derivative(self, expr, *args, **kwargs):
child = self.rec(expr.child, *args, **kwargs)
Expand Down

0 comments on commit 3b361f5

Please sign in to comment.