Part of a set of structural observations — see #1695 (index) for context.
Description
The "output is given at 6 significant digits/figures accuracy" is presented as a fairly big deal in the docs, while such matters are hardly a concern anymore. Moreover, the implementation is bespoke and has significant overhead.
common/math/numbers.py implements custom output rounding: it uses Decimal.adjusted() to find the significant-digit position of each float, then calls np.format_float_positional (the Dragon4 algorithm) with a computed precision. A second function, format_results_to_precision, walks a deep copy of an entire Pydantic result tree, reformatting every float in place.
It isn't a call to np.set_printoptions (which would be free) — it's real, bespoke logic, run on a full copy of every result object, to produce a display property that round() or standard print/string formatting could approximate far more cheaply, if it needs to be programmatic at all rather than left to the presentation layer (the CSV/JSON writer).
Examples
—
Business/User Value
Removes a deep-copy-and-walk pass over the full result tree on every run, and removes bespoke rounding logic that has to be maintained and tested, in favor of either round() at the point of formatting or standard formatting in the CSV/JSON writer.
Files
Part of a set of structural observations — see #1695 (index) for context.
Description
The "output is given at 6 significant digits/figures accuracy" is presented as a fairly big deal in the docs, while such matters are hardly a concern anymore. Moreover, the implementation is bespoke and has significant overhead.
common/math/numbers.pyimplements custom output rounding: it usesDecimal.adjusted()to find the significant-digit position of each float, then callsnp.format_float_positional(the Dragon4 algorithm) with a computed precision. A second function,format_results_to_precision, walks a deep copy of an entire Pydantic result tree, reformatting every float in place.It isn't a call to
np.set_printoptions(which would be free) — it's real, bespoke logic, run on a full copy of every result object, to produce a display property thatround()or standard print/string formatting could approximate far more cheaply, if it needs to be programmatic at all rather than left to the presentation layer (the CSV/JSON writer).Examples
—
Business/User Value
Removes a deep-copy-and-walk pass over the full result tree on every run, and removes bespoke rounding logic that has to be maintained and tested, in favor of either
round()at the point of formatting or standard formatting in the CSV/JSON writer.Files
common/math/numbers.py