1. Pypy
  2. Untitled project
  3. pypy

Commits

mattip  committed fe6cb9e

fix merge, add failing byteswap tests for new dtypes, partial implementations

  • Participants
  • Parent commits ff0c695
  • Branches missing-ndarray-attributes

Comments (0)

Files changed (3)

File pypy/module/micronumpy/test/test_dtypes.py

View file
         a = array([1, 2, 3], dtype=self.non_native_prefix + 'f4')
         assert a[0] == 1
         assert (a + a)[1] == 4
+        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):

File pypy/module/micronumpy/test/test_numarray.py

View file
         assert (a == [1, 256 + 2, 3]).all()
         assert (a.byteswap(True) == [0x0100, 0x0201, 0x0300]).all()
         assert (a == [0x0100, 0x0201, 0x0300]).all()
+        assert False, 'test float, float16, complex byteswap'
 
     def test_clip(self):
         from _numpypy import array

File pypy/module/micronumpy/types.py

View file
         swapped_value = byteswap(rffi.cast(self.T, value))
         raw_storage_setitem(storage, i + offset, swapped_value)
 
-    def pack_str(self, box):
-        return struct.pack(self.format_code, byteswap(self.unbox(box)))
-
 class Float16(BaseType, Float):
     _attrs_ = ()
     _STORAGE_T = rffi.USHORT
     BoxType = interp_boxes.W_Float16Box
 
     def _read(self, storage, i, offset):
-        res = Float16._read(self, storage, i, offset)
-        #return byteswap(res) XXX
-        return res
+        hbits = raw_storage_getitem(self._STORAGE_T, storage, i + offset)
+        return float_unpack(r_ulonglong(byteswap(hbits)), 2)
 
     def _write(self, storage, i, offset, value):
-        #value = byteswap(value) XXX
-        Float16._write(self, storage, i, offset, value)
+        hbits = float_pack(value,2)
+        raw_storage_setitem(storage, i + offset,
+                byteswap(rffi.cast(self._STORAGE_T, hbits)))
+
 
 class Float32(BaseType, Float):
     _attrs_ = ()