Author: mattip <matti.pi...@gmail.com> Branch: numpypy-disable-longdouble Changeset: r61562:ea0500012d37 Date: 2013-02-14 11:58 +0200 http://bitbucket.org/pypy/pypy/changeset/ea0500012d37/
Log: rearrange remaining tests to skip longdouble diff --git a/pypy/module/micronumpy/test/test_dtypes.py b/pypy/module/micronumpy/test/test_dtypes.py --- a/pypy/module/micronumpy/test/test_dtypes.py +++ b/pypy/module/micronumpy/test/test_dtypes.py @@ -43,13 +43,6 @@ raises(TypeError, lambda: dtype("int8") == 3) assert dtype(bool) == bool - def test_dtype_aliases(self): - from _numpypy import dtype - assert dtype('longfloat').num in (12, 13) - assert dtype('longdouble').num in (12, 13) - assert dtype('clongfloat').num in (15, 16) - assert dtype('clongdouble').num in (15, 16) - def test_dtype_with_types(self): from _numpypy import dtype @@ -154,8 +147,6 @@ '?', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd', 'e' ] - if array([0], dtype='longdouble').itemsize > 8: - types += ['g', 'G'] a = array([True], '?') for t in types: assert (a + array([0], t)).dtype is dtype(t) @@ -271,7 +262,6 @@ (numpy.float16, 10.), (numpy.float32, 2.0), (numpy.float64, 4.32), - (numpy.longdouble, 4.32), ]: assert hash(tp(value)) == hash(value) @@ -528,7 +518,6 @@ from math import isnan assert isnan(numpy.float32(None)) assert isnan(numpy.float64(None)) - assert isnan(numpy.longdouble(None)) def test_complex_floating(self): import _numpypy as numpy @@ -789,12 +778,6 @@ a = array([1, 2, 3], dtype=self.non_native_prefix + 'f2') assert a[0] == 1 assert (a + a)[1] == 4 - a = array([1, 2, 3], dtype=self.non_native_prefix + 'g') # longdouble - assert a[0] == 1 - assert (a + a)[1] == 4 - a = array([1, 2, 3], dtype=self.non_native_prefix + 'G') # clongdouble - assert a[0] == 1 - assert (a + a)[1] == 4 class AppTestPyPyOnly(BaseNumpyAppTest): def setup_class(cls): @@ -852,4 +835,37 @@ assert numpy.float64(12) == numpy.longfloat(12) raises(ValueError, numpy.longfloat, '23.2df') + def test_dtype_aliases(self): + from _numpypy import dtype + assert dtype('longfloat').num in (12, 13) + assert dtype('longdouble').num in (12, 13) + assert dtype('clongfloat').num in (15, 16) + assert dtype('clongdouble').num in (15, 16) + def test_bool_binop_types(self): + from _numpypy import array, dtype + types = ['g', 'G'] + a = array([True], '?') + for t in types: + assert (a + array([0], t)).dtype is dtype(t) + + def test_hash(self): + import _numpypy as numpy + for tp, value in [ + (numpy.longdouble, 4.32), + ]: + assert hash(tp(value)) == hash(value) + + def test_float_None(self): + import _numpypy as numpy + from math import isnan + assert isnan(numpy.longdouble(None)) + + def test_non_native(self): + from _numpypy import array + a = array([1, 2, 3], dtype=self.non_native_prefix + 'g') # longdouble + assert a[0] == 1 + assert (a + a)[1] == 4 + a = array([1, 2, 3], dtype=self.non_native_prefix + 'G') # clongdouble + assert a[0] == 1 + assert (a + a)[1] == 4 diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py --- a/pypy/module/micronumpy/test/test_numarray.py +++ b/pypy/module/micronumpy/test/test_numarray.py @@ -1735,15 +1735,6 @@ i2 = (i+1) * a.dtype.itemsize assert list(reversed(s1[i1:i2])) == s2[i1:i2] - a = array([1, -1, 10000], dtype='longfloat') - s1 = map(ord, a.tostring()) - s2 = map(ord, a.byteswap().tostring()) - assert a.dtype.itemsize >= 8 - for i in range(a.size): - i1 = i * a.dtype.itemsize - i2 = (i+1) * a.dtype.itemsize - assert list(reversed(s1[i1:i2])) == s2[i1:i2] - def test_clip(self): from _numpypy import array a = array([1, 2, 17, -3, 12]) @@ -2378,7 +2369,7 @@ def test_fromstring_types(self): from _numpypy import (fromstring, int8, int16, int32, int64, uint8, - uint16, uint32, float16, float32, float64, longfloat, array) + uint16, uint32, float16, float32, float64, array) a = fromstring('\xFF', dtype=int8) assert a[0] == -1 b = fromstring('\xFF', dtype=uint8) @@ -2401,18 +2392,6 @@ assert j[0] == 12 k = fromstring(self.float16val, dtype=float16) assert k[0] == float16(5.) - dt = array([5],dtype=longfloat).dtype - if dt.itemsize == 12: - from _numpypy import float96 - m = fromstring('\x00\x00\x00\x00\x00\x00\x00\xa0\x01@\x00\x00', dtype=float96) - elif dt.itemsize==16: - from _numpypy import float128 - m = fromstring('\x00\x00\x00\x00\x00\x00\x00\xa0\x01@\x00\x00\x00\x00\x00\x00', dtype=float128) - elif dt.itemsize == 8: - skip('longfloat is float64') - else: - skip('unknown itemsize for longfloat') - assert m[0] == longfloat(5.) def test_fromstring_invalid(self): from _numpypy import fromstring, uint16, uint8 @@ -2687,3 +2666,40 @@ assert x.__pypy_data__ is obj del x.__pypy_data__ assert x.__pypy_data__ is None + +class AppTestLongDoubleDtypes(BaseNumpyAppTest): + def setup_class(cls): + from pypy.module.micronumpy import Module + print dir(Module.interpleveldefs) + if not Module.interpleveldefs.get('longfloat', None): + py.test.skip('no longdouble types yet') + BaseNumpyAppTest.setup_class.im_func(cls) + + def test_byteswap(self): + from _numpypy import array + + a = array([1, -1, 10000], dtype='longfloat') + s1 = map(ord, a.tostring()) + s2 = map(ord, a.byteswap().tostring()) + assert a.dtype.itemsize >= 8 + for i in range(a.size): + i1 = i * a.dtype.itemsize + i2 = (i+1) * a.dtype.itemsize + assert list(reversed(s1[i1:i2])) == s2[i1:i2] + + def test_fromstring_types(self): + from _numpypy import (fromstring, longfloat, array) + dt = array([5],dtype=longfloat).dtype + if dt.itemsize == 12: + from _numpypy import float96 + m = fromstring('\x00\x00\x00\x00\x00\x00\x00\xa0\x01@\x00\x00', dtype=float96) + elif dt.itemsize==16: + from _numpypy import float128 + m = fromstring('\x00\x00\x00\x00\x00\x00\x00\xa0\x01@\x00\x00\x00\x00\x00\x00', dtype=float128) + elif dt.itemsize == 8: + skip('longfloat is float64') + else: + skip('unknown itemsize for longfloat') + assert m[0] == longfloat(5.) + + _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit