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


Python numba.typeof方法代码示例

本文整理汇总了Python中numba.typeof方法的典型用法代码示例。如果您正苦于以下问题:Python numba.typeof方法的具体用法?Python numba.typeof怎么用?Python numba.typeof使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numba的用法示例。


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

示例1: _Series_category

# 需要导入模块: import numba [as 别名]
# 或者: from numba import typeof [as 别名]
def _Series_category(data=None, index=None, dtype=None, name=None, copy=False, fastpath=False):
    """
    Implementation of constructor for pandas Series via objmode.
    """
    # TODO: support other parameters (only data and dtype now)

    ty = typeof(_reconstruct_Series(data, dtype))

    from textwrap import dedent
    text = dedent(f"""
    def impl(data=None, index=None, dtype=None, name=None, copy=False, fastpath=False):
        with objmode(series="{ty}"):
            series = pd.Series(data, index, dtype, name, copy, fastpath)
        return series
    """)
    globals, locals = {'objmode': objmode, 'pd': pd}, {}
    exec(text, globals, locals)
    impl = locals['impl']
    return impl 
开发者ID:IntelPython,项目名称:sdc,代码行数:21,代码来源:pdimpl.py

示例2: make_dense_tree

# 需要导入模块: import numba [as 别名]
# 或者: from numba import typeof [as 别名]
def make_dense_tree(data, rng_state, leaf_size=30, angular=False):
    indices = np.arange(data.shape[0]).astype(np.int32)

    hyperplanes = numba.typed.List.empty_list(dense_hyperplane_type)
    offsets = numba.typed.List.empty_list(offset_type)
    children = numba.typed.List.empty_list(children_type)
    point_indices = numba.typed.List.empty_list(point_indices_type)

    if angular:
        make_angular_tree(
            data,
            indices,
            hyperplanes,
            offsets,
            children,
            point_indices,
            rng_state,
            leaf_size,
        )
    else:
        make_euclidean_tree(
            data,
            indices,
            hyperplanes,
            offsets,
            children,
            point_indices,
            rng_state,
            leaf_size,
        )

    # print("Completed a tree")
    result = FlatTree(hyperplanes, offsets, children, point_indices, leaf_size)
    # print("Tree type is:", numba.typeof(result))
    return result 
开发者ID:lmcinnes,项目名称:pynndescent,代码行数:37,代码来源:rp_trees.py

示例3: infer_dictionary_types

# 需要导入模块: import numba [as 别名]
# 或者: from numba import typeof [as 别名]
def infer_dictionary_types(d):
    if not d:
        raise ValueError("Empty dictionary cannot infer")
    keys = list(d.keys())
    type_keys = type(keys[0])
    for k in keys:
        if type(k) != type_keys:
            raise ValueError("Inconsistent key types in dictionary")
    values = list(d.values())
    type_values = type(values[0])
    for v in values:
        if type(v) != type_values:
            raise ValueError("Inconsistent value types in dictionary")
            
    return numba.typeof(keys[0]), numba.typeof(values[0]) 
开发者ID:CalebBell,项目名称:fluids,代码行数:17,代码来源:numba.py

示例4: _Table_typeof

# 需要导入模块: import numba [as 别名]
# 或者: from numba import typeof [as 别名]
def _Table_typeof(val, c):
    return TableType(val.rowname, OrderedDict((n, numba.typeof(x)) for n, x in val.contents.items()), special=type(val), specialrow=type(val).Row) 
开发者ID:scikit-hep,项目名称:awkward-array,代码行数:4,代码来源:table.py

示例5: _JaggedArray_typeof

# 需要导入模块: import numba [as 别名]
# 或者: from numba import typeof [as 别名]
def _JaggedArray_typeof(val, c):
    return JaggedArrayType(numba.typeof(val.starts), numba.typeof(val.stops), numba.typeof(val.content), special=type(val)) 
开发者ID:scikit-hep,项目名称:awkward-array,代码行数:4,代码来源:jagged.py

示例6: _replace_func

# 需要导入模块: import numba [as 别名]
# 或者: from numba import typeof [as 别名]
def _replace_func(self, func, args, const=False, pre_nodes=None, extra_globals=None, pysig=None, kws=None):
        glbls = {'numba': numba, 'numpy': numpy, 'sdc': sdc}
        if extra_globals is not None:
            glbls.update(extra_globals)

        if pysig is not None:
            pre_nodes = [] if pre_nodes is None else pre_nodes
            scope = next(iter(self.state.func_ir.blocks.values())).scope
            loc = scope.loc

            def normal_handler(index, param, default):
                return default

            def default_handler(index, param, default):
                d_var = ir.Var(scope, ir_utils.mk_unique_var('defaults'), loc)
                self.state.typemap[d_var.name] = numba.typeof(default)
                node = ir.Assign(ir.Const(default, loc), d_var, loc)
                pre_nodes.append(node)

                return d_var

            args = numba.core.typing.fold_arguments(pysig, args, kws, normal_handler, default_handler, normal_handler)

        arg_typs = tuple(self.state.typemap[v.name] for v in args)

        if const:
            new_args = []

            for i, arg in enumerate(args):
                val = guard(ir_utils.find_const, self.state.func_ir, arg)
                if val:
                    new_args.append(types.literal(val))
                else:
                    new_args.append(arg_typs[i])
            arg_typs = tuple(new_args)

        return sdc.utilities.utils.ReplaceFunc(func, arg_typs, args, glbls, pre_nodes) 
开发者ID:IntelPython,项目名称:sdc,代码行数:39,代码来源:hpat_pandas_dataframe_pass.py

示例7: _typeof_Categorical

# 需要导入模块: import numba [as 别名]
# 或者: from numba import typeof [as 别名]
def _typeof_Categorical(val, c):
    try:
        dtype = pandas_support.from_dtype(val.dtype)
    except NotImplementedError:
        raise ValueError("Unsupported Categorical dtype: %s" % (val.dtype,))
    codes = typeof(val.codes)
    return Categorical(dtype=dtype, codes=codes) 
开发者ID:IntelPython,项目名称:sdc,代码行数:9,代码来源:typeof.py

示例8: test_typeof

# 需要导入模块: import numba [as 别名]
# 或者: from numba import typeof [as 别名]
def test_typeof(self):
        pd_value = self._pd_value()
        nb_type = nb.typeof(pd_value)

        assert(isinstance(nb_type, SeriesType))
        assert(nb_type.dtype == CategoricalDtypeType(categories=[1, 2, 3], ordered=False))
        assert(nb_type.index == types.none)
        assert(nb_type.data == Categorical(CategoricalDtypeType(categories=[1, 2, 3], ordered=False))) 
开发者ID:IntelPython,项目名称:sdc,代码行数:10,代码来源:test_series_category.py

示例9: test_typeof

# 需要导入模块: import numba [as 别名]
# 或者: from numba import typeof [as 别名]
def test_typeof(self):
        pd_value = self._pd_value()
        nb_type = nb.typeof(pd_value)

        assert(isinstance(nb_type, Categorical))
        assert(nb_type.pd_dtype == CategoricalDtypeType(categories=[1, 2, 3], ordered=False))
        assert(nb_type.codes == types.Array(dtype=types.int8, ndim=1, layout='C', readonly=True)) 
开发者ID:IntelPython,项目名称:sdc,代码行数:9,代码来源:test_categorical.py

示例10: _infer_series_dtype

# 需要导入模块: import numba [as 别名]
# 或者: from numba import typeof [as 别名]
def _infer_series_dtype(S):
    if S.dtype == np.dtype('O'):
        # XXX assuming the whole column is strings if 1st val is string
        # TODO: handle NA as 1st value
        i = 0
        while i < len(S) and (S.iloc[i] is np.nan or S.iloc[i] is None):
            i += 1
        if i == len(S):
            raise ValueError(
                "object dtype infer out of bounds for {}".format(S.name))

        first_val = S.iloc[i]
        if isinstance(first_val, list):
            return _infer_series_list_dtype(S)
        elif isinstance(first_val, str):
            return string_type
        else:
            raise ValueError(
                "object dtype infer: data type for column {} not supported".format(S.name))
    elif isinstance(S.dtype, pd.CategoricalDtype):
        return numba.typeof(S.dtype)
    # regular numpy types
    try:
        return numpy_support.from_dtype(S.dtype)
    except NotImplementedError:
        raise ValueError("np dtype infer: data type for column {} not supported".format(S.name)) 
开发者ID:IntelPython,项目名称:sdc,代码行数:28,代码来源:boxing.py

示例11: _get_cat_obj_items

# 需要导入模块: import numba [as 别名]
# 或者: from numba import typeof [as 别名]
def _get_cat_obj_items(categories, c):
    assert len(categories) > 0
    val = categories[0]
    if isinstance(val, str):
        return [c.pyapi.string_from_constant_string(item) for item in categories]

    dtype = numba.typeof(val)
    return [c.box(dtype, c.context.get_constant(dtype, item)) for item in categories] 
开发者ID:IntelPython,项目名称:sdc,代码行数:10,代码来源:pd_categorical_ext.py

示例12: __call__

# 需要导入模块: import numba [as 别名]
# 或者: from numba import typeof [as 别名]
def __call__(self, *args):
        arg_type = tuple(numba.typeof(arg) for arg in args)
        try:
            func = self.__cache[arg_type]
        except KeyError:
            func = self.__cache[arg_type] = self.__func(*arg_type)
        return func(*args) 
开发者ID:pygae,项目名称:clifford,代码行数:9,代码来源:_numba_utils.py

示例13: paramtypes

# 需要导入模块: import numba [as 别名]
# 或者: from numba import typeof [as 别名]
def paramtypes(args):
    try:
        import numba as nb
    except ImportError:
        return None
    else:
        return tuple(nb.typeof(x) for x in args) 
开发者ID:diana-hep,项目名称:oamap,代码行数:9,代码来源:util.py


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