[Numpy-svn] r5112 - in trunk/numpy/lib: . tests

numpy-svn@scip... numpy-svn@scip...
Tue Apr 29 10:39:36 CDT 2008


Author: cdavid
Date: 2008-04-29 10:39:23 -0500 (Tue, 29 Apr 2008)
New Revision: 5112

Added:
   trunk/numpy/lib/tests/test_machar.py
Modified:
   trunk/numpy/lib/machar.py
Log:
Disable underflow warning reporting when testing for arch + test (#759).

Modified: trunk/numpy/lib/machar.py
===================================================================
--- trunk/numpy/lib/machar.py	2008-04-29 03:05:50 UTC (rev 5111)
+++ trunk/numpy/lib/machar.py	2008-04-29 15:39:23 UTC (rev 5112)
@@ -8,6 +8,7 @@
 __all__ = ['MachAr']
 
 from numpy.core.fromnumeric import any
+from numpy.core.numeric import seterr
 
 # Need to speed this up...especially for longfloat
 
@@ -58,6 +59,15 @@
           float_to_str - convert array float to str
           title        - description of used floating point numbers
         """
+        # We ignore all errors here because we are purposely triggering
+        # underflow to detect the properties of the runninng arch.
+        saverrstate = seterr(under='ignore')
+        try:
+            self._do_init(float_conv, int_conv, float_to_float, float_to_str, title)
+        finally:
+            seterr(**saverrstate)
+
+    def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
         max_iterN = 10000
         msg = "Did not converge after %d tries with %s"
         one = float_conv(1)

Added: trunk/numpy/lib/tests/test_machar.py
===================================================================
--- trunk/numpy/lib/tests/test_machar.py	2008-04-29 03:05:50 UTC (rev 5111)
+++ trunk/numpy/lib/tests/test_machar.py	2008-04-29 15:39:23 UTC (rev 5112)
@@ -0,0 +1,31 @@
+from numpy.testing import NumpyTestCase, NumpyTest
+
+from numpy.lib.machar import MachAr
+import numpy.core.numerictypes as ntypes
+from numpy import seterr, array
+
+class TestMachAr(NumpyTestCase):
+    def _run_machar_highprec(self):
+        # Instanciate MachAr instance with high enough precision to cause
+        # underflow
+        try:
+            hiprec = ntypes.float96
+            machar = MachAr(lambda v:array([v], hiprec))
+        except AttributeError:
+            print "Skipping test: no nyptes.float96 available on this" \
+                  " platform."
+
+    def test_underlow(self):
+        """Regression testing for #759: instanciating MachAr for dtype =
+        np.float96 raises spurious warning."""
+        serrstate = seterr(all='raise')
+        try:
+            try:
+                self._run_machar_highprec()
+            except FloatingPointError, e:
+                self.fail("Caught %s exception, should not have been raised." % e)
+        finally:
+            seterr(**serrstate)
+
+if __name__ == "__main__":
+    NumpyTest().run()



More information about the Numpy-svn mailing list