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
Generate subnormal floats #3152
Conversation
bee92a0
to
b3d4370
Compare
Noting here that Could there be a kwarg like st.floats().filter(lambda n: abs(n) >= float_info.min) |
I think this is incorrect - the spec currently says that float dtypes follow IEEE 754, which would require support for subnormals. Evidently CuPy (/Nvidia hardware) doesn't strictly support IEEE 754, and perhaps the array API standard will be altered to make subnormals optional, but as it stands I consider this a bug in CuPy rather than Hypothesis. Regardless, I'm open to a new allow_subnormal parameter, but in a different PR to this one since they're already supported. |
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.
Quite familiar with the existing sub-normal tests now, so LGTM.
@@ -114,11 +112,6 @@ def test_is_in_exact_int_range(x): | |||
REALLY_SMALL_FLOAT = sys.float_info.min * 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.
Maybe this is obvious to somebody who didn't just learn about the concept of sub-normals today (me), but I couldn't figure this out. My guess is that you could use an interpreter built in one architecture but run this in the other architecture, so sys.float_info
could be incorrect?
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.
Nah, it'll be if the interpreter was built with various unsafe compiler flags which flush denormals to zero (e.g. -funsafe-math-optimizations
). Which is terrible, but here we are.
(I'll clarify the test and comment, and make this a skipif)
b3d4370
to
7411a82
Compare
It turns out that we can generate subnormal values; it's just that we do so with negligible probability because they only occur for one-in-2^11 possible exponents. The obvious workaround is to just add a handful of special values to our
NASTY_FLOATS
table, and so here's a PR to do just that. Fixes #2976.