fix: avoid atan branch cut in complex trigonometric test (musl CI)#1336
Merged
serge-sans-paille merged 1 commit intoxtensor-stack:masterfrom Apr 29, 2026
Merged
Conversation
The atan_input generator sampled (Re=0, Im=1.5) at i=N/2, which lies on the branch cut of complex atan at Re=0, |Im|>=1. C99 7.3.4.1 leaves the sign of Re(catan(+/-0 + i*y)) for |y|>1 implementation-defined: glibc returns +pi/2, musl returns -pi/2. xsimd matches glibc, so the test fails on musl-based CI (e.g. void-linux x86_64-musl) with two mismatches (one per complex<float>/complex<double> batch type). Shift the real start from -10 to -9.5 so Re=0 occurs at i=19000, where |Im|~0.975<1 - analytic territory where atan is uniquely defined and all libcs agree. Negative/positive real coverage is preserved; only the singular point on a region of unspecified behavior is dropped.
Contributor
Author
|
@jason1987d could you verify that this fixes the issue? |
Yes. |
This was referenced Apr 29, 2026
Contributor
|
Thank you so much for handling this 🙇 |
Contributor
|
@DiamonDinoia would it make sense to have a musl validation bot? |
Contributor
Author
|
I makes sense as it uses a different glibc. However, we should be mindful of the length of pipelines. What if push release candidates so the repo maintainers can do these validations and report issues before we push a final release? We could give a week of grace. |
Contributor
|
That's what I do for pythran: maintain a list fo repo maintainer, create a PR
with the release candidate and let maintainer report results there. I'm fine
with that approach.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary (I used claude to reproduce locally, as it is a hassle to handle docker for this)
test_complex_trigonometric.cppfails on musl-based CI (e.g. void-linux x86_64-musl, see void-packages CI run) with two mismatches in[complex trigonometric]forcomplex<float>andcomplex<double>.Root cause
atan_input[i] = (-10 + i*20/N, -9 + i*21/N)lands onz = (0, 1.5)ati = N/2, which is on the branch cut of complexatan(Re=0, |Im|>=1). Per C99 §7.3.4.1, the sign ofRe(catan(±0 + iy))for|y|>1is implementation-defined:atan(0 + 1.5i) = (+π/2, 0.8047…)atan(0 + 1.5i) = (-π/2, 0.8047…)xsimd's
atanimplementation matches glibc, soCHECK_BATCH_EQ(ref, out)against the musl reference fails. The previous test code usedget_nb_diffwhich was lossy; commit ae3822f replaced it with per-elementCHECK_BATCH_EQ, exposing this latent issue.Fix
Shift the real start from
-10to-9.5soRe=0occurs ati = 19000where|Im| ≈ 0.975 < 1— analytic territory whereatanis uniquely defined and all libcs agree. Symmetric negative/positive real coverage is preserved; only the single sample on a region of unspecified behavior is dropped.Verification
std::atan(std::complex<T>)on glibc vs alpine/musl: confirmedResign flip at(0, 1.5).[complex trigonometric]2/2 cases fail.