From 1775a591a73fe76162ea871f07349648620ac5b5 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Wed, 14 Jan 2009 07:55:16 +0000 Subject: Fix printing of limits. --- numpy/lib/getlimits.py | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'numpy/lib/getlimits.py') diff --git a/numpy/lib/getlimits.py b/numpy/lib/getlimits.py index bc5fbbf5e..658549179 100644 --- a/numpy/lib/getlimits.py +++ b/numpy/lib/getlimits.py @@ -115,7 +115,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 +149,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__ @@ -256,6 +256,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 -- cgit v1.2.1 From 9837e0234859a4dc0fcbfe1acd8902faeb5a6558 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Wed, 14 Jan 2009 07:56:10 +0000 Subject: Fix finfo to work on all instances, not just NumPy scalars. --- numpy/lib/getlimits.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'numpy/lib/getlimits.py') diff --git a/numpy/lib/getlimits.py b/numpy/lib/getlimits.py index 658549179..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 @@ -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) @@ -258,7 +267,7 @@ class iinfo: def __str__(self): """String representation.""" - return ''' + return '''\ Machine parameters for %(dtype)s --------------------------------------------------------------------- min = %(min)s -- cgit v1.2.1