예제 #1
0
def resolve_templates(ast, env):
    # TODO: Unify with decorators module
    crnt = env.translation.crnt
    if crnt.template_signature is not None:
        from numba import typesystem

        argnames = [name.id for name in ast.args.args]
        argtypes = list(crnt.func_signature.args)

        typesystem.resolve_templates(crnt.locals, crnt.template_signature, argnames, argtypes)
        crnt.func_signature = minitypes.FunctionType(return_type=crnt.func_signature.return_type, args=tuple(argtypes))

    return ast
예제 #2
0
파일: pipeline.py 프로젝트: hfeeki/numba
    def resolve_templates(self, ast):
        # TODO: Unify with decorators module
        if self.template_signature is not None:
            from numba import typesystem

            argnames = [arg.id for arg in ast.args.args]
            argtypes = list(self.func_signature.args)

            typesystem.resolve_templates(self.locals, self.template_signature,
                                         argnames, argtypes)
            self.func_signature = minitypes.FunctionType(
                    return_type=self.func_signature.return_type,
                    args=tuple(argtypes))

        return ast
예제 #3
0
def resolve_argtypes(numba_func, template_signature,
                     args, kwargs, translator_kwargs):
    """
    Given an autojitting numba function, return the argument types.
    These need to be resolved in order for the function cache to work.

    TODO: have a single entry point that resolved the argument types!
    """
    assert not kwargs, "Keyword arguments are not supported yet"

    locals_dict = translator_kwargs.get("locals", None)

    return_type = None
    argnames = inspect.getargspec(numba_func.py_func).args
    argtypes = map(context.typemapper.from_python, args)

    if template_signature is not None:
        template_context, signature = typesystem.resolve_templates(
                locals_dict, template_signature, argnames, argtypes)
        return_type = signature.return_type
        argtypes = list(signature.args)

    if locals_dict is not None:
        for i, argname in enumerate(argnames):
            if argname in locals_dict:
                new_type = locals_dict[argname]
                argtypes[i] = new_type

    return minitypes.FunctionType(return_type, tuple(argtypes))
예제 #4
0
파일: pipeline.py 프로젝트: meteogrid/numba
def resolve_templates(ast, env):
    # TODO: Unify with decorators module
    crnt = env.translation.crnt
    if crnt.template_signature is not None:
        from numba import typesystem

        argnames = [name.id for name in ast.args.args]
        argtypes = list(crnt.func_signature.args)

        typesystem.resolve_templates(crnt.locals, crnt.template_signature,
                                     argnames, argtypes)
        crnt.func_signature = minitypes.FunctionType(
            return_type=crnt.func_signature.return_type,
            args=tuple(argtypes))

    return ast
예제 #5
0
def resolve_templates(ast, env):
    # TODO: Unify with decorators module
    crnt = env.translation.crnt
    if crnt.template_signature is not None:
        from numba import typesystem

        argnames = [name.id for name in ast.args.args]
        argtypes = list(crnt.func_signature.args)

        template_context, signature = typesystem.resolve_templates(
            crnt.locals, crnt.template_signature, argnames, argtypes)
        crnt.func_signature = signature

    return ast
예제 #6
0
파일: decorators.py 프로젝트: dwf/numba
def resolve_argtypes(numba_func, template_signature,
                     args, kwargs, translator_kwargs):
    """
    Given an autojitting numba function, return the argument types.
    These need to be resolved in order for the function cache to work.

    TODO: have a single entry point that resolved the argument types!
    """
    assert not kwargs, "Keyword arguments are not supported yet"

    locals_dict = translator_kwargs.get("locals", None)

    argcount = numba_func.py_func.__code__.co_argcount
    if argcount != len(args):
        if argcount == 1:
            arguments = 'argument'
        else:
            arguments = 'arguments'
        raise TypeError("%s() takes exactly %d %s (%d given)" % (
                                numba_func.py_func.__name__, argcount,
                                arguments, len(args)))

    return_type = None
    argnames = inspect.getargspec(numba_func.py_func).args
    env = environment.NumbaEnvironment.get_environment(
        translator_kwargs.get('env', None))
    argtypes = [env.context.typemapper.from_python(x) for x in args]

    if template_signature is not None:
        template_context, signature = typesystem.resolve_templates(
                locals_dict, template_signature, argnames, argtypes)
        return_type = signature.return_type
        argtypes = list(signature.args)

    if locals_dict is not None:
        for i, argname in enumerate(argnames):
            if argname in locals_dict:
                new_type = locals_dict[argname]
                argtypes[i] = new_type

    return minitypes.FunctionType(return_type, tuple(argtypes))
예제 #7
0
def resolve_argtypes(env, py_func, template_signature,
                     args, kwargs, translator_kwargs):
    """
    Given an autojitting numba function, return the argument types.
    These need to be resolved in order for the function cache to work.

    TODO: have a single entry point that resolves the argument types!
    """
    assert not kwargs, "Keyword arguments are not supported yet"

    locals_dict = translator_kwargs.get("locals", None)

    argcount = py_func.__code__.co_argcount
    if argcount != len(args):
        if argcount == 1:
            arguments = 'argument'
        else:
            arguments = 'arguments'
        raise TypeError("%s() takes exactly %d %s (%d given)" % (
                                py_func.__name__, argcount,
                                arguments, len(args)))

    return_type = None
    argnames = inspect.getargspec(py_func).args
    argtypes = [env.context.typemapper.from_python(x) for x in args]

    if template_signature is not None:
        template_context, signature = typesystem.resolve_templates(
                locals_dict, template_signature, argnames, argtypes)
        return_type = signature.return_type
        argtypes = list(signature.args)

    if locals_dict is not None:
        for i, argname in enumerate(argnames):
            if argname in locals_dict:
                new_type = locals_dict[argname]
                argtypes[i] = new_type

    return typesystem.function(return_type, tuple(argtypes))