当前位置: 首页>>代码示例>>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;未经允许,请勿转载。