Skip to content

Commit

Permalink
Transformations: Some linter fixes for transformation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mlange05 committed Oct 7, 2024
1 parent db19912 commit cef6cf1
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 34 deletions.
2 changes: 1 addition & 1 deletion loki/transformations/tests/test_hoist_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Scheduler, SchedulerConfig, is_iterable, FindInlineCalls
)
from loki.build import jit_compile_lib, Builder
from loki.frontend import available_frontends, OMNI
from loki.frontend import available_frontends
from loki.ir import nodes as ir, FindNodes
from loki.transformations.hoist_variables import (
HoistVariablesAnalysis, HoistVariablesTransformation,
Expand Down
2 changes: 1 addition & 1 deletion loki/transformations/tests/test_idempotence.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


@pytest.mark.parametrize('frontend', available_frontends())
def test_transform_idempotence(frontend, tmp_path):
def test_transform_idempotence(frontend):
""" Test the do-nothing equivalence of :any:`IdemTransformations` """

fcode_driver = """
Expand Down
4 changes: 1 addition & 3 deletions loki/transformations/tests/test_parametrise.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def stop_execution(**kwargs):

abort_callbacks = (error_stop, stop_execution)

for i, abort_callback in enumerate(abort_callbacks):
for _, abort_callback in enumerate(abort_callbacks):
scheduler = Scheduler(
paths=[proj], config=config, seed_routines=['driver', 'another_driver'],
frontend=frontend, xmods=[tmp_path]
Expand All @@ -380,8 +380,6 @@ def test_parametrise_modified_callback_wrong_input(tmp_path, testdir, frontend,
proj = testdir/'sources/projParametrise'

dic2p = {'a': 12, 'b': 11}
a = dic2p['a']
b = dic2p['b']

def only_warn(**kwargs):
msg = kwargs.get("msg")
Expand Down
2 changes: 1 addition & 1 deletion loki/transformations/tests/test_raw_stack_allocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pytest

from loki.backend import fgen
from loki.batch import Scheduler, SchedulerConfig, ProcedureItem
from loki.batch import Scheduler, SchedulerConfig
from loki.dimension import Dimension
from loki.expression import DeferredTypeSymbol, InlineCall, IntLiteral
from loki.frontend import available_frontends, OMNI
Expand Down
32 changes: 16 additions & 16 deletions loki/transformations/tests/test_transform_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from loki import Subroutine
from loki.build import jit_compile, clean_test
from loki.expression import symbols as sym
from loki.frontend import available_frontends, OMNI
from loki.frontend import available_frontends
from loki.ir import (
is_loki_pragma, pragmas_attached, FindNodes, Loop, Conditional,
Assignment
Expand Down Expand Up @@ -1631,7 +1631,7 @@ def test_transform_loop_unroll(tmp_path, frontend):
# Test the reference solution
s = np.zeros(1)
function(s=s)
assert s == sum([x + 1 for x in range(1, 11)])
assert s == sum(x + 1 for x in range(1, 11))

# Apply transformation
assert len(FindNodes(Loop).visit(routine.body)) == 1
Expand All @@ -1644,7 +1644,7 @@ def test_transform_loop_unroll(tmp_path, frontend):
# Test transformation
s = np.zeros(1)
unrolled_function(s=s)
assert s == sum([x + 1 for x in range(1, 11)])
assert s == sum(x + 1 for x in range(1, 11))

clean_test(filepath)
clean_test(unrolled_filepath)
Expand Down Expand Up @@ -1673,7 +1673,7 @@ def test_transform_loop_unroll_step(tmp_path, frontend):
# Test the reference solution
s = np.zeros(1)
function(s=s)
assert s == sum([x + 1 for x in range(1, 11, 2)])
assert s == sum(x + 1 for x in range(1, 11, 2))

# Apply transformation
assert len(FindNodes(Loop).visit(routine.body)) == 1
Expand All @@ -1686,7 +1686,7 @@ def test_transform_loop_unroll_step(tmp_path, frontend):
# Test transformation
s = np.zeros(1)
unrolled_function(s=s)
assert s == sum([x + 1 for x in range(1, 11, 2)])
assert s == sum(x + 1 for x in range(1, 11, 2))

clean_test(filepath)
clean_test(unrolled_filepath)
Expand Down Expand Up @@ -1717,7 +1717,7 @@ def test_transform_loop_unroll_non_literal_range(tmp_path, frontend):
# Test the reference solution
s = np.zeros(1)
function(s=s)
assert s == sum([x + 1 for x in range(1, 11)])
assert s == sum(x + 1 for x in range(1, 11))

# Apply transformation
assert len(FindNodes(Loop).visit(routine.body)) == 1
Expand All @@ -1730,7 +1730,7 @@ def test_transform_loop_unroll_non_literal_range(tmp_path, frontend):
# Test transformation
s = np.zeros(1)
unrolled_function(s=s)
assert s == sum([x + 1 for x in range(1, 11)])
assert s == sum(x + 1 for x in range(1, 11))

clean_test(filepath)
clean_test(unrolled_filepath)
Expand Down Expand Up @@ -1762,7 +1762,7 @@ def test_transform_loop_unroll_nested(tmp_path, frontend):
# Test the reference solution
s = np.zeros(1)
function(s=s)
assert s == sum([a + b + 1 for (a, b) in itertools.product(range(1, 11), range(1, 6))])
assert s == sum(a + b + 1 for (a, b) in itertools.product(range(1, 11), range(1, 6)))

# Apply transformation
assert len(FindNodes(Loop).visit(routine.body)) == 2
Expand All @@ -1775,7 +1775,7 @@ def test_transform_loop_unroll_nested(tmp_path, frontend):
# Test transformation
s = np.zeros(1)
unrolled_function(s=s)
assert s == sum([a + b + 1 for (a, b) in itertools.product(range(1, 11), range(1, 6))])
assert s == sum(a + b + 1 for (a, b) in itertools.product(range(1, 11), range(1, 6)))

clean_test(filepath)
clean_test(unrolled_filepath)
Expand Down Expand Up @@ -1807,7 +1807,7 @@ def test_transform_loop_unroll_nested_restricted_depth(tmp_path, frontend):
# Test the reference solution
s = np.zeros(1)
function(s=s)
assert s == sum([a + b + 1 for (a, b) in itertools.product(range(1, 11), range(1, 6))])
assert s == sum(a + b + 1 for (a, b) in itertools.product(range(1, 11), range(1, 6)))

# Apply transformation
assert len(FindNodes(Loop).visit(routine.body)) == 2
Expand All @@ -1820,7 +1820,7 @@ def test_transform_loop_unroll_nested_restricted_depth(tmp_path, frontend):
# Test transformation
s = np.zeros(1)
unrolled_function(s=s)
assert s == sum([a + b + 1 for (a, b) in itertools.product(range(1, 11), range(1, 6))])
assert s == sum(a + b + 1 for (a, b) in itertools.product(range(1, 11), range(1, 6)))

clean_test(filepath)
clean_test(unrolled_filepath)
Expand Down Expand Up @@ -1854,7 +1854,7 @@ def test_transform_loop_unroll_nested_restricted_depth_unrollable(tmp_path, fron
# Test the reference solution
s = np.zeros(1)
function(s=s)
assert s == sum([a + b + 1 for (a, b) in itertools.product(range(1, 11), range(1, 6))])
assert s == sum(a + b + 1 for (a, b) in itertools.product(range(1, 11), range(1, 6)))

# Apply transformation
assert len(FindNodes(Loop).visit(routine.body)) == 2
Expand All @@ -1867,7 +1867,7 @@ def test_transform_loop_unroll_nested_restricted_depth_unrollable(tmp_path, fron
# Test transformation
s = np.zeros(1)
unrolled_function(s=s)
assert s == sum([a + b + 1 for (a, b) in itertools.product(range(1, 11), range(1, 6))])
assert s == sum(a + b + 1 for (a, b) in itertools.product(range(1, 11), range(1, 6)))

clean_test(filepath)
clean_test(unrolled_filepath)
Expand Down Expand Up @@ -1915,7 +1915,7 @@ def test_transform_loop_unroll_nested_counters(tmp_path, frontend):
# Test transformation
s = np.zeros(1)
unrolled_function(s=s)
assert s == sum([a + b + 1 for (a, b) in itertools.product(range(1, 11), range(1, 11)) if b <= a])
assert s == sum(a + b + 1 for (a, b) in itertools.product(range(1, 11), range(1, 11)) if b <= a)

clean_test(filepath)
clean_test(unrolled_filepath)
Expand Down Expand Up @@ -1953,7 +1953,7 @@ def test_transform_loop_unroll_nested_neighbours(tmp_path, frontend):
# Test the reference solution
s = np.zeros(1)
function(s=s)
assert s == 2 * sum([a + b + 1 for (a, b) in itertools.product(range(1, 11), range(1, 6))])
assert s == 2 * sum(a + b + 1 for (a, b) in itertools.product(range(1, 11), range(1, 6)))
# Apply transformation
assert len(FindNodes(Loop).visit(routine.body)) == 3
loop_unroll(routine)
Expand All @@ -1965,7 +1965,7 @@ def test_transform_loop_unroll_nested_neighbours(tmp_path, frontend):
# Test transformation
s = np.zeros(1)
unrolled_function(s=s)
assert s == 2 * sum([a + b + 1 for (a, b) in itertools.product(range(1, 11), range(1, 6))])
assert s == 2 * sum(a + b + 1 for (a, b) in itertools.product(range(1, 11), range(1, 6)))

clean_test(filepath)
clean_test(unrolled_filepath)
24 changes: 12 additions & 12 deletions loki/transformations/tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,22 +502,22 @@ def test_transform_utilites_get_local_arrays(frontend, tmp_path):
module = Module.from_source(fcode, frontend=frontend, xmods=[tmp_path], definitions=(global_mod,))
routine = module['test_get_local_arrays']

locals = get_local_arrays(routine, routine.body, unique=True)
assert len(locals) == 1
assert locals[0] == 'local(i)'
local_arrs = get_local_arrays(routine, routine.body, unique=True)
assert len(local_arrs) == 1
assert local_arrs[0] == 'local(i)'

locals = get_local_arrays(routine, routine.body, unique=False)
assert len(locals) == 2
assert all(l == 'local(i)' for l in locals)
local_arrs = get_local_arrays(routine, routine.body, unique=False)
assert len(local_arrs) == 2
assert all(l == 'local(i)' for l in local_arrs)

locals = get_local_arrays(routine, routine.body.body[-1:], unique=False)
assert len(locals) == 1
assert locals[0] == 'local(i)'
local_arrs = get_local_arrays(routine, routine.body.body[-1:], unique=False)
assert len(local_arrs) == 1
assert local_arrs[0] == 'local(i)'

# Test for component arrays on arguments in spec
locals = get_local_arrays(routine, routine.spec, unique=True)
assert len(locals) == 1
assert locals[0] == 'local(n)'
local_arrs = get_local_arrays(routine, routine.spec, unique=True)
assert len(local_arrs) == 1
assert local_arrs[0] == 'local(n)'


@pytest.mark.parametrize('frontend', available_frontends())
Expand Down

0 comments on commit cef6cf1

Please sign in to comment.