Skip to content

Commit

Permalink
Loki string parser based on pymbolic parser
Browse files Browse the repository at this point in the history
Loki string parser: correct ordering of statements, further improved functionality and testing

Load fortran intrinsic procedure names from FParser and expose via global var 'FORTRAN_INTRINSIC_PROCEDURES'

Renaming, improving documentation, improving fortran style numerical literals, use FParser fortran intrinsic procedure names
  • Loading branch information
MichaelSt98 authored and reuterbal committed Apr 16, 2024
1 parent 3e555d5 commit dfc3a92
Show file tree
Hide file tree
Showing 7 changed files with 905 additions and 43 deletions.
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

0 comments on commit dfc3a92

Please sign in to comment.