Skip to content

Commit

Permalink
RF: delay calls of array repr in getlimits
Browse files Browse the repository at this point in the history
Delay use of array repr until needed for string representations of the
float info parameters.  This is to allow getlimits to be imported early
without pulling in too much of the repr machinery.

See: numpy#8983 (comment)
  • Loading branch information
matthew-brett committed May 15, 2017
1 parent 33ce0ba commit 0649ba2
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions numpy/core/getlimits.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def __init__(self,
params = _MACHAR_PARAMS[ftype]
float_conv = lambda v: array([v], ftype)
float_to_float = lambda v : _fr1(float_conv(v))
float_to_str = lambda v: (params['fmt'] % array(_fr0(v)[0], ftype))
self._float_to_str = lambda v: (params['fmt'] %
array(_fr0(v)[0], ftype))
self.title = params['title']
# Parameter types same as for discovered MachAr object.
self.epsilon = self.eps = float_to_float(kwargs.pop('eps'))
Expand All @@ -79,11 +80,30 @@ def __init__(self,
self.__dict__.update(kwargs)
self.precision = int(-log10(self.eps))
self.resolution = float_to_float(float_conv(10) ** (-self.precision))
self._str_eps = float_to_str(self.eps)
self._str_epsneg = float_to_str(self.epsneg)
self._str_xmin = float_to_str(self.xmin)
self._str_xmax = float_to_str(self.xmax)
self._str_resolution = float_to_str(self.resolution)

# Properties below to delay need for float_to_str, and thus avoid circular
# imports during early numpy module loading.
# See: https://github.com/numpy/numpy/pull/8983#discussion_r115838683

@property
def _str_eps(self):
return self._float_to_str(self.eps)

@property
def _str_epsneg(self):
return self._float_to_str(self.epsneg)

@property
def _str_xmin(self):
return self._float_to_str(self.xmin)

@property
def _str_xmax(self):
return self._float_to_str(self.xmax)

@property
def _str_resolution(self):
return self._float_to_str(self.resolution)


# Known parameters for float16
Expand Down

0 comments on commit 0649ba2

Please sign in to comment.