|
1 | | -import operator |
2 | | -import sys |
3 | 1 | import warnings |
4 | 2 | from copy import copy |
5 | 3 | from functools import singledispatch |
|
8 | 6 | import numba |
9 | 7 | import numba.np.unsafe.ndarray as numba_ndarray |
10 | 8 | import numpy as np |
11 | | -from llvmlite import ir |
12 | 9 | from numba import types |
13 | 10 | from numba.core.errors import NumbaWarning, TypingError |
14 | 11 | from numba.cpython.unsafe.tuple import tuple_setitem # noqa: F401 |
15 | | -from numba.extending import box, overload |
| 12 | +from numba.extending import overload |
16 | 13 |
|
17 | 14 | from pytensor import In, config |
18 | 15 | from pytensor.compile import NUMBA |
|
36 | 33 | from pytensor.tensor.shape import Reshape, Shape, Shape_i, SpecifyShape |
37 | 34 | from pytensor.tensor.sort import ArgSortOp, SortOp |
38 | 35 | from pytensor.tensor.type import TensorType |
39 | | -from pytensor.tensor.type_other import MakeSlice, NoneConst |
| 36 | +from pytensor.tensor.type_other import NoneConst |
40 | 37 |
|
41 | 38 |
|
42 | 39 | def numba_njit(*args, fastmath=None, **kwargs): |
@@ -149,69 +146,6 @@ def create_numba_signature( |
149 | 146 | return numba.types.void(*input_types) |
150 | 147 |
|
151 | 148 |
|
152 | | -def slice_new(self, start, stop, step): |
153 | | - fnty = ir.FunctionType(self.pyobj, [self.pyobj, self.pyobj, self.pyobj]) |
154 | | - fn = self._get_function(fnty, name="PySlice_New") |
155 | | - return self.builder.call(fn, [start, stop, step]) |
156 | | - |
157 | | - |
158 | | -def enable_slice_boxing(): |
159 | | - """Enable boxing for Numba's native ``slice``s. |
160 | | -
|
161 | | - TODO: this can be removed when https://github.com/numba/numba/pull/6939 is |
162 | | - merged and a release is made. |
163 | | - """ |
164 | | - |
165 | | - @box(types.SliceType) |
166 | | - def box_slice(typ, val, c): |
167 | | - """Implement boxing for ``slice`` objects in Numba. |
168 | | -
|
169 | | - This makes it possible to return an Numba's internal representation of a |
170 | | - ``slice`` object as a proper ``slice`` to Python. |
171 | | - """ |
172 | | - start = c.builder.extract_value(val, 0) |
173 | | - stop = c.builder.extract_value(val, 1) |
174 | | - |
175 | | - none_val = ir.Constant(ir.IntType(64), sys.maxsize) |
176 | | - |
177 | | - start_is_none = c.builder.icmp_signed("==", start, none_val) |
178 | | - start = c.builder.select( |
179 | | - start_is_none, |
180 | | - c.pyapi.get_null_object(), |
181 | | - c.box(types.int64, start), |
182 | | - ) |
183 | | - |
184 | | - stop_is_none = c.builder.icmp_signed("==", stop, none_val) |
185 | | - stop = c.builder.select( |
186 | | - stop_is_none, |
187 | | - c.pyapi.get_null_object(), |
188 | | - c.box(types.int64, stop), |
189 | | - ) |
190 | | - |
191 | | - if typ.has_step: |
192 | | - step = c.builder.extract_value(val, 2) |
193 | | - step_is_none = c.builder.icmp_signed("==", step, none_val) |
194 | | - step = c.builder.select( |
195 | | - step_is_none, |
196 | | - c.pyapi.get_null_object(), |
197 | | - c.box(types.int64, step), |
198 | | - ) |
199 | | - else: |
200 | | - step = c.pyapi.get_null_object() |
201 | | - |
202 | | - slice_val = slice_new(c.pyapi, start, stop, step) |
203 | | - |
204 | | - return slice_val |
205 | | - |
206 | | - @numba.extending.overload(operator.contains) |
207 | | - def in_seq_empty_tuple(x, y): |
208 | | - if isinstance(x, types.Tuple) and not x.types: |
209 | | - return lambda x, y: False |
210 | | - |
211 | | - |
212 | | -enable_slice_boxing() |
213 | | - |
214 | | - |
215 | 149 | def to_scalar(x): |
216 | 150 | return np.asarray(x).item() |
217 | 151 |
|
@@ -388,15 +322,6 @@ def numba_funcify_DeepCopyOp(op, node, **kwargs): |
388 | 322 | return deepcopyop |
389 | 323 |
|
390 | 324 |
|
391 | | -@numba_funcify.register(MakeSlice) |
392 | | -def numba_funcify_MakeSlice(op, **kwargs): |
393 | | - @numba_njit |
394 | | - def makeslice(*x): |
395 | | - return slice(*x) |
396 | | - |
397 | | - return makeslice |
398 | | - |
399 | | - |
400 | 325 | @numba_funcify.register(Shape) |
401 | 326 | def numba_funcify_Shape(op, **kwargs): |
402 | 327 | @numba_njit |
|
0 commit comments