Brian Kearns avatar Brian Kearns committed 4ce0e12

test/fix scalar.view(complex)

Comments (0)

Files changed (6)

pypy/module/micronumpy/arrayimpl/scalar.py

             raise OperationError(space.w_NotImplementedError, space.wrap(
                 "viewing scalar as record not implemented"))
         else:
-            scalar.value = dtype.itemtype.runpack_str(self.value.raw_str())
+            scalar.value = dtype.itemtype.runpack_str(space, self.value.raw_str())
         return scalar
 
     def get_real(self, orig_array):

pypy/module/micronumpy/interp_boxes.py

             raise OperationError(space.w_NotImplementedError, space.wrap(
                 "viewing scalar as record not implemented"))
         else:
-            return dtype.itemtype.runpack_str(self.raw_str())
+            return dtype.itemtype.runpack_str(space, self.raw_str())
 
     def descr_self(self, space):
         return self

pypy/module/micronumpy/loop.py

         if dtype.is_str_or_unicode():
             val = dtype.coerce(space, space.wrap(sub))
         else:
-            val = dtype.itemtype.runpack_str(sub)
+            val = dtype.itemtype.runpack_str(space, sub)
         ai.setitem(val)
         ai.next()
         i += 1

pypy/module/micronumpy/test/test_numarray.py

         a = array([(1, 2)], dtype=[('a', int), ('b', int)])[0]
         assert a.shape == ()
         assert a.view('S16') == '\x01' + '\x00' * 7 + '\x02'
+        a = array(2, dtype=int)
+        b = a.view('complex64')
+        assert 0 < b.real < 1
+        assert b.imag == 0
 
     def test_array_view(self):
         from numpypy import array, dtype

pypy/module/micronumpy/test/test_scalar.py

         t = s.view('double')
         assert type(t) is np.double
         assert t < 7e-323
+        t = s.view('complex64')
+        assert type(t) is np.complex64
+        assert 0 < t.real < 1
+        assert t.imag == 0
         exc = raises(TypeError, s.view, 'string')
         assert exc.value[0] == "data-type must not be 0-sized"
         t = s.view('S8')

pypy/module/micronumpy/types.py

         for i in xrange(start, stop, width):
             self._write(storage, i, offset, value)
 
-    def runpack_str(self, s):
+    def runpack_str(self, space, s):
         v = runpack(self.format_code, s)
         return self.box(v)
 
     def box(self, value):
         return self.BoxType(rffi.cast(rffi.DOUBLE, value))
 
-    def runpack_str(self, s):
+    def runpack_str(self, space, s):
         assert len(s) == 2
         fval = unpack_float(s, native_is_bigendian)
         return self.box(fval)
             raw_storage_setitem(storage,
                     i+offset+rffi.sizeof(self.T), imag)
 
+    def runpack_str(self, space, s):
+        comp = self.ComponentBoxType._get_dtype(space).itemtype
+        l = len(s) // 2
+        real = comp.runpack_str(space, s[:l])
+        imag = comp.runpack_str(space, s[l:])
+        return self.composite(real, imag)
+
     @staticmethod
     def for_computation(v):
         return float(v[0]), float(v[1])
         T = rffi.LONGDOUBLE
         BoxType = interp_boxes.W_FloatLongBox
 
-        def runpack_str(self, s):
+        def runpack_str(self, space, s):
             assert len(s) == interp_boxes.long_double_size
             fval = unpack_float80(s, native_is_bigendian)
             return self.box(fval)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.