Skip to content

Comments

BUG: amos/amos.h: fix scope of l in seri#92

Open
JaRoSchm wants to merge 1 commit intoscipy:mainfrom
JaRoSchm:amos_seri_fix
Open

BUG: amos/amos.h: fix scope of l in seri#92
JaRoSchm wants to merge 1 commit intoscipy:mainfrom
JaRoSchm:amos_seri_fix

Conversation

@JaRoSchm
Copy link

@JaRoSchm JaRoSchm commented Feb 3, 2026

Hi, while in the long term I am still interested of getting #50 into xsf and scipy, I am using my own Python wrapper around your C translation of AMOS in the meantime. I noticed that for some parameters the implementation of besh tries to write the result into cy[-1]. To find the origin of this I compared the xsf translation to the automatic AMOS translation from https://github.com/jpcima/zbessel. The wrapper I used for this can be found at https://github.com/JaRoSchm/pyamos. There I added a check which allows me to detect if AMOS tries to write out of the range of the result array, see https://github.com/JaRoSchm/pyamos/blob/1cd435a33db41d3bad2448991ca0e5027a87057e/pyamos.cpp#L44C1-L50C10. To see the problem, you can simply run pixi run python compare_xsf_zbessel.py there.

The bug I found using this is the scope of the variable l in the seri function (see the diff of this PR). After the goto L100 statement (line 4494), the value of l from the loop is needed and not the value l = 3 assigned beforehand. Without the change from this PR, we had l = 3 in line 4499, which is not the wanted value. The original Fortran code can be found at https://github.com/scipy/scipy/blob/4edfcaa3ce8a387450b6efce968572def71be089/scipy/special/amos/zseri.f#L147.

I thought about adding a test for this, but I am not sure, how to do this. In https://github.com/JaRoSchm/pyamos/blob/main/compare_xsf_zbessel.py I use n = 260 resulting in a array of this length, which would have to be added as a reference value. Additionally, I actually never used C++ (and its test libraries), so all of this is an extrapolation of my Python and C knowledge.

Fix the scope of l such that its value from the loop is conserved after
the goto statement in the loop's body.
@JaRoSchm JaRoSchm changed the title BUG: amos/amos.h: fix scope of l in seri BUG: amos/amos.h: fix scope of l in seri Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant