How to use the numba.types.intp 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 / types / iterators.py View on Github external
def __init__(self, iterable_type):
        from . import Tuple, intp
        self.source_type = iterable_type.iterator_type
        yield_type = Tuple([intp, self.source_type.yield_type])
        name = 'enumerate(%s)' % (self.source_type)
        super(EnumerateType, self).__init__(name, yield_type)
github numba / numba / numba / typing / arraydecl.py View on Github external
def _expand_integer(ty):
    """
    If *ty* is an integer, expand it to a machine int (like Numpy).
    """
    if isinstance(ty, types.Integer):
        if ty.signed:
            return max(types.intp, ty)
        else:
            return max(types.uintp, ty)
    elif isinstance(ty, types.Boolean):
        return types.intp
    else:
        return ty
github numba / numba / numba / array_analysis.py View on Github external
self.typemap[replacement_slice_var.name] = self.typemap[index.name]

        if config.DEBUG_ARRAY_OPT >= 2:
            print("after rewriting negatives", "lhs_rel", lhs_rel, "rhs_rel", rhs_rel)

        if lhs_known and rhs_known:
            if config.DEBUG_ARRAY_OPT >= 2:
                print("lhs and rhs known so return static size")
            return self.gen_static_slice_size(lhs_rel, rhs_rel, loc, scope, stmts, equiv_set), replacement_slice_var

        if (lhs_rel == 0 and isinstance(rhs_rel, tuple) and
            equiv_set.is_equiv(dsize, rhs_rel[0]) and
            rhs_rel[1] == 0):
            return dsize, None

        slice_typ = types.intp
        orig_slice_typ = slice_typ

        size_var = ir.Var(scope, mk_unique_var("slice_size"), loc)
        size_val = ir.Expr.binop(operator.sub, rhs, lhs, loc=loc)
        self.calltypes[size_val] = signature(slice_typ, rhs_typ, lhs_typ)
        self._define(equiv_set, size_var, slice_typ, size_val)
        size_rel = equiv_set.get_rel(size_var)
        if config.DEBUG_ARRAY_OPT >= 2:
            print("size_rel", size_rel, type(size_rel))

        wrap_var = ir.Var(scope, mk_unique_var("wrap"), loc)
        wrap_def = ir.Global('wrap_index', wrap_index, loc=loc)
        fnty = get_global_func_typ(wrap_index)
        sig = self.context.resolve_function_type(fnty, (orig_slice_typ, size_typ,), {})
        self._define(equiv_set, wrap_var, fnty, wrap_def)
github IntelPython / sdc / sdc / str_arr_ext.py View on Github external
def str_arr_size_impl(context, builder, typ, val):
    string_array = context.make_helper(builder, string_array_type, val)

    attrval = string_array.num_items
    attrty = types.intp
    return impl_ret_borrowed(context, builder, attrty, attrval)
github numba / numba / numba / unicode.py View on Github external
def _slice_span(typingctx, sliceobj):
    """Compute the span from the given slice object.
    """
    sig = types.intp(sliceobj)

    def codegen(context, builder, sig, args):
        [slicetype] = sig.args
        [sliceobj] = args
        slice = context.make_helper(builder, slicetype, sliceobj)
        result_size = slicing.get_slice_length(builder, slice)
        return result_size

    return sig, codegen
github IntelPython / sdc / sdc / str_arr_ext.py View on Github external
ll.add_symbol('set_string_array_range', hstr_ext.set_string_array_range)
ll.add_symbol('str_arr_to_int64', hstr_ext.str_arr_to_int64)
ll.add_symbol('str_arr_to_float64', hstr_ext.str_arr_to_float64)
ll.add_symbol('dtor_string_array', hstr_ext.dtor_string_array)
ll.add_symbol('c_glob', hstr_ext.c_glob)
ll.add_symbol('decode_utf8', hstr_ext.decode_utf8)
ll.add_symbol('get_utf8_size', hstr_ext.get_utf8_size)

convert_len_arr_to_offset = types.ExternalFunction("convert_len_arr_to_offset", types.void(types.voidptr, types.intp))


setitem_string_array = types.ExternalFunction("setitem_string_array",
                                              types.void(types.voidptr, types.voidptr, types.intp, string_type,
                                                         types.intp))
_get_utf8_size = types.ExternalFunction("get_utf8_size",
                                        types.intp(types.voidptr, types.intp, types.int32))


def construct_string_array(context, builder):
    """Creates meminfo and sets dtor.
    """
    alloc_type = context.get_data_type(str_arr_payload_type)
    alloc_size = context.get_abi_sizeof(alloc_type)

    llvoidptr = context.get_value_type(types.voidptr)
    llsize = context.get_value_type(types.uintp)
    dtor_ftype = lir.FunctionType(lir.VoidType(),
                                  [llvoidptr, llsize, llvoidptr])
    dtor_fn = builder.module.get_or_insert_function(
        dtor_ftype, name="dtor_string_array")

    meminfo = context.nrt.meminfo_alloc_dtor(
github numba / numba / numba / targets / slicing.py View on Github external
def slice_step_impl(context, builder, typ, value):
    if typ.has_step:
        sli = context.make_helper(builder, typ, value)
        return sli.step
    else:
        return context.get_constant(types.intp, 1)
github IntelPython / sdc / sdc / hiframes / hiframes_typed.py View on Github external
else:
                ind_var = rhs.index_var

            in_arr = rhs.value

            def f(_in_arr, _ind):
                dt = _in_arr[_ind]
                s = np.int64(dt)
                return sdc.hiframes.pd_timestamp_ext.convert_datetime64_to_timestamp(s)

            data = self._get_series_data(in_arr, nodes)
            assert isinstance(self.state.typemap[ind_var.name],
                              (types.Integer, types.IntegerLiteral))
            f_block = compile_to_numba_ir(f, {'numba': numba, 'np': np,
                                              'sdc': sdc}, self.state.typingctx,
                                          (self.state.typemap[data.name], types.intp),
                                          self.state.typemap, self.state.calltypes).blocks.popitem()[1]
            replace_arg_nodes(f_block, [data, ind_var])
            nodes += f_block.body[:-2]
            nodes[-1].target = assign.target
            return nodes

        if isinstance(self.state.typemap[rhs.value.name], SeriesType):
            rhs.value = self._get_series_data(rhs.value, nodes)
            self._convert_series_calltype(rhs)
            lhs = assign.target
            # convert output to Series from Array
            if isinstance(self.state.typemap[lhs.name], SeriesType):
                new_lhs = ir.Var(
                    lhs.scope, mk_unique_var(lhs.name + '_data'), lhs.loc)
                self.state.typemap[new_lhs.name] = series_to_array_type(
                    self.state.typemap[lhs.name])
github numba / numba / numba / listobject.py View on Github external
def _list_length(typingctx, l):
    """Wrap numba_list_length

    Returns the length of the list.
    """
    resty = types.intp
    sig = resty(l)

    def codegen(context, builder, sig, args):
        fnty = ir.FunctionType(
            ll_ssize_t,
            [ll_list_type],
        )
        fn = builder.module.get_or_insert_function(fnty,
                                                   name='numba_list_length')
        [l] = args
        [tl] = sig.args
        lp = _container_get_data(context, builder, tl, l)
        n = builder.call(fn, [lp])
        return n

    return sig, codegen