diff options
author | David Cournapeau <cournape@gmail.com> | 2008-04-29 15:39:23 +0000 |
---|---|---|
committer | David Cournapeau <cournape@gmail.com> | 2008-04-29 15:39:23 +0000 |
commit | 59e7bda0f6d189428b7268e0150709bacde8544b (patch) | |
tree | c3245f5023b44ed3e8d8e059fc9a119d5fc4ca36 /numpy/lib | |
parent | 240d9a2236213e5439a89bf51cfaf0257bf85729 (diff) | |
download | numpy-59e7bda0f6d189428b7268e0150709bacde8544b.tar.gz |
Disable underflow warning reporting when testing for arch + test (#759).
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/machar.py | 10 | ||||
-rw-r--r-- | numpy/lib/tests/test_machar.py | 31 |
2 files changed, 41 insertions, 0 deletions
diff --git a/numpy/lib/machar.py b/numpy/lib/machar.py index 9d0e08e45..72fde37f2 100644 --- a/numpy/lib/machar.py +++ b/numpy/lib/machar.py @@ -8,6 +8,7 @@ floating-point arithmetic system __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 @@ class MachAr(object): 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) diff --git a/numpy/lib/tests/test_machar.py b/numpy/lib/tests/test_machar.py new file mode 100644 index 000000000..add4c033b --- /dev/null +++ b/numpy/lib/tests/test_machar.py @@ -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() |