-
Notifications
You must be signed in to change notification settings - Fork 100
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
Fix gamma_inc for larga a and small x (and very large x) #314
Conversation
996e3cc
to
a1fa735
Compare
Codecov Report
@@ Coverage Diff @@
## master #314 +/- ##
==========================================
+ Coverage 88.44% 88.79% +0.35%
==========================================
Files 12 12
Lines 2622 2624 +2
==========================================
+ Hits 2319 2330 +11
+ Misses 303 294 -9
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
a1fa735
to
576a2e9
Compare
I've added some tests to increase the test coverage. While doing that I noticed a bug in Update: I've also renamed the |
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 did not check the correctness of the parts where only the formatting was changed. I am sure that rgammax
matches the Fortran implementation and that _gamma_inc_choose_algorithm
also corresponds to the Fortran code (just had a question about the assert statement). It was a bit tricky to follow the Fortran code for _gamma_inc
with all the go-to statements. I couldn't find one of the branches in the Fortran code but otherwise it seems to be correct, in particular the additional branch for _gamma_inc_choose_algorithm
if a >= big1[iop]
and !(abs(s) <= 0.4)
.
end | ||
|
||
y = a*z | ||
rta = sqrt(a) | ||
if abs(s) <= e0[iop]/rta |
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.
In the Fortran code (end of block 20) I can only find a check for abs(s) <= 0.4
which appears after this branch here in SpecialFunctions.
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 just looked and it seems to be part of the single precision version GRATIO
. It's also block 20 and line 13303. However, we shouldn't be using the single precision version (although it seems that they had larger words back when Morris wrote all this code). I'll update this to follow the double precision routine.
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.
Actually, I think it's better to leave that for a separate PR. The single precision version has the extra IOP
argument that controls the precision and we expose that in gamma_inc
. As mentioned, the word size was larger on the machines that Morris wrote this for and he writes in the comment to the single precision version GRATIO
that
IF IND = 0 THEN THE USER IS REQUESTING AS MUCH ACCURACY AS POSSIBLE (UP TO 14 SIGNIFICANT DIGITS).
so I think it's still okay for Float64
. Notice that his double precision literals have 30 digits.
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.
Yes, this seems reasonable. Thanks for looking into this, I didn't check the single precision version.
end | ||
p = erf(sqrt(x)) | ||
return ( p , 1.0 - p ) | ||
return (p, 1.0 - p) | ||
elseif x < 1.1 |
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.
It seems in the Fortran code the cutoff is 2 instead of 1.1 (in the section "SELECT THE APPROPRIATE ALGORITHM" above 10).
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.
Indeed this is similar to the one above. I'll go through the while function.
version from NSWC. Remove redundant constant. Some style consistency adjustments.
86e3285
to
e21c446
Compare
I think this one is ready. |
Did you see my suggestions in #314 (comment) and #314 (comment) and similar lines? It seems they were marked as resolved but maybe that happened automatically when you force pushed the branch. |
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
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.
Looks good to me 👍
I could have sworn that I'd already accepted all of them. Maybe it's a problem if you don't allow enough time between acceptance of different suggestions. |
Fixes #311 as explained in my comment there.