summaryrefslogtreecommitdiff
path: root/numpy/lib/getlimits.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/lib/getlimits.py')
-rw-r--r--numpy/lib/getlimits.py48
1 files changed, 34 insertions, 14 deletions
diff --git a/numpy/lib/getlimits.py b/numpy/lib/getlimits.py
index bc5fbbf5e..ccb0e2b3d 100644
--- a/numpy/lib/getlimits.py
+++ b/numpy/lib/getlimits.py
@@ -88,6 +88,12 @@ class finfo(object):
_finfo_cache = {}
def __new__(cls, dtype):
+ try:
+ dtype = np.dtype(dtype)
+ except TypeError:
+ # In case a float instance was given
+ dtype = np.dtype(type(dtype))
+
obj = cls._finfo_cache.get(dtype,None)
if obj is not None:
return obj
@@ -115,7 +121,7 @@ class finfo(object):
return obj
def _init(self, dtype):
- self.dtype = dtype
+ self.dtype = np.dtype(dtype)
if dtype is ntypes.double:
itype = ntypes.int64
fmt = '%24.16e'
@@ -149,23 +155,23 @@ class finfo(object):
self.nexp = machar.iexp
self.nmant = machar.it
self.machar = machar
- self._str_tiny = machar._str_xmin
- self._str_max = machar._str_xmax
- self._str_epsneg = machar._str_epsneg
- self._str_eps = machar._str_eps
- self._str_resolution = machar._str_resolution
+ self._str_tiny = machar._str_xmin.strip()
+ self._str_max = machar._str_xmax.strip()
+ self._str_epsneg = machar._str_epsneg.strip()
+ self._str_eps = machar._str_eps.strip()
+ self._str_resolution = machar._str_resolution.strip()
return self
def __str__(self):
return '''\
Machine parameters for %(dtype)s
---------------------------------------------------------------------
-precision=%(precision)3s resolution=%(_str_resolution)s
-machep=%(machep)6s eps= %(_str_eps)s
-negep =%(negep)6s epsneg= %(_str_epsneg)s
-minexp=%(minexp)6s tiny= %(_str_tiny)s
-maxexp=%(maxexp)6s max= %(_str_max)s
-nexp =%(nexp)6s min= -max
+precision=%(precision)3s resolution= %(_str_resolution)s
+machep=%(machep)6s eps= %(_str_eps)s
+negep =%(negep)6s epsneg= %(_str_epsneg)s
+minexp=%(minexp)6s tiny= %(_str_tiny)s
+maxexp=%(maxexp)6s max= %(_str_max)s
+nexp =%(nexp)6s min= -max
---------------------------------------------------------------------
''' % self.__dict__
@@ -220,8 +226,11 @@ class iinfo:
_min_vals = {}
_max_vals = {}
- def __init__(self, type):
- self.dtype = np.dtype(type)
+ def __init__(self, int_type):
+ try:
+ self.dtype = np.dtype(int_type)
+ except TypeError:
+ self.dtype = np.dtype(type(int_type))
self.kind = self.dtype.kind
self.bits = self.dtype.itemsize * 8
self.key = "%s%d" % (self.kind, self.bits)
@@ -256,6 +265,17 @@ class iinfo:
max = property(max)
+ def __str__(self):
+ """String representation."""
+ return '''\
+Machine parameters for %(dtype)s
+---------------------------------------------------------------------
+min = %(min)s
+max = %(max)s
+---------------------------------------------------------------------
+''' % {'dtype': self.dtype, 'min': self.min, 'max': self.max}
+
+
if __name__ == '__main__':
f = finfo(ntypes.single)
print 'single epsilon:',f.eps