Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit 9702551

Browse files
Merge pull request #981 from kozlov-alexey/feature/migrate_numba_0.54
Preparing for migration to numba=0.54
2 parents a133254 + 7986ebd commit 9702551

23 files changed

+196
-260
lines changed

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Building on Linux with setuptools
8585

8686
export PYVER=<3.6 or 3.7>
8787
export NUMPYVER=<1.16 or 1.17>
88-
conda create -n sdc-env -q -y -c intel/label/beta -c defaults -c intel -c conda-forge python=$PYVER numpy=$NUMPYVER tbb-devel tbb4py numba=0.53.1 pandas=1.2.0 pyarrow=4.0.1 gcc_linux-64 gxx_linux-64
88+
conda create -n sdc-env -q -y -c intel/label/beta -c defaults -c intel -c conda-forge python=$PYVER numpy=$NUMPYVER tbb-devel tbb4py numba=0.54.0 pandas=1.2.0 pyarrow=4.0.1 gcc_linux-64 gxx_linux-64
8989
source activate sdc-env
9090
git clone https://github.com/IntelPython/sdc.git
9191
cd sdc
@@ -123,7 +123,7 @@ Building on Windows with setuptools
123123

124124
set PYVER=<3.6 or 3.7>
125125
set NUMPYVER=<1.16 or 1.17>
126-
conda create -n sdc-env -c intel/label/beta -c defaults -c intel -c conda-forge python=%PYVER% numpy=%NUMPYVER% tbb-devel tbb4py numba=0.53.1 pandas=1.2.0 pyarrow=4.0.1
126+
conda create -n sdc-env -c intel/label/beta -c defaults -c intel -c conda-forge python=%PYVER% numpy=%NUMPYVER% tbb-devel tbb4py numba=0.54.0 pandas=1.2.0 pyarrow=4.0.1
127127
conda activate sdc-env
128128
set INCLUDE=%INCLUDE%;%CONDA_PREFIX%\Library\include
129129
set LIB=%LIB%;%CONDA_PREFIX%\Library\lib

conda-recipe/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% set NUMBA_VERSION = "==0.53.1" %}
1+
{% set NUMBA_VERSION = "==0.54.0" %}
22
{% set PANDAS_VERSION = "==1.2.0" %}
33
{% set PYARROW_VERSION = "==4.0.1" %}
44

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
numpy>=1.16
22
pandas==1.2.0
33
pyarrow==4.0.1
4-
numba==0.53.1
4+
numba==0.54.0
55
tbb
66
tbb-devel

sdc/cv_ext.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def lower_cv2_imread(context, builder, sig, args):
7575
[ll_shty.as_pointer(),
7676
lir.IntType(8).as_pointer().as_pointer(),
7777
lir.IntType(8).as_pointer()])
78-
fn_imread = builder.module.get_or_insert_function(fnty, name="cv_imread")
78+
fn_imread = cgutils.get_or_insert_function(builder.module, fnty, name="cv_imread")
7979
img = builder.call(fn_imread, [shapes_array, data, fname])
8080

8181
return _image_to_array(context, builder, shapes_array, arrtype, data, img)
@@ -99,7 +99,7 @@ def lower_cv2_imread(context, builder, sig, args):
9999
# lir.IntType(8).as_pointer(),
100100
# lir.IntType(64),
101101
# lir.IntType(64)])
102-
# fn_resize = builder.module.get_or_insert_function(fnty, name="cv_resize")
102+
# fn_resize = cgutils.get_or_insert_function(builder.module, fnty, name="cv_resize")
103103
# img = builder.call(fn_resize, [new_sizes[1], new_sizes[0], ary.data, in_array.data,
104104
# in_shapes[0], in_shapes[1]])
105105
#
@@ -115,7 +115,7 @@ def _image_to_array(context, builder, shapes_array, arrtype, data, img):
115115

116116
# clean up cv::Mat image
117117
fnty = lir.FunctionType(lir.VoidType(), [lir.IntType(8).as_pointer()])
118-
fn_release = builder.module.get_or_insert_function(fnty, name="cv_mat_release")
118+
fn_release = cgutils.get_or_insert_function(builder.module, fnty, name="cv_mat_release")
119119
builder.call(fn_release, [img])
120120

121121
return impl_ret_new_ref(context, builder, arrtype, ary._getvalue())
@@ -203,7 +203,7 @@ def codegen(context, builder, sig, args):
203203

204204
# clean up image buffer
205205
fnty = lir.FunctionType(lir.VoidType(), [lir.IntType(8).as_pointer()])
206-
fn_release = builder.module.get_or_insert_function(fnty, name="cv_delete_buf")
206+
fn_release = cgutils.get_or_insert_function(builder.module, fnty, name="cv_delete_buf")
207207
builder.call(fn_release, [data])
208208

209209
return impl_ret_new_ref(context, builder, sig.return_type, ary._getvalue())

sdc/datatypes/common_functions.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -455,35 +455,29 @@ def sdc_join_series_indexes_impl(left, right):
455455
return None
456456

457457

458-
@numba.njit
459458
def _sdc_pandas_format_percentiles(arr):
459+
pass
460+
461+
462+
@sdc_overload(_sdc_pandas_format_percentiles)
463+
def _sdc_pandas_format_percentiles_ovld(arr):
460464
""" Function converting float array of percentiles to a list of strings formatted
461465
the same as in pandas.io.formats.format.format_percentiles
462466
"""
463467

464-
percentiles_strs = []
465-
for percentile in arr:
466-
p_as_string = str(percentile * 100)
468+
dtype_precision = numpy.finfo(arr.dtype.key).precision
467469

468-
trim_index = len(p_as_string) - 1
469-
while trim_index >= 0:
470-
if p_as_string[trim_index] == '0':
471-
trim_index -= 1
472-
continue
473-
elif p_as_string[trim_index] == '.':
474-
break
475-
476-
trim_index += 1
477-
break
478-
479-
if trim_index < 0:
480-
p_as_string_trimmed = '0'
481-
else:
482-
p_as_string_trimmed = p_as_string[:trim_index]
470+
def _sdc_pandas_format_percentiles_impl(arr):
471+
percentiles_strs = []
472+
for percentile in arr:
473+
p_as_string = str(numpy.round(percentile * 100, dtype_precision - 1))
474+
p_as_string_trimmed = p_as_string.rstrip('0')
475+
p_as_string_trimmed = p_as_string_trimmed.rstrip('.')
476+
percentiles_strs.append(p_as_string_trimmed + '%')
483477

484-
percentiles_strs.append(p_as_string_trimmed + '%')
478+
return percentiles_strs
485479

486-
return percentiles_strs
480+
return _sdc_pandas_format_percentiles_impl
487481

488482

489483
def sdc_arrays_argsort(A, kind='quicksort'):

sdc/datatypes/hpat_pandas_series_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4429,7 +4429,7 @@ def hpat_pandas_series_describe_numeric_impl(self, percentiles=None, include=Non
44294429
sorted_percentiles = sorted(percentiles_list)
44304430

44314431
# check percentiles have correct values:
4432-
arr = numpy.asarray(sorted_percentiles)
4432+
arr = numpy.asarray(sorted_percentiles).astype(numpy.float64)
44334433
if len(numpy.unique(arr)) != len(arr):
44344434
raise ValueError("percentiles cannot contain duplicates")
44354435
if numpy.any(arr[(arr < 0) * (arr > 1)]):

sdc/distributed_lower.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@
8989
@lower_builtin(distributed_api.get_rank)
9090
def dist_get_rank(context, builder, sig, args):
9191
fnty = lir.FunctionType(lir.IntType(32), [])
92-
fn = builder.module.get_or_insert_function(fnty, name="hpat_dist_get_rank")
92+
fn = cgutils.get_or_insert_function(builder.module, fnty, name="hpat_dist_get_rank")
9393
return builder.call(fn, [])
9494

9595

9696
@lower_builtin(distributed_api.get_size)
9797
def dist_get_size(context, builder, sig, args):
9898
fnty = lir.FunctionType(lir.IntType(32), [])
99-
fn = builder.module.get_or_insert_function(fnty, name="hpat_dist_get_size")
99+
fn = cgutils.get_or_insert_function(builder.module, fnty, name="hpat_dist_get_size")
100100
return builder.call(fn, [])
101101

102102

@@ -113,7 +113,7 @@ def dist_get_start(context, builder, sig, args):
113113
def dist_get_end(context, builder, sig, args):
114114
fnty = lir.FunctionType(lir.IntType(64), [lir.IntType(64),
115115
lir.IntType(32), lir.IntType(32)])
116-
fn = builder.module.get_or_insert_function(fnty, name="hpat_dist_get_end")
116+
fn = cgutils.get_or_insert_function(builder.module, fnty, name="hpat_dist_get_end")
117117
return builder.call(fn, [args[0], args[1], args[2]])
118118

119119

@@ -163,7 +163,7 @@ def lower_dist_reduce(context, builder, sig, args):
163163

164164
fnty = lir.FunctionType(lir.VoidType(), [lir.IntType(8).as_pointer(),
165165
lir.IntType(8).as_pointer(), op_typ, lir.IntType(32)])
166-
fn = builder.module.get_or_insert_function(fnty, name="hpat_dist_reduce")
166+
fn = cgutils.get_or_insert_function(builder.module, fnty, name="hpat_dist_reduce")
167167
builder.call(fn, [in_ptr, out_ptr, args[1], builder.load(typ_arg)])
168168
# cast back to value type
169169
out_ptr = builder.bitcast(out_ptr, val_typ.as_pointer())
@@ -206,21 +206,21 @@ def lower_dist_arr_reduce(context, builder, sig, args):
206206
@lower_builtin(time.time)
207207
def dist_get_time(context, builder, sig, args):
208208
fnty = lir.FunctionType(lir.DoubleType(), [])
209-
fn = builder.module.get_or_insert_function(fnty, name="hpat_get_time")
209+
fn = cgutils.get_or_insert_function(builder.module, fnty, name="hpat_get_time")
210210
return builder.call(fn, [])
211211

212212

213213
@lower_builtin(distributed_api.dist_time)
214214
def dist_get_dist_time(context, builder, sig, args):
215215
fnty = lir.FunctionType(lir.DoubleType(), [])
216-
fn = builder.module.get_or_insert_function(fnty, name="hpat_dist_get_time")
216+
fn = cgutils.get_or_insert_function(builder.module, fnty, name="hpat_dist_get_time")
217217
return builder.call(fn, [])
218218

219219

220220
@lower_builtin(distributed_api.barrier)
221221
def dist_barrier(context, builder, sig, args):
222222
fnty = lir.FunctionType(lir.IntType(32), [])
223-
fn = builder.module.get_or_insert_function(fnty, name="hpat_barrier")
223+
fn = cgutils.get_or_insert_function(builder.module, fnty, name="hpat_barrier")
224224
return builder.call(fn, [])
225225

226226

@@ -285,7 +285,7 @@ def lower_dist_irecv(context, builder, sig, args):
285285
32), lir.IntType(32), lir.IntType(32),
286286
lir.IntType(1)]
287287
fnty = lir.FunctionType(mpi_req_llvm_type, arg_typs)
288-
fn = builder.module.get_or_insert_function(fnty, name="hpat_dist_irecv")
288+
fn = cgutils.get_or_insert_function(builder.module, fnty, name="hpat_dist_irecv")
289289
return builder.call(fn, call_args)
290290

291291
# array, size, pe, tag, cond
@@ -313,22 +313,22 @@ def lower_dist_isend(context, builder, sig, args):
313313
32), lir.IntType(32), lir.IntType(32),
314314
lir.IntType(1)]
315315
fnty = lir.FunctionType(mpi_req_llvm_type, arg_typs)
316-
fn = builder.module.get_or_insert_function(fnty, name="hpat_dist_isend")
316+
fn = cgutils.get_or_insert_function(builder.module, fnty, name="hpat_dist_isend")
317317
return builder.call(fn, call_args)
318318

319319

320320
@lower_builtin(distributed_api.wait, mpi_req_numba_type, types.boolean)
321321
def lower_dist_wait(context, builder, sig, args):
322322
fnty = lir.FunctionType(lir.IntType(32), [mpi_req_llvm_type, lir.IntType(1)])
323-
fn = builder.module.get_or_insert_function(fnty, name="hpat_dist_wait")
323+
fn = cgutils.get_or_insert_function(builder.module, fnty, name="hpat_dist_wait")
324324
return builder.call(fn, args)
325325

326326

327327
@lower_builtin(distributed_api.waitall, types.int32, req_array_type)
328328
def lower_dist_waitall(context, builder, sig, args):
329329
fnty = lir.FunctionType(lir.VoidType(),
330330
[lir.IntType(32), lir.IntType(8).as_pointer()])
331-
fn = builder.module.get_or_insert_function(fnty, name="hpat_dist_waitall")
331+
fn = cgutils.get_or_insert_function(builder.module, fnty, name="hpat_dist_waitall")
332332
builder.call(fn, args)
333333
return context.get_dummy_value()
334334

@@ -425,22 +425,22 @@ def lower_dist_allgather(context, builder, sig, args):
425425

426426
fnty = lir.FunctionType(lir.VoidType(), [lir.IntType(8).as_pointer(),
427427
lir.IntType(32), val_ptr.type, lir.IntType(32)])
428-
fn = builder.module.get_or_insert_function(fnty, name="allgather")
428+
fn = cgutils.get_or_insert_function(builder.module, fnty, name="allgather")
429429
builder.call(fn, call_args)
430430
return context.get_dummy_value()
431431

432432

433433
@lower_builtin(distributed_api.comm_req_alloc, types.int32)
434434
def lower_dist_comm_req_alloc(context, builder, sig, args):
435435
fnty = lir.FunctionType(lir.IntType(8).as_pointer(), [lir.IntType(32)])
436-
fn = builder.module.get_or_insert_function(fnty, name="comm_req_alloc")
436+
fn = cgutils.get_or_insert_function(builder.module, fnty, name="comm_req_alloc")
437437
return builder.call(fn, args)
438438

439439

440440
@lower_builtin(distributed_api.comm_req_dealloc, req_array_type)
441441
def lower_dist_comm_req_dealloc(context, builder, sig, args):
442442
fnty = lir.FunctionType(lir.VoidType(), [lir.IntType(8).as_pointer()])
443-
fn = builder.module.get_or_insert_function(fnty, name="comm_req_dealloc")
443+
fn = cgutils.get_or_insert_function(builder.module, fnty, name="comm_req_dealloc")
444444
builder.call(fn, args)
445445
return context.get_dummy_value()
446446

@@ -471,7 +471,7 @@ def setitem_req_array(context, builder, sig, args):
471471
# wraparound=False):
472472
# # get local index or -1 if out of bounds
473473
# fnty = lir.FunctionType(lir.IntType(64), [lir.IntType(64), lir.IntType(64), lir.IntType(64)])
474-
# fn = builder.module.get_or_insert_function(fnty, name="hpat_dist_get_item_pointer")
474+
# fn = cgutils.get_or_insert_function(builder.module, fnty, name="hpat_dist_get_item_pointer")
475475
# first_ind = builder.call(fn, [inds[0], start, count])
476476
# inds = tuple([first_ind, *inds[1:]])
477477
# # regular local pointer with new indices
@@ -481,7 +481,7 @@ def setitem_req_array(context, builder, sig, args):
481481
# not_inbound = builder.icmp_signed('==', first_ind, lir.Constant(lir.IntType(64), -1))
482482
# # get dummy pointer
483483
# dummy_fnty = lir.FunctionType(lir.IntType(8).as_pointer(), [])
484-
# dummy_fn = builder.module.get_or_insert_function(dummy_fnty, name="hpat_get_dummy_ptr")
484+
# dummy_fn = cgutils.get_or_insert_function(builder.module, dummy_fnty, name="hpat_get_dummy_ptr")
485485
# dummy_ptr = builder.bitcast(builder.call(dummy_fn, []), in_ptr.type)
486486
# with builder.if_then(not_inbound, likely=True):
487487
# builder.store(dummy_ptr, ret_ptr)
@@ -613,7 +613,7 @@ def generic(self, args, kws):
613613
@lower_builtin(hpat_finalize)
614614
def lower_hpat_finalize(context, builder, sig, args):
615615
fnty = lir.FunctionType(lir.IntType(32), [])
616-
fn = builder.module.get_or_insert_function(fnty, name="hpat_finalize")
616+
fn = cgutils.get_or_insert_function(builder.module, fnty, name="hpat_finalize")
617617
return builder.call(fn, args)
618618

619619

sdc/extensions/indexes/int64_index_ext.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
from sdc.datatypes.indexes import *
4242
from sdc.utilities.sdc_typing_utils import SDCLimitation
43-
from sdc.utilities.utils import sdc_overload, sdc_overload_attribute, sdc_overload_method, BooleanLiteral
43+
from sdc.utilities.utils import sdc_overload, sdc_overload_attribute, sdc_overload_method
4444
from sdc.utilities.sdc_typing_utils import (
4545
TypeChecker,
4646
check_signed_integer,
@@ -388,10 +388,12 @@ def pd_int64_index_is_overload(context, builder, sig, args):
388388
if ty_lhs != ty_rhs:
389389
return cgutils.false_bit
390390

391+
# llvmlite passes LiteralStructs into functions as separate fields
392+
# and there's no way to get pointer to original struct (where it's allocated)
393+
# other than walk through chain of instruction operands to alloca instruction
394+
# so just check if the instructions themselves match exactly
391395
lhs, rhs = args
392-
lhs_ptr = builder.ptrtoint(lhs.operands[0], cgutils.intp_t)
393-
rhs_ptr = builder.ptrtoint(rhs.operands[0], cgutils.intp_t)
394-
return builder.icmp_signed('==', lhs_ptr, rhs_ptr)
396+
return context.get_constant(types.bool_, lhs == rhs)
395397

396398

397399
@lower_builtin('getiter', Int64IndexType)
@@ -543,7 +545,7 @@ def pd_int64_index_join_overload(self, other, how, level=None, return_indexers=F
543545
if not (isinstance(level, (types.Omitted, types.NoneType)) or level is None):
544546
ty_checker.raise_exc(level, 'None', 'level')
545547

546-
if not (isinstance(return_indexers, (types.Omitted, BooleanLiteral)) or return_indexers is False):
548+
if not (isinstance(return_indexers, (types.Omitted, types.BooleanLiteral)) or return_indexers is False):
547549
ty_checker.raise_exc(return_indexers, 'boolean', 'return_indexers')
548550

549551
if not (isinstance(sort, (types.Omitted, types.Boolean)) or sort is False):

sdc/extensions/indexes/multi_index_ext.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
from sdc.datatypes.indexes import *
4444
from sdc.utilities.sdc_typing_utils import SDCLimitation
45-
from sdc.utilities.utils import sdc_overload, sdc_overload_attribute, sdc_overload_method, BooleanLiteral
45+
from sdc.utilities.utils import sdc_overload, sdc_overload_attribute, sdc_overload_method
4646
from sdc.utilities.sdc_typing_utils import (
4747
TypeChecker,
4848
sdc_pandas_index_types,
@@ -759,10 +759,9 @@ def pd_multi_index_is_overload(context, builder, sig, args):
759759
if ty_lhs != ty_rhs:
760760
return cgutils.false_bit
761761

762+
# similar to Int64Index (compare instructions building index structs)
762763
lhs, rhs = args
763-
lhs_ptr = builder.ptrtoint(lhs.operands[0], cgutils.intp_t)
764-
rhs_ptr = builder.ptrtoint(rhs.operands[0], cgutils.intp_t)
765-
return builder.icmp_signed('==', lhs_ptr, rhs_ptr)
764+
return context.get_constant(types.bool_, lhs == rhs)
766765

767766

768767
@lower_builtin('getiter', MultiIndexType)

sdc/extensions/indexes/positional_index_ext.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from sdc.datatypes.indexes import PositionalIndexType, RangeIndexType
4141
from sdc.datatypes.indexes.range_index_type import RangeIndexDataType
4242
from sdc.utilities.sdc_typing_utils import SDCLimitation
43-
from sdc.utilities.utils import sdc_overload, sdc_overload_attribute, sdc_overload_method, BooleanLiteral
43+
from sdc.utilities.utils import sdc_overload, sdc_overload_attribute, sdc_overload_method
4444
from sdc.extensions.indexes.range_index_ext import box_range_index, unbox_range_index
4545
from sdc.utilities.sdc_typing_utils import (
4646
TypeChecker,
@@ -300,10 +300,9 @@ def pd_positional_index_is_overload(context, builder, sig, args):
300300
if ty_lhs != ty_rhs:
301301
return cgutils.false_bit
302302

303+
# similar to Int64Index (compare instructions building index structs)
303304
lhs, rhs = args
304-
lhs_ptr = builder.ptrtoint(lhs.operands[0], cgutils.intp_t)
305-
rhs_ptr = builder.ptrtoint(rhs.operands[0], cgutils.intp_t)
306-
return builder.icmp_signed('==', lhs_ptr, rhs_ptr)
305+
return context.get_constant(types.bool_, lhs == rhs)
307306

308307

309308
@lower_builtin('getiter', PositionalIndexType)
@@ -433,7 +432,7 @@ def pd_positional_index_join_overload(self, other, how, level=None, return_index
433432
if not (isinstance(level, (types.Omitted, types.NoneType)) or level is None):
434433
ty_checker.raise_exc(level, 'None', 'level')
435434

436-
if not (isinstance(return_indexers, (types.Omitted, BooleanLiteral)) or return_indexers is False):
435+
if not (isinstance(return_indexers, (types.Omitted, types.BooleanLiteral)) or return_indexers is False):
437436
ty_checker.raise_exc(return_indexers, 'boolean', 'return_indexers')
438437

439438
if not (isinstance(sort, (types.Omitted, types.Boolean)) or sort is False):

0 commit comments

Comments
 (0)