-
Notifications
You must be signed in to change notification settings - Fork 73
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
core: Print fp literals losslessly #3381
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3381 +/- ##
==========================================
+ Coverage 90.11% 90.12% +0.01%
==========================================
Files 450 450
Lines 56798 56826 +28
Branches 5459 5461 +2
==========================================
+ Hits 51182 51215 +33
+ Misses 4174 4167 -7
- Partials 1442 1444 +2 ☔ View full report in Codecov by Sentry. |
I think I've missed a bit of discussion, what's wrong with having this as the default? |
I completely agree, but having this as a default requires changing a vast number of tests. Also, I suspect that full-precision is not actually very good for cross-system reproducible file checks, My preference would be to have a reduced-precision flag and use this on file checks, with full-precision mode being the default. |
I've changed the default behaviour to print with full precision. |
tests/filecheck/mlir-conversion/with-mlir/print-fp-precision.mlir
Outdated
Show resolved
Hide resolved
tests/filecheck/mlir-conversion/with-mlir/print-fp-precision.mlir
Outdated
Show resolved
Hide resolved
Here's a minimally intrusive suggestion, which takes the same approach of mlir-opt: attempt to print to scientific 6dp notation iff the resulting string is losslessly reproducible, or else print to full precision using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
I feel I would still personally prefer that "simple" floats print in non scientific format, but I guess this is just too large of a filecheck diff
It can always be done in the future. I'm not sure about the performance of parsing the str back to a float to ensure there is no precision loss, and printing it straight through |
`mlir-opt` attempts to print floats as 6dp scientific notation, but round-trips to ensure there is no precision loss and the printed number will bitwise reproduce exactly. If this fails, it will choose a different printing method to ensure bit-reproducible printing for a given precision of fp types. This PR takes the approach of mlir-opt: attempt to print to scientific 6dp notation iff the resulting string is losslessly reproducible, or else print to full precision using repr. This has the advantage of not affecting a vast number of filechecks, mirroring upstream, and not having a flag for either full or reduced precision. --------- Co-authored-by: n-io <[email protected]>
`mlir-opt` attempts to print floats as 6dp scientific notation, but round-trips to ensure there is no precision loss and the printed number will bitwise reproduce exactly. If this fails, it will choose a different printing method to ensure bit-reproducible printing for a given precision of fp types. This PR takes the approach of mlir-opt: attempt to print to scientific 6dp notation iff the resulting string is losslessly reproducible, or else print to full precision using repr. This has the advantage of not affecting a vast number of filechecks, mirroring upstream, and not having a flag for either full or reduced precision. --------- Co-authored-by: n-io <[email protected]>
mlir-opt
attempts to print floats as 6dp scientific notation, but round-trips to ensure there is no precision loss and the printed number will bitwise reproduce exactly. If this fails, it will choose a different printing method to ensure bit-reproducible printing for a given precision of fp types.This PR introduces a flag to print with full precision. This should eventually become the default.This PR prints with full precision by default, but provides a--print-reduced-precision-fp
flag to enable the legacy behaviour.This PR takes the approach of mlir-opt: attempt to print to scientific 6dp notation iff the resulting string is losslessly reproducible, or else print to full precision using repr. This has the advantage of not affecting a vast number of filechecks, mirroring upstream, and not having a flag for either full or reduced precision.