Skip to content

Commit 6e034b8

Browse files
committed
Resolve result dtype missmatch in tests for trapezoid
1 parent e6dce68 commit 6e034b8

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

dpnp/tests/third_party/cupy/math_tests/test_sumprod.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,51 +1162,75 @@ def test_ediff1d_ed2(self, xp, dtype):
11621162
class TestTrapezoid:
11631163

11641164
@testing.for_all_dtypes()
1165-
@testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-1, "default": 1e-7})
1165+
@testing.numpy_cupy_allclose(
1166+
rtol={numpy.float16: 1e-1, "default": 1e-7},
1167+
type_check=has_support_aspect64(),
1168+
)
11661169
def test_trapz_1dim(self, xp, dtype):
11671170
a = testing.shaped_arange((5,), xp, dtype)
11681171
return xp.trapezoid(a)
11691172

11701173
@testing.for_all_dtypes()
1171-
@testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-1, "default": 1e-7})
1174+
@testing.numpy_cupy_allclose(
1175+
rtol={numpy.float16: 1e-1, "default": 1e-7},
1176+
type_check=has_support_aspect64(),
1177+
)
11721178
def test_trapz_1dim_with_x(self, xp, dtype):
11731179
a = testing.shaped_arange((5,), xp, dtype)
11741180
x = testing.shaped_arange((5,), xp, dtype)
11751181
return xp.trapezoid(a, x=x)
11761182

11771183
@testing.for_all_dtypes()
1178-
@testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-1, "default": 1e-7})
1184+
@testing.numpy_cupy_allclose(
1185+
rtol={numpy.float16: 1e-1, "default": 1e-7},
1186+
type_check=has_support_aspect64(),
1187+
)
11791188
def test_trapz_1dim_with_dx(self, xp, dtype):
11801189
a = testing.shaped_arange((5,), xp, dtype)
11811190
return xp.trapezoid(a, dx=0.1)
11821191

11831192
@testing.for_all_dtypes()
1184-
@testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-1, "default": 1e-7})
1193+
@testing.numpy_cupy_allclose(
1194+
rtol={numpy.float16: 1e-1, "default": 1e-7},
1195+
type_check=has_support_aspect64(),
1196+
)
11851197
def test_trapz_2dim_without_axis(self, xp, dtype):
11861198
a = testing.shaped_arange((4, 5), xp, dtype)
11871199
return xp.trapezoid(a)
11881200

11891201
@testing.for_all_dtypes()
1190-
@testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-1, "default": 1e-7})
1202+
@testing.numpy_cupy_allclose(
1203+
rtol={numpy.float16: 1e-1, "default": 1e-7},
1204+
type_check=has_support_aspect64(),
1205+
)
11911206
def test_trapz_2dim_with_axis(self, xp, dtype):
11921207
a = testing.shaped_arange((4, 5), xp, dtype)
11931208
return xp.trapezoid(a, axis=-2)
11941209

11951210
@testing.for_all_dtypes()
1196-
@testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-1, "default": 1e-7})
1211+
@testing.numpy_cupy_allclose(
1212+
rtol={numpy.float16: 1e-1, "default": 1e-7},
1213+
type_check=has_support_aspect64(),
1214+
)
11971215
def test_trapz_2dim_with_x_and_axis(self, xp, dtype):
11981216
a = testing.shaped_arange((4, 5), xp, dtype)
11991217
x = testing.shaped_arange((5,), xp, dtype)
12001218
return xp.trapezoid(a, x=x, axis=1)
12011219

12021220
@testing.for_all_dtypes()
1203-
@testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-1, "default": 1e-7})
1221+
@testing.numpy_cupy_allclose(
1222+
rtol={numpy.float16: 1e-1, "default": 1e-7},
1223+
type_check=has_support_aspect64(),
1224+
)
12041225
def test_trapz_2dim_with_dx_and_axis(self, xp, dtype):
12051226
a = testing.shaped_arange((4, 5), xp, dtype)
12061227
return xp.trapezoid(a, dx=0.1, axis=1)
12071228

12081229
@testing.for_all_dtypes()
1209-
@testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-1, "default": 1e-7})
1230+
@testing.numpy_cupy_allclose(
1231+
rtol={numpy.float16: 1e-1, "default": 1e-7},
1232+
type_check=has_support_aspect64(),
1233+
)
12101234
def test_trapz_1dim_with_x_and_dx(self, xp, dtype):
12111235
a = testing.shaped_arange((5,), xp, dtype)
12121236
x = testing.shaped_arange((5,), xp, dtype)

dpnp/tests/third_party/cupy/testing/_loops.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -583,12 +583,12 @@ def numpy_cupy_allclose(
583583
# When `type_check` is `False`, cupy result and numpy result may have
584584
# different dtypes so we can not determine the dtype to use from the
585585
# tolerance associations.
586-
if not type_check:
587-
if isinstance(rtol, dict) or isinstance(atol, dict):
588-
raise TypeError(
589-
"When `type_check` is `False`, `rtol` and `atol` "
590-
"must be supplied as float."
591-
)
586+
# if not type_check:
587+
# if isinstance(rtol, dict) or isinstance(atol, dict):
588+
# raise TypeError(
589+
# "When `type_check` is `False`, `rtol` and `atol` "
590+
# "must be supplied as float."
591+
# )
592592

593593
def check_func(c, n):
594594
rtol1, atol1 = _resolve_tolerance(type_check, c, rtol, atol)

0 commit comments

Comments
 (0)