Commits

mattip committed 7e89791

test, implement forgotten method

  • Participants
  • Parent commits 5bfae8c
  • Branches numpypy-real-as-view

Comments (0)

Files changed (2)

File pypy/module/micronumpy/interp_numarray.py

         tmp = self.implementation.get_real()
         tmp.setslice(space, convert_to_array(space, w_value))
 
-    def descr_set_imag(self, space, w_new_val):
+    def descr_set_imag(self, space, w_value):
         # if possible, copy (broadcast) values into self
-        self.implementation.descr_set_imag(space, w_new_val)
+        if not self.get_dtype().is_complex_type():
+            raise OperationError(space.w_TypeError, 
+                    space.wrap('array does not have imaginary part to set'))
+        tmp = self.implementation.get_imag()
+        tmp.setslice(space, convert_to_array(space, w_value))
 
     def descr_reshape(self, space, args_w):
         """reshape(...)

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

         b = a.imag
         assert b[7] == 0
         raises(RuntimeError, 'b[7] = -2')
+        raises(TypeError, 'a.imag = -2')
         a = array(['abc','def'],dtype='S3')
         b = a.real
         assert a[0] == b[0]
         assert a[1] == b[1]
         b[1] = 'xyz'
         assert a[1] == 'xyz'
+        assert a.imag[0] == 'abc'
+        raises(TypeError, 'a.imag = "qop"')
         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
         a=array([1+1j, 2-3j, 4+5j, -6+7j, 8-9j, -2-1j]) 
         a.real = 13
         assert a[3].real == 13
+        a.imag = -5
+        a.imag[3] = -10
+        assert a[3].imag == -10
+        assert a[2].imag == -5
 
     def test_tolist_scalar(self):
         from _numpypy import int32, bool_