1
1
import operator
2
+ import sys
2
3
import warnings
3
4
from contextlib import contextmanager
4
5
from functools import singledispatch
10
11
import numpy as np
11
12
import scipy
12
13
import scipy .special
13
- from llvmlite . ir import Type as llvm_Type
14
+ from llvmlite import ir
14
15
from numba import types
15
16
from numba .core .errors import TypingError
16
17
from numba .cpython .unsafe .tuple import tuple_setitem # noqa: F401
@@ -131,7 +132,7 @@ def create_numba_signature(
131
132
132
133
133
134
def slice_new (self , start , stop , step ):
134
- fnty = llvm_Type . function (self .pyobj , [self .pyobj , self .pyobj , self .pyobj ])
135
+ fnty = ir . FunctionType (self .pyobj , [self .pyobj , self .pyobj , self .pyobj ])
135
136
fn = self ._get_function (fnty , name = "PySlice_New" )
136
137
return self .builder .call (fn , [start , stop , step ])
137
138
@@ -150,11 +151,33 @@ def box_slice(typ, val, c):
150
151
This makes it possible to return an Numba's internal representation of a
151
152
``slice`` object as a proper ``slice`` to Python.
152
153
"""
154
+ start = c .builder .extract_value (val , 0 )
155
+ stop = c .builder .extract_value (val , 1 )
156
+
157
+ none_val = ir .Constant (ir .IntType (64 ), sys .maxsize )
158
+
159
+ start_is_none = c .builder .icmp_signed ("==" , start , none_val )
160
+ start = c .builder .select (
161
+ start_is_none ,
162
+ c .pyapi .get_null_object (),
163
+ c .box (types .int64 , start ),
164
+ )
165
+
166
+ stop_is_none = c .builder .icmp_signed ("==" , stop , none_val )
167
+ stop = c .builder .select (
168
+ stop_is_none ,
169
+ c .pyapi .get_null_object (),
170
+ c .box (types .int64 , stop ),
171
+ )
153
172
154
- start = c .box (types .int64 , c .builder .extract_value (val , 0 ))
155
- stop = c .box (types .int64 , c .builder .extract_value (val , 1 ))
156
173
if typ .has_step :
157
- step = c .box (types .int64 , c .builder .extract_value (val , 2 ))
174
+ step = c .builder .extract_value (val , 2 )
175
+ step_is_none = c .builder .icmp_signed ("==" , step , none_val )
176
+ step = c .builder .select (
177
+ step_is_none ,
178
+ c .pyapi .get_null_object (),
179
+ c .box (types .int64 , step ),
180
+ )
158
181
else :
159
182
step = c .pyapi .get_null_object ()
160
183
0 commit comments