Skip to content

Commit 4ee2ede

Browse files
committed
Merge branch 'master' into compare-shape
2 parents fd343be + 18772b6 commit 4ee2ede

File tree

4 files changed

+124
-62
lines changed

4 files changed

+124
-62
lines changed

.github/workflows/array-api-skips.txt

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# array API tests to be skipped
22

3-
# hypothesis found failures
4-
array_api_tests/test_operators_and_elementwise_functions.py::test_clip
5-
63
# unexpected result is returned - unmute when dpctl-1986 is resolved
74
array_api_tests/test_operators_and_elementwise_functions.py::test_asin
85
array_api_tests/test_operators_and_elementwise_functions.py::test_asinh

dpnp/tests/third_party/cupy/linalg_tests/test_einsum.py

+2
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ def test_einsum_unary_views(self, xp, dtype):
373373
def test_einsum_unary_dtype(self, xp, dtype_a, dtype_out):
374374
if not numpy.can_cast(dtype_a, dtype_out):
375375
pytest.skip()
376+
if cupy.issubdtype(dtype_a, cupy.unsignedinteger):
377+
pytest.skip("dpctl-2055")
376378
a = testing.shaped_arange(self.shape_a, xp, dtype_a)
377379
return xp.einsum(self.subscripts, a, dtype=dtype_out)
378380

dpnp/tests/third_party/cupy/testing/_array.py

+101-31
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import warnings
2+
3+
import numpy
14
import numpy.testing
25

36
import dpnp as cupy
@@ -6,7 +9,15 @@
69

710

811
def assert_allclose(
9-
actual, desired, rtol=1e-7, atol=0, err_msg="", verbose=True
12+
actual,
13+
desired,
14+
rtol=1e-7,
15+
atol=0,
16+
equal_nan=True,
17+
err_msg="",
18+
verbose=True,
19+
*,
20+
strict=False,
1021
):
1122
"""Raises an AssertionError if objects are not equal up to desired tolerance.
1223
@@ -22,18 +33,42 @@ def assert_allclose(
2233
.. seealso:: :func:`numpy.testing.assert_allclose`
2334
2435
"""
25-
numpy.testing.assert_allclose(
26-
cupy.asnumpy(actual),
27-
cupy.asnumpy(desired),
28-
rtol=rtol,
29-
atol=atol,
30-
err_msg=err_msg,
31-
verbose=verbose,
32-
strict=False,
33-
)
36+
if numpy.lib.NumpyVersion(numpy.__version__) >= "2.0.0":
37+
numpy.testing.assert_allclose(
38+
cupy.asnumpy(actual),
39+
cupy.asnumpy(desired),
40+
rtol=rtol,
41+
atol=atol,
42+
equal_nan=equal_nan,
43+
err_msg=err_msg,
44+
verbose=verbose,
45+
strict=strict,
46+
)
47+
else:
48+
if strict:
49+
warnings.warn(
50+
"`dpnp.tests.third_party.cupy.testing.assert_allclose` does not support `strict` "
51+
"option with NumPy v1.",
52+
RuntimeWarning,
53+
)
54+
numpy.testing.assert_allclose(
55+
cupy.asnumpy(actual),
56+
cupy.asnumpy(desired),
57+
rtol=rtol,
58+
atol=atol,
59+
equal_nan=equal_nan,
60+
err_msg=err_msg,
61+
verbose=verbose,
62+
)
3463

3564

36-
def assert_array_almost_equal(x, y, decimal=6, err_msg="", verbose=True):
65+
def assert_array_almost_equal(
66+
actual,
67+
desired,
68+
decimal=6,
69+
err_msg="",
70+
verbose=True,
71+
):
3772
"""Raises an AssertionError if objects are not equal up to desired precision.
3873
3974
Args:
@@ -47,8 +82,8 @@ def assert_array_almost_equal(x, y, decimal=6, err_msg="", verbose=True):
4782
.. seealso:: :func:`numpy.testing.assert_array_almost_equal`
4883
"""
4984
numpy.testing.assert_array_almost_equal(
50-
cupy.asnumpy(x),
51-
cupy.asnumpy(y),
85+
cupy.asnumpy(actual),
86+
cupy.asnumpy(desired),
5287
decimal=decimal,
5388
err_msg=err_msg,
5489
verbose=verbose,
@@ -89,7 +124,13 @@ def assert_array_max_ulp(a, b, maxulp=1, dtype=None):
89124

90125

91126
def assert_array_equal(
92-
x, y, err_msg="", verbose=True, strides_check=False, **kwargs
127+
actual,
128+
desired,
129+
err_msg="",
130+
verbose=True,
131+
*,
132+
strict=False,
133+
strides_check=False,
93134
):
94135
"""Raises an AssertionError if two array_like objects are not equal.
95136
@@ -107,25 +148,36 @@ def assert_array_equal(
107148
108149
.. seealso:: :func:`numpy.testing.assert_array_equal`
109150
"""
110-
111-
strict = kwargs.get("strict", False)
112-
numpy.testing.assert_array_equal(
113-
cupy.asnumpy(x),
114-
cupy.asnumpy(y),
115-
err_msg=err_msg,
116-
verbose=verbose,
117-
strict=strict,
118-
**kwargs,
119-
)
151+
if numpy.lib.NumpyVersion(numpy.__version__) >= "1.24.0":
152+
numpy.testing.assert_array_equal(
153+
cupy.asnumpy(actual),
154+
cupy.asnumpy(desired),
155+
err_msg=err_msg,
156+
verbose=verbose,
157+
strict=strict,
158+
)
159+
else:
160+
if strict:
161+
warnings.warn(
162+
"`dpnp.tests.third_party.cupy.testing.assert_allclose` does not support `strict` "
163+
"option with NumPy v1.",
164+
RuntimeWarning,
165+
)
166+
numpy.testing.assert_array_equal(
167+
cupy.asnumpy(actual),
168+
cupy.asnumpy(desired),
169+
err_msg=err_msg,
170+
verbose=verbose,
171+
)
120172

121173
if strides_check:
122-
if x.strides != y.strides:
174+
if actual.strides != desired.strides:
123175
msg = ["Strides are not equal:"]
124176
if err_msg:
125177
msg = [msg[0] + " " + err_msg]
126178
if verbose:
127-
msg.append(" x: {}".format(x.strides))
128-
msg.append(" y: {}".format(y.strides))
179+
msg.append(" x: {}".format(actual.strides))
180+
msg.append(" y: {}".format(desired.strides))
129181
raise AssertionError("\n".join(msg))
130182

131183

@@ -168,7 +220,7 @@ def assert_array_list_equal(xlist, ylist, err_msg="", verbose=True):
168220
)
169221

170222

171-
def assert_array_less(x, y, err_msg="", verbose=True):
223+
def assert_array_less(x, y, err_msg="", verbose=True, *, strict=False):
172224
"""Raises an AssertionError if array_like objects are not ordered by less than.
173225
174226
Args:
@@ -180,6 +232,24 @@ def assert_array_less(x, y, err_msg="", verbose=True):
180232
181233
.. seealso:: :func:`numpy.testing.assert_array_less`
182234
"""
183-
numpy.testing.assert_array_less(
184-
cupy.asnumpy(x), cupy.asnumpy(y), err_msg=err_msg, verbose=verbose
185-
)
235+
if numpy.lib.NumpyVersion(numpy.__version__) >= "2.0.0":
236+
numpy.testing.assert_array_less(
237+
cupy.asnumpy(x),
238+
cupy.asnumpy(y),
239+
err_msg=err_msg,
240+
verbose=verbose,
241+
strict=strict,
242+
)
243+
else:
244+
if strict:
245+
warnings.warn(
246+
"`dpnp.tests.third_party.cupy.testing.assert_allclose` does not support `strict` "
247+
"option with NumPy v1.",
248+
RuntimeWarning,
249+
)
250+
numpy.testing.assert_array_less(
251+
cupy.asnumpy(x),
252+
cupy.asnumpy(y),
253+
err_msg=err_msg,
254+
verbose=verbose,
255+
)

dpnp/tests/third_party/cupy/testing/_loops.py

+21-28
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def _make_positive_masks(impl, args, kw, name, sp_name, scipy_name):
251251
assert error is None
252252
if not isinstance(result, (tuple, list)):
253253
result = (result,)
254-
return [r >= 0 for r in result]
254+
return [cupy.asnumpy(r) >= 0 for r in result]
255255

256256

257257
def _contains_signed_and_unsigned(kw):
@@ -307,12 +307,9 @@ def decorator(impl):
307307
@_wraps_partial_xp(impl, name, sp_name, scipy_name)
308308
def test_func(*args, **kw):
309309
# Run cupy and numpy
310-
(
311-
cupy_result,
312-
cupy_error,
313-
numpy_result,
314-
numpy_error,
315-
) = _call_func_numpy_cupy(impl, args, kw, name, sp_name, scipy_name)
310+
(cupy_result, cupy_error, numpy_result, numpy_error) = (
311+
_call_func_numpy_cupy(impl, args, kw, name, sp_name, scipy_name)
312+
)
316313
assert cupy_result is not None or cupy_error is not None
317314
assert numpy_result is not None or numpy_error is not None
318315

@@ -411,8 +408,10 @@ def test_func(*args, **kw):
411408
if cupy_r.shape == ():
412409
skip = (mask == 0).all()
413410
else:
414-
cupy_r = cupy_r[mask]
415-
numpy_r = numpy_r[mask.asnumpy()]
411+
# mask is numpy.ndarray here which is not supported now
412+
# TODO remove asarray() once dpctl-2053 is addressed
413+
cupy_r = cupy_r[cupy.asarray(mask)].asnumpy()
414+
numpy_r = numpy_r[mask]
416415

417416
if not skip:
418417
check_func(cupy_r, numpy_r)
@@ -446,7 +445,7 @@ def _convert_output_to_ndarray(c_out, n_out, sp_name, check_sparse_format):
446445
assert scipy.sparse.issparse(n_out)
447446
if check_sparse_format:
448447
assert c_out.format == n_out.format
449-
return c_out.A, n_out.A
448+
return c_out.toarray(), n_out.toarray()
450449
if isinstance(c_out, cupy.ndarray) and isinstance(
451450
n_out, (numpy.ndarray, numpy.generic)
452451
):
@@ -455,7 +454,6 @@ def _convert_output_to_ndarray(c_out, n_out, sp_name, check_sparse_format):
455454
if (
456455
hasattr(cupy, "poly1d")
457456
and isinstance(c_out, cupy.poly1d)
458-
and hasattr(numpy, "poly1d")
459457
and isinstance(n_out, numpy.poly1d)
460458
):
461459
# poly1d output case.
@@ -464,9 +462,6 @@ def _convert_output_to_ndarray(c_out, n_out, sp_name, check_sparse_format):
464462
if isinstance(c_out, numpy.generic) and isinstance(n_out, numpy.generic):
465463
# numpy scalar output case.
466464
return c_out, n_out
467-
if isinstance(c_out, numpy.ndarray) and isinstance(n_out, numpy.ndarray):
468-
# fallback on numpy output case.
469-
return c_out, n_out
470465
if numpy.isscalar(c_out) and numpy.isscalar(n_out):
471466
# python scalar output case.
472467
return cupy.array(c_out), numpy.array(n_out)
@@ -594,7 +589,9 @@ def numpy_cupy_allclose(
594589

595590
def check_func(c, n):
596591
rtol1, atol1 = _resolve_tolerance(type_check, c, rtol, atol)
597-
_array.assert_allclose(c, n, rtol1, atol1, err_msg, verbose)
592+
_array.assert_allclose(
593+
c, n, rtol1, atol1, err_msg=err_msg, verbose=verbose
594+
)
598595

599596
return _make_decorator(
600597
check_func,
@@ -795,7 +792,9 @@ def numpy_cupy_array_equal(
795792
"""
796793

797794
def check_func(x, y):
798-
_array.assert_array_equal(x, y, err_msg, verbose, strides_check)
795+
_array.assert_array_equal(
796+
x, y, err_msg, verbose, strides_check=strides_check
797+
)
799798

800799
return _make_decorator(
801800
check_func, name, type_check, False, accept_error, sp_name, scipy_name
@@ -905,12 +904,9 @@ def decorator(impl):
905904
@_wraps_partial_xp(impl, name, sp_name, scipy_name)
906905
def test_func(*args, **kw):
907906
# Run cupy and numpy
908-
(
909-
cupy_result,
910-
cupy_error,
911-
numpy_result,
912-
numpy_error,
913-
) = _call_func_numpy_cupy(impl, args, kw, name, sp_name, scipy_name)
907+
(cupy_result, cupy_error, numpy_result, numpy_error) = (
908+
_call_func_numpy_cupy(impl, args, kw, name, sp_name, scipy_name)
909+
)
914910

915911
if cupy_error or numpy_error:
916912
_check_cupy_numpy_error(
@@ -964,12 +960,9 @@ def decorator(impl):
964960
@_wraps_partial_xp(impl, name, sp_name, scipy_name)
965961
def test_func(*args, **kw):
966962
# Run cupy and numpy
967-
(
968-
cupy_result,
969-
cupy_error,
970-
numpy_result,
971-
numpy_error,
972-
) = _call_func_numpy_cupy(impl, args, kw, name, sp_name, scipy_name)
963+
(cupy_result, cupy_error, numpy_result, numpy_error) = (
964+
_call_func_numpy_cupy(impl, args, kw, name, sp_name, scipy_name)
965+
)
973966

974967
_check_cupy_numpy_error(
975968
cupy_error, numpy_error, accept_error=accept_error

0 commit comments

Comments
 (0)