• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.pysignature函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中numba.utils.pysignature函数的典型用法代码示例。如果您正苦于以下问题:Python pysignature函数的具体用法?Python pysignature怎么用?Python pysignature使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了pysignature函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, py_func, locals={}, targetoptions={}, impl_kind='direct'):
        """
        Parameters
        ----------
        py_func: function object to be compiled
        locals: dict, optional
            Mapping of local variable names to Numba types.  Used to override
            the types deduced by the type inference engine.
        targetoptions: dict, optional
            Target-specific config options.
        """
        self.typingctx = self.targetdescr.typing_context
        self.targetctx = self.targetdescr.target_context

        pysig = utils.pysignature(py_func)
        arg_count = len(pysig.parameters)
        can_fallback = not targetoptions.get('nopython', False)
        _DispatcherBase.__init__(self, arg_count, py_func, pysig, can_fallback)

        functools.update_wrapper(self, py_func)

        self.targetoptions = targetoptions
        self.locals = locals
        self._cache = NullCache()
        compiler_class = self._impl_kinds[impl_kind]
        self._impl_kind = impl_kind
        self._compiler = compiler_class(py_func, self.targetdescr,
                                        targetoptions, locals)
        self._cache_hits = collections.Counter()
        self._cache_misses = collections.Counter()

        self._type = types.Dispatcher(self)
        self.typingctx.insert_global(self, self._type)
开发者ID:FedericoStra,项目名称:numba,代码行数:33,代码来源:dispatcher.py


示例2: __init__

    def __init__(self, py_func, locals={}, targetoptions={}):
        """
        Parameters
        ----------
        py_func: function object to be compiled
        locals: dict, optional
            Mapping of local variable names to Numba types.  Used to override
            the types deduced by the type inference engine.
        targetoptions: dict, optional
            Target-specific config options.
        """
        self.typingctx = self.targetdescr.typing_context
        self.targetctx = self.targetdescr.target_context

        pysig = utils.pysignature(py_func)
        arg_count = len(pysig.parameters)

        _OverloadedBase.__init__(self, arg_count, py_func, pysig)

        functools.update_wrapper(self, py_func)

        self.targetoptions = targetoptions
        self.locals = locals

        self.typingctx.insert_overloaded(self)
开发者ID:CaptainAL,项目名称:Spyder,代码行数:25,代码来源:dispatcher.py


示例3: __init__

    def __init__(self, func):
        func = get_function_object(func)
        code = get_code_object(func)
        pysig = utils.pysignature(func)
        if not code:
            raise errors.ByteCodeSupportError(
                "%s does not provide its bytecode" % func)

        # A map of {offset: ByteCodeInst}
        table = utils.SortedMap(ByteCodeIter(code))
        labels = set(dis.findlabels(code.co_code))
        labels.add(0)

        try:
            func_qualname = func.__qualname__
        except AttributeError:
            func_qualname = func.__name__

        self._mark_lineno(table, code)
        super(ByteCode, self).__init__(func=func,
                                       func_qualname=func_qualname,
                                       is_generator=inspect.isgeneratorfunction(func),
                                       pysig=pysig,
                                       filename=code.co_filename,
                                       co_names=code.co_names,
                                       co_varnames=code.co_varnames,
                                       co_consts=code.co_consts,
                                       co_freevars=code.co_freevars,
                                       table=table,
                                       labels=list(sorted(labels)))
开发者ID:MatthieuDartiailh,项目名称:numba,代码行数:30,代码来源:bytecode.py


示例4: sum_expand

def sum_expand(self, args, kws):
    """
    sum can be called with or without an axis parameter.
    """
    pysig = None
    if kws:
        def sum_stub(axis):
            pass
        pysig = utils.pysignature(sum_stub)
        # rewrite args
        args = list(args) + [kws['axis']]
        kws = None
    args_len = len(args)
    assert args_len <= 1
    if args_len == 0:
        # No axis parameter so the return type of the summation is a scalar
        # of the type of the array.
        out = signature(_expand_integer(self.this.dtype), *args,
                        recvr=self.this)
    else:
        # There is an axis paramter so the return type of this summation is
        # an array of dimension one less than the input array.
        return_type = types.Array(dtype=_expand_integer(self.this.dtype),
                                  ndim=self.this.ndim-1, layout='C')
        out = signature(return_type, *args, recvr=self.this)
    return out.replace(pysig=pysig)
开发者ID:cpcloud,项目名称:numba,代码行数:26,代码来源:arraydecl.py


示例5: __init__

    def __init__(self, arg_count, py_func):
        self._tm = default_type_manager
        # _dispatcher.Dispatcher.__init__(self, self._tm.get_pointer(), arg_count)

        # A mapping of signatures to entry points
        self.overloads = {}
        # A mapping of signatures to compile results
        self._compileinfos = {}
        # A list of nopython signatures
        self._npsigs = []

        self.py_func = py_func
        # other parts of Numba assume the old Python 2 name for code object
        self.func_code = get_code_object(py_func)
        # but newer python uses a different name
        self.__code__ = self.func_code

        self._pysig = utils.pysignature(self.py_func)
        _argnames = tuple(self._pysig.parameters)
        _dispatcher.Dispatcher.__init__(self, self._tm.get_pointer(), arg_count, _argnames)

        self.doc = py_func.__doc__
        self._compile_lock = utils.NonReentrantLock()

        utils.finalize(self, self._make_finalizer())
开发者ID:ymarfoq,项目名称:outilACVDesagregation,代码行数:25,代码来源:dispatcher.py


示例6: __init__

 def __init__(self, py_func, targetdescr, targetoptions, locals,
              pipeline_class):
     self.py_func = py_func
     self.targetdescr = targetdescr
     self.targetoptions = targetoptions
     self.locals = locals
     self.pysig = utils.pysignature(self.py_func)
     self.pipeline_class = pipeline_class
开发者ID:yuguen,项目名称:numba,代码行数:8,代码来源:dispatcher.py


示例7: _getargs

def _getargs(fn):
    """
    Returns list of positional and keyword argument names in order.
    """
    sig = utils.pysignature(fn)
    params = sig.parameters
    args = [k for k, v in params.items()
            if (v.kind & v.POSITIONAL_OR_KEYWORD) == v.POSITIONAL_OR_KEYWORD]
    return args
开发者ID:esc,项目名称:numba,代码行数:9,代码来源:base.py


示例8: resolve_argsort

 def resolve_argsort(self, ary, args, kws):
     assert not args
     kwargs = dict(kws)
     kind = kwargs.pop('kind', types.Const('quicksort'))
     if kwargs:
         msg = "Unsupported keywords: {!r}"
         raise TypingError(msg.format([k for k in kwargs.keys()]))
     if ary.ndim == 1:
         def argsort_stub(kind='quicksort'):
             pass
         pysig = utils.pysignature(argsort_stub)
         sig = signature(types.Array(types.intp, 1, 'C'), kind).replace(pysig=pysig)
         return sig
开发者ID:cpcloud,项目名称:numba,代码行数:13,代码来源:arraydecl.py


示例9: _get_implementation

 def _get_implementation(self, args, kws):
     impl = self.py_func(*args, **kws)
     # Check the generating function and implementation signatures are
     # compatible, otherwise compiling would fail later.
     pysig = utils.pysignature(self.py_func)
     implsig = utils.pysignature(impl)
     ok = len(pysig.parameters) == len(implsig.parameters)
     if ok:
         for pyparam, implparam in zip(pysig.parameters.values(),
                                       implsig.parameters.values()):
             # We allow the implementation to omit default values, but
             # if it mentions them, they should have the same value...
             if (pyparam.name != implparam.name or
                 pyparam.kind != implparam.kind or
                 (implparam.default is not implparam.empty and
                  implparam.default != pyparam.default)):
                 ok = False
     if not ok:
         raise TypeError("generated implementation %s should be compatible "
                         "with signature '%s', but has signature '%s'"
                         % (impl, pysig, implsig))
     self.impls.add(impl)
     return impl
开发者ID:FedericoStra,项目名称:numba,代码行数:23,代码来源:dispatcher.py


示例10: _set_init

 def _set_init(cls):
     """
     Generate a wrapper for calling the constructor from pure Python.
     Note the wrapper will only accept positional arguments.
     """
     init = cls.class_type.instance_type.methods['__init__']
     init_sig = utils.pysignature(init)
     # get postitional and keyword arguments
     # offset by one to exclude the `self` arg
     args = _getargs(init_sig)[1:]
     cls._ctor_sig = init_sig
     ctor_source = _ctor_template.format(args=', '.join(args))
     glbls = {"__numba_cls_": cls}
     exec_(ctor_source, glbls)
     ctor = glbls['ctor']
     cls._ctor = njit(ctor)
开发者ID:numba,项目名称:numba,代码行数:16,代码来源:base.py


示例11: from_function

    def from_function(cls, pyfunc):
        """
        Create the FunctionIdentity of the given function.
        """
        func = get_function_object(pyfunc)
        code = get_code_object(func)
        pysig = utils.pysignature(func)
        if not code:
            raise errors.ByteCodeSupportError(
                "%s does not provide its bytecode" % func)

        try:
            func_qualname = func.__qualname__
        except AttributeError:
            func_qualname = func.__name__

        self = cls()
        self.func = func
        self.func_qualname = func_qualname
        self.func_name = func_qualname.split('.')[-1]
        self.code = code
        self.module = inspect.getmodule(func)
        self.modname = (utils._dynamic_modname
                        if self.module is None
                        else self.module.__name__)
        self.is_generator = inspect.isgeneratorfunction(func)
        self.pysig = pysig
        self.filename = code.co_filename
        self.firstlineno = code.co_firstlineno
        self.arg_count = len(pysig.parameters)
        self.arg_names = list(pysig.parameters)

        # Even the same function definition can be compiled into
        # several different function objects with distinct closure
        # variables, so we make sure to disambiguate using an unique id.
        uid = next(cls._unique_ids)
        self.unique_name = '{}${}'.format(self.func_qualname, uid)

        return self
开发者ID:sklam,项目名称:numba,代码行数:39,代码来源:bytecode.py


示例12: _type_me

    def _type_me(self, argtys, kwtys):
        """
        Implement AbstractTemplate.generic() for the typing class
        built by StencilFunc._install_type().
        Return the call-site signature.
        """
        if (self.neighborhood is not None and
            len(self.neighborhood) != argtys[0].ndim):
            raise ValueError("%d dimensional neighborhood specified "
                             "for %d dimensional input array" %
                             (len(self.neighborhood), argtys[0].ndim))

        argtys_extra = argtys
        sig_extra = ""
        result = None
        if 'out' in kwtys:
            argtys_extra += (kwtys['out'],)
            sig_extra += ", out=None"
            result = kwtys['out']

        if 'neighborhood' in kwtys:
            argtys_extra += (kwtys['neighborhood'],)
            sig_extra += ", neighborhood=None"

        # look in the type cache first
        if argtys_extra in self._type_cache:
            (_sig, _, _, _) = self._type_cache[argtys_extra]
            return _sig

        (real_ret, typemap, calltypes) = self.get_return_type(argtys)
        sig = signature(real_ret, *argtys_extra)
        dummy_text = ("def __numba_dummy_stencil({}{}):\n    pass\n".format(
                        ",".join(self.kernel_ir.arg_names), sig_extra))
        exec_(dummy_text) in globals(), locals()
        dummy_func = eval("__numba_dummy_stencil")
        sig.pysig = utils.pysignature(dummy_func)
        self._targetctx.insert_func_defn([(self._lower_me, self, argtys_extra)])
        self._type_cache[argtys_extra] = (sig, result, typemap, calltypes)
        return sig
开发者ID:cpcloud,项目名称:numba,代码行数:39,代码来源:stencil.py


示例13: _has_loc

def _has_loc(fn):
    """Does function *fn* take ``loc`` argument?
    """
    sig = utils.pysignature(fn)
    return 'loc' in sig.parameters
开发者ID:numba,项目名称:numba,代码行数:5,代码来源:base.py


示例14: _stencil_wrapper


#.........这里部分代码省略.........
            # but minimum's greater than 0 don't preclude any entry in the array.
            # So, take the minimum of 0 and the minimum index found in the kernel
            # and this will be a negative number (potentially -0).  Then, we do
            # unary - on that to get the positive offset in this dimension whose
            # use is precluded.
            # ranges[i][1] is the maximum of 0 and the observed maximum index
            # in this dimension because negative maximums would not cause us to
            # preclude any entry in the array from being used.
            func_text += ("for {} in range(-min(0,{}),"
                          "{}[{}]-max(0,{})):\n").format(
                            index_vars[i],
                            ranges[i][0],
                            shape_name,
                            i,
                            ranges[i][1])
            offset += 1

        for j in range(offset):
            func_text += "    "
        # Put a sentinel in the code so we can locate it in the IR.  We will
        # remove this sentinel assignment and replace it with the IR for the
        # stencil kernel body.
        func_text += "{} = 0\n".format(sentinel_name)
        func_text += "    return {}\n".format(out_name)

        if config.DEBUG_ARRAY_OPT == 1:
            print("new stencil func text")
            print(func_text)

        # Force the new stencil function into existence.
        exec_(func_text) in globals(), locals()
        stencil_func = eval(stencil_func_name)
        if sigret is not None:
            pysig = utils.pysignature(stencil_func)
            sigret.pysig = pysig
        # Get the IR for the newly created stencil function.
        stencil_ir = compiler.run_frontend(stencil_func)
        ir_utils.remove_dels(stencil_ir.blocks)

        # rename all variables in stencil_ir afresh
        var_table = ir_utils.get_name_var_table(stencil_ir.blocks)
        new_var_dict = {}
        reserved_names = ([sentinel_name, out_name, neighborhood_name,
                           shape_name] + kernel_copy.arg_names + index_vars)
        for name, var in var_table.items():
            if not name in reserved_names:
                new_var_dict[name] = ir_utils.mk_unique_var(name)
        ir_utils.replace_var_names(stencil_ir.blocks, new_var_dict)

        stencil_stub_last_label = max(stencil_ir.blocks.keys()) + 1

        # Shift lables in the kernel copy so they are guaranteed unique
        # and don't conflict with any labels in the stencil_ir.
        kernel_copy.blocks = ir_utils.add_offset_to_labels(
                                kernel_copy.blocks, stencil_stub_last_label)
        new_label = max(kernel_copy.blocks.keys()) + 1
        # Adjust ret_blocks to account for addition of the offset.
        ret_blocks = [x + stencil_stub_last_label for x in ret_blocks]

        if config.DEBUG_ARRAY_OPT == 1:
            print("ret_blocks w/ offsets", ret_blocks, stencil_stub_last_label)
            print("before replace sentinel stencil_ir")
            ir_utils.dump_blocks(stencil_ir.blocks)
            print("before replace sentinel kernel_copy")
            ir_utils.dump_blocks(kernel_copy.blocks)
开发者ID:cpcloud,项目名称:numba,代码行数:66,代码来源:stencil.py



注:本文中的numba.utils.pysignature函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python cuda.grid函数代码示例发布时间:2022-05-27
下一篇:
Python utils.itervalues函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap