-
Notifications
You must be signed in to change notification settings - Fork 575
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
Downcast numbers passed to floats()
internally in constrained_complex()
#3574
Downcast numbers passed to floats()
internally in constrained_complex()
#3574
Conversation
d6299c3
to
4c9f1a9
Compare
I think we have existing but accepting-broken-behavior tests for this - we shouldn't be accepting epsilon errors here for example: Going to be a annoying, but I think this should include a review of our existing tests for |
Oh no, what have I done in 3b4918f (part of #3570) ... 😅 As an explanation, these were just copied from here, so that should also be investigated: hypothesis/hypothesis-python/tests/cover/test_complex_numbers.py Lines 51 to 69 in d53b129
As a note: One has to use the builtin |
(I'm taking a staycation in 2 weeks time where I'll be able work on reviewing the complex-related tests) |
4c9f1a9
to
72624d2
Compare
So uhh that staycation came and went 🙈 My exploration on
amounts to the use of hypothesis/hypothesis-python/src/hypothesis/strategies/_internal/core.py Lines 1623 to 1625 in d53b129
hypothesis/hypothesis-python/src/hypothesis/internal/cathetus.py Lines 26 to 28 in d53b129
Looking at #1154 (adding Anywho happy to explore it all more thoroughly (seem to have no time for coding outside of work now so that might take a while 🙃), thought I'd just brain dump now incase @Zac-HD had any insight/direction. |
...I suspect we might need to just slap on a filter and call it a day 😥 That's imperfect but still clearly better than the status quo, and so long as we document that it might be inefficient when there are very few allowed values I'll be happy with it. |
I guess that's pragmatic. It is honestly quite nieche, so it's probably okay if it is not 100% efficient (my outsider's view on this). |
@honno any updates here? I'd be keen to get something in ASAP. |
Thanks for the shout, I'll have a go tomorrow! Been busy with local election campaigning stuff which just ended 😅 |
Remove erroneous tests as complex_numbers({min/max}_magnitude=1.8, width=64) should validate
72624d2
to
67a9da9
Compare
67a9da9
to
97dc464
Compare
Hmm, I couldn't figure out how to filter out examples which are outside the magnitude range due to epsilon errors. Say we slapped a filter on the resulting # hypothesis/strategies/_internal.py:1746
+ if max_magnitude is None:
+ filter = lambda n: abs(n) >= min_magnitude
+ else:
+ filter = lambda n: min_magnitude <= abs(n) <= max_magnitude
- return constrained_complex()
+ return constrained_complex().filter(filter) This is inadequate as Any alternative approach to robustly identify epsilon errors? I couldn't seem to do filtering internally in If there's no resolution, I suggest we at least merge this PR to fix #3573 (also leaving comments about the allowance of epsilon errors), and write an issue about finding some kind of resolution to this epsilon error issue. FWIW I hadn't found any other problem with the complex tests, and alongside the introduced Ugh |
We could try else:
def pred(n):
try:
return min_magnitude <= abs(n) <= max_magnitude
except OverflowError:
return True # at least we improved on the status quo, see #3574 which is at least a weak improvement on the status quo? But let's try to get this PR in with just the width bugfix first. |
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.
I guess we need to look at the too-slow issue, but otherwise this looks good to me!
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.
🙏 thanks again @honno, you're a hero for array users everywhere!
Should resolve #3573, where we used the builtin width (i.e. 64) results of
cathetus()
, which don't validate infloats()
for any width but64
. Currently this PR downcasts the output ofcathetus()
, but I wonder if some of those downcasts would need clipping... EDIT: yeah somethings wrong