Skip to content

Commit 739a450

Browse files
committed
Adopt elementwise op tests to pass on a device without fp64 support
1 parent 06e3b0c commit 739a450

File tree

2 files changed

+51
-22
lines changed

2 files changed

+51
-22
lines changed

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

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pytest
88

99
import dpnp as cupy
10+
from dpnp.tests.helper import has_support_aspect64
1011
from dpnp.tests.third_party.cupy import testing
1112

1213

@@ -60,7 +61,9 @@ def skip_inplace_numpy_uint64_casting_error(xp, x_type, y_type):
6061
class TestArrayElementwiseOp:
6162

6263
@testing.for_all_dtypes_combination(names=["x_type", "y_type"])
63-
@testing.numpy_cupy_allclose(rtol=1e-6, accept_error=TypeError)
64+
@testing.numpy_cupy_allclose(
65+
rtol=1e-6, accept_error=TypeError, type_check=has_support_aspect64()
66+
)
6467
@cast_exception_type()
6568
def check_array_scalar_op(
6669
self,
@@ -214,7 +217,9 @@ def test_ne_scalar(self):
214217
self.check_array_scalar_op(operator.ne)
215218

216219
@testing.for_all_dtypes_combination(names=["x_type", "y_type"])
217-
@testing.numpy_cupy_allclose(accept_error=TypeError)
220+
@testing.numpy_cupy_allclose(
221+
accept_error=TypeError, type_check=has_support_aspect64()
222+
)
218223
@cast_exception_type()
219224
def check_array_array_op(
220225
self,
@@ -278,7 +283,12 @@ def test_ifloordiv_array(self):
278283
)
279284

280285
@testing.for_all_dtypes_combination(names=["x_type", "y_type"])
281-
@testing.numpy_cupy_allclose(atol=1e-5, rtol=1e-6, accept_error=TypeError)
286+
@testing.numpy_cupy_allclose(
287+
atol=1e-5,
288+
rtol=1e-6,
289+
accept_error=TypeError,
290+
type_check=has_support_aspect64(),
291+
)
282292
def check_pow_array(self, xp, x_type, y_type):
283293
a = xp.array([[1, 2, 3], [4, 5, 6]], x_type)
284294
b = xp.array([[6, 5, 4], [3, 2, 1]], y_type)
@@ -332,7 +342,9 @@ def test_ne_array(self):
332342
self.check_array_array_op(operator.ne)
333343

334344
@testing.for_all_dtypes_combination(names=["x_type", "y_type"])
335-
@testing.numpy_cupy_allclose(accept_error=TypeError)
345+
@testing.numpy_cupy_allclose(
346+
accept_error=TypeError, type_check=has_support_aspect64()
347+
)
336348
@cast_exception_type()
337349
def check_array_broadcasted_op(
338350
self,
@@ -400,7 +412,12 @@ def test_broadcasted_ifloordiv(self):
400412
)
401413

402414
@testing.for_all_dtypes_combination(names=["x_type", "y_type"])
403-
@testing.numpy_cupy_allclose(atol=1e-5, rtol=1e-6, accept_error=TypeError)
415+
@testing.numpy_cupy_allclose(
416+
atol=1e-5,
417+
rtol=1e-6,
418+
accept_error=TypeError,
419+
type_check=has_support_aspect64(),
420+
)
404421
def check_broadcasted_pow(self, xp, x_type, y_type):
405422
a = xp.array([[1, 2, 3], [4, 5, 6]], x_type)
406423
b = xp.array([[1], [2]], y_type)
@@ -458,7 +475,7 @@ def test_broadcasted_ne(self):
458475
self.check_array_broadcasted_op(operator.ne)
459476

460477
@testing.for_all_dtypes_combination(names=["x_type", "y_type"])
461-
@testing.numpy_cupy_allclose(rtol=1e-6)
478+
@testing.numpy_cupy_allclose(rtol=1e-6, type_check=has_support_aspect64())
462479
def check_array_doubly_broadcasted_op(
463480
self, op, xp, x_type, y_type, no_bool=False, no_complex=False
464481
):
@@ -525,7 +542,7 @@ def test_doubly_broadcasted_ne(self):
525542
self.check_array_doubly_broadcasted_op(operator.ne)
526543

527544
@testing.for_all_dtypes_combination(names=["x_type", "y_type"])
528-
@testing.numpy_cupy_allclose()
545+
@testing.numpy_cupy_allclose(type_check=has_support_aspect64())
529546
def check_array_reversed_op(self, op, xp, x_type, y_type, no_bool=False):
530547
if no_bool and x_type == numpy.bool_ and y_type == numpy.bool_:
531548
return xp.array(True)
@@ -567,7 +584,9 @@ def test_array_reversed_mul(self):
567584
],
568585
)
569586
@testing.for_all_dtypes(no_bool=True)
570-
@testing.numpy_cupy_allclose(accept_error=OverflowError)
587+
@testing.numpy_cupy_allclose(
588+
accept_error=OverflowError, type_check=has_support_aspect64()
589+
)
571590
def test_typecast_(self, xp, op, dtype, val):
572591
a = op(val, (testing.shaped_arange((5,), xp, dtype) - 2))
573592
return a
@@ -618,7 +637,9 @@ def test_iadd_array_boolarray(self):
618637
class TestArrayIntElementwiseOp:
619638

620639
@testing.for_all_dtypes_combination(names=["x_type", "y_type"])
621-
@testing.numpy_cupy_allclose(accept_error=TypeError)
640+
@testing.numpy_cupy_allclose(
641+
accept_error=TypeError, type_check=has_support_aspect64()
642+
)
622643
@cast_exception_type()
623644
def check_array_scalar_op(self, op, xp, x_type, y_type, swap=False):
624645
a = xp.array([[0, 1, 2], [1, 0, 2]], dtype=x_type)
@@ -666,7 +687,9 @@ def test_rmod_scalar(self):
666687
self.check_array_scalar_op(operator.mod, swap=True)
667688

668689
@testing.for_all_dtypes_combination(names=["x_type", "y_type"])
669-
@testing.numpy_cupy_allclose(accept_error=TypeError)
690+
@testing.numpy_cupy_allclose(
691+
accept_error=TypeError, type_check=has_support_aspect64()
692+
)
670693
@cast_exception_type()
671694
def check_array_scalarzero_op(self, op, xp, x_type, y_type, swap=False):
672695
a = xp.array([[0, 1, 2], [1, 0, 2]], dtype=x_type)
@@ -714,7 +737,9 @@ def test_rmod_scalarzero(self):
714737
self.check_array_scalarzero_op(operator.mod, swap=True)
715738

716739
@testing.for_all_dtypes_combination(names=["x_type", "y_type"])
717-
@testing.numpy_cupy_allclose(accept_error=TypeError)
740+
@testing.numpy_cupy_allclose(
741+
accept_error=TypeError, type_check=has_support_aspect64()
742+
)
718743
@cast_exception_type()
719744
def check_array_array_op(self, op, xp, x_type, y_type, inplace=False):
720745
if inplace:
@@ -763,7 +788,9 @@ def test_imod_array(self):
763788
self.check_array_array_op(operator.imod, inplace=True)
764789

765790
@testing.for_all_dtypes_combination(names=["x_type", "y_type"])
766-
@testing.numpy_cupy_allclose(accept_error=TypeError)
791+
@testing.numpy_cupy_allclose(
792+
accept_error=TypeError, type_check=has_support_aspect64()
793+
)
767794
@cast_exception_type()
768795
def check_array_broadcasted_op(self, op, xp, x_type, y_type, inplace=False):
769796
if inplace:
@@ -812,7 +839,9 @@ def test_broadcasted_imod(self):
812839
self.check_array_broadcasted_op(operator.imod, inplace=True)
813840

814841
@testing.for_all_dtypes_combination(names=["x_type", "y_type"])
815-
@testing.numpy_cupy_allclose(accept_error=TypeError)
842+
@testing.numpy_cupy_allclose(
843+
accept_error=TypeError, type_check=has_support_aspect64()
844+
)
816845
@cast_exception_type()
817846
def check_array_doubly_broadcasted_op(self, op, xp, x_type, y_type):
818847
a = xp.array([[[0, 1, 2]], [[1, 0, 2]]], dtype=x_type)
@@ -890,7 +919,7 @@ class CustomInt(int):
890919
pass
891920

892921

893-
@pytest.mark.parametrize("dtype", ["int32", "float64"])
922+
@pytest.mark.parametrize("dtype", ["int32", cupy.default_float_type()])
894923
@pytest.mark.parametrize(
895924
"value",
896925
[

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def test_types(self, xp, ufunc):
209209

210210
@testing.numpy_cupy_allclose()
211211
def test_unary_out_tuple(self, xp):
212-
dtype = xp.float64
212+
dtype = cupy.default_float_type()
213213
a = testing.shaped_arange((2, 3), xp, dtype)
214214
out = xp.zeros((2, 3), dtype=dtype)
215215
ret = xp.sin(a, out=(out,))
@@ -218,13 +218,13 @@ def test_unary_out_tuple(self, xp):
218218

219219
@testing.numpy_cupy_allclose()
220220
def test_unary_out_positional_none(self, xp):
221-
dtype = xp.float64
221+
dtype = cupy.default_float_type()
222222
a = testing.shaped_arange((2, 3), xp, dtype)
223223
return xp.sin(a, None)
224224

225225
@testing.numpy_cupy_allclose()
226226
def test_binary_out_tuple(self, xp):
227-
dtype = xp.float64
227+
dtype = cupy.default_float_type()
228228
a = testing.shaped_arange((2, 3), xp, dtype)
229229
b = xp.ones((2, 3), dtype=dtype)
230230
out = xp.zeros((2, 3), dtype=dtype)
@@ -234,14 +234,14 @@ def test_binary_out_tuple(self, xp):
234234

235235
@testing.numpy_cupy_allclose()
236236
def test_biary_out_positional_none(self, xp):
237-
dtype = xp.float64
237+
dtype = cupy.default_float_type()
238238
a = testing.shaped_arange((2, 3), xp, dtype)
239239
b = xp.ones((2, 3), dtype=dtype)
240240
return xp.add(a, b, None)
241241

242242
@testing.numpy_cupy_allclose()
243243
def test_divmod_out_tuple(self, xp):
244-
dtype = xp.float64
244+
dtype = cupy.default_float_type()
245245
a = testing.shaped_arange((2, 3), xp, dtype)
246246
b = testing.shaped_reverse_arange((2, 3), xp, dtype)
247247
out0 = xp.zeros((2, 3), dtype=dtype)
@@ -253,14 +253,14 @@ def test_divmod_out_tuple(self, xp):
253253

254254
@testing.numpy_cupy_allclose()
255255
def test_divmod_out_positional_none(self, xp):
256-
dtype = xp.float64
256+
dtype = cupy.default_float_type()
257257
a = testing.shaped_arange((2, 3), xp, dtype)
258258
b = xp.ones((2, 3), dtype=dtype)
259259
return xp.divmod(a, b, None, None)
260260

261261
@testing.numpy_cupy_allclose()
262262
def test_divmod_out_partial(self, xp):
263-
dtype = xp.float64
263+
dtype = cupy.default_float_type()
264264
a = testing.shaped_arange((2, 3), xp, dtype)
265265
b = testing.shaped_reverse_arange((2, 3), xp, dtype)
266266
out0 = xp.zeros((2, 3), dtype=dtype)
@@ -270,7 +270,7 @@ def test_divmod_out_partial(self, xp):
270270

271271
@testing.numpy_cupy_allclose()
272272
def test_divmod_out_partial_tuple(self, xp):
273-
dtype = xp.float64
273+
dtype = cupy.default_float_type()
274274
a = testing.shaped_arange((2, 3), xp, dtype)
275275
b = testing.shaped_reverse_arange((2, 3), xp, dtype)
276276
out1 = xp.zeros((2, 3), dtype=dtype)

0 commit comments

Comments
 (0)