Skip to content

Commit

Permalink
Merge branch 'master' into impl-matvec
Browse files Browse the repository at this point in the history
  • Loading branch information
vtavana authored Jan 31, 2025
2 parents 4b02bac + 6e9d830 commit 0ac3212
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 21 deletions.
17 changes: 12 additions & 5 deletions dpnp/tests/third_party/cupy/core_tests/test_nep50_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pytest

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

# TODO: remove once all dtype aliases added
Expand All @@ -15,8 +16,6 @@
"uint8(1) + 2",
"array([1], uint8) + int64(1)",
"array([1], uint8) + array(1, int64)",
"array([1.], float32) + float64(1.)",
"array([1.], float32) + array(1., float64)",
"array([1], uint8) + 1",
"array([1], uint8) + 200",
"array([100], uint8) + 200",
Expand All @@ -25,7 +24,6 @@
"uint8(100) + 200",
"float32(1) + 3e100",
"array([1.0], float32) + 1e-14 == 1.0",
"array([0.1], float32) == float64(0.1)",
"array(1.0, float32) + 1e-14 == 1.0",
"array([1.], float32) + 3",
"array([1.], float32) + int64(3)",
Expand All @@ -42,25 +40,34 @@
"1.0 + array([1, 2, 3], int8)",
"array([1], float32) + 1j",
]
if has_support_aspect64():
examples += [
"array([1.], float32) + float64(1.)",
"array([1.], float32) + array(1., float64)",
"array([0.1], float32) == float64(0.1)",
]


@pytest.mark.filterwarnings("ignore::RuntimeWarning")
@testing.with_requires("numpy>=2.0")
@pytest.mark.parametrize("example", examples)
@testing.numpy_cupy_allclose(atol=1e-15, accept_error=OverflowError)
@testing.numpy_cupy_allclose(
atol=1e-15, accept_error=OverflowError, type_check=has_support_aspect64()
)
def test_nep50_examples(xp, example):
dct = {
"array": xp.array,
"uint8": xp.uint8,
"int64": xp.int64,
"float32": xp.float32,
"float64": xp.float64,
"int16": xp.int16,
"bool_": xp.bool_,
"int32": xp.int32,
"complex64": xp.complex64,
"int8": xp.int8,
}
if has_support_aspect64():
dct["float64"] = xp.float64

if isinstance(example, tuple):
example, mesg = example
Expand Down
2 changes: 1 addition & 1 deletion dpnp/tests/third_party/cupy/linalg_tests/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class TestLinalgCrossProduct(unittest.TestCase):

@testing.with_requires("numpy>=2.0")
@testing.for_all_dtypes_combination(["dtype_a", "dtype_b"])
@testing.numpy_cupy_allclose()
@testing.numpy_cupy_allclose(type_check=has_support_aspect64())
def test_cross(self, xp, dtype_a, dtype_b):
if dtype_a == dtype_b == numpy.bool_:
# cross does not support bool-bool inputs.
Expand Down
2 changes: 1 addition & 1 deletion dpnp/tests/third_party/cupy/math_tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def test_fabs(self, xp, dtype):

@testing.with_requires("numpy>=2.0")
@testing.for_all_dtypes(no_complex=True)
@testing.numpy_cupy_allclose(atol=1e-5)
@testing.numpy_cupy_allclose(atol=1e-5, type_check=has_support_aspect64())
def test_fabs_negative(self, xp, dtype):
if numpy.issubdtype(dtype, numpy.unsignedinteger):
pytest.skip("trying to set negative value to unsigned integer")
Expand Down
40 changes: 32 additions & 8 deletions dpnp/tests/third_party/cupy/math_tests/test_sumprod.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,51 +1162,75 @@ def test_ediff1d_ed2(self, xp, dtype):
class TestTrapezoid:

@testing.for_all_dtypes()
@testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-1, "default": 1e-7})
@testing.numpy_cupy_allclose(
rtol={numpy.float16: 1e-1, "default": 1e-7},
type_check=has_support_aspect64(),
)
def test_trapz_1dim(self, xp, dtype):
a = testing.shaped_arange((5,), xp, dtype)
return xp.trapezoid(a)

@testing.for_all_dtypes()
@testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-1, "default": 1e-7})
@testing.numpy_cupy_allclose(
rtol={numpy.float16: 1e-1, "default": 1e-7},
type_check=has_support_aspect64(),
)
def test_trapz_1dim_with_x(self, xp, dtype):
a = testing.shaped_arange((5,), xp, dtype)
x = testing.shaped_arange((5,), xp, dtype)
return xp.trapezoid(a, x=x)

@testing.for_all_dtypes()
@testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-1, "default": 1e-7})
@testing.numpy_cupy_allclose(
rtol={numpy.float16: 1e-1, "default": 1e-7},
type_check=has_support_aspect64(),
)
def test_trapz_1dim_with_dx(self, xp, dtype):
a = testing.shaped_arange((5,), xp, dtype)
return xp.trapezoid(a, dx=0.1)

@testing.for_all_dtypes()
@testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-1, "default": 1e-7})
@testing.numpy_cupy_allclose(
rtol={numpy.float16: 1e-1, "default": 1e-7},
type_check=has_support_aspect64(),
)
def test_trapz_2dim_without_axis(self, xp, dtype):
a = testing.shaped_arange((4, 5), xp, dtype)
return xp.trapezoid(a)

@testing.for_all_dtypes()
@testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-1, "default": 1e-7})
@testing.numpy_cupy_allclose(
rtol={numpy.float16: 1e-1, "default": 1e-7},
type_check=has_support_aspect64(),
)
def test_trapz_2dim_with_axis(self, xp, dtype):
a = testing.shaped_arange((4, 5), xp, dtype)
return xp.trapezoid(a, axis=-2)

@testing.for_all_dtypes()
@testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-1, "default": 1e-7})
@testing.numpy_cupy_allclose(
rtol={numpy.float16: 1e-1, "default": 1e-7},
type_check=has_support_aspect64(),
)
def test_trapz_2dim_with_x_and_axis(self, xp, dtype):
a = testing.shaped_arange((4, 5), xp, dtype)
x = testing.shaped_arange((5,), xp, dtype)
return xp.trapezoid(a, x=x, axis=1)

@testing.for_all_dtypes()
@testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-1, "default": 1e-7})
@testing.numpy_cupy_allclose(
rtol={numpy.float16: 1e-1, "default": 1e-7},
type_check=has_support_aspect64(),
)
def test_trapz_2dim_with_dx_and_axis(self, xp, dtype):
a = testing.shaped_arange((4, 5), xp, dtype)
return xp.trapezoid(a, dx=0.1, axis=1)

@testing.for_all_dtypes()
@testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-1, "default": 1e-7})
@testing.numpy_cupy_allclose(
rtol={numpy.float16: 1e-1, "default": 1e-7},
type_check=has_support_aspect64(),
)
def test_trapz_1dim_with_x_and_dx(self, xp, dtype):
a = testing.shaped_arange((5,), xp, dtype)
x = testing.shaped_arange((5,), xp, dtype)
Expand Down
12 changes: 6 additions & 6 deletions dpnp/tests/third_party/cupy/testing/_loops.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,12 +583,12 @@ def numpy_cupy_allclose(
# When `type_check` is `False`, cupy result and numpy result may have
# different dtypes so we can not determine the dtype to use from the
# tolerance associations.
if not type_check:
if isinstance(rtol, dict) or isinstance(atol, dict):
raise TypeError(
"When `type_check` is `False`, `rtol` and `atol` "
"must be supplied as float."
)
# if not type_check:
# if isinstance(rtol, dict) or isinstance(atol, dict):
# raise TypeError(
# "When `type_check` is `False`, `rtol` and `atol` "
# "must be supplied as float."
# )

def check_func(c, n):
rtol1, atol1 = _resolve_tolerance(type_check, c, rtol, atol)
Expand Down

0 comments on commit 0ac3212

Please sign in to comment.