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

Commit 47f94fe

Browse files
PokhodenkoSAshssf
authored andcommitted
Replace sdc.jit with self.jit for using numba.jit for new pipeline (#351)
1 parent 4683b6e commit 47f94fe

13 files changed

Lines changed: 393 additions & 393 deletions

sdc/tests/test_basic.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ class BaseTest(TestCase):
6060

6161
def __init__(self, *args, **kwargs):
6262
super().__init__(*args, **kwargs)
63-
self.rank = sdc.jit(lambda: sdc.distributed_api.get_rank())()
64-
self.num_ranks = sdc.jit(lambda: sdc.distributed_api.get_size())()
63+
self.rank = self.jit(lambda: sdc.distributed_api.get_rank())()
64+
self.num_ranks = self.jit(lambda: sdc.distributed_api.get_size())()
6565

6666
def _rank_begin(self, arr_len):
67-
f = sdc.jit(
67+
f = self.jit(
6868
lambda arr_len, num_ranks, rank: sdc.distributed_api.get_start(
6969
arr_len, np.int32(num_ranks), np.int32(rank)))
7070
return f(arr_len, self.num_ranks, self.rank)
7171

7272
def _rank_end(self, arr_len):
73-
f = sdc.jit(
73+
f = self.jit(
7474
lambda arr_len, num_ranks, rank: sdc.distributed_api.get_end(
7575
arr_len, np.int32(num_ranks), np.int32(rank)))
7676
return f(arr_len, self.num_ranks, self.rank)
@@ -93,7 +93,7 @@ def test_impl(N):
9393
C = A[B]
9494
return C.sum()
9595

96-
hpat_func = sdc.jit(test_impl)
96+
hpat_func = self.jit(test_impl)
9797
n = 128
9898
np.testing.assert_allclose(hpat_func(n), test_impl(n))
9999
self.assertEqual(count_array_REPs(), 0)
@@ -105,7 +105,7 @@ def test_impl(N):
105105
A[0] = 30
106106
return A.sum()
107107

108-
hpat_func = sdc.jit(test_impl)
108+
hpat_func = self.jit(test_impl)
109109
n = 128
110110
np.testing.assert_allclose(hpat_func(n), test_impl(n))
111111
self.assertEqual(count_array_REPs(), 0)
@@ -117,7 +117,7 @@ def test_impl(N):
117117
A[0:4] = 30
118118
return A.sum()
119119

120-
hpat_func = sdc.jit(test_impl)
120+
hpat_func = self.jit(test_impl)
121121
n = 128
122122
np.testing.assert_allclose(hpat_func(n), test_impl(n))
123123
self.assertEqual(count_array_REPs(), 0)
@@ -127,7 +127,7 @@ def test_astype(self):
127127
def test_impl(N):
128128
return np.ones(N).astype(np.int32).sum()
129129

130-
hpat_func = sdc.jit(test_impl)
130+
hpat_func = self.jit(test_impl)
131131
n = 128
132132
np.testing.assert_allclose(hpat_func(n), test_impl(n))
133133
self.assertEqual(count_array_REPs(), 0)
@@ -137,7 +137,7 @@ def test_shape(self):
137137
def test_impl(N):
138138
return np.ones(N).shape[0]
139139

140-
hpat_func = sdc.jit(test_impl)
140+
hpat_func = self.jit(test_impl)
141141
n = 128
142142
np.testing.assert_allclose(hpat_func(n), test_impl(n))
143143
self.assertEqual(count_array_REPs(), 0)
@@ -146,7 +146,7 @@ def test_impl(N):
146146
# def test_impl(N):
147147
# return np.ones((N, 3, 4)).shape
148148
#
149-
# hpat_func = sdc.jit(test_impl)
149+
# hpat_func = self.jit(test_impl)
150150
# n = 128
151151
# np.testing.assert_allclose(hpat_func(n), test_impl(n))
152152
# self.assertEqual(count_array_REPs(), 0)
@@ -159,7 +159,7 @@ def test_impl(N):
159159
B += A
160160
return B.sum()
161161

162-
hpat_func = sdc.jit(test_impl)
162+
hpat_func = self.jit(test_impl)
163163
n = 128
164164
np.testing.assert_allclose(hpat_func(n), test_impl(n))
165165
self.assertEqual(count_array_REPs(), 0)
@@ -172,7 +172,7 @@ def test_impl(N):
172172
C = A[B, 2]
173173
return C.sum()
174174

175-
hpat_func = sdc.jit(test_impl)
175+
hpat_func = self.jit(test_impl)
176176
n = 128
177177
np.testing.assert_allclose(hpat_func(n), test_impl(n))
178178
self.assertEqual(count_array_REPs(), 0)
@@ -184,7 +184,7 @@ def test_impl(N):
184184
X[:, 3] = (X[:, 3]) / (np.max(X[:, 3]) - np.min(X[:, 3]))
185185
return X.sum()
186186

187-
hpat_func = sdc.jit(test_impl)
187+
hpat_func = self.jit(test_impl)
188188
n = 128
189189
np.testing.assert_allclose(hpat_func(n), test_impl(n))
190190
self.assertEqual(count_array_REPs(), 0)
@@ -196,7 +196,7 @@ def test_impl(N):
196196
B = A[::7]
197197
return B.sum()
198198

199-
hpat_func = sdc.jit(test_impl)
199+
hpat_func = self.jit(test_impl)
200200
n = 128
201201
np.testing.assert_allclose(hpat_func(n), test_impl(n))
202202
self.assertEqual(count_array_REPs(), 0)
@@ -208,26 +208,26 @@ def test_assert(self):
208208
def g(a):
209209
assert a == 0
210210

211-
hpat_g = sdc.jit(g)
211+
hpat_g = self.jit(g)
212212

213213
def f():
214214
hpat_g(0)
215215

216-
hpat_f = sdc.jit(f)
216+
hpat_f = self.jit(f)
217217
hpat_f()
218218

219219
@skip_numba_jit
220220
def test_inline_locals(self):
221221
# make sure locals in inlined function works
222-
@sdc.jit(locals={'B': types.float64[:]})
222+
@self.jit(locals={'B': types.float64[:]})
223223
def g(S):
224224
B = pd.to_numeric(S, errors='coerce')
225225
return B
226226

227227
def f():
228228
return g(pd.Series(['1.2']))
229229

230-
pd.testing.assert_series_equal(sdc.jit(f)(), f())
230+
pd.testing.assert_series_equal(self.jit(f)(), f())
231231

232232
def test_reduce(self):
233233
import sys
@@ -247,7 +247,7 @@ def test_reduce(self):
247247
exec(func_text, {'np': np}, loc_vars)
248248
test_impl = loc_vars['f']
249249

250-
hpat_func = sdc.jit(test_impl)
250+
hpat_func = self.jit(test_impl)
251251
n = 21 # XXX arange() on float32 has overflow issues on large n
252252
np.testing.assert_almost_equal(hpat_func(n), test_impl(n))
253253
self.assertEqual(count_array_REPs(), 0)
@@ -271,7 +271,7 @@ def test_reduce2(self):
271271
exec(func_text, {'np': np}, loc_vars)
272272
test_impl = loc_vars['f']
273273

274-
hpat_func = sdc.jit(locals={'A:input': 'distributed'})(test_impl)
274+
hpat_func = self.jit(locals={'A:input': 'distributed'})(test_impl)
275275
n = 21
276276
start, end = get_start_end(n)
277277
np.random.seed(0)
@@ -300,7 +300,7 @@ def test_reduce_filter1(self):
300300
exec(func_text, {'np': np}, loc_vars)
301301
test_impl = loc_vars['f']
302302

303-
hpat_func = sdc.jit(locals={'A:input': 'distributed'})(test_impl)
303+
hpat_func = self.jit(locals={'A:input': 'distributed'})(test_impl)
304304
n = 21
305305
start, end = get_start_end(n)
306306
np.random.seed(0)
@@ -327,7 +327,7 @@ def test_array_reduce(self):
327327
exec(func_text, {'np': np, 'numba': numba}, loc_vars)
328328
test_impl = loc_vars['f']
329329

330-
hpat_func = sdc.jit(test_impl)
330+
hpat_func = self.jit(test_impl)
331331
n = 128
332332
np.testing.assert_allclose(hpat_func(n), test_impl(n))
333333
self.assertEqual(count_array_OneDs(), 0)
@@ -340,9 +340,9 @@ def test_impl(N):
340340
A = np.arange(N)
341341
return A
342342

343-
hpat_func = sdc.jit(locals={'A:return': 'distributed'})(test_impl)
343+
hpat_func = self.jit(locals={'A:return': 'distributed'})(test_impl)
344344
n = 128
345-
dist_sum = sdc.jit(
345+
dist_sum = self.jit(
346346
lambda a: sdc.distributed_api.dist_reduce(
347347
a, np.int32(sdc.distributed_api.Reduce_Type.Sum.value)))
348348
dist_sum(1) # run to compile
@@ -359,10 +359,10 @@ def test_impl(N):
359359
B = np.arange(N) + 1.5
360360
return A, B
361361

362-
hpat_func = sdc.jit(locals={'A:return': 'distributed',
362+
hpat_func = self.jit(locals={'A:return': 'distributed',
363363
'B:return': 'distributed'})(test_impl)
364364
n = 128
365-
dist_sum = sdc.jit(
365+
dist_sum = self.jit(
366366
lambda a: sdc.distributed_api.dist_reduce(
367367
a, np.int32(sdc.distributed_api.Reduce_Type.Sum.value)))
368368
dist_sum(1.0) # run to compile
@@ -376,7 +376,7 @@ def test_dist_input(self):
376376
def test_impl(A):
377377
return len(A)
378378

379-
hpat_func = sdc.jit(distributed=['A'])(test_impl)
379+
hpat_func = self.jit(distributed=['A'])(test_impl)
380380
n = 128
381381
arr = np.ones(n)
382382
np.testing.assert_allclose(hpat_func(arr) / self.num_ranks, test_impl(arr))
@@ -393,7 +393,7 @@ def test_impl(N):
393393

394394
try:
395395
sdc.distributed_analysis.auto_rebalance = True
396-
hpat_func = sdc.jit(test_impl)
396+
hpat_func = self.jit(test_impl)
397397
n = 128
398398
np.testing.assert_allclose(hpat_func(n), test_impl(n))
399399
self.assertEqual(count_array_OneDs(), 3)
@@ -414,7 +414,7 @@ def test_impl(N):
414414

415415
try:
416416
sdc.distributed_analysis.auto_rebalance = True
417-
hpat_func = sdc.jit(test_impl)
417+
hpat_func = self.jit(test_impl)
418418
n = 128
419419
np.testing.assert_allclose(hpat_func(n), test_impl(n))
420420
self.assertEqual(count_array_OneDs(), 4)
@@ -430,7 +430,7 @@ def test_impl(n):
430430
C = A.transpose(0, 2, 1)
431431
return B.sum() + C.sum()
432432

433-
hpat_func = sdc.jit(test_impl)
433+
hpat_func = self.jit(test_impl)
434434
n = 128
435435
np.testing.assert_allclose(hpat_func(n), test_impl(n))
436436
self.assertEqual(count_array_REPs(), 0)
@@ -472,7 +472,7 @@ def python_one_dim(arr_len, r):
472472
# details please see https://github.com/numba/numba/issues/2782.
473473
r = self._follow_cpython(get_np_state_ptr())
474474

475-
hpat_func1 = sdc.jit(locals={'A:return': 'distributed',
475+
hpat_func1 = self.jit(locals={'A:return': 'distributed',
476476
'B:return': 'distributed'})(test_one_dim)
477477

478478
# Test one-dimensional array indexing.
@@ -502,7 +502,7 @@ def python_two_dim(arr_len, r):
502502
A, B = A[P], B[P]
503503
return A, B
504504

505-
hpat_func2 = sdc.jit(locals={'A:return': 'distributed',
505+
hpat_func2 = self.jit(locals={'A:return': 'distributed',
506506
'B:return': 'distributed'})(test_two_dim)
507507

508508
for arr_len in [18, 66, 128]:
@@ -521,7 +521,7 @@ def test_rhs(arr_len):
521521
C = A[P]
522522
return A, B, C
523523

524-
hpat_func3 = sdc.jit(locals={'A:return': 'distributed',
524+
hpat_func3 = self.jit(locals={'A:return': 'distributed',
525525
'B:return': 'distributed',
526526
'C:return': 'distributed'})(test_rhs)
527527

sdc/tests/test_d4p.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ def prdct_impl(n, d, model):
6666
)
6767
return algo.compute(w, model)
6868

69-
train_hpat = sdc.jit(train_impl)
70-
prdct_hpat = sdc.jit(prdct_impl)
69+
train_hpat = self.jit(train_impl)
70+
prdct_hpat = self.jit(prdct_impl)
7171
n = 11
7272
d = 4
7373
pred_impl = prdct_impl(n, d, train_impl(n, d).model).prediction

0 commit comments

Comments
 (0)