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

update third party tests for newly added integr dtypes (int8, int16, uint8-uint64) #2239

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/conda-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ jobs:
env:
DPNP_TEST_ALL_INT_TYPES: 1
run: |
pytest -n auto -ra --pyargs ${{ env.PACKAGE_NAME }}.tests
pytest -ra --pyargs ${{ env.PACKAGE_NAME }}.tests

upload:
name: Upload ['${{ matrix.os }}', python='${{ matrix.python }}']
Expand Down
11 changes: 6 additions & 5 deletions dpnp/dpnp_algo/dpnp_elementwise_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,12 +590,13 @@ def __init__(
def __call__(self, x, decimals=0, out=None, dtype=None):
if decimals != 0:
x_usm = dpnp.get_usm_ndarray(x)
if dpnp.issubdtype(x_usm.dtype, dpnp.integer) and dtype is None:
dtype = x_usm.dtype

out_usm = None if out is None else dpnp.get_usm_ndarray(out)
x_usm = dpt.round(x_usm * 10**decimals, out=out_usm)
res_usm = dpt.divide(x_usm, 10**decimals, out=out_usm)

if dpnp.issubdtype(x_usm.dtype, dpnp.integer):
res_usm = dpt.round(x_usm, out=out_usm)
else:
x_usm = dpt.round(x_usm * 10**decimals, out=out_usm)
res_usm = dpt.divide(x_usm, 10**decimals, out=out_usm)

if dtype is not None:
res_usm = dpt.astype(res_usm, dtype, copy=False)
Expand Down
13 changes: 13 additions & 0 deletions dpnp/dpnp_iface_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1469,7 +1469,20 @@ def copyto(dst, src, casting="same_kind", where=True):
f"but got {type(dst)}"
)
if not dpnp.is_supported_array_type(src):
no_dtype_attr = not hasattr(src, "dtype")
src = dpnp.array(src, sycl_queue=dst.sycl_queue)
if no_dtype_attr:
# This case (scalar, list, etc) needs special handling to
# behave similar to NumPy
if dpnp.issubdtype(src, dpnp.integer) and dpnp.issubdtype(
dst, dpnp.unsignedinteger
):
if dpnp.any(src < 0):
raise OverflowError(
"Cannot copy negative values to an unsigned int array"
)

src = src.astype(dst.dtype)

if not dpnp.can_cast(src.dtype, dst.dtype, casting=casting):
raise TypeError(
Expand Down
1 change: 1 addition & 0 deletions dpnp/tests/test_sycl_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ def test_reduce_hypot(device):
[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0],
[5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0],
),
pytest.param("round", [1.234, 2.567], 2),
pytest.param("searchsorted", [11, 12, 13, 14, 15], [-10, 20, 12, 13]),
pytest.param(
"subtract",
Expand Down
1 change: 1 addition & 0 deletions dpnp/tests/test_usm_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ def test_1in_1out(func, data, usm_type):
pytest.param("maximum", [0.0, 1.0, 2.0], [3.0, 4.0, 5.0]),
pytest.param("minimum", [0.0, 1.0, 2.0], [3.0, 4.0, 5.0]),
pytest.param("nextafter", [1, 2], [2, 1]),
pytest.param("round", [1.234, 2.567], 2),
pytest.param("searchsorted", [11, 12, 13, 14, 15], [-10, 20, 12, 13]),
pytest.param(
"tensordot",
Expand Down
46 changes: 33 additions & 13 deletions dpnp/tests/third_party/cupy/core_tests/test_elementwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import pytest

import dpnp as cupy
from dpnp.tests.helper import has_support_aspect64
from dpnp.tests.helper import (
has_support_aspect64,
is_win_platform,
numpy_version,
)
from dpnp.tests.third_party.cupy import testing


Expand Down Expand Up @@ -94,20 +98,22 @@ class TestElementwiseType(unittest.TestCase):
@testing.for_int_dtypes(no_bool=True)
@testing.numpy_cupy_array_equal(accept_error=OverflowError)
def test_large_int_upper_1(self, xp, dtype):
a = xp.array([0], dtype=numpy.int8)
a = xp.array([0], dtype=xp.int8)
b = xp.iinfo(dtype).max
return a + b

@testing.for_int_dtypes(no_bool=True)
@testing.numpy_cupy_array_equal(accept_error=OverflowError)
def test_large_int_upper_2(self, xp, dtype):
if (
numpy.issubdtype(dtype, numpy.unsignedinteger)
and numpy.lib.NumpyVersion(numpy.__version__) < "2.0.0"
):
pytest.skip("numpy promotes dtype differently")
if numpy_version() < "2.0.0":
flag = dtype in [xp.int16, xp.int32, xp.int64, xp.longlong]
if xp.issubdtype(dtype, xp.unsignedinteger) or flag:
pytest.skip("numpy doesn't raise OverflowError")

if dtype in [xp.int8, xp.intc] and is_win_platform():
pytest.skip("numpy promotes dtype differently")

a = xp.array([1], dtype=numpy.int8)
a = xp.array([1], dtype=xp.int8)
b = xp.iinfo(dtype).max - 1
return a + b

Expand All @@ -116,7 +122,7 @@ def test_large_int_upper_2(self, xp, dtype):
def test_large_int_upper_3(self, xp, dtype):
if (
numpy.issubdtype(dtype, numpy.unsignedinteger)
and numpy.lib.NumpyVersion(numpy.__version__) < "2.0.0"
and numpy_version() < "2.0.0"
):
pytest.skip("numpy promotes dtype differently")
elif (
Expand All @@ -134,7 +140,7 @@ def test_large_int_upper_3(self, xp, dtype):
def test_large_int_upper_4(self, xp, dtype):
if (
numpy.issubdtype(dtype, numpy.unsignedinteger)
and numpy.lib.NumpyVersion(numpy.__version__) < "2.0.0"
and numpy_version() < "2.0.0"
):
pytest.skip("numpy promotes dtype differently")
elif (
Expand All @@ -150,14 +156,28 @@ def test_large_int_upper_4(self, xp, dtype):
@testing.for_int_dtypes(no_bool=True)
@testing.numpy_cupy_array_equal(accept_error=OverflowError)
def test_large_int_lower_1(self, xp, dtype):
a = xp.array([0], dtype=numpy.int8)
if numpy_version() < "2.0.0":
if dtype in [xp.int16, xp.int32, xp.int64, xp.longlong]:
pytest.skip("numpy doesn't raise OverflowError")

if dtype in [xp.int8, xp.intc] and is_win_platform():
pytest.skip("numpy promotes dtype differently")

a = xp.array([0], dtype=xp.int8)
b = xp.iinfo(dtype).min
return a + b

@testing.for_int_dtypes(no_bool=True)
@testing.numpy_cupy_array_equal(accept_error=OverflowError)
def test_large_int_lower_2(self, xp, dtype):
a = xp.array([-1], dtype=numpy.int8)
if numpy_version() < "2.0.0":
if dtype in [xp.int16, xp.int32, xp.int64, xp.longlong]:
pytest.skip("numpy doesn't raise OverflowError")

if dtype in [xp.int8, xp.intc] and is_win_platform():
pytest.skip("numpy promotes dtype differently")

a = xp.array([-1], dtype=xp.int8)
b = xp.iinfo(dtype).min + 1
return a + b

Expand All @@ -166,7 +186,7 @@ def test_large_int_lower_2(self, xp, dtype):
def test_large_int_lower_3(self, xp, dtype):
if (
numpy.issubdtype(dtype, numpy.unsignedinteger)
and numpy.lib.NumpyVersion(numpy.__version__) < "2.0.0"
and numpy_version() < "2.0.0"
):
pytest.skip("numpy promotes dtype differently")
elif (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import pytest

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


Expand Down Expand Up @@ -41,8 +40,10 @@ def test_conjugate_pass(self, xp, dtype):

class TestAngle(unittest.TestCase):

# For dtype=int8, uint8, NumPy returns float16, but dpnp returns float32
# so type_check=False
@testing.for_all_dtypes()
@testing.numpy_cupy_array_almost_equal(type_check=has_support_aspect64())
@testing.numpy_cupy_array_almost_equal(type_check=False)
vtavana marked this conversation as resolved.
Show resolved Hide resolved
def test_angle(self, xp, dtype):
x = testing.shaped_arange((2, 3), xp, dtype)
return xp.angle(x)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def test_astype_type(self, src_dtype, dst_dtype, order):
b = astype_without_warning(a, dst_dtype, order=order)
a_cpu = testing.shaped_arange((2, 3, 4), numpy, src_dtype)
b_cpu = astype_without_warning(a_cpu, dst_dtype, order=order)
assert b.dtype.type == b_cpu.dtype.type
assert b.dtype == b_cpu.dtype
vtavana marked this conversation as resolved.
Show resolved Hide resolved

@testing.for_orders("CAK")
@testing.for_all_dtypes()
Expand Down
8 changes: 7 additions & 1 deletion dpnp/tests/third_party/cupy/creation_tests/test_ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,13 @@ def test_linspace_mixed_start_stop2(self, xp, dtype_range, dtype_out):
# TODO (ev-br): np 2.0: had to bump the default rtol on Windows
# and numpy 1.26+weak promotion from 0 to 5e-6
if xp.dtype(dtype_range).kind in "u":
start = xp.array([160, 120], dtype=dtype_range)
# to avoid overflow, limit `val` to be smaller
# than xp.iinfo(dtype).max
if dtype_range == xp.uint8 or dtype_out == xp.uint8:
val = 125
vtavana marked this conversation as resolved.
Show resolved Hide resolved
else:
val = 160
start = xp.array([val, 120], dtype=dtype_range)
else:
start = xp.array([-120, 120], dtype=dtype_range)
stop = 0
Expand Down
4 changes: 4 additions & 0 deletions dpnp/tests/third_party/cupy/indexing_tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ class TestChoose(unittest.TestCase):
@testing.for_all_dtypes()
@testing.numpy_cupy_array_equal()
def test_choose(self, xp, dtype):
# TODO: include additional dtype when dpnp#2201 is merged
dtype_list = [xp.int8, xp.int16]
if dtype in dtype_list or xp.issubdtype(dtype, xp.unsignedinteger):
pytest.skip("dpnp.choose() does not support new integer dtypes.")
a = xp.array([0, 2, 1, 2])
c = testing.shaped_arange((3, 4), xp, dtype)
return a.choose(c)
Expand Down
16 changes: 10 additions & 6 deletions dpnp/tests/third_party/cupy/linalg_tests/test_einsum.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,8 @@ def test_scalar_float(self, xp, dtype):
)
)
class TestEinSumBinaryOperation:
@testing.for_all_dtypes_combination(
["dtype_a", "dtype_b"], no_bool=False, no_float16=False
)
# no_int8=True is added to avoid overflow
@testing.for_all_dtypes_combination(["dtype_a", "dtype_b"], no_int8=True)
vtavana marked this conversation as resolved.
Show resolved Hide resolved
@testing.numpy_cupy_allclose(
type_check=has_support_aspect64(), contiguous_check=False
)
Expand Down Expand Up @@ -555,13 +554,18 @@ def test_scalar_2(self, xp, dtype):
)
)
class TestEinSumTernaryOperation:
@testing.for_all_dtypes_combination(
["dtype_a", "dtype_b", "dtype_c"], no_bool=False, no_float16=False
)

@testing.for_all_dtypes_combination(["dtype_a", "dtype_b", "dtype_c"])
@testing.numpy_cupy_allclose(
type_check=has_support_aspect64(), contiguous_check=False
)
def test_einsum_ternary(self, xp, dtype_a, dtype_b, dtype_c):
flag = all(
dtype in [xp.int8, xp.uint8]
for dtype in [dtype_a, dtype_b, dtype_c]
)
if self.subscripts == "ij,jk,kl" and flag:
pytest.skip("avoid overflow")
a = testing.shaped_arange(self.shape_a, xp, dtype_a)
b = testing.shaped_arange(self.shape_b, xp, dtype_b)
c = testing.shaped_arange(self.shape_c, xp, dtype_c)
Expand Down
27 changes: 17 additions & 10 deletions dpnp/tests/third_party/cupy/linalg_tests/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@
)
)
class TestDot(unittest.TestCase):

@testing.for_all_dtypes_combination(["dtype_a", "dtype_b"])
# no_int8=True is added to avoid overflow for shape=((2, 3, 4), (3, 4, 2))
# and ((2, 3), (3, 4)) cases on cpu
@testing.for_all_dtypes_combination(["dtype_a", "dtype_b"], no_int8=True)
vtavana marked this conversation as resolved.
Show resolved Hide resolved
@testing.numpy_cupy_allclose(type_check=has_support_aspect64())
def test_dot(self, xp, dtype_a, dtype_b):
shape_a, shape_b = self.shape
Expand Down Expand Up @@ -238,14 +239,14 @@ def test_dot_vec3(self, xp, dtype):
b = testing.shaped_arange((2,), xp, dtype)
return xp.dot(a, b)

@testing.for_all_dtypes()
@testing.for_all_dtypes(no_int8=True)
@testing.numpy_cupy_allclose()
def test_transposed_dot(self, xp, dtype):
a = testing.shaped_arange((2, 3, 4), xp, dtype).transpose(1, 0, 2)
b = testing.shaped_arange((2, 3, 4), xp, dtype).transpose(0, 2, 1)
return xp.dot(a, b)

@testing.for_all_dtypes()
@testing.for_all_dtypes(no_int8=True)
@testing.numpy_cupy_allclose()
def test_transposed_dot_with_out(self, xp, dtype):
a = testing.shaped_arange((2, 3, 4), xp, dtype).transpose(1, 0, 2)
Expand Down Expand Up @@ -320,14 +321,16 @@ def test_reversed_inner(self, xp, dtype):
b = testing.shaped_reverse_arange((5,), xp, dtype)[::-1]
return xp.inner(a, b)

@testing.for_all_dtypes()
# no_int8=True is added to avoid overflow
@testing.for_all_dtypes(no_int8=True)
@testing.numpy_cupy_allclose()
def test_multidim_inner(self, xp, dtype):
a = testing.shaped_arange((2, 3, 4), xp, dtype)
b = testing.shaped_arange((3, 2, 4), xp, dtype)
return xp.inner(a, b)

@testing.for_all_dtypes()
# no_int8=True is added to avoid overflow
@testing.for_all_dtypes(no_int8=True)
@testing.numpy_cupy_allclose()
def test_transposed_higher_order_inner(self, xp, dtype):
a = testing.shaped_arange((2, 4, 3), xp, dtype).transpose(2, 0, 1)
Expand Down Expand Up @@ -355,14 +358,16 @@ def test_multidim_outer(self, xp, dtype):
b = testing.shaped_arange((4, 5), xp, dtype)
return xp.outer(a, b)

@testing.for_all_dtypes()
# no_int8=True is added to avoid overflow
@testing.for_all_dtypes(no_int8=True)
@testing.numpy_cupy_allclose()
def test_tensordot(self, xp, dtype):
a = testing.shaped_arange((2, 3, 4), xp, dtype)
b = testing.shaped_arange((3, 4, 5), xp, dtype)
return xp.tensordot(a, b)

@testing.for_all_dtypes()
# no_int8=True is added to avoid overflow
@testing.for_all_dtypes(no_int8=True)
@testing.numpy_cupy_allclose()
def test_transposed_tensordot(self, xp, dtype):
a = testing.shaped_arange((2, 3, 4), xp, dtype).transpose(1, 0, 2)
Expand Down Expand Up @@ -516,13 +521,15 @@ def test_matrix_power_1(self, xp, dtype):
a = testing.shaped_arange((3, 3), xp, dtype)
return xp.linalg.matrix_power(a, 1)

@testing.for_all_dtypes()
# no_int8=True is added to avoid overflow
@testing.for_all_dtypes(no_int8=True)
@testing.numpy_cupy_allclose()
def test_matrix_power_2(self, xp, dtype):
a = testing.shaped_arange((3, 3), xp, dtype)
return xp.linalg.matrix_power(a, 2)

@testing.for_all_dtypes()
# no_int8=True is added to avoid overflow
@testing.for_all_dtypes(no_int8=True)
@testing.numpy_cupy_allclose()
def test_matrix_power_3(self, xp, dtype):
a = testing.shaped_arange((3, 3), xp, dtype)
Expand Down
3 changes: 2 additions & 1 deletion dpnp/tests/third_party/cupy/logic_tests/test_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ def test_allclose_array_scalar(self, xp, dtype):

class TestIsclose(unittest.TestCase):

@testing.for_all_dtypes(no_complex=True)
# no_int8=True is added to avoid overflow
@testing.for_all_dtypes(no_complex=True, no_int8=True)
@testing.numpy_cupy_array_equal()
def test_is_close_finite(self, xp, dtype):
# In numpy<1.10 this test fails when dtype is bool
Expand Down
Loading
Loading