Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unmute result type tests and modify TypeError/ValueError tests #1663

Merged
merged 9 commits into from
Feb 8, 2024
3 changes: 0 additions & 3 deletions tests/test_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ def test_repeat(arr):
assert_array_equal(expected, result)


# TODO: Temporary skipping the test, until Internal CI is updated with
# recent changed in dpctl regarding dpt.result_type function
@pytest.mark.skip("Temporary skipping the test")
def test_result_type():
X = [dpnp.ones((2), dtype=dpnp.int64), dpnp.int32, "float32"]
X_np = [numpy.ones((2), dtype=numpy.int64), numpy.int32, "float32"]
Expand Down
44 changes: 11 additions & 33 deletions tests/test_mathematical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,9 +1199,7 @@ def test_invalid_dtype(self, dtype):
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
dp_out = dpnp.empty(10, dtype=dtype)

# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
with pytest.raises(ValueError):
dpnp.ceil(dp_array, out=dp_out)

@pytest.mark.parametrize("dtype", get_float_dtypes())
Expand Down Expand Up @@ -1241,9 +1239,7 @@ def test_invalid_dtype(self, dtype):
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
dp_out = dpnp.empty(10, dtype=dtype)

# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
with pytest.raises(ValueError):
dpnp.floor(dp_array, out=dp_out)

@pytest.mark.parametrize("dtype", get_float_dtypes())
Expand Down Expand Up @@ -1283,9 +1279,7 @@ def test_invalid_dtype(self, dtype):
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
dp_out = dpnp.empty(10, dtype=dtype)

# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
with pytest.raises(ValueError):
dpnp.trunc(dp_array, out=dp_out)

@pytest.mark.parametrize("dtype", get_float_dtypes())
Expand Down Expand Up @@ -1336,9 +1330,7 @@ def test_out_dtypes(self, dtype):
dp_out = dpnp.empty(size, dtype=dpnp.complex64)
if dtype != dpnp.complex64:
# dtype of out mismatches types of input arrays
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
with pytest.raises(ValueError):
dpnp.add(dp_array1, dp_array2, out=dp_out)

# allocate new out with expected type
Expand Down Expand Up @@ -1435,9 +1427,7 @@ def test_out_dtypes(self, dtype):
check_dtype = True
if dtype != dpnp.complex64:
# dtype of out mismatches types of input arrays
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
with pytest.raises(ValueError):
dpnp.divide(dp_array1, dp_array2, out=dp_out)

# allocate new out with expected type
Expand Down Expand Up @@ -1538,9 +1528,7 @@ def test_out_dtypes(self, dtype):
dp_out = dpnp.empty(size, dtype=dpnp.complex64)
if dtype != dpnp.complex64:
# dtype of out mismatches types of input arrays
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
with pytest.raises(ValueError):
dpnp.floor_divide(dp_array1, dp_array2, out=dp_out)

# allocate new out with expected type
Expand Down Expand Up @@ -1800,9 +1788,7 @@ def test_out_dtypes(self, dtype):
dp_out = dpnp.empty(size, dtype=dpnp.float32)
if dtype != dpnp.float32:
# dtype of out mismatches types of input arrays
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
with pytest.raises(ValueError):
dpnp.hypot(dp_array1, dp_array2, out=dp_out)

# allocate new out with expected type
Expand Down Expand Up @@ -1970,9 +1956,7 @@ def test_out_dtypes(self, dtype):
dp_out = dpnp.empty(size, dtype=dpnp.complex64)
if dtype != dpnp.complex64:
# dtype of out mismatches types of input arrays
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
with pytest.raises(ValueError):
dpnp.maximum(dp_array1, dp_array2, out=dp_out)

# allocate new out with expected type
Expand Down Expand Up @@ -2053,9 +2037,7 @@ def test_out_dtypes(self, dtype):
dp_out = dpnp.empty(size, dtype=dpnp.complex64)
if dtype != dpnp.complex64:
# dtype of out mismatches types of input arrays
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
with pytest.raises(ValueError):
dpnp.minimum(dp_array1, dp_array2, out=dp_out)

# allocate new out with expected type
Expand Down Expand Up @@ -2136,9 +2118,7 @@ def test_out_dtypes(self, dtype):
dp_out = dpnp.empty(size, dtype=dpnp.complex64)
if dtype != dpnp.complex64:
# dtype of out mismatches types of input arrays
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
with pytest.raises(ValueError):
dpnp.multiply(dp_array1, dp_array2, out=dp_out)

# allocate new out with expected type
Expand Down Expand Up @@ -2233,9 +2213,7 @@ def test_out_dtypes(self, dtype):
dp_out = dpnp.empty(size, dtype=dpnp.complex64)
if dtype != dpnp.complex64:
# dtype of out mismatches types of input arrays
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
with pytest.raises(ValueError):
dpnp.power(dp_array1, dp_array2, out=dp_out)

# allocate new out with expected type
Expand Down
28 changes: 7 additions & 21 deletions tests/test_umath.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,7 @@ def test_invalid_dtype(self, func_params, dtype):
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
dp_out = dpnp.empty(10, dtype=dtype)

# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
with pytest.raises(ValueError):
getattr(dpnp, func_name)(dp_array, out=dp_out)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -256,9 +254,7 @@ def test_invalid_dtype(self, dtype):
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
dp_out = dpnp.empty(10, dtype=dtype)

# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
with pytest.raises(ValueError):
dpnp.cbrt(dp_array, out=dp_out)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -295,9 +291,7 @@ def test_invalid_dtype(self, dtype):
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
dp_out = dpnp.empty(10, dtype=dtype)

# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
with pytest.raises(ValueError):
dpnp.rsqrt(dp_array, out=dp_out)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -338,9 +332,7 @@ def test_invalid_dtype(self, dtype):
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
dp_out = dpnp.empty(10, dtype=dtype)

# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
with pytest.raises(ValueError):
dpnp.square(dp_array, out=dp_out)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -423,9 +415,7 @@ def test_invalid_dtype(self, dtype):
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
dp_out = dpnp.empty(10, dtype=dtype)

# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
with pytest.raises(ValueError):
dpnp.arctan2(dp_array, dp_array, out=dp_out)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -461,9 +451,7 @@ def test_invalid_dtype(self, dtype):
dpnp_dtype = get_all_dtypes(no_complex=True, no_none=True)[-1]
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
dp_out = dpnp.empty(10, dtype=dtype)
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
with pytest.raises(ValueError):
dpnp.copysign(dp_array, dp_array, out=dp_out)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -499,9 +487,7 @@ def test_invalid_dtype(self, dtype):
dpnp_dtype = get_all_dtypes(no_complex=True, no_none=True)[-1]
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
dp_out = dpnp.empty(10, dtype=dtype)
# TODO: change it to ValueError, when dpctl
# is being used in internal CI
with pytest.raises((TypeError, ValueError)):
with pytest.raises(ValueError):
dpnp.logaddexp(dp_array, dp_array, out=dp_out)

@pytest.mark.parametrize(
Expand Down
21 changes: 18 additions & 3 deletions tests/third_party/cupy/test_type_routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

import dpnp as cupy
from tests.helper import has_support_aspect64
from tests.third_party.cupy import testing


Expand Down Expand Up @@ -87,9 +88,6 @@ def test_common_type_bool(self, dtype):
}
)
)
# TODO: Temporary skipping the test, until Internal CI is updated with
# recent changed in dpctl regarding dpt.result_type function
@pytest.mark.skip("Temporary skipping the test")
class TestResultType(unittest.TestCase):
@testing.for_all_dtypes_combination(names=("dtype1", "dtype2"))
@testing.numpy_cupy_equal()
Expand All @@ -100,6 +98,23 @@ def test_result_type(self, xp, dtype1, dtype2):
input1 = _generate_type_routines_input(xp, dtype1, self.obj_type1)

input2 = _generate_type_routines_input(xp, dtype2, self.obj_type2)

flag1 = isinstance(input1, (numpy.ndarray, cupy.ndarray))
flag2 = isinstance(input2, (numpy.ndarray, cupy.ndarray))
dt1 = cupy.dtype(input1) if not flag1 else None
dt2 = cupy.dtype(input2) if not flag2 else None
# dpnp takes into account devices capabilities only if one of the
# inputs is an array, for such a case, if the other dtype is not
# supported by device, dpnp raise ValueError. So, we skip the test.
if flag1 or flag2:
if (
dt1 in [cupy.float64, cupy.complex128]
or dt2 in [cupy.float64, cupy.complex128]
and not has_support_aspect64()
):
pytest.skip("No fp64 support by device.")

ret = xp.result_type(input1, input2)

assert isinstance(ret, numpy.dtype)
return ret
Loading