Skip to content

Commit b4d0d74

Browse files
committed
Update manipulation_tests/test_join.py
1 parent 6ad6d5a commit b4d0d74

File tree

1 file changed

+106
-41
lines changed

1 file changed

+106
-41
lines changed

dpnp/tests/third_party/cupy/manipulation_tests/test_join.py

Lines changed: 106 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313

1414
class TestJoin:
15+
1516
@testing.for_all_dtypes(name="dtype1")
1617
@testing.for_all_dtypes(name="dtype2")
1718
@testing.numpy_cupy_array_equal(type_check=has_support_aspect64())
@@ -94,6 +95,20 @@ def test_concatenate_large_5(self, xp, dtype):
9495
b = testing.shaped_reverse_arange((2, 3, 4), xp, "i")
9596
return xp.concatenate((a, b) * 10, axis=-1)
9697

98+
@pytest.mark.skip("multi GPU is not supported")
99+
@testing.multi_gpu(2)
100+
def test_concatenate_large_different_devices(self):
101+
arrs = []
102+
for i in range(10):
103+
with cuda.Device(i % 2):
104+
arrs.append(cupy.empty((2, 3, 4)))
105+
if cuda.runtime.deviceCanAccessPeer(0, 1) == 1:
106+
with pytest.warns(cupy._util.PerformanceWarning):
107+
cupy.concatenate(arrs)
108+
else:
109+
with pytest.raises(ValueError):
110+
cupy.concatenate(arrs)
111+
97112
@testing.for_all_dtypes(name="dtype")
98113
@testing.numpy_cupy_array_equal()
99114
def test_concatenate_f_contiguous(self, xp, dtype):
@@ -112,14 +127,12 @@ def test_concatenate_large_f_contiguous(self, xp, dtype):
112127
e = testing.shaped_arange((2, 3, 2), xp, dtype)
113128
return xp.concatenate((a, b, c, d, e) * 2, axis=-1)
114129

115-
@pytest.mark.skip(reason="lead to crash due to reported issue in OCL RT")
116130
@testing.numpy_cupy_array_equal(type_check=has_support_aspect64())
117131
def test_concatenate_many_multi_dtype(self, xp):
118132
a = testing.shaped_arange((2, 1), xp, "i")
119133
b = testing.shaped_arange((2, 1), xp, "f")
120134
return xp.concatenate((a, b) * 1024, axis=1)
121135

122-
@pytest.mark.skip("dpnp.int8 is not supported yet")
123136
@testing.slow
124137
def test_concatenate_32bit_boundary(self):
125138
a = cupy.zeros((2**30,), dtype=cupy.int8)
@@ -129,7 +142,7 @@ def test_concatenate_32bit_boundary(self):
129142
del b
130143
del ret
131144
# Free huge memory for slow test
132-
cupy.get_default_memory_pool().free_all_blocks()
145+
# cupy.get_default_memory_pool().free_all_blocks()
133146

134147
def test_concatenate_wrong_ndim(self):
135148
a = cupy.empty((2, 3))
@@ -156,36 +169,40 @@ def test_concatenate_out(self, xp, dtype):
156169

157170
@testing.numpy_cupy_array_equal()
158171
def test_concatenate_out_same_kind(self, xp):
159-
a = testing.shaped_arange((3, 4), xp, xp.float32)
160-
b = testing.shaped_reverse_arange((3, 4), xp, xp.float32)
161-
c = testing.shaped_arange((3, 4), xp, xp.float32)
172+
dtype = cupy.default_float_type()
173+
a = testing.shaped_arange((3, 4), xp, dtype)
174+
b = testing.shaped_reverse_arange((3, 4), xp, dtype)
175+
c = testing.shaped_arange((3, 4), xp, dtype)
162176
out = xp.zeros((3, 12), dtype=xp.float32)
163177
xp.concatenate((a, b, c), axis=1, out=out)
164178
return out
165179

166180
def test_concatenate_out_invalid_shape(self):
167181
for xp in (numpy, cupy):
168-
a = testing.shaped_arange((3, 4), xp, xp.float32)
169-
b = testing.shaped_reverse_arange((3, 4), xp, xp.float32)
170-
c = testing.shaped_arange((3, 4), xp, xp.float32)
171-
out = xp.zeros((4, 10), dtype=xp.float32)
182+
dtype = cupy.default_float_type()
183+
a = testing.shaped_arange((3, 4), xp, dtype)
184+
b = testing.shaped_reverse_arange((3, 4), xp, dtype)
185+
c = testing.shaped_arange((3, 4), xp, dtype)
186+
out = xp.zeros((4, 10), dtype=dtype)
172187
with pytest.raises(ValueError):
173188
xp.concatenate((a, b, c), axis=1, out=out)
174189

175190
def test_concatenate_out_invalid_shape_2(self):
176191
for xp in (numpy, cupy):
177-
a = testing.shaped_arange((3, 4), xp, xp.float32)
178-
b = testing.shaped_reverse_arange((3, 4), xp, xp.float32)
179-
c = testing.shaped_arange((3, 4), xp, xp.float32)
180-
out = xp.zeros((2, 2, 10), dtype=xp.float32)
192+
dtype = cupy.default_float_type()
193+
a = testing.shaped_arange((3, 4), xp, dtype)
194+
b = testing.shaped_reverse_arange((3, 4), xp, dtype)
195+
c = testing.shaped_arange((3, 4), xp, dtype)
196+
out = xp.zeros((2, 2, 10), dtype=dtype)
181197
with pytest.raises(ValueError):
182198
xp.concatenate((a, b, c), axis=1, out=out)
183199

184200
def test_concatenate_out_invalid_dtype(self):
185201
for xp in (numpy, cupy):
186-
a = testing.shaped_arange((3, 4), xp, xp.float32)
187-
b = testing.shaped_reverse_arange((3, 4), xp, xp.float32)
188-
c = testing.shaped_arange((3, 4), xp, xp.float32)
202+
dtype = cupy.default_float_type()
203+
a = testing.shaped_arange((3, 4), xp, dtype)
204+
b = testing.shaped_reverse_arange((3, 4), xp, dtype)
205+
c = testing.shaped_arange((3, 4), xp, dtype)
189206
out = xp.zeros((3, 12), dtype=xp.int64)
190207
with pytest.raises(TypeError):
191208
xp.concatenate((a, b, c), axis=1, out=out)
@@ -216,19 +233,31 @@ def test_concatenate_dtype(self, xp, dtype1, dtype2):
216233
@testing.with_requires("numpy>=1.20.0")
217234
def test_concatenate_dtype_invalid_out(self):
218235
for xp in (numpy, cupy):
219-
a = testing.shaped_arange((3, 4), xp, xp.float32)
220-
b = testing.shaped_arange((3, 4), xp, xp.float32)
236+
dtype = cupy.default_float_type()
237+
a = testing.shaped_arange((3, 4), xp, dtype)
238+
b = testing.shaped_arange((3, 4), xp, dtype)
221239
out = xp.zeros((6, 4), dtype=xp.int64)
222240
with pytest.raises(TypeError):
223241
xp.concatenate((a, b), out=out, dtype=xp.int64)
224242

225243
@testing.with_requires("numpy>=1.20.0")
226-
@testing.for_castings()
244+
# @pytest.mark.filterwarnings("error::cupy.exceptions.ComplexWarning")
245+
@pytest.mark.parametrize(
246+
"casting",
247+
[
248+
"no",
249+
"equiv",
250+
"safe",
251+
"same_kind",
252+
"unsafe",
253+
],
254+
)
227255
@testing.for_all_dtypes_combination(names=["dtype1", "dtype2"])
228256
@testing.numpy_cupy_array_equal(accept_error=(TypeError, ComplexWarning))
229257
def test_concatenate_casting(self, xp, dtype1, dtype2, casting):
230258
a = testing.shaped_arange((3, 4), xp, dtype1)
231259
b = testing.shaped_arange((3, 4), xp, dtype1)
260+
# may raise TypeError or ComplexWarning
232261
return xp.concatenate((a, b), dtype=dtype2, casting=casting)
233262

234263
@testing.numpy_cupy_array_equal()
@@ -282,7 +311,17 @@ def test_hstack_dtype(self, xp, dtype1, dtype2):
282311
return xp.hstack((a, b), dtype=dtype2)
283312

284313
@testing.with_requires("numpy>=1.24.0")
285-
@testing.for_castings()
314+
# @pytest.mark.filterwarnings("error::cupy.exceptions.ComplexWarning")
315+
@pytest.mark.parametrize(
316+
"casting",
317+
[
318+
"no",
319+
"equiv",
320+
"safe",
321+
"same_kind",
322+
"unsafe",
323+
],
324+
)
286325
@testing.for_all_dtypes_combination(names=["dtype1", "dtype2"])
287326
@testing.numpy_cupy_array_equal(accept_error=(TypeError, ComplexWarning))
288327
def test_hstack_casting(self, xp, dtype1, dtype2, casting):
@@ -317,7 +356,17 @@ def test_vstack_dtype(self, xp, dtype1, dtype2):
317356
return xp.vstack((a, b), dtype=dtype2)
318357

319358
@testing.with_requires("numpy>=1.24.0")
320-
@testing.for_castings()
359+
# @pytest.mark.filterwarnings("error::cupy.exceptions.ComplexWarning")
360+
@pytest.mark.parametrize(
361+
"casting",
362+
[
363+
"no",
364+
"equiv",
365+
"safe",
366+
"same_kind",
367+
"unsafe",
368+
],
369+
)
321370
@testing.for_all_dtypes_combination(names=["dtype1", "dtype2"])
322371
@testing.numpy_cupy_array_equal(accept_error=(TypeError, ComplexWarning))
323372
def test_vstack_casting(self, xp, dtype1, dtype2, casting):
@@ -410,36 +459,40 @@ def test_stack_out(self, xp, dtype):
410459

411460
@testing.numpy_cupy_array_equal()
412461
def test_stack_out_same_kind(self, xp):
413-
a = testing.shaped_arange((3, 4), xp, xp.float32)
414-
b = testing.shaped_reverse_arange((3, 4), xp, xp.float32)
415-
c = testing.shaped_arange((3, 4), xp, xp.float32)
462+
dtype = cupy.default_float_type()
463+
a = testing.shaped_arange((3, 4), xp, dtype)
464+
b = testing.shaped_reverse_arange((3, 4), xp, dtype)
465+
c = testing.shaped_arange((3, 4), xp, dtype)
416466
out = xp.zeros((3, 3, 4), dtype=xp.float32)
417467
xp.stack((a, b, c), axis=1, out=out)
418468
return out
419469

420470
def test_stack_out_invalid_shape(self):
421471
for xp in (numpy, cupy):
422-
a = testing.shaped_arange((3, 4), xp, xp.float32)
423-
b = testing.shaped_reverse_arange((3, 4), xp, xp.float32)
424-
c = testing.shaped_arange((3, 4), xp, xp.float32)
425-
out = xp.zeros((3, 3, 10), dtype=xp.float32)
472+
dtype = cupy.default_float_type()
473+
a = testing.shaped_arange((3, 4), xp, dtype)
474+
b = testing.shaped_reverse_arange((3, 4), xp, dtype)
475+
c = testing.shaped_arange((3, 4), xp, dtype)
476+
out = xp.zeros((3, 3, 10), dtype=dtype)
426477
with pytest.raises(ValueError):
427478
xp.stack((a, b, c), axis=1, out=out)
428479

429480
def test_stack_out_invalid_shape_2(self):
430481
for xp in (numpy, cupy):
431-
a = testing.shaped_arange((3, 4), xp, xp.float32)
432-
b = testing.shaped_reverse_arange((3, 4), xp, xp.float32)
433-
c = testing.shaped_arange((3, 4), xp, xp.float32)
434-
out = xp.zeros((3, 3, 3, 10), dtype=xp.float32)
482+
dtype = cupy.default_float_type()
483+
a = testing.shaped_arange((3, 4), xp, dtype)
484+
b = testing.shaped_reverse_arange((3, 4), xp, dtype)
485+
c = testing.shaped_arange((3, 4), xp, dtype)
486+
out = xp.zeros((3, 3, 3, 10), dtype=dtype)
435487
with pytest.raises(ValueError):
436488
xp.stack((a, b, c), axis=1, out=out)
437489

438490
def test_stack_out_invalid_dtype(self):
439491
for xp in (numpy, cupy):
440-
a = testing.shaped_arange((3, 4), xp, xp.float32)
441-
b = testing.shaped_reverse_arange((3, 4), xp, xp.float32)
442-
c = testing.shaped_arange((3, 4), xp, xp.float32)
492+
dtype = cupy.default_float_type()
493+
a = testing.shaped_arange((3, 4), xp, dtype)
494+
b = testing.shaped_reverse_arange((3, 4), xp, dtype)
495+
c = testing.shaped_arange((3, 4), xp, dtype)
443496
out = xp.zeros((3, 3, 4), dtype=xp.int64)
444497
with pytest.raises(TypeError):
445498
xp.stack((a, b, c), axis=1, out=out)
@@ -453,7 +506,17 @@ def test_stack_dtype(self, xp, dtype1, dtype2):
453506
return xp.stack((a, b), dtype=dtype2)
454507

455508
@testing.with_requires("numpy>=1.24.0")
456-
@testing.for_castings()
509+
# @pytest.mark.filterwarnings("error::cupy.exceptions.ComplexWarning")
510+
@pytest.mark.parametrize(
511+
"casting",
512+
[
513+
"no",
514+
"equiv",
515+
"safe",
516+
"same_kind",
517+
"unsafe",
518+
],
519+
)
457520
@testing.for_all_dtypes_combination(names=["dtype1", "dtype2"])
458521
@testing.numpy_cupy_array_equal(accept_error=(TypeError, ComplexWarning))
459522
def test_stack_casting(self, xp, dtype1, dtype2, casting):
@@ -462,29 +525,31 @@ def test_stack_casting(self, xp, dtype1, dtype2, casting):
462525
# may raise TypeError or ComplexWarning
463526
return xp.stack((a, b), dtype=dtype2, casting=casting)
464527

528+
@testing.with_requires("numpy>=2.0")
465529
@testing.for_all_dtypes(name="dtype1")
466530
@testing.for_all_dtypes(name="dtype2")
467531
@testing.numpy_cupy_array_equal(type_check=has_support_aspect64())
468532
def test_row_stack(self, xp, dtype1, dtype2):
469533
a = testing.shaped_arange((4, 3), xp, dtype1)
470534
b = testing.shaped_arange((3,), xp, dtype2)
471535
c = testing.shaped_arange((2, 3), xp, dtype1)
472-
return xp.row_stack((a, b, c))
536+
with pytest.warns(DeprecationWarning):
537+
return xp.row_stack((a, b, c))
473538

474539
def test_row_stack_wrong_ndim1(self):
475540
a = cupy.zeros(())
476541
b = cupy.zeros((3,))
477-
with pytest.raises(ValueError):
542+
with pytest.raises(ValueError): # pytest.warns(DeprecationWarning):
478543
cupy.row_stack((a, b))
479544

480545
def test_row_stack_wrong_ndim2(self):
481546
a = cupy.zeros((3, 2, 3))
482547
b = cupy.zeros((3, 2))
483-
with pytest.raises(ValueError):
548+
with pytest.raises(ValueError): # pytest.warns(DeprecationWarning):
484549
cupy.row_stack((a, b))
485550

486551
def test_row_stack_wrong_shape(self):
487552
a = cupy.zeros((3, 2))
488553
b = cupy.zeros((4, 3))
489-
with pytest.raises(ValueError):
554+
with pytest.raises(ValueError): # pytest.warns(DeprecationWarning):
490555
cupy.row_stack((a, b))

0 commit comments

Comments
 (0)