Closed
Description
test_special_cases.py::test_unary
derives tests from docstring. For signbit
it says:
- If
x_i
isNaN
and the sign bit ofx_i
is0
, the result isFalse
.- If
x_i
isNaN
and the sign bit ofx_i
is1
, the result isTrue
.
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"
.