Skip to content

sumpy.codegen.BesselGetter creates duplicate CSEs with same structure

BesselGetter doesn't take account redundant structures within the CSE, which means that code such as the following

@memoize_method
def hankel_1(self, order, arg):
    if order == 0:
        return prim.Lookup(
                prim.CommonSubexpression(self.hank1_01(arg), "hank1_01_result"),
                "order0")
    elif order == 1:
        return prim.Lookup(
                prim.CommonSubexpression(self.hank1_01(arg), "hank1_01_result"),
                "order1")

ends up creating two distinct CSE objects that have the same structure. This leads to slowness when doing a comparison for equality, because if the id of the sub components isn't the same we are forced to do a deep comparison, and the expanded CSEs for the expressions are massive (built of components that are equal but with different id).