Repository navigation
Make pictures independent of floating-point rounding (-O3) - #27
Merged
Merged
Conversation
…unding Built with -O3 (gfortran or flang, fused multiply-add allowed), six test pictures differed visibly from the plain build, and four more had a tick one pixel off: - A tick meant to be at 0 comes out of the locator as exactly 0 or as about 1e-17, and format_tick_fixed sent the second to the power-of-ten branch, which writes "0" where the rest of the axis writes "0.0". Values within 1e-8 of zero are now zero, as in matplotlib's ScalarFormatter. - label_window took the straightest window by a strict comparison, so on a straight run of a contour, where every window deviates by 0 up to 1e-14, rounding chose where the label went. A later window now has to be straighter by more than 1e-6. - pb_snap rounded with floor(x + 0.5), so a coordinate meant to be x.5 snapped to either pixel. It is rounded to 1/65536 px first. The plain and -O3 builds now differ only by single intensity levels. The nine pictures whose plain output changed are all closer to matplotlib than before, so their fingerprints are updated. CI runs the tests with flang -O3 -march=native to keep it that way.
certik
force-pushed
the
fix-numerical-robustness
branch
from
September 14, 2026 05:44
e49ad21 to
e363533
Compare
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.
Builds on #26 (merged), which added the fingerprint tests; rebased onto
mainas a single commit.With
-O3(gfortran or flang, where fused multiply-add changes rounding),fpm testfailed six pictures, and four more had a colorbar tick moved by one pixel. Three causes:0vs0.0tick labels (quiver3d,trisurf,mosaic,subplots_2x2,subplots_shared). The zero tick comes out of the locator as exactly 0 or about 1e-17, andformat_tick_fixedsent the tiny value to the power-of-ten branch. Values within 1e-8 of zero are now formatted as zero, which is what matplotlib'sScalarFormatterdoes.clabel).label_windowchose the straightest window with a strict<, so on straight runs (deviation 0 up to 1e-14) rounding decided. A later window now has to win by more than 1e-6.imshow,interp,cmap_special,colorbar_orient, …).pb_snapusedfloor(x + 0.5)on values meant to be exactly x.5. It rounds to 1/65536 px first.Verification (macOS, locally):
-O0vs gfortran-O3vs flang-O3: no visible difference in any of the 124 PNGs (only single intensity levels).colorbar_orient9.70 → 0.18/255,clabel5.13 → 4.76), so their fingerprints are updated.fpm testwith gfortran, gfortran--profile release, flang-O3 -march=native, and the flang script build all pass. The PNG comparison against matplotlib passes (1.50/255). LFortran 0.66.0 passes as well.CI: all steps pass, including
Test with LFortran(0.66.0). New steppixi run test-flang-O3(fpm test --compiler flang --flag '-O3 -march=native'), so a picture that depends on rounding fails in CI.