當前位置: 首頁>>代碼示例>>Python>>正文


Python numba.from_dtype方法代碼示例

本文整理匯總了Python中numba.from_dtype方法的典型用法代碼示例。如果您正苦於以下問題:Python numba.from_dtype方法的具體用法?Python numba.from_dtype怎麽用?Python numba.from_dtype使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numba的用法示例。


在下文中一共展示了numba.from_dtype方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_numba_array_types_for_csv

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import from_dtype [as 別名]
def get_numba_array_types_for_csv(df):
    """Extracts Numba array types from the given DataFrame."""
    result = []
    for numpy_type in df.dtypes.values:
        try:
            numba_type = numpy_support.from_dtype(numpy_type)
        except NotImplementedError:
            numba_type = None

        if numba_type and numba_type != types.pyobject:
            array_type = types.Array(numba_type, 1, 'C')
        else:
            # default type for CSV is string
            array_type = string_array_type

        result.append(array_type)
    return result 
開發者ID:IntelPython,項目名稱:sdc,代碼行數:19,代碼來源:hpat_pandas_functions.py

示例2: generic_resolve

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import from_dtype [as 別名]
def generic_resolve(self, typ, attr):
            if typ.matchable:
                if attr == "nullable":
                    return numba.types.boolean

                elif isinstance(typ.schema, oamap.schema.Primitive) and attr == "dtype":
                    return numba.types.DType(numba.from_dtype(typ.schema.dtype))

                elif isinstance(typ.schema, oamap.schema.List) and attr == "content":
                    return typ.content()

                elif isinstance(typ.schema, oamap.schema.Union) and attr == "possibilities":
                    return typ.unmatchable()

                elif isinstance(typ.schema, oamap.schema.Record) and attr == "fields":
                    return typ.unmatchable()

                elif isinstance(typ.schema, oamap.schema.Tuple) and attr == "types":
                    return typ.unmatchable()

                elif isinstance(typ.schema, oamap.schema.Pointer) and attr == "target":
                    return typ.target()

                else:
                    raise AssertionError("unrecognized schema type: {0} ({1})".format(typ.schema.__class__, repr(typ.schema))) 
開發者ID:diana-hep,項目名稱:oamap,代碼行數:27,代碼來源:compiler.py

示例3: __init__

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import from_dtype [as 別名]
def __init__(self, data_dtype: np.dtype, coords_dtype: np.dtype, ndim: int):
        assert isinstance(data_dtype, np.dtype)
        assert isinstance(coords_dtype, np.dtype)
        self.data_dtype = data_dtype
        self.coords_dtype = coords_dtype
        self.ndim = ndim
        super().__init__(
            name="COOType[{!r}, {!r}, {!r}]".format(
                numba.from_dtype(data_dtype), numba.from_dtype(coords_dtype), ndim
            )
        ) 
開發者ID:pydata,項目名稱:sparse,代碼行數:13,代碼來源:numba_extension.py

示例4: data_type

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import from_dtype [as 別名]
def data_type(self):
        return numba.from_dtype(self.data_dtype)[:] 
開發者ID:pydata,項目名稱:sparse,代碼行數:4,代碼來源:numba_extension.py

示例5: coords_type

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import from_dtype [as 別名]
def coords_type(self):
        return numba.from_dtype(self.coords_dtype)[:, :] 
開發者ID:pydata,項目名稱:sparse,代碼行數:4,代碼來源:numba_extension.py

示例6: fill_value_type

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import from_dtype [as 別名]
def fill_value_type(self):
        return numba.from_dtype(self.data_dtype) 
開發者ID:pydata,項目名稱:sparse,代碼行數:4,代碼來源:numba_extension.py

示例7: resolve_cast

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import from_dtype [as 別名]
def resolve_cast(self, schematype, args, kwds):
            if len(args) == 1:
                arg, = args
                if isinstance(schematype.schema, oamap.schema.Primitive):
                    if schematype.schema.nullable:
                        return numba.types.optional(numba.from_dtype(schematype.schema.dtype))(arg)
                    else:
                        return numba.from_dtype(schematype.schema.dtype)(arg)

                elif isinstance(schematype.schema, (oamap.schema.List, oamap.schema.Union, oamap.schema.Record, oamap.schema.Tuple)):
                    if isinstance(arg, UnionProxyNumbaType):
                        for datatag, datatype in enumerate(arg.generator.schema.possibilities):
                            if schematype.schema == datatype:
                                return typeof_generator(arg.generator.possibilities[datatag])(arg)

                    if isinstance(arg, numba.types.Optional) and isinstance(arg.type, UnionProxyNumbaType):
                        for datatag, datatype in enumerate(arg.type.generator.schema.possibilities):
                            if schematype.schema == datatype:
                                return typeof_generator(arg.type.generator.possibilities[datatag])(arg)

                    if arg.generator.schema == schematype.schema:
                        return typeof_generator(arg.generator)(arg)
                    else:
                        return typeof_generator(schematype.generator)(arg)

                elif isinstance(schematype.schema, oamap.schema.Pointer):
                    raise TypeError("cannot cast data as a Pointer")

                else:
                    raise AssertionError("unrecognized schema type: {0} ({1})".format(schematype.schema.__class__, repr(schematype.schema))) 
開發者ID:diana-hep,項目名稱:oamap,代碼行數:32,代碼來源:compiler.py

示例8: schema_getattr

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import from_dtype [as 別名]
def schema_getattr(context, builder, typ, val, attr):
        if attr == "nullable":
            return literal_boolean(1 if typ.schema.nullable else 0)

        elif attr == "dtype":
            return numba.targets.imputils.impl_ret_untracked(context, builder, numba.types.DType(numba.from_dtype(typ.schema.dtype)), context.get_dummy_value())

        else:
            return numba.cgutils.create_struct_proxy(typ)(context, builder)._getvalue() 
開發者ID:diana-hep,項目名稱:oamap,代碼行數:11,代碼來源:compiler.py

示例9: typeof_generator

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import from_dtype [as 別名]
def typeof_generator(generator, checkmasked=True):
        if checkmasked and isinstance(generator, oamap.generator.Masked):
            tpe = typeof_generator(generator, checkmasked=False)
            if isinstance(tpe, numba.types.Optional):
                return tpe
            else:
                return numba.types.optional(tpe)

        if isinstance(generator, oamap.generator.PrimitiveGenerator):
            return numba.from_dtype(generator.dtype)

        elif isinstance(generator, oamap.generator.ListGenerator):
            return ListProxyNumbaType(generator)

        elif isinstance(generator, oamap.generator.UnionGenerator):
            return UnionProxyNumbaType(generator)

        elif isinstance(generator, oamap.generator.RecordGenerator):
            return RecordProxyNumbaType(generator)

        elif isinstance(generator, oamap.generator.TupleGenerator):
            return TupleProxyNumbaType(generator)

        elif isinstance(generator, oamap.generator.PointerGenerator):
            return typeof_generator(generator.target)

        elif isinstance(generator, oamap.generator.ExtendedGenerator):
            return typeof_generator(generator.generic)

        else:
            raise AssertionError("unrecognized generator type: {0} ({1})".format(generator.__class__, repr(generator))) 
開發者ID:diana-hep,項目名稱:oamap,代碼行數:33,代碼來源:compiler.py

示例10: unionproxytype_eq_left_primitive

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import from_dtype [as 別名]
def unionproxytype_eq_left_primitive(context, builder, sig, args):
        ltype, rtype = sig.args
        lval, rval = args
        lproxy = numba.cgutils.create_struct_proxy(ltype)(context, builder, value=lval)
        out_ptr = numba.cgutils.alloca_once_value(builder, literal_boolean(False))
        for li, lgen in enumerate(ltype.generator.possibilities):
            if isinstance(lgen.schema, oamap.schema.Primitive) and numba.from_dtype(lgen.schema.dtype) == rtype:
                with builder.if_then(builder.icmp_signed("==", lproxy.tag, literal_int(li, ltype.generator.tagdtype.itemsize))):
                    ldata = generate(context, builder, lgen, lproxy.baggage, lproxy.ptrs, lproxy.lens, lproxy.offset)
                    with builder.if_then(context.get_function("==", numba.types.boolean(typeof_generator(lgen), rtype))(builder, (ldata, rval))):
                        builder.store(literal_boolean(True), out_ptr)
        return builder.load(out_ptr) 
開發者ID:diana-hep,項目名稱:oamap,代碼行數:14,代碼來源:compiler.py

示例11: schema_case

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import from_dtype [as 別名]
def schema_case(context, builder, sig, args):
        schematype, argtype = sig.args
        dummy, argval = args

        if isinstance(argtype, numba.types.Optional):
            # unwrap the optval and apply the check to the contents
            optval = context.make_helper(builder, argtype, value=argval)
            out = schema_case(context, builder, numba.types.boolean(schematype, argtype.type), (dummy, optval.data))
            if schematype.schema.nullable:
                return out
            else:
                return builder.and_(optval.valid, out)

        elif isinstance(argtype, UnionProxyNumbaType):
            # do a runtime check
            for datatag, datatype in enumerate(argtype.generator.schema.possibilities):
                if schematype.schema == datatype:
                    unionproxy = numba.cgutils.create_struct_proxy(argtype)(context, builder, value=argval)
                    out_ptr = numba.cgutils.alloca_once(builder, llvmlite.llvmpy.core.Type.int(1))
                    with builder.if_else(builder.icmp_unsigned("==", unionproxy.tag, literal_int(datatag, argtype.generator.tagdtype.itemsize))) as (success, failure):
                        with success:
                            builder.store(literal_boolean(True), out_ptr)
                        with failure:
                            builder.store(literal_boolean(False), out_ptr)
                    out = builder.load(out_ptr)
                    return out

            # none of the data possibilities will ever match
            return literal_boolean(False)

        elif isinstance(argtype, primtypes):
            # do a compile-time check
            if isinstance(schematype.schema, oamap.schema.Primitive):
                return literal_boolean(numba.from_dtype(schematype.schema.dtype) == argtype)
            else:
                return literal_boolean(False)

        elif isinstance(argtype, ProxyNumbaType):
            # do a compile-time check
            return literal_boolean(schematype.schema == argtype.generator.schema)

        else:
            raise AssertionError 
開發者ID:diana-hep,項目名稱:oamap,代碼行數:45,代碼來源:compiler.py

示例12: generate_empty

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import from_dtype [as 別名]
def generate_empty(context, builder, generator, baggage):
        typ = typeof_generator(generator, checkmasked=False)

        if isinstance(generator, oamap.generator.PrimitiveGenerator):
            return llvmlite.llvmpy.core.Constant.null(context.get_value_type(numba.from_dtype(generator.dtype)))

        elif isinstance(generator, oamap.generator.ListGenerator):
            listproxy = numba.cgutils.create_struct_proxy(typ)(context, builder)
            listproxy.baggage = baggage
            listproxy.ptrs = llvmlite.llvmpy.core.Constant.null(context.get_value_type(numba.types.voidptr))
            listproxy.lens = llvmlite.llvmpy.core.Constant.null(context.get_value_type(numba.types.voidptr))
            listproxy.whence = literal_int64(-1)
            listproxy.stride = literal_int64(-1)
            listproxy.length = literal_int64(-1)
            return listproxy._getvalue()

        elif isinstance(generator, oamap.generator.UnionGenerator):
            unionproxy = numba.cgutils.create_struct_proxy(typ)(context, builder)
            unionproxy.baggage = baggage
            unionproxy.ptrs = llvmlite.llvmpy.core.Constant.null(context.get_value_type(numba.types.voidptr))
            unionproxy.lens = llvmlite.llvmpy.core.Constant.null(context.get_value_type(numba.types.voidptr))
            unionproxy.tag = literal_int64(-1)
            unionproxy.offset = literal_int64(-1)
            return unionproxy._getvalue()

        elif isinstance(generator, oamap.generator.RecordGenerator):
            recordproxy = numba.cgutils.create_struct_proxy(typ)(context, builder)
            recordproxy.baggage = baggage
            recordproxy.ptrs = llvmlite.llvmpy.core.Constant.null(context.get_value_type(numba.types.voidptr))
            recordproxy.lens = llvmlite.llvmpy.core.Constant.null(context.get_value_type(numba.types.voidptr))
            recordproxy.index = literal_int64(-1)
            return recordproxy._getvalue()

        elif isinstance(generator, oamap.generator.TupleGenerator):
            tupleproxy = numba.cgutils.create_struct_proxy(typ)(context, builder)
            tupleproxy.baggage = baggage
            tupleproxy.ptrs = llvmlite.llvmpy.core.Constant.null(context.get_value_type(numba.types.voidptr))
            tupleproxy.lens = llvmlite.llvmpy.core.Constant.null(context.get_value_type(numba.types.voidptr))
            tupleproxy.index = literal_int64(-1)
            return tupleproxy._getvalue()

        elif isinstance(generator, oamap.generator.PointerGenerator):
            return generate_empty(context, builder, generator.target, baggage)

        elif isinstance(generator, oamap.generator.ExtendedGenerator):
            return generate(context, builder, generator.generic, baggage, ptrs, lens, at)

        else:
            raise AssertionError("unrecognized generator type: {0} ({1})".format(generator.__class__, repr(generator))) 
開發者ID:diana-hep,項目名稱:oamap,代碼行數:51,代碼來源:compiler.py

示例13: generic

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import from_dtype [as 別名]
def generic(self, args, kwds):
            lhs, rhs = args
            if isinstance(lhs, numba.types.Optional):
                lhs = lhs.type
            if isinstance(rhs, numba.types.Optional):
                rhs = rhs.type

            if isinstance(lhs, ListProxyNumbaType) and isinstance(rhs, ListProxyNumbaType):
                if lhs.generator.schema.content == rhs.generator.schema.content:
                    return numba.types.boolean(*args)

            elif isinstance(lhs, RecordProxyNumbaType) and isinstance(rhs, RecordProxyNumbaType):
                if lhs.generator.schema.fields == rhs.generator.schema.fields:
                    return numba.types.boolean(*args)

            elif isinstance(lhs, TupleProxyNumbaType) and isinstance(rhs, TupleProxyNumbaType):
                if lhs.generator.schema.types == rhs.generator.schema.types:
                    return numba.types.boolean(*args)

            elif isinstance(lhs, UnionProxyNumbaType) and isinstance(rhs, UnionProxyNumbaType):
                for x in lhs.generator.schema.possibilities:
                    for y in rhs.generator.schema.possibilities:
                        if x.copy(nullable=False) == y.copy(nullable=False):
                            return numba.types.boolean(*args)

            elif isinstance(lhs, UnionProxyNumbaType) and isinstance(rhs, ProxyNumbaType):
                for x in lhs.generator.schema.possibilities:
                    if x.copy(nullable=False) == rhs.generator.schema.copy(nullable=False):
                        return numba.types.boolean(*args)

            elif isinstance(rhs, UnionProxyNumbaType) and isinstance(lhs, ProxyNumbaType):
                for x in rhs.generator.schema.possibilities:
                    if x.copy(nullable=False) == lhs.generator.schema.copy(nullable=False):
                        return numba.types.boolean(*args)

            elif isinstance(lhs, UnionProxyNumbaType) and isinstance(rhs, primtypes):
                for x in lhs.generator.schema.possibilities:
                    if isinstance(x, oamap.schema.Primitive) and numba.from_dtype(x.dtype) == rhs:
                        return numba.types.boolean(*args)

            elif isinstance(rhs, UnionProxyNumbaType) and isinstance(lhs, primtypes):
                for x in rhs.generator.schema.possibilities:
                    if isinstance(x, oamap.schema.Primitive) and numba.from_dtype(x.dtype) == lhs:
                        return numba.types.boolean(*args)

    ################################################################ ListProxy 
開發者ID:diana-hep,項目名稱:oamap,代碼行數:48,代碼來源:compiler.py


注:本文中的numba.from_dtype方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。