Commits

mattip  committed b36dcab

some tests pass

  • Participants
  • Parent commits db688ce
  • Branches numpypy-real-as-view

Comments (0)

Files changed (3)

File pypy/module/micronumpy/arrayimpl/concrete.py

             return None
     
     def get_real(self):
+        strides = self.get_strides()
+        backstrides = self.get_backstrides()
         if self.dtype.is_complex_type():
-            raise NotImplementedError('waiting for astype()')
-        return SliceArray(self.start, self.get_strides(), 
-                          self.get_backstrides(), self.get_shape(), self)
+            dtype =  self.dtype.float_type
+            return SliceArray(self.start, strides, backstrides,
+                          self.get_shape(), self, dtype=dtype)
+        return SliceArray(self.start, strides, backstrides, 
+                          self.get_shape(), self)
 
     def get_imag(self):
+        strides = self.get_strides()
+        backstrides = self.get_backstrides()
         if self.dtype.is_complex_type():
-            raise NotImplementedError('waiting for astype()')
+            dtype =  self.dtype.float_type
+            return SliceArray(self.start + dtype.get_size(), strides, 
+                    backstrides, self.get_shape(), self, dtype=dtype)
         if self.dtype.is_flexible_type():
             # numpy returns self for self.imag
-            return SliceArray(self.start, self.get_strides(), 
-                          self.get_backstrides(), self.get_shape(), self)
-   
-        strides, backstrides = support.calc_strides(self.get_shape(), self.dtype,
-                                                    self.order)
+            return SliceArray(self.start, strides, backstrides,
+                    self.get_shape(), self)
         impl = NonWritableArray(self.get_shape(), self.dtype, self.order, strides,
                              backstrides)
         impl.fill(self.dtype.box(0))

File pypy/module/micronumpy/interp_dtype.py

         return self.kind == SIGNEDLTR
 
     def is_complex_type(self):
-        return (self.num == 14 or self.num == 15 or self.num == 16)
+        return False
 
     def is_bool_type(self):
         return self.kind == BOOLLTR
     def get_size(self):
         return self.itemtype.get_element_size()
 
+class W_ComplexDtype(W_Dtype):
+
+    def __init__(self, itemtype, num, kind, name, char, w_box_type,
+                 alternate_constructors=[], aliases=[],
+                 fields=None, fieldnames=None, native=True, float_type=None):
+        W_Dtype.__init__(self, itemtype, num, kind, name, char, w_box_type,
+                 alternate_constructors=[], aliases=[],
+                 fields=None, fieldnames=None, native=True)
+        self.float_type = float_type
+
+    def is_complex_type(self):
+        return True
+
 def dtype_from_list(space, w_lst):
     lst_w = space.listview(w_lst)
     fields = {}
             alternate_constructors=[space.w_float],
             aliases=["float"],
         )
-        self.w_complex64dtype = W_Dtype(
+        self.w_complex64dtype = W_ComplexDtype(
             types.Complex64(),
             num=14,
             kind=COMPLEXLTR,
             name="complex64",
             char="F",
             w_box_type = space.gettypefor(interp_boxes.W_Complex64Box),
+            float_type = self.w_float32dtype,
         )
-        self.w_complex128dtype = W_Dtype(
+        self.w_complex128dtype = W_ComplexDtype(
             types.Complex128(),
             num=15,
             kind=COMPLEXLTR,
             w_box_type = space.gettypefor(interp_boxes.W_Complex128Box),
             alternate_constructors=[space.w_complex],
             aliases=["complex"],
+            float_type = self.w_float64dtype,
         )
         if interp_boxes.long_double_size == 12:
             self.w_float96dtype = W_Dtype(
             )
             self.w_longdouble = self.w_float96dtype
 
-            self.w_complex192dtype = W_Dtype(
+            self.w_complex192dtype = W_ComplexDtype(
                 types.Complex192(),
                 num=16,
                 kind=COMPLEXLTR,
                 w_box_type = space.gettypefor(interp_boxes.W_Complex192Box),
                 alternate_constructors=[space.w_complex],
                 aliases=["clongdouble", "clongfloat"],
+                float_type = self.w_float96dtype,
             )
             self.w_clongdouble = self.w_complex192dtype
 
             )
             self.w_longdouble = self.w_float128dtype
 
-            self.w_complex256dtype = W_Dtype(
+            self.w_complex256dtype = W_ComplexDtype(
                 types.Complex256(),
                 num=16,
                 kind=COMPLEXLTR,
                 w_box_type = space.gettypefor(interp_boxes.W_Complex256Box),
                 alternate_constructors=[space.w_complex],
                 aliases=["clongdouble", "clongfloat"],
+                float_type = self.w_float128dtype,
             )
             self.w_clongdouble = self.w_complex256dtype
         else:

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

         assert a[1] == b[1]
         b[1] = 'xyz'
         assert a[1] == 'xyz'
-        a=array([1+1j, 2-3j]) 
-        assert a.real[1] == 2
-        a.real[1] = -20
-        assert a[1].real == -20
+        a=array([[1+1j, 2-3j, 4+5j],[-6+7j, 8-9j, -2-1j]]) 
+        assert a.real[0,1] == 2
+        a.real[0,1] = -20
+        assert a[0,1].real == -20
+        b = a.imag
+        assert b[1,2] == -1
+        b[1,2] = 30
+        assert a[1,2].imag == 30
 
     def test_tolist_scalar(self):
         from _numpypy import int32, bool_