Skip to content

BUG: delay calls of array repr in getlimits #9113

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 2 commits into from
May 15, 2017
Merged
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
42 changes: 26 additions & 16 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 Expand Up @@ -538,13 +558,3 @@ def __repr__(self):
return "%s(min=%s, max=%s, dtype=%s)" % (self.__class__.__name__,
self.min, self.max, self.dtype)

if __name__ == '__main__':
f = finfo(ntypes.single)
print('single epsilon:', f.eps)
print('single tiny:', f.tiny)
f = finfo(ntypes.float)
print('float epsilon:', f.eps)
print('float tiny:', f.tiny)
f = finfo(ntypes.longfloat)
print('longfloat epsilon:', f.eps)
print('longfloat tiny:', f.tiny)