-
Notifications
You must be signed in to change notification settings - Fork 68
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
Refactored obsolescent code #23
base: master
Are you sure you want to change the base?
Conversation
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 for doing that. I left some minor comments, that perhaps make the code even simpler / more readable.
My main comment is this: does the new code actually work? It's very easy to make a tiny mistake in such refactoring (even though I haven't found any by just looking at it), which will make the code fail in various ways.
One reason I just took the subroutines verbatim from scipy is that they were extensively tested in scipy.
Given that the changes are essentially just syntax changes, it does seem it should work. So maybe it's fine.
Did you test the subroutines to ensure they work as before? If so, then I think we can merge it.
real(dp) :: sa,sb,f,f0,f1,cs | ||
|
||
! .3333333333333333d0 in original | ||
real(dp),parameter :: one_third = 1.0_dp / 3.0_dp |
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.
You can also write this as 1._dp / 3
.
if (abs(x)<1.0e-100_dp) then | ||
do k=0,n | ||
sj(k)=0.0_dp | ||
dj(k)=0.0_dp |
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.
You can also just assign 0
, it will be converted to double precision.
sj(k)=0.0_dp | ||
dj(k)=0.0_dp | ||
end do | ||
sj(0)=1.0_dp |
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.
One can just do sj(0) = 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.
Agreed. I'm usually paranoid about the kinds, so I usually keep the _dp
even for 0 and 1.
f0=0.0_dp | ||
f1=1.0_dp-100 | ||
do k=m,0,-1 | ||
f=(2.0_dp*k+3.0_dp)*f1/x-f0 |
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.
Since f1
is double precision, this can also be written as:
f=(2*k+3)*f1/x-f0
endif | ||
f=0.0_dp | ||
f0=0.0_dp | ||
f1=1.0_dp-100 |
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.
The original is F1=1.0D0-100
, which is a bit confusing, but I think it's just 1-100
which is -99
. Since f1
is double precision, you can just write it as 1-100
.
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, I noticed that. I actually wondered if that was some kind of typo (is it possible they meant 1.0e-100?)
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 first thought you made a typo, but then the original is the same. I wonder that too, it really looks like a typo. I don't remember with these, but I know it's possible that some of these old Fortran routines can produce incorrect answers, a different example that I found is:
https://mail.scipy.org/pipermail/scipy-user/2012-September/033189.html
(This has since been fixed.)
end do | ||
endif | ||
do k=1,nm | ||
dj(k)=sj(k-1)-(k+1.0_dp)*sj(k)/x |
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.
dj(k)=sj(k-1)-(k+1)*sj(k)/x
Test case (same result from refactored version and the one in scipy):
This is the only one I did. |
Here's another one (same result for both):
|
@jacobwilliams thanks for doing the tests. If you wouldn't mind doing a few more just to make sure, that would be great. If there is a bug introduced by this, we can always trace it to this PR and fix it. |
Fixes #19