Skip to content

ENH: Use Dragon4 algorithm to print floating values #9941

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

Merged
merged 11 commits into from
Nov 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions doc/release/1.14.0-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ New functions

* ``parametrize``: decorator added to numpy.testing
* ``chebinterpolate``: Interpolate function at Chebyshev points.
* ``format_float_positional`` and ``format_float_scientific`` : format
floating-point scalars unambiguously with control of rounding and padding.


Deprecations
Expand Down Expand Up @@ -306,6 +308,28 @@ now supported for these arrays:
* `arr.resize(...)`
* `pickle.dumps(arr)`

Float printing now uses "dragon4" algorithm for shortest decimal representation
-------------------------------------------------------------------------------
All numpy floating-point types (16, 32, 64 and 128 bit) can now be printed to
give shortest decimal representation of the number, which uniquely identifies
the value from others of the same type.

New functions ``np.format_float_scientific`` and ``np.format_float_positional``
are provided to generate these decimal representations, with control over
rounding, trimming and padding.

The ``str`` and ``repr`` of floating-point scalars now shows the shortest
unique decimal representation. This means there will be a different number of
digits compared to numpy 1.13, for instance float64 and float128 will be longer
and float16 will be shorter.

For arrays of floating-point type, a new formatting option ``floatmode`` has
been added to ``np.set_printoptions`` and ``np.array2string``, which gives
control over uniqueness and rounding of printed elements in arrays. The new
default is ``floatmode='maxprec'`` with ``precision=8``, which will print at most
8 fractional digits, or fewer if an element can be uniquely represented with
fewer.


Changes
=======
Expand Down
2 changes: 2 additions & 0 deletions doc/source/reference/routines.io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ String formatting
array2string
array_repr
array_str
format_float_positional
format_float_scientific

Memory mapping files
--------------------
Expand Down
447 changes: 298 additions & 149 deletions numpy/core/arrayprint.py

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions numpy/core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ def get_mathlib_info(*args):
join('src', 'multiarray', 'conversion_utils.h'),
join('src', 'multiarray', 'ctors.h'),
join('src', 'multiarray', 'descriptor.h'),
join('src', 'multiarray', 'dragon4.h'),
join('src', 'multiarray', 'getset.h'),
join('src', 'multiarray', 'hashdescr.h'),
join('src', 'multiarray', 'iterators.h'),
Expand Down Expand Up @@ -793,6 +794,7 @@ def get_mathlib_info(*args):
join('src', 'multiarray', 'datetime_busday.c'),
join('src', 'multiarray', 'datetime_busdaycal.c'),
join('src', 'multiarray', 'descriptor.c'),
join('src', 'multiarray', 'dragon4.c'),
join('src', 'multiarray', 'dtype_transfer.c'),
join('src', 'multiarray', 'einsum.c.src'),
join('src', 'multiarray', 'flagsobject.c'),
Expand Down
Loading