Skip to content

Commit 8e926ab

Browse files
committed
fix: correctly interpret typetracer array for cuda backend
1 parent 1148b95 commit 8e926ab

File tree

2 files changed

+42
-21
lines changed

2 files changed

+42
-21
lines changed

src/awkward/contents/regulararray.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,6 @@ def _carry(self, carry: Index, allow_lazy: bool) -> Content:
358358
nextcarry = ak.index.Index64.empty(
359359
where.shape[0] * self._size, self._backend.index_nplike
360360
)
361-
362361
assert nextcarry.nplike is self._backend.index_nplike
363362
self._maybe_index_error(
364363
self._backend[
@@ -472,6 +471,8 @@ def _getitem_next(
472471
nexthead, nexttail = ak._slicing.head_tail(tail)
473472
nextcarry = ak.index.Index64.empty(self._length, index_nplike)
474473
assert nextcarry.nplike is index_nplike
474+
if ak.backend(nextcarry.data) == "cuda":
475+
head = int(ak.to_backend(head, backend=self._backend)[0])
475476
self._maybe_index_error(
476477
self._backend[
477478
"awkward_RegularArray_getitem_next_at", nextcarry.dtype.type

tests-cuda/test_3136_cuda_reducers.py

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def prod(xs):
2424
return out
2525

2626

27-
def test_sumprod_types():
27+
def test_0115_generic_reducer_operation_sumprod_types():
2828
array = np.array([[True, False, False], [True, False, False]])
2929
content2 = ak.contents.NumpyArray(array.reshape(-1))
3030
offsets3 = ak.index.Index64(np.array([0, 3, 3, 5, 6], dtype=np.int64))
@@ -41,7 +41,7 @@ def test_sumprod_types():
4141
del depth1
4242

4343

44-
def test_sumprod_types_1():
44+
def test_0115_generic_reducer_operation_sumprod_types_1():
4545
array = np.array([[0, 1, 2], [3, 4, 5]], dtype=np.int8)
4646
content2 = ak.contents.NumpyArray(array.reshape(-1))
4747
offsets3 = ak.index.Index64(np.array([0, 3, 3, 5, 6], dtype=np.int64))
@@ -66,7 +66,7 @@ def test_sumprod_types_1():
6666
del depth1
6767

6868

69-
def test_sumprod_types_2():
69+
def test_0115_generic_reducer_operation_sumprod_types_2():
7070
array = np.array([[0, 1, 2], [3, 4, 5]], dtype=np.uint8)
7171
content2 = ak.contents.NumpyArray(array.reshape(-1))
7272
offsets3 = ak.index.Index64(np.array([0, 3, 3, 5, 6], dtype=np.int64))
@@ -91,7 +91,7 @@ def test_sumprod_types_2():
9191
del depth1
9292

9393

94-
def test_sumprod_types_3():
94+
def test_0115_generic_reducer_operation_sumprod_types_3():
9595
array = np.array([[0, 1, 2], [3, 4, 5]], dtype=np.int16)
9696
content2 = ak.contents.NumpyArray(array.reshape(-1))
9797
offsets3 = ak.index.Index64(np.array([0, 3, 3, 5, 6], dtype=np.int64))
@@ -116,7 +116,7 @@ def test_sumprod_types_3():
116116
del depth1
117117

118118

119-
def test_sumprod_types_4():
119+
def test_0115_generic_reducer_operation_sumprod_types_4():
120120
array = np.array([[0, 1, 2], [3, 4, 5]], dtype=np.uint16)
121121
content2 = ak.contents.NumpyArray(array.reshape(-1))
122122
offsets3 = ak.index.Index64(np.array([0, 3, 3, 5, 6], dtype=np.int64))
@@ -140,7 +140,7 @@ def test_sumprod_types_4():
140140
)
141141

142142

143-
def test_sumprod_types_5():
143+
def test_0115_generic_reducer_operation_sumprod_types_5():
144144
array = np.array([[0, 1, 2], [3, 4, 5]], dtype=np.int32)
145145
content2 = ak.contents.NumpyArray(array.reshape(-1))
146146
offsets3 = ak.index.Index64(np.array([0, 3, 3, 5, 6], dtype=np.int64))
@@ -165,7 +165,7 @@ def test_sumprod_types_5():
165165
del depth1
166166

167167

168-
def test_sumprod_types_6():
168+
def test_0115_generic_reducer_operation_sumprod_types_6():
169169
array = np.array([[0, 1, 2], [3, 4, 5]], dtype=np.uint32)
170170
content2 = ak.contents.NumpyArray(array.reshape(-1))
171171
offsets3 = ak.index.Index64(np.array([0, 3, 3, 5, 6], dtype=np.int64))
@@ -190,7 +190,7 @@ def test_sumprod_types_6():
190190
del depth1
191191

192192

193-
def test_sumprod_types_7():
193+
def test_0115_generic_reducer_operation_sumprod_types_7():
194194
array = np.array([[0, 1, 2], [3, 4, 5]], dtype=np.int64)
195195
content2 = ak.contents.NumpyArray(array.reshape(-1))
196196
offsets3 = ak.index.Index64(np.array([0, 3, 3, 5, 6], dtype=np.int64))
@@ -215,7 +215,7 @@ def test_sumprod_types_7():
215215
del depth1
216216

217217

218-
def test_sumprod_types_8():
218+
def test_0115_generic_reducer_operation_sumprod_types_8():
219219
array = np.array([[0, 1, 2], [3, 4, 5]], dtype=np.uint64)
220220
content2 = ak.contents.NumpyArray(array.reshape(-1))
221221
offsets3 = ak.index.Index64(np.array([0, 3, 3, 5, 6], dtype=np.int64))
@@ -240,7 +240,7 @@ def test_sumprod_types_8():
240240
del depth1
241241

242242

243-
def test_sumprod_types_FIXME():
243+
def test_0115_generic_reducer_operation_sumprod_types_FIXME():
244244
array = np.array([[True, False, False], [True, False, False]])
245245
content2 = ak.contents.NumpyArray(array.reshape(-1))
246246
offsets3 = ak.index.Index64(np.array([0, 3, 3, 5, 6], dtype=np.int64))
@@ -258,7 +258,7 @@ def test_sumprod_types_FIXME():
258258
del depth1
259259

260260

261-
def test_sum():
261+
def test_2020_reduce_axis_none_sum():
262262
array = ak.Array(
263263
[[0, 2, 3.0], [4, 5, 6, 7, 8], [], [9, 8, None], [10, 1], []], backend="cuda"
264264
)
@@ -277,7 +277,7 @@ def test_sum():
277277
del array
278278

279279

280-
def test_prod():
280+
def test_2020_reduce_axis_none_prod():
281281
array = ak.Array(
282282
[[0, 2, 3.0], [4, 5, 6, 7, 8], [], [9, 8, None], [10, 1], []], backend="cuda"
283283
)
@@ -303,7 +303,7 @@ def test_prod():
303303
del array
304304

305305

306-
def test_min():
306+
def test_2020_reduce_axis_none_min():
307307
array = ak.Array(
308308
[[0, 2, 3.0], [4, 5, 6, 7, 8], [], [9, 8, None], [10, 1], []], backend="cuda"
309309
)
@@ -334,7 +334,7 @@ def test_min():
334334
del array
335335

336336

337-
def test_max():
337+
def test_2020_reduce_axis_none_max():
338338
array = ak.Array(
339339
[[0, 2, 3.0], [4, 5, 6, 7, 8], [], [9, 8, None], [10, 1], []], backend="cuda"
340340
)
@@ -365,7 +365,7 @@ def test_max():
365365
del array
366366

367367

368-
def test_count():
368+
def test_2020_reduce_axis_none_count():
369369
array = ak.Array(
370370
[[0, 2, 3.0], [4, 5, 6, 7, 8], [], [9, 8, None], [10, 1], []], backend="cuda"
371371
)
@@ -391,7 +391,7 @@ def test_count():
391391
del array
392392

393393

394-
def test_count_nonzero():
394+
def test_2020_reduce_axis_none_count_nonzero():
395395
array = ak.Array(
396396
[[0, 2, 3.0], [4, 5, 6, 7, 8], [], [9, 8, None], [10, 1], []], backend="cuda"
397397
)
@@ -417,7 +417,7 @@ def test_count_nonzero():
417417
del array
418418

419419

420-
def test_std_no_mask_axis_none():
420+
def test_2020_reduce_axis_none_std_no_mask_axis_none():
421421
array = ak.Array(
422422
[[0, 2, 3.0], [4, 5, 6, 7, 8], [], [9, 8, None], [10, 1], []], backend="cuda"
423423
)
@@ -427,9 +427,29 @@ def test_std_no_mask_axis_none():
427427
)
428428
assert ak.almost_equal(out1, out2)
429429

430-
# FIXME:
431-
# out3 = ak.std(array[2], axis=None, mask_identity=True)
432-
# assert out3 is None
430+
out3 = ak.std(array[2], axis=None, mask_identity=True)
431+
assert out3 is None
433432
del array
434433
del out1
435434
del out2
435+
436+
437+
def test_2020_reduce_axis_none_std():
438+
array = ak.Array(
439+
[[0, 2, 3.0], [4, 5, 6, 7, 8], [], [9, 8, None], [10, 1], []], backend="cuda"
440+
)
441+
cpt.assert_allclose(ak.std(array, axis=None), 3.139134700306227)
442+
cpt.assert_allclose(
443+
ak.std(array, axis=None, keepdims=True, mask_identity=False),
444+
ak.to_regular([[3.139134700306227]]),
445+
)
446+
cpt.assert_allclose(
447+
ak.std(array, axis=None, keepdims=True, mask_identity=True),
448+
ak.to_regular(
449+
ak.Array([[3.139134700306227]], backend="cuda").mask[
450+
ak.Array([[True]], backend="cuda")
451+
]
452+
),
453+
)
454+
assert np.isnan(ak.std(array[2], axis=None, mask_identity=False))
455+
del array

0 commit comments

Comments
 (0)