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


Python cgutils.create_struct_proxy函数代码示例

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


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

示例1: imp

            def imp(context, builder, sig, args):
                if attr in typ.struct:
                    instance_struct = cgutils.create_struct_proxy(typ)
                    [this, val] = args
                    inst = instance_struct(context, builder, value=this)
                    data_ptr = inst.data
                    data_struct = cgutils.create_struct_proxy(typ.get_data_type(),
                                                              kind='data')
                    data = data_struct(context, builder, ref=data_ptr)

                    # Get old value
                    attr_type = typ.struct[attr]
                    oldvalue = getattr(data, attr)

                    # Store n
                    setattr(data, attr, val)
                    context.nrt_incref(builder, attr_type, val)

                    # Delete old value
                    context.nrt_decref(builder, attr_type, oldvalue)
                elif attr in typ.jitprops:
                    setter = typ.jitprops[attr]['set']
                    setter.compile(sig)
                    cres = setter._compileinfos[sig.args]
                    out = context.call_internal(builder, cres.fndesc,
                                                cres.signature, args)
                    return imputils.impl_ret_new_ref(context, builder,
                                                     cres.signature, out)

                else:
                    msg = 'attribute {0!r} not implemented'.format(attr)
                    raise NotImplementedError(msg)
开发者ID:dhavide,项目名称:numba,代码行数:32,代码来源:base.py

示例2: attr_impl

def attr_impl(context, builder, typ, value, attr):
    """
    Generic getattr() for @jitclass instances.
    """
    if attr in typ.struct:
        # It's a struct field
        inst_struct = cgutils.create_struct_proxy(typ)
        inst = inst_struct(context, builder, value=value)
        data_pointer = inst.data
        data_struct = cgutils.create_struct_proxy(typ.get_data_type(),
                                                  kind='data')
        data = data_struct(context, builder, ref=data_pointer)
        return imputils.impl_ret_borrowed(context, builder,
                                          typ.struct[attr],
                                          getattr(data, attr))
    elif attr in typ.jitprops:
        # It's a jitted property
        getter = typ.jitprops[attr]['get']
        sig = templates.signature(None, typ)
        dispatcher = types.Dispatcher(getter)
        sig = dispatcher.get_call_type(context.typing_context, [typ], {})
        call = context.get_function(dispatcher, sig)
        out = call(builder, [value])
        return imputils.impl_ret_new_ref(context, builder, sig.return_type, out)

    raise NotImplementedError('attribute {0!r} not implemented'.format(attr))
开发者ID:MatthieuDartiailh,项目名称:numba,代码行数:26,代码来源:base.py

示例3: codegen

 def codegen(context, builder, sig, args):
     src, start, length = args
     in_str = cgutils.create_struct_proxy(
         types.unicode_type)(context, builder, value=src)
     view_str = cgutils.create_struct_proxy(
         types.unicode_type)(context, builder)
     view_str.meminfo = in_str.meminfo
     view_str.kind = in_str.kind
     view_str.is_ascii = in_str.is_ascii
     view_str.length = length
     # hash value -1 to indicate "need to compute hash"
     view_str.hash = context.get_constant(_Py_hash_t, -1)
     # get a pointer to start of slice data
     bw_typ = context.typing_context.resolve_value_type(_kind_to_byte_width)
     bw_sig = bw_typ.get_call_type(
         context.typing_context, (types.int32,), {})
     bw_impl = context.get_function(bw_typ, bw_sig)
     byte_width = bw_impl(builder, (in_str.kind,))
     offset = builder.mul(start, byte_width)
     view_str.data = builder.gep(in_str.data, [offset])
     # Set parent pyobject to NULL
     view_str.parent = cgutils.get_null_value(view_str.parent.type)
     # incref original string
     if context.enable_nrt:
         context.nrt.incref(builder, sig.args[0], src)
     return view_str._getvalue()
开发者ID:numba,项目名称:numba,代码行数:26,代码来源:unicode.py

示例4: imp_dtor

def imp_dtor(context, module, instance_type):
    llvoidptr = context.get_value_type(types.voidptr)
    llsize = context.get_value_type(types.uintp)
    dtor_ftype = llvmir.FunctionType(llvmir.VoidType(),
                                     [llvoidptr, llsize, llvoidptr])

    fname = "_Dtor.{0}".format(instance_type.name)
    dtor_fn = module.get_or_insert_function(dtor_ftype,
                                            name=fname)
    if dtor_fn.is_declaration:
        # Define
        builder = llvmir.IRBuilder(dtor_fn.append_basic_block())

        alloc_fe_type = instance_type.get_data_type()
        alloc_type = context.get_value_type(alloc_fe_type)

        data_struct = cgutils.create_struct_proxy(alloc_fe_type)

        ptr = builder.bitcast(dtor_fn.args[0], alloc_type.as_pointer())
        data = data_struct(context, builder, ref=ptr)

        context.nrt_decref(builder, alloc_fe_type, data._getvalue())

        builder.ret_void()

    return dtor_fn
开发者ID:dhavide,项目名称:numba,代码行数:26,代码来源:base.py

示例5: make_slice

def make_slice(context, builder, typ, value=None):
    """
    Create a slice structure, optionally initialized from the given LLVM
    *value*.
    """
    cls = cgutils.create_struct_proxy(typ)
    return cls(context, builder, value=value)
开发者ID:kalatestimine,项目名称:numba,代码行数:7,代码来源:slicing.py

示例6: get_helper_class

 def get_helper_class(self, typ, kind='value'):
     """
     Get a helper class for the given *typ*.
     """
     # XXX handle all types: complex, array, etc.
     # XXX should it be a method on the model instead? this would allow a default kind...
     return cgutils.create_struct_proxy(typ, kind)
开发者ID:yuguen,项目名称:numba,代码行数:7,代码来源:base.py

示例7: _unbox_class_instance

def _unbox_class_instance(typ, val, c):
    def access_member(member_offset):
        # Access member by byte offset
        offset = c.context.get_constant(types.uintp, member_offset)
        llvoidptr = ir.IntType(8).as_pointer()
        ptr = cgutils.pointer_add(c.builder, val, offset)
        casted = c.builder.bitcast(ptr, llvoidptr.as_pointer())
        return c.builder.load(casted)

    struct_cls = cgutils.create_struct_proxy(typ)
    inst = struct_cls(c.context, c.builder)

    # load from Python object
    ptr_meminfo = access_member(_box.box_meminfoptr_offset)
    ptr_dataptr = access_member(_box.box_dataptr_offset)

    # store to native structure
    inst.meminfo = c.builder.bitcast(ptr_meminfo, inst.meminfo.type)
    inst.data = c.builder.bitcast(ptr_dataptr, inst.data.type)

    ret = inst._getvalue()

    c.context.nrt.incref(c.builder, typ, ret)

    return NativeValue(ret, is_error=c.pyapi.c_api_error())
开发者ID:FedericoStra,项目名称:numba,代码行数:25,代码来源:boxing.py

示例8: make_payload_cls

def make_payload_cls(list_type):
    """
    Return the Structure representation of the given *list_type*'s payload
    (an instance of types.List).
    """
    # Note the payload is stored durably in memory, so we consider it
    # data and not value.
    return cgutils.create_struct_proxy(types.ListPayload(list_type), kind="data")
开发者ID:maartenscholl,项目名称:numba,代码行数:8,代码来源:listobj.py

示例9: codegen

 def codegen(context, builder, sig, args):
     [td] = sig.args
     [d] = args
     # Incref
     context.nrt.incref(builder, td, d)
     ctor = cgutils.create_struct_proxy(td)
     dstruct = ctor(context, builder, value=d)
     # Returns the plain MemInfo
     return dstruct.meminfo
开发者ID:numba,项目名称:numba,代码行数:9,代码来源:dictobject.py

示例10: array_ctypes

def array_ctypes(context, builder, typ, value):
    arrayty = make_array(typ)
    array = arrayty(context, builder, value)
    # Cast void* data to uintp
    addr = builder.ptrtoint(array.data, context.get_value_type(types.uintp))
    # Create new ArrayCType structure
    ctinfo_type = cgutils.create_struct_proxy(types.ArrayCTypes(typ))
    ctinfo = ctinfo_type(context, builder)
    ctinfo.data = addr
    return ctinfo._getvalue()
开发者ID:meego,项目名称:numba,代码行数:10,代码来源:arrayobj.py

示例11: box_unicode_str

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
开发者ID:esc,项目名称:numba,代码行数:12,代码来源:unicode.py

示例12: make_string_from_constant

def make_string_from_constant(context, builder, typ, literal_string):
    """
    Get string data by `compile_time_get_string_data()` and return a
    unicode_type LLVM value
    """
    databytes, length, kind, hashv = \
        compile_time_get_string_data(literal_string)
    mod = builder.module
    gv = context.insert_const_bytes(mod, databytes)
    uni_str = cgutils.create_struct_proxy(typ)(context, builder)
    uni_str.data = gv
    uni_str.length = uni_str.length.type(length)
    uni_str.kind = uni_str.kind.type(kind)
    uni_str.hash = uni_str.hash.type(hashv)
    return uni_str._getvalue()
开发者ID:esc,项目名称:numba,代码行数:15,代码来源:unicode.py

示例13: unbox_unicode_str

def unbox_unicode_str(typ, obj, c):
    """
    Convert a unicode str object to a native unicode structure.
    """
    ok, data, length, kind, hashv = 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.hash = hashv
    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)
开发者ID:esc,项目名称:numba,代码行数:18,代码来源:unicode.py

示例14: details

    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
        # empty string has hash value -1 to indicate "need to compute hash"
        uni_str.hash = context.get_constant(_Py_hash_t, -1)
        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()
开发者ID:esc,项目名称:numba,代码行数:19,代码来源:unicode.py

示例15: ctor_impl

def ctor_impl(context, builder, sig, args):
    # Allocate the instance
    inst_typ = sig.return_type
    alloc_type = context.get_data_type(inst_typ.get_data_type())
    alloc_size = context.get_abi_sizeof(alloc_type)

    meminfo = context.nrt_meminfo_alloc_dtor(
        builder,
        context.get_constant(types.uintp, alloc_size),
        imp_dtor(context, builder.module, inst_typ),
    )
    data_pointer = context.nrt_meminfo_data(builder, meminfo)
    data_pointer = builder.bitcast(data_pointer,
                                   alloc_type.as_pointer())

    # Nullify all data
    builder.store(cgutils.get_null_value(alloc_type),
                  data_pointer)

    inst_struct_typ = cgutils.create_struct_proxy(inst_typ)
    inst_struct = inst_struct_typ(context, builder)
    inst_struct.meminfo = meminfo
    inst_struct.data = data_pointer

    # Call the __init__
    # TODO: extract the following into a common util
    init_sig = (sig.return_type,) + sig.args

    init = inst_typ.jitmethods['__init__']
    init.compile(init_sig)
    cres = init._compileinfos[init_sig]
    realargs = [inst_struct._getvalue()] + list(args)
    context.call_internal(builder, cres.fndesc, types.void(*init_sig),
                          realargs)

    # Prepare reutrn value
    ret = inst_struct._getvalue()

    # Add function to link
    codegen = context.codegen()
    codegen.add_linking_library(cres.library)

    return imputils.impl_ret_new_ref(context, builder, inst_typ, ret)
开发者ID:dhavide,项目名称:numba,代码行数:43,代码来源:base.py


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