def outer(pyfn): assert callable(pyfn), "Lifted function must be callable" fname = pyfn.func_name try: caterm.aterm(signature) except caterm.InvalidATerm as e: raise InvalidLibraryDefinton(*e.args + (fname,)) # #effectful libcall = PythonFn(signature, pyfn) install(signature, libcall) sig = getargspec(pyfn) nargs = len(sig.args) # Return a new Fun() class that is a graph node # constructor. # Either we have a codomain annotation or we default to # the dynamic type. cod = params.pop('cod', dynamic) return type(pyfn.func_name, (Fun,), { 'nargs' : nargs, 'fn' : pyfn, 'fname' : fname, 'typesig' : typesig, 'cod' : cod, 'constraints' : constraints, })
def outer(pyfn): assert callable(pyfn), "Lifted function must be callable" fname = pyfn.func_name try: caterm.aterm(signature) except caterm.InvalidATerm as e: raise InvalidLibraryDefinton(*e.args + (fname, )) # #effectful libcall = PythonFn(signature, pyfn) install(signature, libcall) sig = getargspec(pyfn) nargs = len(sig.args) # Return a new Fun() class that is a graph node # constructor. # Either we have a codomain annotation or we default to # the dynamic type. cod = params.pop('cod', dynamic) return type( pyfn.func_name, (Fun, ), { 'nargs': nargs, 'fn': pyfn, 'fname': fname, 'typesig': typesig, 'cod': cod, 'constraints': constraints, })
def lookup(self, aterm): # convert into a C ATerm, inefficent but whatever ct = caterm.aterm(str(aterm)) # canidate functions, functions matching the signature of # the term # Use the C libraries better pattern matching library, # find a function in the Blaze library that matches the # given aterm c = [f for f, sig in self.funs.iteritems() if ct.matches(sig)] if len(c) == 0: raise NoDispatch(aterm) # the canidate which has the minimal cost function costs = [(f, self.costs[f](aterm)) for f in c] return min(costs, key=lambda x: x[1])
def lookup(self, aterm): # convert into a C ATerm, inefficent but whatever aterm_str = str(aterm) ct = caterm.aterm(aterm_str) # canidate functions, functions matching the signature of # the term # Use the C libraries better pattern matching library, # find a function in the Blaze library that matches the # given aterm c = [f for f, sig in self.funs.iteritems() if ct.matches(sig)] if len(c) == 0: raise NoDispatch(aterm) # the canidate which has the minimal cost function costs = [(f, self.costs[f](aterm)) for f in c] return min(costs, key=lambda x: x[1])