-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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: handle the edge case lambda=0 in pdtr, pdtrc and pdtrik #3155
Conversation
I haven't been able to reproduce the failure that is occurring in travis with python 2.7. With the changes in the PR, |
I can reproduce this on 32-bit linux, will have a look. |
IF ((xlam .LT. 1.0D-2) .AND. (p .LT. 0.975D0)) THEN | ||
C For sufficiently small xlam and p, the result is 0.0. | ||
s = 0.0D0 | ||
stats = 0 |
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.
This should be status = 0
, that should fix the failure.
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.
Ah. I must have looked at that line dozens of times and never noticed the typo.
Adding IMPLICIT NONE
would have caught it. Apparently IMPLICIT NONE
is not standard Fortran 77, but we're already using it in special/specfun/specfun.f. Any objections to adding it to this subroutine?
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.
No opinion, I don't really speak Fortran.
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.
Unless implicit none breaks in some of our more esoteric fortan 77 setups, please please please add it!
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 personally am more wary of Fortran code without implicit none
--- standard or not, as long as it actually compiles.
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.
Still strange that the failure depends on Python version (or even the way I call it; within IPython it doesn't fail). So something else may still be wrong. |
@rgommers wrote:
Because of the typo, the variable was never assigned in the Fortran code. The variable was originally declared on the stack in the C wrapper, so it was uninitialized. If the value happened to be negative, 3 or 4, the wrapper function returned nan. So it is not surprising that it would fail in random ways. (Of course, I may be overconfident here--the tests on Travis for the updated code haven't finished yet. :) |
We already use "implicit none" quite a bit (search for "implicit none"), so apparently it is not a problem, even though it is not standard Fortran 77. I added it to the |
All the tests pass now. Yesterday the Python 3.3 build had a timeout error. |
@pv: As the resident |
A weird comment very very late: do we actually need to have |
In some cases it's useful to have a continuous extension for calculations, even if we convert to integers at the end. Maybe it would be easy to generate Poisson random numbers with a continuous pdtrik return. |
BUG: special: handle the edge case lambda=0 in pdtr, pdtrc and pdtrik
LGTM. Some checking shows that
|
This PR makes a few changes so that
special.pdtr
,special.pdtrc
andspecial.pdtrik
give the correct limiting value when the Poisson parameter lambda is 0.In the case of
pdtrik
, the function now immediately returns 0 forlambda
< 0.01 andp
< 0.975. This is a lot more than the simple edge caselambda = 0
, but it is based on the following figure showing the results of computingpdtrik
from master on a grid of values:The gray dots are where the result is 0. The red dots are where
pdtrik
returns 1e+100; the "correct" value is 0 at those points.The script to generate the plot is in a gist: https://gist.github.com/WarrenWeckesser/7995139