From 8b998015bb484d2d1719a04f2ee7f147c89634a4 Mon Sep 17 00:00:00 2001 From: Holger Kohr Date: Thu, 13 Sep 2018 00:26:40 +0200 Subject: [PATCH] ENH: use np precision instead of hardcoded one in npy tensor repr --- odl/space/npy_tensors.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/odl/space/npy_tensors.py b/odl/space/npy_tensors.py index 9f86ad0cbdd..2b363fe6758 100644 --- a/odl/space/npy_tensors.py +++ b/odl/space/npy_tensors.py @@ -2606,12 +2606,14 @@ def __hash__(self): def repr_part(self): """String usable in a space's ``__repr__`` method.""" max_elems = 2 * np.get_printoptions()['edgeitems'] + precision = np.get_printoptions()['precision'] def factors_repr(factors): factor_strs = [] for fac in factors: if fac.ndim == 0: - factor_strs.append('{:.4}'.format(float(fac))) + fmt = '{{:{}}}'.format(precision) + factor_strs.append(fmt.format(float(fac))) else: factor_strs.append(array_str(fac, nprint=max_elems)) if len(factor_strs) == 1: @@ -2633,12 +2635,14 @@ def factors_repr(factors): def __repr__(self): """Return ``repr(self)``.""" max_elems = 2 * np.get_printoptions()['edgeitems'] + precision = np.get_printoptions()['precision'] def factors_repr(factors): factor_strs = [] for fac in factors: if fac.ndim == 0: - factor_strs.append('{:.4}'.format(float(fac))) + fmt = '{{:{}}}'.format(precision) + factor_strs.append(fmt.format(float(fac))) else: factor_strs.append(array_str(fac, nprint=max_elems)) return '({})'.format(', '.join(factor_strs))