How to use the numba.typing.templates.signature function in numba

To help you get started, we’ve selected a few numba examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github numba / numba / numba / typing / listdecl.py View on Github external
def generic(self, args, kws):
        if len(args) == 2:
            a, b = args
            if isinstance(a, types.List) and isinstance(b, types.List):
                if self.context.can_convert(b.dtype, a.dtype):
                    return signature(a, a, b)
github numba / numba / numba / typing / randomdecl.py View on Github external
cases = [signature(types.uint64, types.int32)]

@infer_global(random.random, typing_key="random.random")
@infer_global(np.random.random, typing_key="np.random.random")
class Random_random(ConcreteRandomTemplate):
    cases = [signature(types.float64)]

    def generic(self):
        def typer(size=None):
            return self.array_typer(size)()
        return typer


@infer_global(random.randint, typing_key="random.randint")
class Random_randint(ConcreteTemplate):
    cases = [signature(tp, tp, tp) for tp in _int_types]

@infer_global(np.random.randint, typing_key="np.random.randint")
class Random_randint(ConcreteRandomTemplate):
    cases = [signature(tp, tp) for tp in _int_types]
    cases += [signature(tp, tp, tp) for tp in _int_types]

    def generic(self):
        def typer(low, high=None, size=None):
            return self.array_typer(size)(low, high)
        return typer


@infer_global(random.randrange, typing_key="random.randrange")
class Random_randrange(ConcreteTemplate):
    cases = [signature(tp, tp) for tp in _int_types]
    cases += [signature(tp, tp, tp) for tp in _int_types]
github IntelPython / sdc / sdc / hiframes / pd_index_ext.py View on Github external
def resolve_min(self, ary, args, kws):
        assert not kws
        return signature(pandas_timestamp_type, *args)
github numba / numba / numba / typing / arraydecl.py View on Github external
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
github IntelPython / sdc / sdc / hiframes / pd_groupby_ext.py View on Github external
def generic(self, args, kws):
            grpby, idx = args
            # df.groupby('A')['B', 'C']
            if isinstance(grpby, DataFrameGroupByType):
                if isinstance(idx, tuple):
                    assert all(isinstance(c, str) for c in idx)
                    selection = idx
                elif isinstance(idx, str):
                    selection = (idx,)
                else:
                    raise ValueError("invalid groupby selection {}".format(idx))
                ret_grp = DataFrameGroupByType(
                    grpby.df_type, grpby.keys, selection, grpby.as_index, True)
                return signature(ret_grp, *args)
github IntelPython / sdc / sdc / hiframes / pd_groupby_ext.py View on Github external
selection = list(df.columns)
            for k in keys:
                selection.remove(k)

            if isinstance(as_index, sdc.utilities.utils.BooleanLiteral):
                as_index = as_index.literal_value
            else:
                # XXX as_index type is just bool when value not passed. Therefore,
                # we assume the default True value.
                # TODO: more robust fix or just check
                as_index = True

            out_typ = DataFrameGroupByType(
                df, keys, tuple(selection), as_index, False)
            return signature(out_typ, *args)
github numba / numba / numba / roc / hsadecl.py View on Github external
# Even though the following functions return size_t in the OpenCL standard,
# It should be rare (and unrealistic) to have 2**63 number of work items.
# We are choosing to use intp (signed 64-bit in large model) due to potential
# loss of precision in coerce(intp, uintp) that results in double.


@intrinsic
class Hsa_get_global_id(ConcreteTemplate):
    key = roc.get_global_id
    cases = [signature(types.intp, types.uint32)]


@intrinsic
class Hsa_get_local_id(ConcreteTemplate):
    key = roc.get_local_id
    cases = [signature(types.intp, types.uint32)]


@intrinsic
class Hsa_get_group_id(ConcreteTemplate):
    key = roc.get_group_id
    cases = [signature(types.intp, types.uint32)]


@intrinsic
class Hsa_get_num_groups(ConcreteTemplate):
    key = roc.get_num_groups
    cases = [signature(types.intp, types.uint32)]


@intrinsic
class Hsa_get_work_dim(ConcreteTemplate):
github numba / numba / numba / typing / builtins.py View on Github external
cases = [signature(max(types.intp, op), op)
             for op in sorted(types.signed_domain)]
    cases += [signature(max(types.uintp, op), op)
              for op in sorted(types.unsigned_domain)]
    cases += [signature(op, op) for op in sorted(types.real_domain)]
    cases += [signature(op, op) for op in sorted(types.complex_domain)]


@builtin
class UnaryPositive(UnaryOp):
    key = "+"
    cases = UnaryNegate.cases


class OrderedCmpOp(ConcreteTemplate):
    cases = [signature(types.boolean, types.boolean, types.boolean)]
    cases += [signature(types.boolean, op, op) for op in sorted(types.signed_domain)]
    cases += [signature(types.boolean, op, op) for op in sorted(types.unsigned_domain)]
    cases += [signature(types.boolean, op, op) for op in sorted(types.real_domain)]


class UnorderedCmpOp(ConcreteTemplate):
    cases = OrderedCmpOp.cases + [
        signature(types.boolean, op, op) for op in sorted(types.complex_domain)]


@builtin
class CmpOpLt(OrderedCmpOp):
    key = '<'


@builtin
github numba / numba / numba / typing / arraydecl.py View on Github external
def resolve_view(self, ary, args, kws):
        from .npydecl import _parse_dtype
        assert not kws
        dtype, = args
        dtype = _parse_dtype(dtype)
        if dtype is None:
            return
        retty = ary.copy(dtype=dtype)
        return signature(retty, *args)
github IntelPython / sdc / hpat / hiframes / pd_dataframe_ext.py View on Github external
if (isinstance(idx, (SeriesType, types.Array, types.List))
                    and (idx.dtype == types.bool_
                         or isinstance(idx.dtype, types.Integer))):
                return signature(df.df_type, *args)
            # df.loc[1:n]
            if isinstance(idx, types.SliceType):
                return signature(df.df_type, *args)
            # df.loc[1:n,'A']
            if (isinstance(idx, types.Tuple) and len(idx) == 2
                    and isinstance(idx.types[1], types.StringLiteral)):
                col_name = idx.types[1].literal_value
                col_no = df.df_type.columns.index(col_name)
                data_typ = df.df_type.data[col_no]
                # TODO: index
                ret_typ = SeriesType(data_typ.dtype, None, True)
                return signature(ret_typ, *args)