[Numpy-svn] r3314 - trunk/numpy/core

numpy-svn at scipy.org numpy-svn at scipy.org
Wed Oct 11 18:52:55 CDT 2006


Author: oliphant
Date: 2006-10-11 18:52:53 -0500 (Wed, 11 Oct 2006)
New Revision: 3314

Modified:
   trunk/numpy/core/numeric.py
Log:
Add errstate object to be created in new 'with' statement

Modified: trunk/numpy/core/numeric.py
===================================================================
--- trunk/numpy/core/numeric.py	2006-10-11 23:28:16 UTC (rev 3313)
+++ trunk/numpy/core/numeric.py	2006-10-11 23:52:53 UTC (rev 3314)
@@ -16,7 +16,7 @@
            'load', 'loads', 'isscalar', 'binary_repr', 'base_repr',
            'ones', 'identity', 'allclose', 'compare_chararrays', 'putmask',
            'seterr', 'geterr', 'setbufsize', 'getbufsize',
-           'seterrcall', 'geterrcall', 'flatnonzero',
+           'seterrcall', 'geterrcall', 'errstate', 'flatnonzero',
            'Inf', 'inf', 'infty', 'Infinity',
            'nan', 'NaN', 'False_', 'True_', 'bitwise_not',
            'CLIP', 'RAISE', 'WRAP', 'MAXDIMS', 'BUFSIZE', 'ALLOW_THREADS']
@@ -716,6 +716,14 @@
     """
     return umath.geterrobj()[2]
 
+class errstate(object):
+    def __init__(self, **kwargs):
+        self.kwargs = kwargs
+    def __enter__(self):
+        self.oldstate = seterr(**self.kwargs)
+    def __exit__(self, *exc_info):
+        numpy.seterr(**self.oldstate)
+
 def _setdef():
     defval = [UFUNC_BUFSIZE_DEFAULT, ERR_DEFAULT, None]
     umath.seterrobj(defval)



More information about the Numpy-svn mailing list