Exemplo n.º 1
0
    def outer(pyfn):
        assert callable(pyfn), "Lifted function must be callable"
        fname = pyfn.func_name

        try:
            parse(signature)
        except AtermSyntaxError 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,
        })
Exemplo n.º 2
0
    def outer(pyfn):
        assert callable(pyfn), "Lifted function must be callable"
        fname = pyfn.func_name

        try:
            parse(signature)
        except AtermSyntaxError as e:
            raise InvalidLibraryDefinition(*e.args + (fname, ))

        # #effectful
        libcall = PythonFn(signature, typesig, pyfn)
        install(signature, libcall)

        sig = getargspec(pyfn)
        nargs = len(sig.args)

        # Either we have a codomain annotation or we default to
        # the dynamic type.
        cod = params.pop('cod', dynamic)

        _ast = ast.parse(getsource(pyfn))

        fun = type(
            pyfn.func_name, (Fun, ), {
                'nargs': nargs,
                'fn': pyfn,
                'fname': fname,
                'typesig': typesig,
                'cod': cod,
                'constraints': constraints,
                '_ast': _ast,
            })

        @wraps(pyfn)
        def inner(*args):
            # differentiate execution based on whether the
            # arguments are manifest or deferred.

            #allmanifest = all_prop(args, manifest)
            allmanifest = all_manifest(args)

            if allmanifest:
                # do immediete evaluation
                if constraints.get('passthrough', False):
                    # don't generate descriptors just call Python fn
                    # with the whatever was passed in
                    return pyfn(*args)
                else:
                    # generate descriptors
                    return ieval(pyfn, args)
            else:
                # Return a new Fun() class that is a graph node
                # constructor.
                return fun(args)

        return inner
Exemplo n.º 3
0
    def outer(pyfn):
        assert callable(pyfn), "Lifted function must be callable"
        fname = pyfn.func_name

        try:
            parse(signature)
        except AtermSyntaxError as e:
            raise InvalidLibraryDefinition(*e.args + (fname,))

        # #effectful
        libcall = PythonFn(signature, typesig, pyfn)
        install(signature, libcall)

        sig = getargspec(pyfn)
        nargs = len(sig.args)

        # Either we have a codomain annotation or we default to
        # the dynamic type.
        cod = params.pop('cod', dynamic)

        _ast = ast.parse(getsource(pyfn))

        fun = type(pyfn.func_name, (Fun,), {
            'nargs'       : nargs,
            'fn'          : pyfn,
            'fname'       : fname,
            'typesig'     : typesig,
            'cod'         : cod,
            'constraints' : constraints,
            '_ast'        : _ast,
        })

        @wraps(pyfn)
        def inner(*args):
            # differentiate execution based on whether the
            # arguments are manifest or deferred.

            #allmanifest = all_prop(args, manifest)
            allmanifest = all_manifest(args)

            if allmanifest:
                # do immediete evaluation
                if constraints.get('passthrough', False):
                    # don't generate descriptors just call Python fn
                    # with the whatever was passed in
                    return pyfn(*args)
                else:
                    # generate descriptors
                    return ieval(pyfn, args)
            else:
                # Return a new Fun() class that is a graph node
                # constructor.
                return fun(args)

        return inner
Exemplo n.º 4
0
def test_match1():
    expr = parse('Add(1,2)')
    fn, cost = lookup(expr)
Exemplo n.º 5
0
def test_match2():
    expr = parse('Mul(1,2)')
    fn, cost = lookup(expr)
Exemplo n.º 6
0
def test_match1():
    expr = parse('Add(1,2)')
    fn, cost = lookup(expr)
Exemplo n.º 7
0
def test_match2():
    expr = parse('Mul(1,2)')
    fn, cost = lookup(expr)