Beispiel #1
0
 def test_buffer_info(self):
     try:
         from _numpypy import multiarray as np
     except ImportError:
         skip('pypy built without _numpypy')
     module = self.import_module(name='buffer_test')
     get_buffer_info = module.get_buffer_info
     raises(ValueError, get_buffer_info, np.arange(5)[::2], ('SIMPLE', ))
     arr = np.zeros((1, 10), order='F')
     shape, strides = get_buffer_info(arr, ['F_CONTIGUOUS'])
     assert strides[0] == 8
     arr = np.zeros((10, 1), order='C')
     shape, strides = get_buffer_info(arr, ['C_CONTIGUOUS'])
     assert strides[-1] == 8
     dt1 = np.dtype([('a', 'b'), ('b', 'i'), ('sub0', np.dtype('b,i')),
                     ('sub1', np.dtype('b,i')), ('sub2', np.dtype('b,i')),
                     ('sub3', np.dtype('b,i')), ('sub4', np.dtype('b,i')),
                     ('sub5', np.dtype('b,i')), ('sub6', np.dtype('b,i')),
                     ('sub7', np.dtype('b,i')), ('c', 'i')], )
     x = np.arange(dt1.itemsize, dtype='int8').view(dt1)
     # pytest can catch warnings from v2.8 and up, we ship 2.5
     import warnings
     warnings.filterwarnings("error")
     try:
         try:
             y = get_buffer_info(x, ['SIMPLE'])
         except UserWarning as e:
             pass
         else:
             assert False ,"PyPy-specific UserWarning not raised" \
                       " on too long format string"
     finally:
         warnings.resetwarnings()
Beispiel #2
0
    def test_buffer_info(self):
        try:
            from _numpypy import multiarray as np
        except ImportError:
            skip("pypy built without _numpypy")
        module = self.import_module(name="buffer_test")
        get_buffer_info = module.get_buffer_info
        raises(ValueError, get_buffer_info, np.arange(5)[::2], ("SIMPLE",))
        arr = np.zeros((1, 10), order="F")
        shape, strides = get_buffer_info(arr, ["F_CONTIGUOUS"])
        assert strides[0] == 8
        arr = np.zeros((10, 1), order="C")
        shape, strides = get_buffer_info(arr, ["C_CONTIGUOUS"])
        assert strides[-1] == 8
        dt1 = np.dtype(
            [
                ("a", "b"),
                ("b", "i"),
                ("sub0", np.dtype("b,i")),
                ("sub1", np.dtype("b,i")),
                ("sub2", np.dtype("b,i")),
                ("sub3", np.dtype("b,i")),
                ("sub4", np.dtype("b,i")),
                ("sub5", np.dtype("b,i")),
                ("sub6", np.dtype("b,i")),
                ("sub7", np.dtype("b,i")),
                ("c", "i"),
            ]
        )
        x = np.arange(dt1.itemsize, dtype="int8").view(dt1)
        # pytest can catch warnings from v2.8 and up, we ship 2.5
        import warnings

        warnings.filterwarnings("error")
        try:
            try:
                y = get_buffer_info(x, ["SIMPLE"])
            except UserWarning as e:
                pass
            else:
                assert False, "PyPy-specific UserWarning not raised" " on too long format string"
        finally:
            warnings.resetwarnings()
Beispiel #3
0
 def test_buffer_info(self):
     try:
         from _numpypy import multiarray as np
     except ImportError:
         skip('pypy built without _numpypy')
     module = self.import_module(name='buffer_test')
     get_buffer_info = module.get_buffer_info
     raises(ValueError, get_buffer_info, np.arange(5)[::2], ('SIMPLE', ))
     arr = np.zeros((1, 10), order='F')
     shape, strides = get_buffer_info(arr, ['F_CONTIGUOUS'])
     assert strides[0] == 8
     arr = np.zeros((10, 1), order='C')
     shape, strides = get_buffer_info(arr, ['C_CONTIGUOUS'])
     assert strides[-1] == 8
     dt1 = np.dtype([('a', 'b'), ('b', 'i'), ('sub0', np.dtype('b,i')),
                     ('sub1', np.dtype('b,i')), ('sub2', np.dtype('b,i')),
                     ('sub3', np.dtype('b,i')), ('sub4', np.dtype('b,i')),
                     ('sub5', np.dtype('b,i')), ('sub6', np.dtype('b,i')),
                     ('sub7', np.dtype('b,i')), ('c', 'i')], )
     x = np.arange(dt1.itemsize, dtype='int8').view(dt1)
Beispiel #4
0
import pypytools
assert pypytools.IS_PYPY
from _numpypy.multiarray import dtype

_types = [
    'bool_', 'int8', 'uint8', 'int16', 'uint16', 'int32', 'uint32', 'int64',
    'uint64', 'float16', 'float32', 'float64', 'complex64', 'complex128',
    'object'
]

for _typename in _types:
    globals()[_typename] = dtype(_typename).type