• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python cgutils.create_struct_proxy函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: ctor_impl

def ctor_impl(context, builder, sig, args):
    """
    Generic constructor (__new__) for jitclasses.
    """
    # 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 jitted __init__
    # TODO: extract the following into a common util
    init_sig = (sig.return_type,) + sig.args

    init = inst_typ.jitmethods['__init__']
    disp_type = types.Dispatcher(init)
    call = context.get_function(disp_type, types.void(*init_sig))
    realargs = [inst_struct._getvalue()] + list(args)
    call(builder, realargs)

    # Prepare return value
    ret = inst_struct._getvalue()

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


示例17: _unbox_class_instance

def _unbox_class_instance(typ, val, c):
    struct_cls = cgutils.create_struct_proxy(typ)
    inst = struct_cls(c.context, c.builder)

    int_meminfo = c.pyapi.object_getattr_string(val, "_meminfoptr")
    int_dataptr = c.pyapi.object_getattr_string(val, "_dataptr")

    ptr_meminfo = c.pyapi.long_as_voidptr(int_meminfo)
    ptr_dataptr = c.pyapi.long_as_voidptr(int_dataptr)

    c.pyapi.decref(int_meminfo)
    c.pyapi.decref(int_dataptr)

    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:EGQM,项目名称:numba,代码行数:21,代码来源:boxing.py


示例18: make_range_impl

def make_range_impl(range_state_type, range_iter_type, int_type):
    RangeState = cgutils.create_struct_proxy(range_state_type)

    @builtin
    @implement(types.range_type, int_type)
    def range1_impl(context, builder, sig, args):
        """
        range(stop: int) -> range object
        """
        [stop] = args
        state = RangeState(context, builder)
        state.start = context.get_constant(int_type, 0)
        state.stop = stop
        state.step = context.get_constant(int_type, 1)
        return state._getvalue()

    @builtin
    @implement(types.range_type, int_type, int_type)
    def range2_impl(context, builder, sig, args):
        """
        range(start: int, stop: int) -> range object
        """
        start, stop = args
        state = RangeState(context, builder)
        state.start = start
        state.stop = stop
        state.step = context.get_constant(int_type, 1)
        return state._getvalue()

    @builtin
    @implement(types.range_type, int_type, int_type, int_type)
    def range3_impl(context, builder, sig, args):
        """
        range(start: int, stop: int, step: int) -> range object
        """
        [start, stop, step] = args
        state = RangeState(context, builder)
        state.start = start
        state.stop = stop
        state.step = step
        return state._getvalue()

    @builtin
    @implement('getiter', range_state_type)
    def getiter_range32_impl(context, builder, sig, args):
        """
        range.__iter__
        """
        (value,) = args
        state = RangeState(context, builder, value)
        return RangeIter.from_range_state(context, builder, state)._getvalue()

    @iterator_impl(range_state_type, range_iter_type)
    class RangeIter(make_range_iterator(range_iter_type)):

        @classmethod
        def from_range_state(cls, context, builder, state):
            """
            Create a RangeIter initialized from the given RangeState *state*.
            """
            self = cls(context, builder)
            start = state.start
            stop = state.stop
            step = state.step

            startptr = cgutils.alloca_once(builder, start.type)
            builder.store(start, startptr)

            countptr = cgutils.alloca_once(builder, start.type)

            self.iter = startptr
            self.stop = stop
            self.step = step
            self.count = countptr

            diff = builder.sub(stop, start)
            zero = context.get_constant(int_type, 0)
            one = context.get_constant(int_type, 1)
            pos_diff = builder.icmp(lc.ICMP_SGT, diff, zero)
            pos_step = builder.icmp(lc.ICMP_SGT, step, zero)
            sign_differs = builder.xor(pos_diff, pos_step)
            zero_step = builder.icmp(lc.ICMP_EQ, step, zero)

            with cgutils.if_unlikely(builder, zero_step):
                # step shouldn't be zero
                context.call_conv.return_user_exc(builder, ValueError,
                                                  ("range() arg 3 must not be zero",))

            with builder.if_else(sign_differs) as (then, orelse):
                with then:
                    builder.store(zero, self.count)

                with orelse:
                    rem = builder.srem(diff, step)
                    rem = builder.select(pos_diff, rem, builder.neg(rem))
                    uneven = builder.icmp(lc.ICMP_SGT, rem, zero)
                    newcount = builder.add(builder.sdiv(diff, step),
                                           builder.select(uneven, one, zero))
                    builder.store(newcount, self.count)

#.........这里部分代码省略.........
开发者ID:hargup,项目名称:numba,代码行数:101,代码来源:rangeobj.py


示例19: make_range_iterator

def make_range_iterator(typ):
    """
    Return the Structure representation of the given *typ* (an
    instance of types.RangeIteratorType).
    """
    return cgutils.create_struct_proxy(typ)
开发者ID:hargup,项目名称:numba,代码行数:6,代码来源:rangeobj.py


示例20: make_listiter_cls

def make_listiter_cls(iterator_type):
    """
    Return the Structure representation of the given *iterator_type* (an
    instance of types.ListIter).
    """
    return cgutils.create_struct_proxy(iterator_type)
开发者ID:dhavide,项目名称:numba,代码行数:6,代码来源:listobj.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python cgutils.for_range函数代码示例发布时间:2022-05-27
下一篇:
Python cgutils.alloca_once_value函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap