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

Python cgutils.is_not_null函数代码示例

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

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



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

示例1: codegen

    def codegen(context, builder, signature, args):
        instance, = args

        # TODO: probably a more general way to do this
        second_element = builder.extract_value(instance, [1])
        result = cgutils.is_not_null(builder, second_element)
        return result
开发者ID:cpcloud,项目名称:cysqlite3,代码行数:7,代码来源:casting.py


示例2: raise_error

    def raise_error(self, builder, api, status):
        """
        Given a non-ok *status*, raise the corresponding Python exception.
        """
        bbend = builder.function.append_basic_block()

        with builder.if_then(status.is_user_exc):
            # Unserialize user exception.
            # Make sure another error may not interfere.
            api.err_clear()
            exc = api.unserialize(status.excinfoptr)
            with cgutils.if_likely(builder,
                                   cgutils.is_not_null(builder, exc)):
                api.raise_object(exc)  # steals ref
            builder.branch(bbend)

        with builder.if_then(status.is_stop_iteration):
            api.err_set_none("PyExc_StopIteration")
            builder.branch(bbend)

        with builder.if_then(status.is_python_exc):
            # Error already raised => nothing to do
            builder.branch(bbend)

        api.err_set_string("PyExc_SystemError",
                           "unknown error when calling native function")
        builder.branch(bbend)

        builder.position_at_end(bbend)
开发者ID:EGQM,项目名称:numba,代码行数:29,代码来源:callconv.py


示例3: print_item_impl

def print_item_impl(context, builder, sig, args):
    """
    Print a single native value by boxing it in a Python object and
    invoking the Python interpreter's print routine.
    """
    ty, = sig.args
    val, = args

    pyapi = context.get_python_api(builder)

    if context.enable_nrt:
        context.nrt.incref(builder, ty, val)
    # XXX unfortunately, we don't have access to the env manager from here
    obj = pyapi.from_native_value(ty, val)
    with builder.if_else(cgutils.is_not_null(builder, obj), likely=True) as (if_ok, if_error):
        with if_ok:
            pyapi.print_object(obj)
            pyapi.decref(obj)
        with if_error:
            cstr = context.insert_const_string(builder.module,
                                               "the print() function")
            strobj = pyapi.string_from_string(cstr)
            pyapi.err_write_unraisable(strobj)
            pyapi.decref(strobj)

    res = context.get_dummy_value()
    return impl_ret_untracked(context, builder, sig.return_type, res)
开发者ID:FedericoStra,项目名称:numba,代码行数:27,代码来源:printimpl.py


示例4: set_iter_valid

    def set_iter_valid(self, state, item):
        iterstate = PyIterState(self.context, self.builder, ref=state)
        iterstate.valid = cgutils.as_bool_byte(self.builder,
                                               cgutils.is_not_null(self.builder,
                                                                   item))

        with cgutils.if_unlikely(self.builder, self.is_null(item)):
            self.check_occurred()
开发者ID:B-Rich,项目名称:numba,代码行数:8,代码来源:lowering.py


示例5: list_pack

 def list_pack(self, items):
     n = len(items)
     seq = self.list_new(self.context.get_constant(types.intp, n))
     not_null = cgutils.is_not_null(self.builder, seq)
     with cgutils.if_likely(self.builder, not_null):
         for i in range(n):
             idx = self.context.get_constant(types.intp, i)
             self.incref(items[i])
             self.list_setitem(seq, idx, items[i])
     return seq
开发者ID:johandroid,项目名称:numba,代码行数:10,代码来源:pythonapi.py


示例6: check_lapack_return

def check_lapack_return(context, builder, res):
    """
    Check the integer error return from one of the LAPACK wrappers in
    _helperlib.c.
    """
    with builder.if_then(cgutils.is_not_null(builder, res), likely=False):
        # Those errors shouldn't happen, it's easier to just abort the process
        pyapi = context.get_python_api(builder)
        pyapi.gil_ensure()
        pyapi.fatal_error("LAPACK wrapper returned with an error")
开发者ID:Alexhuszagh,项目名称:numba,代码行数:10,代码来源:linalg.py


示例7: to_native_array

 def to_native_array(self, ary, typ):
     # TODO check matching dtype.
     #      currently, mismatching dtype will still work and causes
     #      potential memory corruption
     nativearycls = self.context.make_array(typ)
     nativeary = nativearycls(self.context, self.builder)
     aryptr = nativeary._getpointer()
     ptr = self.builder.bitcast(aryptr, self.voidptr)
     errcode = self.numba_array_adaptor(ary, ptr)
     failed = cgutils.is_not_null(self.builder, errcode)
     return self.builder.load(aryptr), failed
开发者ID:molodiuc,项目名称:numba,代码行数:11,代码来源:pythonapi.py


示例8: dict_pack

 def dict_pack(self, keyvalues):
     """
     Args
     -----
     keyvalues: iterable of (str, llvm.Value of PyObject*)
     """
     dictobj = self.dict_new()
     not_null = cgutils.is_not_null(self.builder, dictobj)
     with cgutils.if_likely(self.builder, not_null):
         for k, v in keyvalues:
             self.dict_setitem_string(dictobj, k, v)
     return dictobj
开发者ID:johandroid,项目名称:numba,代码行数:12,代码来源:pythonapi.py


示例9: store

 def store(retval):
     is_ok = cgutils.is_not_null(builder, retval)
     # If an error is raised by the object mode ufunc, it will
     # simply get caught by the Numpy ufunc machinery.
     with builder.if_then(is_ok, likely=True):
         # Unbox
         native = pyapi.to_native_value(signature.return_type, retval)
         assert native.cleanup is None
         # Store
         out.store_direct(native.value, builder.load(store_offset))
         # Release owned reference
         pyapi.decref(retval)
开发者ID:MatthieuDartiailh,项目名称:numba,代码行数:12,代码来源:wrappers.py


示例10: is_leap_year

def is_leap_year(builder, year_val):
    """
    Return a predicate indicating whether *year_val* (offset by 1970) is a
    leap year.
    """
    actual_year = builder.add(year_val, Constant.int(DATETIME64, 1970))
    multiple_of_4 = cgutils.is_null(
        builder, builder.and_(actual_year, Constant.int(DATETIME64, 3)))
    not_multiple_of_100 = cgutils.is_not_null(
        builder, builder.srem(actual_year, Constant.int(DATETIME64, 100)))
    multiple_of_400 = cgutils.is_null(
        builder, builder.srem(actual_year, Constant.int(DATETIME64, 400)))
    return builder.and_(multiple_of_4,
                        builder.or_(not_multiple_of_100, multiple_of_400))
开发者ID:genba,项目名称:numba,代码行数:14,代码来源:npdatetime.py


示例11: to_native_array

 def to_native_array(self, typ, ary):
     # TODO check matching dtype.
     #      currently, mismatching dtype will still work and causes
     #      potential memory corruption
     voidptr = Type.pointer(Type.int(8))
     nativearycls = self.context.make_array(typ)
     nativeary = nativearycls(self.context, self.builder)
     aryptr = nativeary._getpointer()
     ptr = self.builder.bitcast(aryptr, voidptr)
     errcode = self.numba_array_adaptor(ary, ptr)
     failed = cgutils.is_not_null(self.builder, errcode)
     with cgutils.if_unlikely(self.builder, failed):
         # TODO
         self.builder.unreachable()
     return self.builder.load(aryptr)
开发者ID:johandroid,项目名称:numba,代码行数:15,代码来源:pythonapi.py


示例12: make_exception_switch

    def make_exception_switch(self, api, builder, status):
        """
        Handle user exceptions.  Unserialize the exception info and raise it.
        """
        code = status.code
        # Handle user exceptions
        with builder.if_then(status.is_user_exc):
            exc = api.unserialize(status.excinfoptr)
            with cgutils.if_likely(builder, cgutils.is_not_null(builder, exc)):
                api.raise_object(exc)  # steals ref
            builder.ret(api.get_null_object())

        with builder.if_then(status.is_stop_iteration):
            api.err_set_none("PyExc_StopIteration")
            builder.ret(api.get_null_object())

        msg = "unknown error in native function: %s" % self.fndesc.mangled_name
        api.err_set_string("PyExc_SystemError", msg)
开发者ID:shivamvats,项目名称:numba,代码行数:18,代码来源:callwrapper.py


示例13: to_native_buffer

    def to_native_buffer(self, obj, typ):
        buf = self.alloca_buffer()
        res = self.get_buffer(obj, buf)
        is_error = cgutils.is_not_null(self.builder, res)

        nativearycls = self.context.make_array(typ)
        nativeary = nativearycls(self.context, self.builder)
        aryptr = nativeary._getpointer()

        with cgutils.if_likely(self.builder, self.builder.not_(is_error)):
            ptr = self.builder.bitcast(aryptr, self.voidptr)
            self.numba_buffer_adaptor(buf, ptr)

        def cleanup():
            self.release_buffer(buf)

        return NativeValue(self.builder.load(aryptr), is_error=is_error,
                           cleanup=cleanup)
开发者ID:molodiuc,项目名称:numba,代码行数:18,代码来源:pythonapi.py


示例14: 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


示例15: _emit_python_wrapper

    def _emit_python_wrapper(self, llvm_module):
        # Figure out the Python C API module creation function, and
        # get a LLVM function for it.
        create_module_fn = llvm_module.add_function(*self.module_create_definition)
        create_module_fn.linkage = lc.LINKAGE_EXTERNAL

        # Define a constant string for the module name.
        mod_name_const = self.context.insert_const_string(llvm_module,
                                                          self.module_name)

        mod_def_base_init = lc.Constant.struct(
            (lt._pyobject_head_init,                        # PyObject_HEAD
             lc.Constant.null(self.m_init_ty),              # m_init
             lc.Constant.null(lt._llvm_py_ssize_t),         # m_index
             lc.Constant.null(lt._pyobject_head_p),         # m_copy
            )
        )
        mod_def_base = llvm_module.add_global_variable(mod_def_base_init.type,
                                                       '.module_def_base')
        mod_def_base.initializer = mod_def_base_init
        mod_def_base.linkage = lc.LINKAGE_INTERNAL

        method_array = self._emit_method_array(llvm_module)

        mod_def_init = lc.Constant.struct(
            (mod_def_base_init,                              # m_base
             mod_name_const,                                 # m_name
             lc.Constant.null(self._char_star),              # m_doc
             lc.Constant.int(lt._llvm_py_ssize_t, -1),       # m_size
             method_array,                                   # m_methods
             lc.Constant.null(self.inquiry_ty),              # m_reload
             lc.Constant.null(self.traverseproc_ty),         # m_traverse
             lc.Constant.null(self.inquiry_ty),              # m_clear
             lc.Constant.null(self.freefunc_ty)              # m_free
            )
        )

        # Define a constant string for the module name.
        mod_def = llvm_module.add_global_variable(mod_def_init.type,
                                                  '.module_def')
        mod_def.initializer = mod_def_init
        mod_def.linkage = lc.LINKAGE_INTERNAL

        # Define the module initialization function.
        mod_init_fn = llvm_module.add_function(*self.module_init_definition)
        entry = mod_init_fn.append_basic_block('Entry')
        builder = lc.Builder(entry)
        pyapi = self.context.get_python_api(builder)

        mod = builder.call(create_module_fn,
                           (mod_def,
                            lc.Constant.int(lt._int32, sys.api_version)))

        # Test if module has been created correctly.
        # (XXX for some reason comparing with the NULL constant fails llvm
        #  with an assertion in pydebug mode)
        with builder.if_then(cgutils.is_null(builder, mod)):
            builder.ret(NULL.bitcast(mod_init_fn.type.pointee.return_type))

        env_array = self._emit_environment_array(llvm_module, builder, pyapi)
        ret = self._emit_module_init_code(llvm_module, builder, mod,
                                          method_array, env_array)
        if ret is not None:
            with builder.if_then(cgutils.is_not_null(builder, ret)):
                # Init function errored out
                builder.ret(lc.Constant.null(mod.type))

        builder.ret(mod)

        self.dll_exports.append(mod_init_fn.name)
开发者ID:yuguen,项目名称:numba,代码行数:70,代码来源:compiler.py


示例16: to_native_value

    def to_native_value(self, obj, typ):
        builder = self.builder
        def c_api_error():
            return cgutils.is_not_null(builder, self.err_occurred())

        if isinstance(typ, types.Object) or typ == types.pyobject:
            return NativeValue(obj)

        elif typ == types.boolean:
            istrue = self.object_istrue(obj)
            zero = Constant.null(istrue.type)
            val = builder.icmp(lc.ICMP_NE, istrue, zero)
            return NativeValue(val, is_error=c_api_error())

        elif isinstance(typ, types.Integer):
            val = self.to_native_int(obj, typ)
            return NativeValue(val, is_error=c_api_error())

        elif typ == types.float32:
            fobj = self.number_float(obj)
            fval = self.float_as_double(fobj)
            self.decref(fobj)
            val = builder.fptrunc(fval,
                                  self.context.get_argument_type(typ))
            return NativeValue(val, is_error=c_api_error())

        elif typ == types.float64:
            fobj = self.number_float(obj)
            val = self.float_as_double(fobj)
            self.decref(fobj)
            return NativeValue(val, is_error=c_api_error())

        elif typ in (types.complex128, types.complex64):
            cplxcls = self.context.make_complex(types.complex128)
            cplx = cplxcls(self.context, builder)
            pcplx = cplx._getpointer()
            ok = self.complex_adaptor(obj, pcplx)
            failed = cgutils.is_false(builder, ok)

            with cgutils.if_unlikely(builder, failed):
                self.err_set_string("PyExc_TypeError",
                                    "conversion to %s failed" % (typ,))

            if typ == types.complex64:
                c64cls = self.context.make_complex(typ)
                c64 = c64cls(self.context, builder)
                freal = self.context.cast(builder, cplx.real,
                                          types.float64, types.float32)
                fimag = self.context.cast(builder, cplx.imag,
                                          types.float64, types.float32)
                c64.real = freal
                c64.imag = fimag
                return NativeValue(c64._getvalue(), is_error=failed)
            else:
                return NativeValue(cplx._getvalue(), is_error=failed)

        elif isinstance(typ, types.NPDatetime):
            val = self.extract_np_datetime(obj)
            return NativeValue(val, is_error=c_api_error())

        elif isinstance(typ, types.NPTimedelta):
            val = self.extract_np_timedelta(obj)
            return NativeValue(val, is_error=c_api_error())

        elif isinstance(typ, types.Record):
            buf = self.alloca_buffer()
            ptr = self.extract_record_data(obj, buf)
            is_error = cgutils.is_null(self.builder, ptr)

            ltyp = self.context.get_value_type(typ)
            val = builder.bitcast(ptr, ltyp)

            def cleanup():
                self.release_buffer(buf)
            return NativeValue(val, cleanup=cleanup, is_error=is_error)

        elif isinstance(typ, types.Array):
            val, failed = self.to_native_array(obj, typ)
            return NativeValue(val, is_error=failed)

        elif isinstance(typ, types.Buffer):
            return self.to_native_buffer(obj, typ)

        elif isinstance(typ, types.Optional):
            return self.to_native_optional(obj, typ)

        elif isinstance(typ, (types.Tuple, types.UniTuple)):
            return self.to_native_tuple(obj, typ)

        elif isinstance(typ, types.Generator):
            return self.to_native_generator(obj, typ)

        elif isinstance(typ, types.ExternalFunctionPointer):
            if typ.get_pointer is not None:
                # Call get_pointer() on the object to get the raw pointer value
                ptrty = self.context.get_function_pointer_type(typ)
                ret = cgutils.alloca_once_value(builder,
                                                Constant.null(ptrty),
                                                name='fnptr')
                ser = self.serialize_object(typ.get_pointer)
#.........这里部分代码省略.........
开发者ID:molodiuc,项目名称:numba,代码行数:101,代码来源:pythonapi.py


示例17: if_object_ok

 def if_object_ok(self, obj):
     with cgutils.if_likely(self.builder,
                            cgutils.is_not_null(self.builder, obj)):
         yield
开发者ID:ibtawfik,项目名称:numba,代码行数:4,代码来源:pythonapi.py


示例18: c_api_error

 def c_api_error(self):
     return cgutils.is_not_null(self.builder, self.err_occurred())
开发者ID:ibtawfik,项目名称:numba,代码行数:2,代码来源:pythonapi.py


示例19: check_blas_return

def check_blas_return(context, builder, res):
    with builder.if_then(cgutils.is_not_null(builder, res), likely=False):
        # Those errors shouldn't happen, it's easier to just abort the process
        pyapi = context.get_python_api(builder)
        pyapi.gil_ensure()
        pyapi.fatal_error("BLAS wrapper returned with an error")
开发者ID:maartenscholl,项目名称:numba,代码行数:6,代码来源:arraymath.py


示例20: check_occurred

    def check_occurred(self):
        err_occurred = cgutils.is_not_null(self.builder,
                                           self.pyapi.err_occurred())

        with cgutils.if_unlikely(self.builder, err_occurred):
            self.return_exception_raised()
开发者ID:ymarfoq,项目名称:outilACVDesagregation,代码行数:6,代码来源:objmode.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python cgutils.is_null函数代码示例发布时间:2022-05-27
下一篇:
Python cgutils.ifthen函数代码示例发布时间: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