loopy
loopy copied to clipboard
`lp.extract_subst` does not search for subexpressions of `Product` or `Sum`
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.
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?
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.
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.