GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-153144: Avoid checking `errno` for `atan2` by hpkfft · Pull Request #153148 · python/cpython Conversation
|
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
If this PR is merged, it looks to me like #146402 can (and should) be reverted. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
No, I doubt that this is a right approach. We must handle error in same way for all libm functions.
Perhaps, m_atan2() (like m_log1p() we have currently) could be restored (see #122681) to workaround broken platform functions.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The mathmodule currently has 3 ways of handling 1-argument libm functions:
Maybe it's not so bad to have |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Perhaps, we could modify math_2() helper to check that errno!=EDOM, if inputs and output are finite. When domain error occurs - result should be nan. But I think that a little wrapper for libm's atan2 is better, if we are going to add some workaround for the given issue. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please revert unrelated changes.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@vstinner, can you look at this at your convenience? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
If this PR is merged, it looks to me like #146402 can (and should) be reverted.
I would prefer to update tests for Solaris in the same PR.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
You also could use new helper function for copysign. On another hand, I would prefer just remove errno stuff from math_2(), per #156145. It should be possible for all two-argument functions: atan2, atan2pi, copysign, remainder and fmod (which could utilize same wrapper). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
My thinking is only to do what is necessary to fix the bug (the incorrect results when building with Intel or Solaris math libraries). Then, I would recommend applying this fix to Python 3.14 and 3.15. With that in mind, I don't want to make any enhancements that are not necessary to fix the reported bug.
Yes, 156145 can have a more ambitious goal. Can you trigger the buildbots to run this PR? I am not able to check myself that it works on Solaris. (I do think it will work based on what I read in the Solaris bug report.) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Then we loose chance of using new helper function for copysign().
!buildbot Solaris |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
!buildbot Solaris |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
🤖 New build scheduled with the buildbot fleet by @skirpichev for commit 5b6d005 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F153148%2Fmerge The command will test the builders whose names match following regular expression: The builders matched are:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
OK, I'll add that commit tomorrow. Since it will be a separate commit, it can easily be reverted (or skipped when squashing all the commits before the final merge). The same is true for the comments Victor requested--they're in their own separate commit. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@serhiy-storchaka @skirpichev @picnixz: What is your opinion on changing |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
FWIW, I don't think there is a change in behavior: atan2() shouldn't overflow. Underflows in Python are silent. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I totally forgot about this PR. Let me read the issue and the history first (and now my speech resembles that of an AI...) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Well, fixing a bug is a change in behavior. But I know what you mean. Let me walk through an example (using Python 3.13.5 built to use GNU libm). and note that, for both of them, imag/real underflows to zero: The math module's In the first case, the result underflows to DetailsThe wrapper In the second case, the infinitely precise result is very close to Pi, and libm rounds the result to three point something in order to return a double precision result. The result did not underflow to zero (nor did it overflow to infinity), so GNU's libm leaves errno unchanged. Python code had set Now, we get to the bug. Python calls GNU libm's In the second case, GNU's With this PR: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@picnixz: So did you find time to review this change? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
No I'm sorry. I am quite busy in my daily job and haven't found time for that. I think I will have time on Sunday as I'm flying (or next thursday as I'm flying back). But the past weeks have been very busy (I can only do simple triaging or review). Now, after a quick glance:
This makes at least Did I catch the issue well? we wouldn't break code though, just fixing things. What I'm worried about however is implementations that really want to raise an EDOM for
In addition, Annex F says what to return when using (0,0). I would have imagined:
But in the second case, we can say it's garbage in-garbage out and it's likely an unsupported compiler (even less supported than icx!) So... I guess we canj ust ignore EDOM? Did I get it right? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Done.
Yes. Although, technically, it's about the C math library, not the compiler. (It's possible to mix and match, e.g., use the Intel or Solaris math libraries with GCC.) Perhaps the title of my bug report for icx was too informal. Note that a math library might not strictly conform to Annex F for many reasons. Here, we only care about the values it returns for atan2(), which I would venture to guess would be correct even if the compiler and math library as a whole cannot claim to be compliant with the entirety of Annex F. Finally, I would like to suggest that, in my opinion, raising an exception where one should not happen is a serious bug. A Python programmer would not be expected to put My understanding is that bugfixes for Python 3.13 must be merged this month. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Do not click the "Update branch" button without a good reason because it notifies everyone watching the PR that there are new changes, when there are not, and it uses up limited CI resources. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
We unfortunately get past 3.13 release and it is not security-only. I am ok with putting it in 3.16 and maybe 3.14/3.15 but I would be interested in having some NumPy's opinion just in case (cc @ngoldbaum). I think fixing the phase/atan2 inconsistency takes precedence over other behavioral change concerns. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks for the ping. NumPy already behaves the way CPython will behave after this PR. The only difference is that NumPy can optionally surface the underflow, and it reports it as an underflow, never as an overflow. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Yeah so this matches what users will expect. I am fine with this PR then! thanks for doing it. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
@skirpichev PTAL again
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| /* variant of math_2, to be used when the function being wrapped is known NOT | ||
| to need error checking (i.e., no overflow, invalid, or divide-by-zero). */ |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I suggest expand this with atan2() example and remove other comments below.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (y == -1.0 && PyErr_Occurred()) { | ||
| return NULL; | ||
| } | ||
| r = (*func)(x, y); // Ignore errno on purpose. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| r = (*func)(x, y); // Ignore errno on purpose. | |
| r = (*func)(x, y); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@vstinner asked for this comment on August 14: #153148 (comment)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| /* gh-153144: Ignore atan2 and atan2pi errno on purpose since it can optionally | ||
| * be EDOM, which we should ignore, or ERANGE on underflow, which is | ||
| * silent on Python. Overflow is not possible. */ |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| /* gh-153144: Ignore atan2 and atan2pi errno on purpose since it can optionally | |
| * be EDOM, which we should ignore, or ERANGE on underflow, which is | |
| * silent on Python. Overflow is not possible. */ |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@vstinner asked for the "ignore errno on purpose" part of this comment on August 14: #153148 (comment)
@picnixz asked to "document the reason why we ignore errno in this case" on September 18: #153148 (comment)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| C89 but for which HUGE_VAL is not an infinity. | ||
|
|
||
| For most two-argument functions (copysign, fmod, hypot, atan2) | ||
| For most two-argument functions (fmod, hypot) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actually, the only remaining math_2()-type function is remainder()...
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think (fmod, hypot) in the comment above refers to the C math library functions.
Unless I've missed it, Python does not use the C math library function double remainder(double, double), so I don't think we should add it to this comment.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think (fmod, hypot) in the comment above refers to the C math library functions.
I don't think so. Before 53876d9, both fmod and hypot were using FUNC2 macro.
Python does not use the C math library function double remainder(double, double)
Yes, but m_remainder (name in style m_log and co, suggesting a workarounded libm's function) is just an implementation of Annex F remainder.
Perhaps, nowadays we could replace this function by standard library call: at least this works well for me locally. See previous attempt of removing legacy stuff: #101679
Edit: FYI, #158826.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Interesting. But it seems sufficiently unrelated as to allow this PR to be merged without further tweaks to the comments.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.