From df0fcb97c2d5260e18760610b9bfb4b68f590b60 Mon Sep 17 00:00:00 2001 From: Kaushik Kulkarni Date: Sat, 4 May 2019 16:43:29 -0500 Subject: [PATCH 1/3] fixes nested substs in insns --- loopy/symbolic.py | 3 ++- test/test_transform.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/loopy/symbolic.py b/loopy/symbolic.py index 60473ada5..f5cf07b0e 100644 --- a/loopy/symbolic.py +++ b/loopy/symbolic.py @@ -866,7 +866,8 @@ class RuleAwareIdentityMapper(IdentityMapper): if name not in self.rule_mapping_context.old_subst_rules: return super(RuleAwareIdentityMapper, self).map_call(expr, expn_state) else: - return self.map_substitution(name, tag, expr.parameters, expn_state) + return self.map_substitution(name, tag, self.rec( + expr.parameters, expn_state), expn_state) @staticmethod def make_new_arg_context(rule_name, arg_names, arguments, arg_context): diff --git a/test/test_transform.py b/test/test_transform.py index 394cf6688..bc2c7e58f 100644 --- a/test/test_transform.py +++ b/test/test_transform.py @@ -550,6 +550,25 @@ def test_split_iname_only_if_in_within(): assert insn.within_inames == frozenset({'i'}) +def test_nested_substs_in_insns(ctx_factory): + ctx = ctx_factory() + import loopy as lp + + ref_knl = lp.make_kernel( + "{[i]: 0<=i<10}", + """ + a(x) := 2 * x + b(x) := x**2 + c(x) := 7 * x + f[i] = c(b(a(i))) + """ + ) + + knl = lp.expand_subst(ref_knl) + + lp.auto_test_vs_ref(ref_knl, ctx, knl) + + if __name__ == "__main__": if len(sys.argv) > 1: exec(sys.argv[1]) -- GitLab From 4b31d5c9e10b8dba6215e6cd58da40b8f4fc3f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kl=C3=B6ckner?= Date: Sun, 5 May 2019 20:07:40 +0200 Subject: [PATCH 2/3] test_nested_substs_in_insns: Assert that there are no substitutions left --- test/test_transform.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_transform.py b/test/test_transform.py index bc2c7e58f..3ee67b703 100644 --- a/test/test_transform.py +++ b/test/test_transform.py @@ -565,6 +565,7 @@ def test_nested_substs_in_insns(ctx_factory): ) knl = lp.expand_subst(ref_knl) + assert not knl.substitutions lp.auto_test_vs_ref(ref_knl, ctx, knl) -- GitLab From 0ab4ed220ab3973bac7f55ee225b249396e3d09a Mon Sep 17 00:00:00 2001 From: Kaushik Kulkarni Date: Sun, 5 May 2019 13:27:51 -0500 Subject: [PATCH 3/3] adds doc for expand_subst --- loopy/transform/subst.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/loopy/transform/subst.py b/loopy/transform/subst.py index a681afe06..b92698ffa 100644 --- a/loopy/transform/subst.py +++ b/loopy/transform/subst.py @@ -469,6 +469,13 @@ def assignment_to_subst(kernel, lhs_name, extra_arguments=(), within=None, # {{{ expand_subst def expand_subst(kernel, within=None): + """ + Returns an instance of :class:`loopy.LoopKernel` with the substitutions + referenced in instructions of *kernel* matched by *within* expanded. + + :arg within: a stack match as understood by + :func:`loopy.match.parse_stack_match`. + """ if not kernel.substitutions: return kernel -- GitLab