-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
BUG:special:amos: Fix exit path in amos_asyi
#19939
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
Conversation
|
Actually this is because of that extra in the for (int j = 1; j < (jl+1); j++) Without that, if ((j == jl+1) && (aa > atol)) { return -2; }because C loop increments In Python, loop exhaustion check is wonderful but in these languages, they are left to the developer unfortunately. |
|
We might also be missing a diff --git a/scipy/special/_amos.c b/scipy/special/_amos.c
index 7629d350b..7bc59cb3d 100644
--- a/scipy/special/_amos.c
+++ b/scipy/special/_amos.c
@@ -1115,7 +1115,10 @@ int amos_asyi(
if (koded == 0) { return nz; }
ck = cexp(cz);
for (int i = 0; i < (nn + 1); i++) { y[i] *= ck; }
+ /* 90 */
+ return nz;
}
+ /* 100 */
return -1;
}scipy/scipy/special/amos/zasyi.f Lines 153 to 161 in e5f2129
|
Yes I think so too. By the way, thanks a lot for these @inkydragon ! Keep them coming as you encounter them please. A bit embarrassing on my side but crucial fixes. |
I think this is normal, given the number of lines of code in _amos.c, and the complex function call relationships, it's easy for there to be areas that the tests don't cover. I'm trying to rewrite the amos code in Julia based on your C translation. The way I'm doing it is to start rewriting from the leaf functions that have no dependencies, and then test the new code against the original fortran code and try to improve the test coverage. So these bugs were found through testing, and I probably wouldn't have been able to find them if I had just stared at the code. Even with line coverage close to 100%, I was able to find some inconsistencies, mainly in special floating point inputs such as NAN, INF, etc. This could mean that my implementation is still buggy, or that the way fortran handles special floating point numbers is inconsistent with julia. I would recommend my rewrite approach: @ilayn
|
|
Actually, except from item 4, about C coverage, that's how I did it too. But I don't really know how to get the result of gcov triggered from Regardless, thanks again for these fixes, let's get this one in. |
|
@ilayn it is fairly painless to get, you do a build with |
|
I must be doing something wrong then since I couldn't manage to get things work but thanks for the heads up, I'll try again. |
I haven't been able to get it to work either. Let me know if you get it working and if so what you did differently. |
|
What part specifically isn't working? I checked the coverage on one of these recent PRs so pretty sure I had it working |
I think it's really awesome to see this translation might be helpful for the Julia ecosystem too. It's actually something I'd mentioned in a recent grant proposal asking for funding to rewrite SciPy's F77 code. It's very cool to see that really start taking shape. Good luck in your efforts @inkydragon. Thanks for taking a close look and helping to find these bugs. |
Two parts; I tried both with the |
Indeed, that's the whole point of all why I got into this and frankly, rejuvenated my motivation to finish things off. I know that there were multiple attempts in the past while I was researching about the appetite such as JuliaMath/SpecialFunctions.jl#52 Thank you indeed. |
Feel free to ping me on future PRs and I can just upload the coverage artefacts |
Reference issue
xref: #19587 cc @ilayn
What does this implement/fix?
amos_asyiwas always falseAdditional information
C:
scipy/scipy/special/_amos.c
Lines 1078 to 1095 in b882f1b
The value of the first expression,
(j == jl), on line 1093 is independent of how theforloop exits.Because the
forloop introduces a new variable scope, modifying the loop variablejused by for does not affect thejvariable of the same name outsidefor.So in fact there is always
j==1.My modification introduces a new flag to check if you're exiting from
break, and if so, continue the function.Otherwise, it returns an error code.
There are a number of ways to fix this, perhaps using
aa > atoldirectly as a judgment condition for exiting the function would work without introducing a new variable, I'm not sure.Fortran:
scipy/scipy/special/amos/zasyi.f
Lines 99 to 117 in e5f2129
scipy/scipy/special/amos/zasyi.f
Lines 162 to 164 in e5f2129