Skip to content
Snippets Groups Projects

Ternary Expressions, Improved Integer Divisions, and Iteration Space Fix

Merged Frederik Hennig requested to merge fhennig/ternary into backend-rework
All threads resolved!
Viewing commit 89789777
Prev
Show latest version
1 file
+ 0
33
Preferences
Compare changes
@@ -757,36 +757,3 @@ class PsArrayInitList(PsExpression):
def __repr__(self) -> str:
return f"PsArrayInitList({repr(self._items)})"
def evaluate_expression(
expr: PsExpression, valuation: dict[str | PsSymbol, Any]
) -> Any:
"""Evaluate a pystencils backend expression tree with values assigned to symbols according to the given valuation.
Only a subset of expression nodes can be processed by this evaluator.
"""
def visit(node):
match node:
case PsSymbolExpr(symb):
if value := valuation.get(symb, None) is not None:
return value
else:
return valuation[symb.name]
case PsConstantExpr(c):
return c.value
case PsUnOp(op1) if node.python_operator is not None:
return node.python_operator(visit(op1))
case PsBinOp(op1, op2) if node.python_operator is not None:
return node.python_operator(visit(op1), visit(op2))
case other:
raise NotImplementedError(
f"Unable to evaluate {other}: No implementation available."
)
return visit(expr)