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

TST: stats array API failure for test_skew_constant_value[torch] on GPU #20564

Closed
tylerjereddy opened this issue Apr 23, 2024 · 1 comment · Fixed by #20575
Closed

TST: stats array API failure for test_skew_constant_value[torch] on GPU #20564

tylerjereddy opened this issue Apr 23, 2024 · 1 comment · Fixed by #20575
Labels
array types Items related to array API support and input array validation (see gh-18286) maintenance Items related to regular maintenance tasks scipy.stats
Milestone

Comments

@tylerjereddy
Copy link
Contributor

On latest main at time of writing.

SCIPY_DEVICE=cuda python dev.py test -j 32 -t scipy/stats/tests/test_stats.py::TestSkew::test_skew_constant_value -b all

______________________________________________________________________________________________________________________________________ TestSkew.test_skew_constant_value[torch] ______________________________________________________________________________________________________________________________________
[gw1] linux -- Python 3.11.2 /home/treddy/python_venvs/py_311_scipy_dev/bin/python
scipy/stats/tests/test_stats.py:3436: in test_skew_constant_value
    assert_equal(stats.skew(a), xp.asarray(xp.nan))
E   AssertionError: 
E   Items are not equal:
E    ACTUAL: tensor(nan, device='cuda:0')
E    DESIRED: tensor(nan, device='cuda:0')
        a          = tensor([-0.2783, -0.2783, -0.2783, -0.2783, -0.2783, -0.2783, -0.2783, -0.2783,
        -0.2783, -0.2783], device='cuda:0')
        self       = <scipy.stats.tests.test_stats.TestSkew object at 0x7f1da916e550>
        xp         = <module 'torch' from '/home/treddy/python_venvs/py_311_scipy_dev/lib/python3.11/site-packages/torch/__init__.py'>

The patch below the fold switches to using the xp_assert.. flavor in a few places and restores the passing test. It is more idiomatic anyway, so we should perhaps do that? I'll leave it to Matt and Lucas though, I'm probably rusty on this stuff compared to them.

--- a/scipy/stats/tests/test_stats.py
+++ b/scipy/stats/tests/test_stats.py
@@ -3433,16 +3433,16 @@ class TestSkew(SkewKurtosisTest):
         # exact (gh-13245)
         with pytest.warns(RuntimeWarning, match="Precision loss occurred"):
             a = xp.asarray([-0.27829495]*10)  # xp.repeat not currently available
-            assert_equal(stats.skew(a), xp.asarray(xp.nan))
-            assert_equal(stats.skew(a*2.**50), xp.asarray(xp.nan))
-            assert_equal(stats.skew(a/2.**50), xp.asarray(xp.nan))
-            assert_equal(stats.skew(a, bias=False), xp.asarray(xp.nan))
+            xp_assert_equal(stats.skew(a), xp.asarray(xp.nan))
+            xp_assert_equal(stats.skew(a*2.**50), xp.asarray(xp.nan))
+            xp_assert_equal(stats.skew(a/2.**50), xp.asarray(xp.nan))
+            xp_assert_equal(stats.skew(a, bias=False), xp.asarray(xp.nan))
 
             # # similarly, from gh-11086:
             a = xp.asarray([14.3]*7)
-            assert_equal(stats.skew(a), xp.asarray(xp.nan))
+            xp_assert_equal(stats.skew(a), xp.asarray(xp.nan))
             a = 1. + xp.arange(-3., 4)*1e-16
-            assert_equal(stats.skew(a), xp.asarray(xp.nan))
+            xp_assert_equal(stats.skew(a), xp.asarray(xp.nan))
 
     @array_api_compatible
     def test_precision_loss_gh15554(self, xp):
@tylerjereddy tylerjereddy added scipy.stats maintenance Items related to regular maintenance tasks array types Items related to array API support and input array validation (see gh-18286) labels Apr 23, 2024
@tylerjereddy tylerjereddy added this to the 1.14.0 milestone Apr 23, 2024
@mdhaber
Copy link
Contributor

mdhaber commented Apr 23, 2024

Oops! I think our eyes just missed that it was assert_equal and not xp_assert_equal. Thanks; I'll submit a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
array types Items related to array API support and input array validation (see gh-18286) maintenance Items related to regular maintenance tasks scipy.stats
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants