当前位置: 首页>>代码示例>>Python>>正文


Python templates.signature函数代码示例

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


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


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