Skip to content

BUG: amos.h: fix translation errors in asyi, unk1, and besi#158

Merged
fbourgey merged 4 commits into
scipy:mainfrom
JaRoSchm:amos_asyi_unk1_fix
Jun 4, 2026
Merged

BUG: amos.h: fix translation errors in asyi, unk1, and besi#158
fbourgey merged 4 commits into
scipy:mainfrom
JaRoSchm:amos_asyi_unk1_fix

Conversation

@JaRoSchm

@JaRoSchm JaRoSchm commented May 20, 2026

Copy link
Copy Markdown
Contributor

Reference issue

None

What does this implement/fix?

After the number of translation errors I found by hand, I decided to try an LLM for comparing the Fortran and C versions of amos. These are the translation errors unveiled this way. The disadvantage is, that I cannot add I test as it's hard to predict how to hit these branches.

Additional information

None

AI Generation Disclosure

Used Gemini 3.5 Flash to compare amos.f with amos.h. All suggestions were checked by hand (there was one additional false positive). Using a more powerful (= more expansive) model might also be rewarding.

Comment thread include/xsf/amos/amos.h
}
ck = std::exp(cz);
for (int i = 0; i < (nn + 1); i++) {
for (int i = 0; i < nn; i++) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread include/xsf/amos/amos.h
}
nz = n;
for (i = 0; i < (n + 1); i++) {
for (i = 0; i < n; i++) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread include/xsf/amos/amos.h
aphi = std::abs(phid);
aarg = std::abs(argd);
rs1 += std::log(aphi) - 0.25 * std::log(aarg) - aic;
rs1 += std::log(aphi);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JaRoSchm JaRoSchm changed the title BUG: amos.h: fix translation errors in asyi and unk1 BUG: amos.h: fix translation errors in asyi, unk1, and besi May 21, 2026
@JaRoSchm

Copy link
Copy Markdown
Contributor Author

I added a fix for another translation bug in besi to this PR.

Comment thread include/xsf/amos/amos.h
return 0;
}
if (xx > 0.0) {
if (xx >= 0.0) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fbourgey fbourgey self-requested a review June 3, 2026 11:56

@fbourgey fbourgey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

I potentially see one more

From https://github.com/scipy/scipy/blob/4edfcaa3ce8a387450b6efce968572def71be089/scipy/special/amos/zunk2.f#L60-L62, it seems https://github.com/scipy/xsf/blob/main/include/xsf/amos/amos.h#L5879 should be changed to

double bry[3] = {1e3 * d1mach[0] / tol, tol / (1e3 * d1mach[0]), d1mach[1]};

@JaRoSchm can you confirm?

@JaRoSchm

JaRoSchm commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

@fbourgey Thank you for the review!

From https://github.com/scipy/scipy/blob/4edfcaa3ce8a387450b6efce968572def71be089/scipy/special/amos/zunk2.f#L60-L62, it seems https://github.com/scipy/xsf/blob/main/include/xsf/amos/amos.h#L5879 should be changed to

double bry[3] = {1e3 * d1mach[0] / tol, tol / (1e3 * d1mach[0]), d1mach[1]};

@JaRoSchm can you confirm?

Yeah, your are right. But this fix is already included in #132. :) I notice that splitting the fixes into different PRs might have been a bit confusing.

}
}

TEST_CASE("amos besi vectorized", "[amos][xsf_tests]") {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a small regression test for asyi too? A regression test forunk1 and unk2 would be nice too but they look harder to hit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Your intuition was right, I did not find a way to hit the fixes in unk1 and unk2.

@fbourgey

fbourgey commented Jun 4, 2026

Copy link
Copy Markdown
Member

@fbourgey Thank you for the review!

From https://github.com/scipy/scipy/blob/4edfcaa3ce8a387450b6efce968572def71be089/scipy/special/amos/zunk2.f#L60-L62, it seems https://github.com/scipy/xsf/blob/main/include/xsf/amos/amos.h#L5879 should be changed to

double bry[3] = {1e3 * d1mach[0] / tol, tol / (1e3 * d1mach[0]), d1mach[1]};

@JaRoSchm can you confirm?

Yeah, your are right. But this fix is already included in #132. :) I notice that splitting the fixes into different PRs might have been a bit confusing.

Great, thanks. Let's get that one in first.

@fbourgey fbourgey merged commit 156579c into scipy:main Jun 4, 2026
6 of 8 checks passed
@fbourgey

fbourgey commented Jun 4, 2026

Copy link
Copy Markdown
Member

Thanks @JaRoSchm!

@JaRoSchm

JaRoSchm commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for the review!

@JaRoSchm JaRoSchm deleted the amos_asyi_unk1_fix branch June 4, 2026 18:19
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.

2 participants