How to use the numba.cgutils.create_struct_proxy 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 diana-hep / oamap / oamap / compiler.py View on Github external
def unionproxytype_is_left(context, builder, sig, args):
        ltype, rtype = sig.args
        lval, rval = args
        for datatag, datatype in ltype.generator.possibilities:
            if datatype.generator.id == rtype.generator.id:
                lproxy = numba.cgutils.create_struct_proxy(ltype)(context, builder, value=lval)
                lbaggage = numba.cgutils.create_struct_proxy(baggagetype)(context, builder, value=lproxy.baggage)
                rproxy = numba.cgutils.create_struct_proxy(rtype)(context, builder, value=rval)
                rbaggage = numba.cgutils.create_struct_proxy(baggagetype)(context, builder, value=rproxy.baggage)
                if isinstance(rtype, ListProxyNumbaType):
                    rindex = rproxy.whence
                elif isinstance(rtype, RecordProxyNumbaType):
                    rindex = rproxy.index
                elif isinstance(rtype, TupleProxyNumbaType):
                    rindex = rproxy.index
                return all_(builder, [
                    builder.icmp_signed("==", lbaggage.arrays, rbaggage.arrays),
                    builder.icmp_signed("==", lproxy.tag, literal_int64(datatag)),
                    builder.icmp_signed("==", lproxy.offset, rindex)
                    ])
        return literal_boolean(False)
github diana-hep / oamap / oamap / compiler.py View on Github external
def partitionedlist_partition(context, builder, sig, args):
        partitionedlisttype, indextype = sig.args
        partitionedlistval, indexval = args
        partitionedlist = numba.cgutils.create_struct_proxy(partitionedlisttype)(context, builder, value=partitionedlistval)

        raise_exception(context,
                        builder,
                        builder.or_(builder.icmp_signed("<", indexval, literal_int64(0)),
                                    builder.icmp_signed(">=", indexval, partitionedlist.numpartitions)),
                        TypeError("partition index out of range for PartitionedListProxy"))

        with builder.if_then(builder.icmp_signed("!=", builder.load(partitionedlist.current), indexval), likely=False):
            pyapi = context.get_python_api(builder)
            generator_obj = partitionedlist.generator

            with builder.if_then(builder.icmp_signed("!=", builder.load(partitionedlist.current), literal_int64(-1)), likely=True):
                listproxy = numba.cgutils.create_struct_proxy(ListProxyNumbaType(partitionedlisttype.generator))(context, builder, value=builder.load(partitionedlist.listproxy))
                baggage = numba.cgutils.create_struct_proxy(baggagetype)(context, builder, value=listproxy.baggage)

                pyapi.decref(baggage.ptrs)
github scikit-hep / awkward-array / awkward-numba / awkward / numba / array / jagged.py View on Github external
def _JaggedArray_lower_len(context, builder, sig, args):
    arraytype, = sig.args
    arrayval, = args

    array = numba.cgutils.create_struct_proxy(arraytype)(context, builder, value=arrayval)

    return numba.targets.arrayobj.array_len(context, builder, numba.types.intp(arraytype.startstype), (array.starts,))
github IntelPython / sdc / hpat / hiframes / pd_dataframe_ext.py View on Github external
def codegen(context, builder, signature, args):
        in_tup = args[0]
        data_arrs = [builder.extract_value(in_tup, i) for i in range(n_cols)]
        index = builder.extract_value(in_tup, n_cols)
        column_strs = [numba.unicode.make_string_from_constant(
            context, builder, string_type, c) for c in column_names]
        # create dataframe struct and store values
        dataframe = cgutils.create_struct_proxy(
            signature.return_type)(context, builder)

        data_tup = context.make_tuple(
            builder, types.Tuple(data_typs), data_arrs)
        column_tup = context.make_tuple(
            builder, types.UniTuple(string_type, n_cols), column_strs)
        zero = context.get_constant(types.int8, 0)
        unboxed_tup = context.make_tuple(
            builder, types.UniTuple(types.int8, n_cols + 1), [zero] * (n_cols + 1))

        dataframe.data = data_tup
        dataframe.index = index
        dataframe.columns = column_tup
        dataframe.unboxed = unboxed_tup
        dataframe.parent = context.get_constant_null(types.pyobject)
github numba / numba / numba / unicode.py View on Github external
def unbox_unicode_str(typ, obj, c):
    """
    Convert a unicode str object to a native unicode structure.
    """
    ok, data, length, kind = c.pyapi.string_as_string_size_and_kind(obj)
    uni_str = cgutils.create_struct_proxy(typ)(c.context, c.builder)
    uni_str.data = data
    uni_str.length = length
    uni_str.kind = kind
    uni_str.meminfo = c.pyapi.nrt_meminfo_new_from_pyobject(
        data,  # the borrowed data pointer
        obj,   # the owner pyobject; the call will incref it.
    )
    uni_str.parent = obj

    is_error = cgutils.is_not_null(c.builder, c.pyapi.err_occurred())
    return NativeValue(uni_str._getvalue(), is_error=is_error)
github numba / numba / numba / unicode.py View on Github external
def box_unicode_str(typ, val, c):
    """
    Convert a native unicode structure to a unicode string
    """
    uni_str = cgutils.create_struct_proxy(typ)(c.context, c.builder, value=val)
    res = c.pyapi.string_from_kind_and_data(
        uni_str.kind, uni_str.data, uni_str.length)
    # hash isn't needed now, just compute it so it ends up in the unicodeobject
    # hash cache, cpython doesn't always do this, depends how a string was
    # created it's safe, just burns the cycles required to hash on @box
    c.pyapi.object_hash(res)
    c.context.nrt.decref(c.builder, typ, val)
    return res
github numba / numba / numba / unicode.py View on Github external
def details(context, builder, signature, args):
        [kind_val, char_bytes_val, length_val] = args

        # fill the struct
        uni_str_ctor = cgutils.create_struct_proxy(types.unicode_type)
        uni_str = uni_str_ctor(context, builder)
        # add null padding character
        nbytes_val = builder.mul(char_bytes_val,
                                 builder.add(length_val,
                                             Constant(length_val.type, 1)))
        uni_str.meminfo = context.nrt.meminfo_alloc(builder, nbytes_val)
        uni_str.kind = kind_val
        uni_str.length = length_val
        uni_str.data = context.nrt.meminfo_data(builder, uni_str.meminfo)
        # Set parent to NULL
        uni_str.parent = cgutils.get_null_value(uni_str.parent.type)
        return uni_str._getvalue()
github numba / numba / numba / targets / arrayobj.py View on Github external
"""

        def compute_pointer(self, context, builder, indices, arrty, arr):
            return arr.data


    class ScalarSubIter(BaseSubIter):
        """
        Sub-iterator "walking" a scalar value.
        """

        def compute_pointer(self, context, builder, indices, arrty, arr):
            return arr


    class NdIter(cgutils.create_struct_proxy(nditerty)):
        """
        .nditer() implementation.

        Note: 'F' layout means the shape is iterated in reverse logical order,
        so indices and shapes arrays have to be reversed as well.
        """

        @utils.cached_property
        def subiters(self):
            l = []
            factories = {'flat': FlatSubIter if nditerty.need_shaped_indexing
                                 else TrivialFlatSubIter,
                         'indexed': IndexedSubIter,
                         '0d': ZeroDimSubIter,
                         'scalar': ScalarSubIter,
                         }
github numba / numba / numba / typed / typeddict.py View on Github external
def box_dicttype(typ, val, c):
    context = c.context
    builder = c.builder

    # XXX deduplicate
    ctor = cgutils.create_struct_proxy(typ)
    dstruct = ctor(context, builder, value=val)
    # Returns the plain MemInfo
    boxed_meminfo = c.box(
        types.MemInfoPointer(types.voidptr),
        dstruct.meminfo,
    )

    modname = c.context.insert_const_string(
        c.builder.module, 'numba.typed.typeddict',
    )
    typeddict_mod = c.pyapi.import_module_noblock(modname)
    fmp_fn = c.pyapi.object_getattr_string(typeddict_mod, '_from_meminfo_ptr')

    dicttype_obj = c.pyapi.unserialize(c.pyapi.serialize_object(typ))

    res = c.pyapi.call_function_objargs(fmp_fn, (boxed_meminfo, dicttype_obj))