Ejemplo n.º 1
0
def namedtuple_getattr(context, builder, typ, value, attr):
    """
    Fetch a namedtuple's field.
    """
    index = typ.fields.index(attr)
    res = builder.extract_value(value, index)
    return impl_ret_borrowed(context, builder, typ[index], res)
Ejemplo n.º 2
0
def impl_MultiVector(context, builder, sig, args):
    typ = sig.return_type
    layout, value = args
    mv = cgutils.create_struct_proxy(typ)(context, builder)
    mv.layout = layout
    mv.value = value
    return impl_ret_borrowed(context, builder, sig.return_type, mv._getvalue())
Ejemplo n.º 3
0
def var_getattr_impl(context, builder, typ, val, attr):
    #If the attribute is one of the var struct fields then retrieve it.
    if(attr in var_fields_dict):
        # print("GETATTR", attr)
        utils = _Utils(context, builder, typ)
        dataval = utils.get_data_struct(val)
        ret = getattr(dataval, attr)
        fieldtype = typ.field_dict[attr]
        return imputils.impl_ret_borrowed(context, builder, fieldtype, ret)

    #Otherwise return a new instance with a new 'attr' and 'offset' append 
    else:
        fact_type = typ.field_dict['fact_type'].instance_type 
        fd = fact_type.field_dict
        offset = fact_type._attr_offsets[list(fd.keys()).index(attr)]
        ctor = cgutils.create_struct_proxy(typ)
        st = ctor(context, builder, value=val)._getvalue()

        def new_var_and_append(self):
            st = new(typ)
            copy_and_append(self,st,attr,offset)
            return st

        ret = context.compile_internal(builder, new_var_and_append, typ(typ,), (st,))
        context.nrt.incref(builder, typ, ret)
        return ret
Ejemplo n.º 4
0
        def codegen(context, builder, sig, args):
            str_val, = args

            ty_ret_type_pointer = lir.PointerType(
                context.get_data_type(ret_type))
            casted_ptr = builder.bitcast(str_val, ty_ret_type_pointer)

            return impl_ret_borrowed(context, builder, ret_type,
                                     builder.load(casted_ptr))
Ejemplo n.º 5
0
def impl_COO(context, builder, sig, args):
    typ = sig.return_type
    coords, data, shape = args
    coo = cgutils.create_struct_proxy(typ)(context, builder)
    coo.coords = coords
    coo.data = data
    coo.shape = shape
    coo.fill_value = context.get_constant_generic(
        builder, typ.fill_value_type, _zero_of_dtype(typ.data_dtype))
    return impl_ret_borrowed(context, builder, sig.return_type,
                             coo._getvalue())
Ejemplo n.º 6
0
    def codegen(context, builder, signature, args):
        def check(array):
            if not array.flags.c_contiguous:
                raise ValueError("Attempted to force type contiguity "
                                 "on an array whose layout is "
                                 "non-contiguous")

        check_sig = typing.signature(types.none, signature.args[0])
        context.compile_internal(builder, check, check_sig, args)

        return impl_ret_borrowed(context, builder, return_type, args[0])
Ejemplo n.º 7
0
def impl_conc_dict_getiter(context, builder, sig, args):
    index_type, = sig.args
    index_val, = args

    it = context.make_helper(builder, index_type.iterator_type)
    it.parent = index_val
    zero = context.get_constant(types.intp, 0)
    it.state = cgutils.alloca_once_value(builder, zero)

    res = it._getvalue()
    return impl_ret_borrowed(context, builder, index_type.iterator_type, res)
Ejemplo n.º 8
0
def lower_constant_COO(context, builder, typ, pyval):
    coords = context.get_constant_generic(builder, typ.coords_type,
                                          pyval.coords)
    data = context.get_constant_generic(builder, typ.data_type, pyval.data)
    shape = context.get_constant_generic(builder, typ.shape_type, pyval.shape)
    fill_value = context.get_constant_generic(builder, typ.fill_value_type,
                                              pyval.fill_value)
    return impl_ret_borrowed(
        context,
        builder,
        typ,
        cgutils.pack_struct(builder, (data, coords, shape, fill_value)),
    )
Ejemplo n.º 9
0
    def codegen(context, builder, sig, args):
        [tmi, tdref] = sig.args
        td = tdref.instance_type
        [mi, _] = args

        ctor = cgutils.create_struct_proxy(td)
        dstruct = ctor(context, builder)

        data_pointer = context.nrt.meminfo_data(builder, mi)
        data_pointer = builder.bitcast(data_pointer, ll_list_type.as_pointer())

        dstruct.data = builder.load(data_pointer)
        dstruct.meminfo = mi

        return impl_ret_borrowed(context, builder, listtype, dstruct._getvalue(),)
Ejemplo n.º 10
0
def static_getitem_tuple(context, builder, sig, args):
    tupty, _ = sig.args
    tup, idx = args
    if isinstance(idx, int):
        if idx < 0:
            idx += len(tupty)
        if not 0 <= idx < len(tupty):
            raise IndexError("cannot index at %d in %s" % (idx, tupty))
        res = builder.extract_value(tup, idx)
    elif isinstance(idx, slice):
        items = cgutils.unpack_tuple(builder, tup)[idx]
        res = context.make_tuple(builder, sig.return_type, items)
    else:
        raise NotImplementedError("unexpected index %r for %s" %
                                  (idx, sig.args[0]))
    return impl_ret_borrowed(context, builder, sig.return_type, res)
Ejemplo n.º 11
0
def multi_index_typeref_call_impl(context, builder, sig, args):

    # FIXME_Numba#7111: this uses low-level API as a workaround for numba issue
    # TO-DO: remove and use @overload(MultiIndexTypeRef), once issue is fixed
    # and now we do the following:
    # (1) lookup function type for the actual ctor (sdc_pandas_multi_index_ctor)
    # (2) get compiled implementation for provided args (hardcodes 0 as selected overload template,
    #     i.e. we rely on the fact that sdc_pandas_multi_index_ctor was overloaded only once)
    # (3) get the function descriptor from compiled result and emit the call to it
    call_sig = context.typing_context._resolve_user_function_type(
        sdc_pandas_multi_index_ctor, sig.args, {})
    fnty = context.typing_context._lookup_global(sdc_pandas_multi_index_ctor)
    disp = fnty.templates[0](context.typing_context)._get_impl(
        call_sig.args, {})
    cres = disp[0].get_compile_result(call_sig)

    res = context.call_internal(builder, cres.fndesc, sig, args)

    return impl_ret_borrowed(context, builder, sig.return_type, res)
Ejemplo n.º 12
0
def impl_list_getiter(context, builder, sig, args):
    """Implement iter(List)."""
    [tl] = sig.args
    [l] = args
    iterablety = types.ListTypeIterableType(tl)
    it = context.make_helper(builder, iterablety.iterator_type)

    fnty = ir.FunctionType(ir.VoidType(), [ll_listiter_type, ll_list_type],)

    fn = builder.module.get_or_insert_function(fnty, name="numba_list_iter")

    proto = ctypes.CFUNCTYPE(ctypes.c_size_t)
    listiter_sizeof = proto(_helperlib.c_helpers["list_iter_sizeof"])
    state_type = ir.ArrayType(ir.IntType(8), listiter_sizeof())

    pstate = cgutils.alloca_once(builder, state_type, zfill=True)
    it.state = _as_bytes(builder, pstate)
    it.parent = l

    dp = _container_get_data(context, builder, iterablety.parent, args[0])
    builder.call(fn, [it.state, dp])
    return impl_ret_borrowed(context, builder, sig.return_type, it._getvalue(),)