loopy icon indicating copy to clipboard operation
loopy copied to clipboard

`lp.extract_subst` does not search for subexpressions of `Product` or `Sum`

Open kaushikcfd opened this issue 3 years ago • 3 comments

Consider the kernel:

import loopy as lp

knl = lp.make_einsum("k,ij,ij->i", arg_names=("a", "b", "c"))
knl = lp.extract_subst(knl, "tmp_hoist", "b[i, j] * c[i, j]")

raises the following exception:

RuntimeError: no expressions matching 'b[i, j]*c[i, j]'

The expected behavior would be that b[i,j] * c[i,j] should have resulted in a match.

kaushikcfd avatar Feb 06 '22 04:02 kaushikcfd

Also, I wanted to bring up the discussion if using the extract_subst for the purposes of hoisting expressions is a reasonable approach, i.e. can this be perceived as an anti-pattern?

kaushikcfd avatar Feb 06 '22 04:02 kaushikcfd

I personally think instead of going down this road we might want to explore integrating with something like MatchPy in the future to allow richer expression matching including caring for associativity, etc.

kaushikcfd avatar Feb 06 '22 04:02 kaushikcfd

I think this is legitimate functionality to want. extract_subst for now (IIRC) only finds exact subtree matches. I agree that matchpy is likely a better approach than trying to roll our own, for the more general case. A pymbolic/matchpy interop layer might be a good first step.

inducer avatar Feb 06 '22 06:02 inducer