Skip to content

Commit 91a8277

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

File tree

1 file changed

+40
-13
lines changed

1 file changed

+40
-13
lines changed

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

Lines changed: 40 additions & 13 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:
@@ -812,7 +837,9 @@ def test_broadcasted_imod(self):
812837
self.check_array_broadcasted_op(operator.imod, inplace=True)
813838

814839
@testing.for_all_dtypes_combination(names=["x_type", "y_type"])
815-
@testing.numpy_cupy_allclose(accept_error=TypeError)
840+
@testing.numpy_cupy_allclose(
841+
accept_error=TypeError, type_check=has_support_aspect64()
842+
)
816843
@cast_exception_type()
817844
def check_array_doubly_broadcasted_op(self, op, xp, x_type, y_type):
818845
a = xp.array([[[0, 1, 2]], [[1, 0, 2]]], dtype=x_type)
@@ -890,7 +917,7 @@ class CustomInt(int):
890917
pass
891918

892919

893-
@pytest.mark.parametrize("dtype", ["int32", "float64"])
920+
@pytest.mark.parametrize("dtype", ["int32", cupy.default_float_type()])
894921
@pytest.mark.parametrize(
895922
"value",
896923
[

0 commit comments

Comments
 (0)