Repository navigation
Add tests with subnormal inputs and results #3212
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1771,6 +1771,22 @@ def test_zeros(self, dt): | |
| expected[1] *= -1 | ||
| assert_allclose(result, expected) | ||
|
|
||
| @pytest.mark.parametrize("sign", [1, -1]) | ||
| @pytest.mark.parametrize("dt", get_float_dtypes()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: float16 has the narrowest subnormal range, and |
||
| def test_subnormal(self, sign, dt): | ||
| fi = numpy.finfo(dt) | ||
| sub, tiny = fi.smallest_subnormal, fi.tiny | ||
|
|
||
| a = numpy.array( | ||
| [sub, 2 * sub, 3 * sub, tiny - sub, tiny, 2 * tiny], dtype=dt | ||
| ) | ||
| a *= sign | ||
| ia = dpnp.array(a) | ||
|
|
||
| result = dpnp.spacing(ia) | ||
| expected = numpy.spacing(a) | ||
| assert_equal(result, expected) | ||
|
|
||
| @pytest.mark.parametrize("dt", get_float_dtypes(no_float16=False)) | ||
| @pytest.mark.parametrize("val", [1, 1e-5, 1000]) | ||
| @pytest.mark.parametrize("xp", [numpy, dpnp]) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -855,6 +855,20 @@ def test_error(self, func): | |
| with pytest.raises(NotImplementedError): | ||
| getattr(dpnp, func)(ia, initial=6) | ||
|
|
||
| @pytest.mark.parametrize("axis", [None, 1]) | ||
| @pytest.mark.parametrize("dtype", get_float_dtypes()) | ||
| def test_subnormal(self, func, axis, dtype): | ||
| sub = numpy.finfo(dtype).smallest_subnormal | ||
| # a permutation of -5000..4999, so the extremes are not at the ends | ||
| n = 10**4 | ||
| a = ((numpy.arange(n) * 7919) % n - n // 2).astype(dtype) * sub | ||
|
Comment on lines
+862
to
+864
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: The minimum is the first element here: index 0 gives |
||
| a = a.reshape(100, 100) | ||
| ia = dpnp.array(a) | ||
|
|
||
| result = getattr(dpnp, func)(ia, axis=axis) | ||
| expected = getattr(numpy, func)(a, axis=axis) | ||
| assert_array_equal(result, expected) | ||
|
|
||
|
|
||
| class TestMinMax: | ||
| @pytest.mark.parametrize("axis", [None, 0, 1, -1, 2, -2, (1, 2), (0, -2)]) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test has no
-sub→ 0 case, andassert_equaldoes not check the sign of zero. On Intel GPUs this case is wrong:nextafter(-smallest_subnormal, 0)gives+0.0, NumPy gives-0.0:Could you add
(-sub, 0)with asignbitcheck, astest_signed_zerodoes? On GPUs it then needs a kernel fix or an xfail with an issue.