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

Python templates.signature函数代码示例

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

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



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

示例1: 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


示例2: generic

 def generic(self, args, kws):
     assert not kws
     (val,) = args
     if isinstance(val, (types.Buffer, types.BaseTuple)):
         return signature(types.intp, val)
     elif isinstance(val, (types.RangeType)):
         return signature(val.dtype, val)
开发者ID:esc,项目名称:numba,代码行数:7,代码来源:builtins.py


示例3: resolve_transpose

    def resolve_transpose(self, ary, args, kws):
        def sentry_shape_scalar(ty):
            if ty in types.number_domain:
                # Guard against non integer type
                if not isinstance(ty, types.Integer):
                    raise TypeError("transpose() arg cannot be {0}".format(ty))
                return True
            else:
                return False

        assert not kws
        if len(args) == 0:
            return signature(self.resolve_T(ary))

        if len(args) == 1:
            shape, = args

            if sentry_shape_scalar(shape):
                assert ary.ndim == 1
                return signature(ary, *args)

            shape = normalize_shape(shape)
            if shape is None:
                return

            assert ary.ndim == shape.count
            return signature(self.resolve_T(ary), shape)

        else:
            if any(not sentry_shape_scalar(a) for a in args):
                raise TypeError("transpose({0}) is not supported".format(
                    ', '.join(args)))
            assert ary.ndim == len(args)
            return signature(self.resolve_T(ary), *args)
开发者ID:cpcloud,项目名称:numba,代码行数:34,代码来源:arraydecl.py


示例4: generic_hetero_always_real

def generic_hetero_always_real(self, args, kws):
    assert not args
    assert not kws
    if isinstance(self.this.dtype, (types.Integer, types.Boolean)):
        return signature(types.float64, recvr=self.this)
    if isinstance(self.this.dtype, types.Complex):
        return signature(self.this.dtype.underlying_float, recvr=self.this)
    return signature(self.this.dtype, recvr=self.this)
开发者ID:cpcloud,项目名称:numba,代码行数:8,代码来源:arraydecl.py


示例5: generic_expand

def generic_expand(self, args, kws):
    if isinstance(self.this.dtype, types.Integer):
        # Expand to a machine int, not larger (like Numpy)
        if self.this.dtype.signed:
            return signature(max(types.intp, self.this.dtype), recvr=self.this)
        else:
            return signature(max(types.uintp, self.this.dtype), recvr=self.this)
    return signature(self.this.dtype, recvr=self.this)
开发者ID:molodiuc,项目名称:numba,代码行数:8,代码来源:builtins.py


示例6: generic

    def generic(self, args, kws):
        assert not kws
        ary, idx, val = args

        if ary.ndim == 1:
            return signature(ary.dtype, ary, types.intp, ary.dtype)
        elif ary.ndim > 1:
            return signature(ary.dtype, ary, idx, ary.dtype)
开发者ID:yuguen,项目名称:numba,代码行数:8,代码来源:cudadecl.py


示例7: generic

 def generic(self, args, kws):
     if len(args) == 1:
         # Guard against unary + and -
         return
     left, right = args
     if not all(isinstance(tp, types.NPTimedelta) for tp in args):
         return
     if npdatetime.can_cast_timedelta_units(left.unit, right.unit):
         return signature(right, left, right)
     elif npdatetime.can_cast_timedelta_units(right.unit, left.unit):
         return signature(left, left, right)
开发者ID:stefanseefeld,项目名称:numba,代码行数:11,代码来源:npdatetime.py


示例8: generic

 def generic(self, args, kws):
     assert not kws
     nargs = len(args)
     if nargs == 2:
         [inp, out] = args
         if isinstance(inp, types.Array) and isinstance(out, types.Array):
             return signature(out, inp, out)
     elif nargs == 1:
         [inp] = args
         if inp in types.number_domain:
             return signature(types.float64, types.float64)
开发者ID:apsaltis,项目名称:numba,代码行数:11,代码来源:npydecl.py


示例9: generic

    def generic(self, args, kws):
        assert not kws
        ary, idx, val = args

        # Implementation presently supports float64 only,
        # so fail typing otherwise
        if ary.dtype != types.float64:
            return

        if ary.ndim == 1:
            return signature(ary.dtype, ary, types.intp, ary.dtype)
        elif ary.ndim > 1:
            return signature(ary.dtype, ary, idx, ary.dtype)
开发者ID:CaptainAL,项目名称:Spyder,代码行数:13,代码来源:cudadecl.py


示例10: generic

    def generic(self, args, kws):
        assert not kws
        ary, idx, val = args
        if not isinstance(ary, types.Buffer):
            return
        if not ary.mutable:
            raise TypeError("Cannot modify value of type %s" %(ary,))
        out = get_array_index_type(ary, idx)
        if out is None:
            return

        idx = out.index
        res = out.result
        if isinstance(res, types.Array):
            # Indexing produces an array
            if isinstance(val, types.Array):
                if not self.context.can_convert(val.dtype, res.dtype):
                    # DType conversion not possible
                    return
                else:
                    res = val
            elif isinstance(val, types.Sequence):
                if (res.ndim == 1 and
                    self.context.can_convert(val.dtype, res.dtype)):
                    # Allow assignement of sequence to 1d array
                    res = val
                else:
                    # NOTE: sequence-to-array broadcasting is unsupported
                    return
            else:
                # Allow scalar broadcasting
                if self.context.can_convert(val, res.dtype):
                    res = res.dtype
                else:
                    # Incompatible scalar type
                    return
        elif not isinstance(val, types.Array):
            # Single item assignment
            if not self.context.can_convert(val, res):
                # if the array dtype is not yet defined
                if not res.is_precise():
                    # set the array type to use the dtype of value (RHS)
                    newary = ary.copy(dtype=val)
                    return signature(types.none, newary, idx, res)
                else:
                    return
            res = val
        else:
            return
        return signature(types.none, ary, idx, res)
开发者ID:cpcloud,项目名称:numba,代码行数:50,代码来源:arraydecl.py


示例11: resolve_take

 def resolve_take(self, ary, args, kws):
     assert not kws
     argty, = args
     if isinstance(argty, types.Integer):
         sig = signature(ary.dtype, *args)
     elif isinstance(argty, types.Array):
         sig = signature(argty.copy(layout='C', dtype=ary.dtype), *args)
     elif isinstance(argty, types.List): # 1d lists only
         sig = signature(types.Array(ary.dtype, 1, 'C'), *args)
     elif isinstance(argty, types.BaseTuple):
         sig = signature(types.Array(ary.dtype, np.ndim(argty), 'C'), *args)
     else:
         raise TypeError("take(%s) not supported for %s" % argty)
     return sig
开发者ID:cpcloud,项目名称:numba,代码行数:14,代码来源:arraydecl.py


示例12: generic

    def generic(self, args, kws):
        assert not kws
        [ary, idx] = args
        if not isinstance(ary, types.Array):
            return

        idx = normalize_index(idx)
        if not idx:
            return

        if idx == types.slice3_type: #(types.slice2_type, types.slice3_type):
            res = ary.copy(layout='A')
        elif isinstance(idx, (types.UniTuple, types.Tuple)):
            if ary.ndim > len(idx):
                return
            elif ary.ndim < len(idx):
                return
            elif any(i == types.slice3_type for i in idx):
                ndim = ary.ndim
                for i in idx:
                    if i != types.slice3_type:
                        ndim -= 1
                res = ary.copy(ndim=ndim, layout='A')
            else:
                res = ary.dtype
        elif idx == types.intp:
            if ary.ndim != 1:
                return
            res = ary.dtype

        else:
            raise Exception("unreachable: index type of %s" % idx)

        return signature(res, ary, idx)
开发者ID:ASPP,项目名称:numba,代码行数:34,代码来源:builtins.py


示例13: resolve_view

 def resolve_view(self, ary, args, kws):
     from .npydecl import _parse_dtype
     assert not kws
     dtype, = args
     dtype = _parse_dtype(dtype)
     retty = ary.copy(dtype=dtype)
     return signature(retty, *args)
开发者ID:hajs,项目名称:numba,代码行数:7,代码来源:arraydecl.py


示例14: generic

    def generic(self, args, kws):
        assert not kws
        ary, idx, val = args
        if not isinstance(ary, types.Buffer):
            return
        if not ary.mutable:
            raise TypeError("Cannot modify value of type %s" %(ary,))
        out = get_array_index_type(ary, idx)
        if out is None:
            return

        idx = out.index
        res = out.result
        if isinstance(res, types.Array):
            # Indexing produces an array
            if not isinstance(val, types.Array):
                # Allow scalar broadcasting
                res = res.dtype
            elif (val.ndim == res.ndim and
                  self.context.can_convert(val.dtype, res.dtype)):
                # Allow assignement of same-dimensionality compatible-dtype array
                res = val
            else:
                # Unexpected dimensionality of assignment source
                # (array broadcasting is unsupported)
                return
        elif not isinstance(val, types.Array):
            # Single item assignment
            res = val
        else:
            return
        return signature(types.none, ary, idx, res)
开发者ID:hajs,项目名称:numba,代码行数:32,代码来源:arraydecl.py


示例15: generic

 def generic(self, args, kws):
     assert not kws
     ary, idx, val = args
     if isinstance(ary, types.Buffer):
         if not ary.mutable:
             raise TypeError("Immutable array")
         return signature(types.none, ary, normalize_index(idx), ary.dtype)
开发者ID:suensummit,项目名称:numba,代码行数:7,代码来源:builtins.py


示例16: generic

 def generic(self, args, kws):
     assert not kws
     ary, idx, val = args
     if isinstance(ary, types.Array):
         if ary.const:
             raise TypeError("Constant array")
         return signature(types.none, ary, normalize_index(idx), ary.dtype)
开发者ID:genba,项目名称:numba,代码行数:7,代码来源:builtins.py


示例17: resolve_nonzero

 def resolve_nonzero(self, ary, args, kws):
     assert not args
     assert not kws
     # 0-dim arrays return one result array
     ndim = max(ary.ndim, 1)
     retty = types.UniTuple(types.Array(types.intp, 1, 'C'), ndim)
     return signature(retty)
开发者ID:gmarkall,项目名称:numba,代码行数:7,代码来源:arraydecl.py


示例18: generic

 def generic(self, args, kws):
     assert not kws
     [ary, idx] = args
     out = get_array_index_type(ary, idx)
     if out is not None:
         ary, idx, res = out
         return signature(res, ary, idx)
开发者ID:dvincelli,项目名称:numba,代码行数:7,代码来源:arraydecl.py


示例19: resolve_itemset

 def resolve_itemset(self, ary, args, kws):
     assert not kws
     # We don't support explicit arguments as that's exactly equivalent
     # to regular indexing.  The no-argument form is interesting to
     # allow some degree of genericity when writing functions.
     if len(args) == 1:
         return signature(types.none, ary.dtype)
开发者ID:gmarkall,项目名称:numba,代码行数:7,代码来源:arraydecl.py


示例20: generic

 def generic(self, args, kws):
     # Resolution of members for record and structured arrays
     record, idx, value = args
     if isinstance(record, types.Record) and isinstance(idx, str):
         expectedty = record.typeof(idx)
         if self.context.can_convert(value, expectedty) is not None:
             return signature(types.void, record, types.Const(idx), value)
开发者ID:gmarkall,项目名称:numba,代码行数:7,代码来源:arraydecl.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python unittest_support.main函数代码示例发布时间:2022-05-27
下一篇:
Python typing.signature函数代码示例发布时间: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