Beispiel #1
0
 def visit_DecompFor(self, node):
     if (isinstance(node.iter, L.Name) and node.iter.id in self.rels):
         if len(node.vars) != 1:
             raise L.TransformationError(
                 'Singleton unwrapping requires all DecompFor loops '
                 'over relation to have exactly one target variable')
         return L.For(node.vars[0], node.iter, node.body)
     return node
Beispiel #2
0
    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
Beispiel #3
0
    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