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

Special case parser produces incorrect test case for signbit expected behavior for NaN #250

Closed
oleksandr-pavlyk opened this issue Mar 29, 2024 · 1 comment · Fixed by #253
Assignees
Labels
bug Something isn't working

Comments

@oleksandr-pavlyk
Copy link
Contributor

test_special_cases.py::test_unary derives tests from docstring. For signbit it says:

  • If x_i is NaN and the sign bit of x_i is 0, the result is False.
  • If x_i is NaN and the sign bit of x_i is 1, the result is True.

The parser of these strings is not able to handle the distinction:

(dev_dpctl) opavlyk@opavlyk-mobl:~/repos/array-api-tests$ SYCL_CACHE_PERSISTENT=1 ONEAPI_DEVICE_SELECTOR=*:cpu ARRAY_API_TESTS_MODULE=dpctl.tensor ipython
Python 3.9.12 (main, Jun  1 2022, 11:38:51)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.18.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import warnings

In [2]: warnings.filterwarnings("ignore")

In [3]: import array_api_tests.test_special_cases as tsc

In [4]: signbit_params = [f for f in tsc.unary_params if f.values[0] == "signbit"]

In [5]: sb_f, sb_t = signbit_params[-1].values[-1], signbit_params[-2].values[-1]

In [6]: (sb_f, sb_t)
Out[6]: (UnaryCase(<x_i is NaN -> True>), UnaryCase(<x_i is NaN -> False>))

In [7]: p_nan = float('nan')

In [8]: n_nan = -p_nan

In [9]: {repr(case):(case.check_result(p_nan, 0.0), case.check_result(p_nan, 1.0)) for case in [sb_f, sb_t]}
Out[9]:
{'UnaryCase(<x_i is NaN -> True>)': (False, True),
 'UnaryCase(<x_i is NaN -> False>)': (True, False)}

In [10]: {repr(case):(case.check_result(n_nan, 0.0), case.check_result(n_nan, 1.0)) for case in [sb_f, sb_t]}
Out[10]:
{'UnaryCase(<x_i is NaN -> True>)': (False, True),
 'UnaryCase(<x_i is NaN -> False>)': (True, False)}

We can use NumPy to verify that the sign bit of p_nan is not set, while the sign bit of n_nan is:

In [11]: import numpy as np

In [12]: hex(np.asarray(p_nan, dtype="f4").view(np.uint32))
Out[12]: '0x7fc00000'

In [13]: hex(np.asarray(n_nan, dtype="f4").view(np.uint32))
Out[13]: '0xffc00000'

In [14]: np.signbit(p_nan), np.signbit(n_nan)
Out[14]: (False, True)

This is causing unexpected test failure in array-api-test suite for dpctl when its __array_api_version__ is set to "2023.12".

@honno
Copy link
Member

honno commented Apr 12, 2024

Thanks for the issue/detailed reproducer, I opened #253 which resolves the same issue at least for array_api_strict/NumPy/etc., although I had problems getting dpctl.tensor working locally so haven't verified that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants