Skip to content

Commit

Permalink
ENH: use np precision instead of hardcoded one in npy tensor repr
Browse files Browse the repository at this point in the history
  • Loading branch information
kohr-h committed Sep 12, 2018
1 parent 527bf45 commit 8b99801
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions odl/space/npy_tensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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))
Expand Down

0 comments on commit 8b99801

Please sign in to comment.