Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loki expression parser based on pymbolic parser #272

Merged
merged 3 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions loki/analyse/tests/test_util_polyhedron.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
from loki.ir import Loop, FindNodes
from loki.scope import Scope
from loki.sourcefile import Sourcefile
from loki.frontend.fparser import parse_fparser_expression, HAVE_FP
from loki.analyse.util_polyhedron import Polyhedron
from loki.expression import symbols as sym

from loki.expression import symbols as sym, parse_expr

@pytest.fixture(scope="module", name="here")
def fixture_here():
Expand All @@ -27,9 +25,6 @@ def fixture_testdir(here):
return here.parent.parent/'tests'


# Polyhedron functionality relies on FParser's expression parsing
pytestmark = pytest.mark.skipif(not HAVE_FP, reason="Fparser not available")


@pytest.mark.parametrize(
"variables, lbounds, ubounds, A, b, variable_names",
Expand Down Expand Up @@ -81,9 +76,9 @@ def test_polyhedron_from_loop_ranges(variables, lbounds, ubounds, A, b, variable
Test converting loop ranges to polyedron representation of iteration space.
"""
scope = Scope()
loop_variables = [parse_fparser_expression(expr, scope) for expr in variables]
loop_lbounds = [parse_fparser_expression(expr, scope) for expr in lbounds]
loop_ubounds = [parse_fparser_expression(expr, scope) for expr in ubounds]
loop_variables = [parse_expr(expr, scope) for expr in variables]
loop_lbounds = [parse_expr(expr, scope) for expr in lbounds]
loop_ubounds = [parse_expr(expr, scope) for expr in ubounds]
loop_ranges = [sym.LoopRange((l, u)) for l, u in zip(loop_lbounds, loop_ubounds)]
p = Polyhedron.from_loop_ranges(loop_variables, loop_ranges)
assert np.all(p.A == np.array(A, dtype=np.dtype(int)))
Expand All @@ -97,15 +92,15 @@ def test_polyhedron_from_loop_ranges_failures():
"""
# m*n is non-affine and thus can't be represented
scope = Scope()
loop_variable = parse_fparser_expression("i", scope)
lower_bound = parse_fparser_expression("1", scope)
upper_bound = parse_fparser_expression("m * n", scope)
loop_variable = parse_expr("i", scope)
lower_bound = parse_expr("1", scope)
upper_bound = parse_expr("m * n", scope)
loop_range = sym.LoopRange((lower_bound, upper_bound))
with pytest.raises(ValueError):
_ = Polyhedron.from_loop_ranges([loop_variable], [loop_range])

# no functionality to flatten exponentials, yet
upper_bound = parse_fparser_expression("5**2", scope)
upper_bound = parse_expr("5**2", scope)
loop_range = sym.LoopRange((lower_bound, upper_bound))
with pytest.raises(ValueError):
_ = Polyhedron.from_loop_ranges([loop_variable], [loop_range])
Expand Down Expand Up @@ -148,7 +143,7 @@ def test_polyhedron_bounds(A, b, variable_names, lower_bounds, upper_bounds):
Test the production of lower and upper bounds.
"""
scope = Scope()
variables = [parse_fparser_expression(v, scope) for v in variable_names]
variables = [parse_expr(v, scope) for v in variable_names]
p = Polyhedron(A, b, variables)
for var, ref_bounds in zip(variables, lower_bounds):
lbounds = p.lower_bounds(var)
Expand Down
1 change: 1 addition & 0 deletions loki/expression/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
from loki.expression.operations import * # noqa
from loki.expression.mappers import * # noqa
from loki.expression.symbolic import * # noqa
from loki.expression.parser import * # noqa
Loading
Loading