Author: mattip <[email protected]>
Branch: numpypy-real-as-view
Changeset: r59902:7e8979164700
Date: 2013-01-09 23:25 +0200
http://bitbucket.org/pypy/pypy/changeset/7e8979164700/

Log:    test, implement forgotten method

diff --git a/pypy/module/micronumpy/interp_numarray.py 
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -250,9 +250,13 @@
         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(...)
diff --git a/pypy/module/micronumpy/test/test_numarray.py 
b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -1354,12 +1354,15 @@
         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
@@ -1373,6 +1376,10 @@
         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_
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to