Skip to content

Commit 7918bcf

Browse files
committed
Update third party tests
1 parent 9455faf commit 7918bcf

File tree

4 files changed

+53
-53
lines changed

4 files changed

+53
-53
lines changed

dpnp/tests/third_party/cupy/core_tests/test_dlpack.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ def __dlpack_device__(self):
4141
@pytest.mark.skip("toDlpack() and fromDlpack() are not supported")
4242
class TestDLPackConversion:
4343

44-
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
4544
@testing.for_all_dtypes(no_bool=False)
46-
def test_conversion(self, dtype):
45+
def test_conversion(self, dtype, recwarn):
4746
orig_array = _gen_array(dtype)
4847
tensor = orig_array.toDlpack()
4948
out_array = cupy.fromDlpack(tensor)
5049
testing.assert_array_equal(orig_array, out_array)
51-
assert orig_array.get_array()._pointer == out_array.get_array()._pointer
50+
testing.assert_array_equal(orig_array.data.ptr, out_array.data.ptr)
51+
for w in recwarn:
52+
assert issubclass(w.category, cupy.VisibleDeprecationWarning)
5253

5354

5455
class TestNewDLPackConversion:
@@ -82,7 +83,7 @@ def test_conversion(self, dtype):
8283
orig_array = _gen_array(dtype)
8384
out_array = cupy.from_dlpack(orig_array)
8485
testing.assert_array_equal(orig_array, out_array)
85-
assert orig_array.get_array()._pointer == out_array.get_array()._pointer
86+
testing.assert_array_equal(orig_array.data.ptr, out_array.data.ptr)
8687

8788
@pytest.mark.skip("no limitations in from_dlpack()")
8889
def test_from_dlpack_and_conv_errors(self):
@@ -121,7 +122,7 @@ def test_conversion_max_version(self, kwargs, versioned):
121122
)
122123

123124
testing.assert_array_equal(orig_array, out_array)
124-
assert orig_array.get_array()._pointer == out_array.get_array()._pointer
125+
testing.assert_array_equal(orig_array.data.ptr, out_array.data.ptr)
125126

126127
def test_conversion_device(self):
127128
orig_array = _gen_array("float32")
@@ -135,7 +136,7 @@ def test_conversion_device(self):
135136
)
136137

137138
testing.assert_array_equal(orig_array, out_array)
138-
assert orig_array.get_array()._pointer == out_array.get_array()._pointer
139+
testing.assert_array_equal(orig_array.data.ptr, out_array.data.ptr)
139140

140141
def test_conversion_bad_device(self):
141142
arr = _gen_array("float32")
@@ -212,9 +213,8 @@ def test_stream(self):
212213
out_array = dlp.from_dlpack_capsule(dltensor)
213214
out_array = cupy.from_dlpack(out_array, device=dst_s)
214215
testing.assert_array_equal(orig_array, out_array)
215-
assert (
216-
orig_array.get_array()._pointer
217-
== out_array.get_array()._pointer
216+
testing.assert_array_equal(
217+
orig_array.data.ptr, out_array.data.ptr
218218
)
219219

220220

@@ -267,12 +267,13 @@ def test_deleter2(self, pool, max_version):
267267
# assert pool.n_free_blocks() == 1
268268

269269
@pytest.mark.skip("toDlpack() and fromDlpack() are not supported")
270-
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
271-
def test_multiple_consumption_error(self):
270+
def test_multiple_consumption_error(self, recwarn):
272271
# Prevent segfault, see #3611
273272
array = cupy.empty(10)
274273
tensor = array.toDlpack()
275274
array2 = cupy.fromDlpack(tensor)
276275
with pytest.raises(ValueError) as e:
277276
array3 = cupy.fromDlpack(tensor)
278277
assert "consumed multiple times" in str(e.value)
278+
for w in recwarn:
279+
assert issubclass(w.category, cupy.VisibleDeprecationWarning)

dpnp/tests/third_party/cupy/core_tests/test_ndarray.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ def test_shape_not_integer(self):
4343

4444
def test_shape_int_with_strides(self):
4545
dummy = cupy.ndarray(3)
46-
a = cupy.ndarray(3, strides=(0,), buffer=dummy)
46+
a = cupy.ndarray(3, strides=(0,), buffer=dummy.data)
4747
assert a.shape == (3,)
4848
assert a.strides == (0,)
4949

5050
def test_memptr(self):
5151
a = cupy.arange(6).astype(numpy.float32).reshape((2, 3))
52-
memptr = a
52+
memptr = a.data
5353

5454
b = cupy.ndarray((2, 3), numpy.float32, memptr)
5555
testing.assert_array_equal(a, b)
@@ -62,7 +62,7 @@ def test_memptr(self):
6262
)
6363
def test_memptr_with_strides(self):
6464
buf = cupy.ndarray(20, numpy.uint8)
65-
memptr = buf
65+
memptr = buf.data
6666

6767
# self-overlapping strides
6868
a = cupy.ndarray((2, 3), numpy.float32, memptr, strides=(2, 1))
@@ -82,7 +82,9 @@ def test_strides_without_memptr(self):
8282

8383
def test_strides_is_given_and_order_is_ignored(self):
8484
buf = cupy.ndarray(20, numpy.uint8)
85-
a = cupy.ndarray((2, 3), numpy.float32, buf, strides=(2, 1), order="C")
85+
a = cupy.ndarray(
86+
(2, 3), numpy.float32, buf.data, strides=(2, 1), order="C"
87+
)
8688
assert a.strides == (2, 1)
8789

8890
@testing.with_requires("numpy>=1.19")

dpnp/tests/third_party/cupy/creation_tests/test_from_data.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def test_array_from_numpy_broad_cast(self, xp, dtype, order):
6262
@testing.for_orders("CFAK", name="src_order")
6363
@testing.for_orders("CFAK", name="dst_order")
6464
@testing.for_all_dtypes()
65-
@testing.numpy_cupy_array_equal()
65+
@testing.numpy_cupy_array_equal(strides_check=True)
6666
def test_array_from_list_of_numpy(self, xp, dtype, src_order, dst_order):
6767
# compares numpy.array(<list of numpy.ndarray>) with
6868
# cupy.array(<list of numpy.ndarray>)
@@ -75,7 +75,7 @@ def test_array_from_list_of_numpy(self, xp, dtype, src_order, dst_order):
7575
@testing.for_orders("CFAK", name="src_order")
7676
@testing.for_orders("CFAK", name="dst_order")
7777
@testing.for_all_dtypes()
78-
@testing.numpy_cupy_array_equal()
78+
@testing.numpy_cupy_array_equal(strides_check=True)
7979
def test_array_from_list_of_numpy_view(
8080
self, xp, dtype, src_order, dst_order
8181
):
@@ -93,7 +93,7 @@ def test_array_from_list_of_numpy_view(
9393

9494
@testing.for_orders("CFAK")
9595
@testing.for_all_dtypes()
96-
@testing.numpy_cupy_array_equal()
96+
@testing.numpy_cupy_array_equal(strides_check=True)
9797
def test_array_from_list_of_numpy_scalar(self, xp, dtype, order):
9898
# compares numpy.array(<list of numpy.ndarray>) with
9999
# cupy.array(<list of numpy.ndarray>)
@@ -103,7 +103,7 @@ def test_array_from_list_of_numpy_scalar(self, xp, dtype, order):
103103
@testing.for_orders("CFAK", name="src_order")
104104
@testing.for_orders("CFAK", name="dst_order")
105105
@testing.for_all_dtypes()
106-
@testing.numpy_cupy_array_equal()
106+
@testing.numpy_cupy_array_equal(strides_check=True)
107107
def test_array_from_nested_list_of_numpy(
108108
self, xp, dtype, src_order, dst_order
109109
):
@@ -118,7 +118,9 @@ def test_array_from_nested_list_of_numpy(
118118
@testing.for_orders("CFAK", name="src_order")
119119
@testing.for_orders("CFAK", name="dst_order")
120120
@testing.for_all_dtypes_combination(names=("dtype1", "dtype2"))
121-
@testing.numpy_cupy_array_equal(type_check=has_support_aspect64())
121+
@testing.numpy_cupy_array_equal(
122+
type_check=has_support_aspect64(), strides_check=True
123+
)
122124
def test_array_from_list_of_cupy(
123125
self, xp, dtype1, dtype2, src_order, dst_order
124126
):
@@ -133,7 +135,7 @@ def test_array_from_list_of_cupy(
133135
@testing.for_orders("CFAK", name="src_order")
134136
@testing.for_orders("CFAK", name="dst_order")
135137
@testing.for_all_dtypes()
136-
@testing.numpy_cupy_array_equal()
138+
@testing.numpy_cupy_array_equal(strides_check=True)
137139
def test_array_from_list_of_cupy_view(
138140
self, xp, dtype, src_order, dst_order
139141
):
@@ -152,7 +154,7 @@ def test_array_from_list_of_cupy_view(
152154
@testing.for_orders("CFAK", name="src_order")
153155
@testing.for_orders("CFAK", name="dst_order")
154156
@testing.for_all_dtypes()
155-
@testing.numpy_cupy_array_equal()
157+
@testing.numpy_cupy_array_equal(strides_check=True)
156158
def test_array_from_nested_list_of_cupy(
157159
self, xp, dtype, src_order, dst_order
158160
):
@@ -166,7 +168,7 @@ def test_array_from_nested_list_of_cupy(
166168

167169
@testing.for_orders("CFAK")
168170
@testing.for_all_dtypes()
169-
@testing.numpy_cupy_array_equal()
171+
@testing.numpy_cupy_array_equal(strides_check=True)
170172
def test_array_from_list_of_cupy_scalar(self, xp, dtype, order):
171173
# compares numpy.array(<list of numpy.ndarray>) with
172174
# cupy.array(<list of cupy.ndarray>)
@@ -240,7 +242,7 @@ def test_array_copy_with_dtype_being_none(self, xp, order):
240242
@testing.for_orders("CFAK", name="dst_order")
241243
@testing.for_all_dtypes(name="dtype1", no_complex=True)
242244
@testing.for_all_dtypes(name="dtype2")
243-
@testing.numpy_cupy_array_equal()
245+
@testing.numpy_cupy_array_equal(strides_check=True)
244246
def test_array_copy_list_of_numpy_with_dtype(
245247
self, xp, dtype1, dtype2, src_order, dst_order
246248
):
@@ -256,7 +258,7 @@ def test_array_copy_list_of_numpy_with_dtype(
256258
@testing.for_orders("CFAK", name="dst_order")
257259
@testing.for_all_dtypes(name="dtype1", no_complex=True)
258260
@testing.for_all_dtypes(name="dtype2")
259-
@testing.numpy_cupy_array_equal()
261+
@testing.numpy_cupy_array_equal(strides_check=True)
260262
def test_array_copy_list_of_numpy_with_dtype_char(
261263
self, xp, dtype1, dtype2, src_order, dst_order
262264
):
@@ -272,7 +274,7 @@ def test_array_copy_list_of_numpy_with_dtype_char(
272274
@testing.for_orders("CFAK", name="dst_order")
273275
@testing.for_all_dtypes(name="dtype1", no_complex=True)
274276
@testing.for_all_dtypes(name="dtype2")
275-
@testing.numpy_cupy_array_equal()
277+
@testing.numpy_cupy_array_equal(strides_check=True)
276278
def test_array_copy_list_of_cupy_with_dtype(
277279
self, xp, dtype1, dtype2, src_order, dst_order
278280
):
@@ -288,7 +290,7 @@ def test_array_copy_list_of_cupy_with_dtype(
288290
@testing.for_orders("CFAK", name="dst_order")
289291
@testing.for_all_dtypes(name="dtype1", no_complex=True)
290292
@testing.for_all_dtypes(name="dtype2")
291-
@testing.numpy_cupy_array_equal()
293+
@testing.numpy_cupy_array_equal(strides_check=True)
292294
def test_array_copy_list_of_cupy_with_dtype_char(
293295
self, xp, dtype1, dtype2, src_order, dst_order
294296
):
@@ -656,7 +658,7 @@ def test_with_strides(self, dtype):
656658
DummyObjectWithCudaArrayInterface(a, self.ver, self.strides)
657659
)
658660
assert a.strides == b.strides
659-
assert a.nbytes == b.nbytes
661+
assert a.nbytes == b.data.mem.size
660662

661663
@testing.for_all_dtypes()
662664
def test_with_zero_size_array(self, dtype):
@@ -665,7 +667,8 @@ def test_with_zero_size_array(self, dtype):
665667
DummyObjectWithCudaArrayInterface(a, self.ver, self.strides)
666668
)
667669
assert a.strides == b.strides
668-
assert a.nbytes == b.nbytes
670+
assert a.nbytes == b.data.mem.size
671+
assert a.data.ptr == 0
669672
assert a.size == 0
670673

671674
@testing.for_all_dtypes()
@@ -724,7 +727,7 @@ def test_with_over_size_array(self):
724727
testing.assert_array_equal(a, b)
725728

726729

727-
class DummyObjectWithCudaArrayInterface(object):
730+
class DummyObjectWithCudaArrayInterface:
728731
def __init__(self, a, ver, include_strides=False, mask=None, stream=None):
729732
assert ver in tuple(range(max_cuda_array_interface_version + 1))
730733
self.a = None
@@ -834,7 +837,7 @@ def test_cupy_array(self, dtype):
834837
is_copied = not (
835838
(actual is a)
836839
or (self.xp is cupy)
837-
and (a.get_array()._pointer == actual.get_array()._pointer)
840+
and (a.data.ptr == actual.data.ptr)
838841
)
839842
assert should_copy == is_copied
840843

dpnp/tests/third_party/cupy/misc_tests/test_byte_bounds.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,74 +8,68 @@ class TestByteBounds:
88
def test_1d_contiguous(self, dtype):
99
a = cupy.zeros(12, dtype=dtype)
1010
itemsize = a.itemsize
11-
a_low = a.get_array()._pointer
12-
a_high = a.get_array()._pointer + 12 * itemsize
11+
a_low = a.data.ptr
12+
a_high = a.data.ptr + 12 * itemsize
1313
assert cupy.byte_bounds(a) == (a_low, a_high)
1414

1515
@testing.for_all_dtypes()
1616
def test_2d_contiguous(self, dtype):
1717
a = cupy.zeros((4, 7), dtype=dtype)
1818
itemsize = a.itemsize
19-
a_low = a.get_array()._pointer
20-
a_high = a.get_array()._pointer + 4 * 7 * itemsize
19+
a_low = a.data.ptr
20+
a_high = a.data.ptr + 4 * 7 * itemsize
2121
assert cupy.byte_bounds(a) == (a_low, a_high)
2222

2323
@testing.for_all_dtypes()
2424
def test_1d_noncontiguous_pos_stride(self, dtype):
2525
a = cupy.zeros(12, dtype=dtype)
2626
itemsize = a.itemsize
2727
b = a[::2]
28-
b_low = b.get_array()._pointer
29-
b_high = b.get_array()._pointer + 11 * itemsize # a[10]
28+
b_low = b.data.ptr
29+
b_high = b.data.ptr + 11 * itemsize # a[10]
3030
assert cupy.byte_bounds(b) == (b_low, b_high)
3131

3232
@testing.for_all_dtypes()
3333
def test_2d_noncontiguous_pos_stride(self, dtype):
3434
a = cupy.zeros((4, 7), dtype=dtype)
3535
b = a[::2, ::2]
3636
itemsize = b.itemsize
37-
b_low = a.get_array()._pointer
38-
b_high = b.get_array()._pointer + 3 * 7 * itemsize # a[2][6]
37+
b_low = a.data.ptr
38+
b_high = b.data.ptr + 3 * 7 * itemsize # a[2][6]
3939
assert cupy.byte_bounds(b) == (b_low, b_high)
4040

4141
@testing.for_all_dtypes()
4242
def test_1d_contiguous_neg_stride(self, dtype):
4343
a = cupy.zeros(12, dtype=dtype)
4444
b = a[::-1]
4545
itemsize = b.itemsize
46-
b_low = b.get_array()._pointer - 11 * itemsize
47-
b_high = b.get_array()._pointer + 1 * itemsize
46+
b_low = b.data.ptr - 11 * itemsize
47+
b_high = b.data.ptr + 1 * itemsize
4848
assert cupy.byte_bounds(b) == (b_low, b_high)
4949

5050
@testing.for_all_dtypes()
5151
def test_2d_noncontiguous_neg_stride(self, dtype):
5252
a = cupy.zeros((4, 7), dtype=dtype)
5353
b = a[::-2, ::-2] # strides = (-56, -8), shape = (2, 4)
5454
itemsize = b.itemsize
55-
b_low = (
56-
b.get_array()._pointer
57-
- 2 * 7 * itemsize * (2 - 1)
58-
- 2 * itemsize * (4 - 1)
59-
)
60-
b_high = b.get_array()._pointer + 1 * itemsize
55+
b_low = b.data.ptr - 2 * 7 * itemsize * (2 - 1) - 2 * itemsize * (4 - 1)
56+
b_high = b.data.ptr + 1 * itemsize
6157
assert cupy.byte_bounds(b) == (b_low, b_high)
6258

6359
@testing.for_all_dtypes()
6460
def test_2d_noncontiguous_posneg_stride_1(self, dtype):
6561
a = cupy.zeros((4, 7), dtype=dtype)
6662
b = a[::1, ::-1] # strides = (28, -4), shape=(4, 7)
6763
itemsize = b.itemsize
68-
b_low = b.get_array()._pointer - itemsize * (7 - 1)
69-
b_high = b.get_array()._pointer + 1 * itemsize + 7 * itemsize * (4 - 1)
64+
b_low = b.data.ptr - itemsize * (7 - 1)
65+
b_high = b.data.ptr + 1 * itemsize + 7 * itemsize * (4 - 1)
7066
assert cupy.byte_bounds(b) == (b_low, b_high)
7167

7268
@testing.for_all_dtypes()
7369
def test_2d_noncontiguous_posneg_stride_2(self, dtype):
7470
a = cupy.zeros((4, 7), dtype=dtype)
7571
b = a[::2, ::-2] # strides = (56, -8), shape=(2, 4)
7672
itemsize = b.itemsize
77-
b_low = b.get_array()._pointer - 2 * itemsize * (4 - 1)
78-
b_high = (
79-
b.get_array()._pointer + 1 * itemsize + 2 * 7 * itemsize * (2 - 1)
80-
)
73+
b_low = b.data.ptr - 2 * itemsize * (4 - 1)
74+
b_high = b.data.ptr + 1 * itemsize + 2 * 7 * itemsize * (2 - 1)
8175
assert cupy.byte_bounds(b) == (b_low, b_high)

0 commit comments

Comments
 (0)