提交 ea146df8 authored 作者: Brandon T. Willard's avatar Brandon T. Willard 提交者: Brandon T. Willard

Move Numba slice boxing implementation into a function

上级 f8a1d6b9
...@@ -101,24 +101,39 @@ def slice_new(self, start, stop, step): ...@@ -101,24 +101,39 @@ def slice_new(self, start, stop, step):
return self.builder.call(fn, [start, stop, step]) return self.builder.call(fn, [start, stop, step])
@box(types.SliceType) def enable_slice_boxing():
def box_slice(typ, val, c): """Enable boxing for Numba's native ``slice``s.
"""Implement boxing for ``slice`` objects in Numba.
This makes it possible to return an Numba's internal representation of a TODO: this can be removed when https://github.com/numba/numba/pull/6939 is
``slice`` object as a proper ``slice`` to Python. merged and a release is made.
""" """
start = c.box(types.int64, c.builder.extract_value(val, 0)) @box(types.SliceType)
stop = c.box(types.int64, c.builder.extract_value(val, 1)) def box_slice(typ, val, c):
if typ.has_step: """Implement boxing for ``slice`` objects in Numba.
step = c.box(types.int64, c.builder.extract_value(val, 2))
else: This makes it possible to return an Numba's internal representation of a
step = c.pyapi.get_null_object() ``slice`` object as a proper ``slice`` to Python.
"""
start = c.box(types.int64, c.builder.extract_value(val, 0))
stop = c.box(types.int64, c.builder.extract_value(val, 1))
if typ.has_step:
step = c.box(types.int64, c.builder.extract_value(val, 2))
else:
step = c.pyapi.get_null_object()
slice_val = slice_new(c.pyapi, start, stop, step) slice_val = slice_new(c.pyapi, start, stop, step)
return slice_val return slice_val
@numba.extending.overload(operator.contains)
def in_seq_empty_tuple(x, y):
if isinstance(x, types.Tuple) and not x.types:
return lambda x, y: False
enable_slice_boxing()
@numba.generated_jit(nopython=True) @numba.generated_jit(nopython=True)
...@@ -158,12 +173,6 @@ def create_tuple_string(x): ...@@ -158,12 +173,6 @@ def create_tuple_string(x):
return f"({args})" return f"({args})"
@numba.extending.overload(operator.contains)
def in_seq_empty_tuple(x, y):
if isinstance(x, types.Tuple) and not x.types:
return lambda x, y: False
@singledispatch @singledispatch
def numba_typify(data, dtype=None, **kwargs): def numba_typify(data, dtype=None, **kwargs):
return data return data
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论