def get_code(self, cl, bindenv, body): vars = self.lhs_vars(cl) assert_unique(vars) mask = L.mask_from_bounds(vars, bindenv) if L.mask_is_allbound(mask): comparison = L.Compare(L.Name(cl.elem), L.In(), L.Name(cl.set)) code = (L.If(comparison, body, ()), ) needs_typecheck = True elif mask == L.mask('bu'): code = (L.For(cl.elem, L.Name(cl.set), body), ) needs_typecheck = True else: code = super().get_code(cl, bindenv, body) needs_typecheck = False if needs_typecheck and self.use_typecheck: code = (L.If(L.IsSet(L.Name(cl.set)), code, ()), ) return code
def get_code(self, cl, bindenv, body): vars = self.lhs_vars(cl) rel = self.rhs_rel(cl) assert_unique(vars) mask = L.mask_from_bounds(vars, bindenv) if L.mask_is_allbound(mask): comparison = L.Compare(L.tuplify(vars), L.In(), L.Name(rel)) code = (L.If(comparison, body, ()), ) elif L.mask_is_allunbound(mask): code = (L.DecompFor(vars, L.Name(rel), body), ) else: bvars, uvars = L.split_by_mask(mask, vars) lookup = L.ImgLookup(L.Name(rel), mask, bvars) # Optimize in the case where there's only one unbound. if len(uvars) == 1: code = (L.For(uvars[0], L.Unwrap(lookup), body), ) else: code = (L.DecompFor(uvars, lookup, body), ) return code