Author: Ronan Lamy <[email protected]>
Branch: longdouble2
Changeset: r62853:7141f6c474cd
Date: 2013-03-28 05:11 +0000
http://bitbucket.org/pypy/pypy/changeset/7141f6c474cd/

Log:    dispatch set_imag on the dtype

diff --git a/pypy/module/micronumpy/arrayimpl/concrete.py 
b/pypy/module/micronumpy/arrayimpl/concrete.py
--- a/pypy/module/micronumpy/arrayimpl/concrete.py
+++ b/pypy/module/micronumpy/arrayimpl/concrete.py
@@ -11,7 +11,6 @@
 from rpython.rtyper.lltypesystem import rffi, lltype
 from rpython.rlib.rawstorage import free_raw_storage, raw_storage_getitem,\
      raw_storage_setitem, RAW_STORAGE
-from pypy.module.micronumpy.arrayimpl.sort import argsort_array
 from rpython.rlib.debug import make_sure_not_resized
 
 
@@ -103,7 +102,9 @@
         return impl
 
     def set_imag(self, space, orig_array, w_value):
-        tmp = self.get_imag(orig_array)
+        from pypy.module.micronumpy.interp_dtype import W_ComplexDtype
+        assert isinstance(self.dtype, W_ComplexDtype)
+        tmp = self.dtype._writable_imag_array(orig_array)
         tmp.setslice(space, convert_to_array(space, w_value))
 
     # -------------------- applevel get/setitem -----------------------
@@ -321,6 +322,7 @@
                           orig_array)
 
     def argsort(self, space, w_axis):
+        from pypy.module.micronumpy.arrayimpl.sort import argsort_array
         return argsort_array(self, space, w_axis)
 
     def base(self):
diff --git a/pypy/module/micronumpy/arrayimpl/scalar.py 
b/pypy/module/micronumpy/arrayimpl/scalar.py
--- a/pypy/module/micronumpy/arrayimpl/scalar.py
+++ b/pypy/module/micronumpy/arrayimpl/scalar.py
@@ -1,3 +1,4 @@
+from rpython.rlib.objectmodel import specialize
 
 from pypy.module.micronumpy.arrayimpl import base
 from pypy.module.micronumpy.base import W_NDimArray, convert_to_array
@@ -73,7 +74,7 @@
         dtype = self.dtype.float_type or self.dtype
         if len(w_arr.get_shape()) > 0:
             raise OperationError(space.w_ValueError, space.wrap(
-                "could not broadcast input array from shape " + 
+                "could not broadcast input array from shape " +
                 "(%s) into shape ()" % (
                     ','.join([str(x) for x in w_arr.get_shape()],))))
         if self.dtype.is_complex_type():
@@ -96,19 +97,21 @@
         return scalar
 
     def set_imag(self, space, orig_array, w_val):
-        #Only called on complex dtype
-        assert self.dtype.is_complex_type()
         w_arr = convert_to_array(space, w_val)
-        dtype = self.dtype.float_type
-        if len(w_arr.get_shape()) > 0:
+        if not w_arr.is_scalar():
             raise OperationError(space.w_ValueError, space.wrap(
-                "could not broadcast input array from shape " + 
+                "could not broadcast input array from shape " +
                 "(%s) into shape ()" % (
                     ','.join([str(x) for x in w_arr.get_shape()],))))
-        self.value = self.dtype.itemtype.composite(
-                            self.value.convert_real_to(dtype),
-                            w_arr.get_scalar_value().convert_to(dtype),
-                            )
+        value = w_arr.get_scalar_value()
+        self._set_imag(value)
+
+    @specialize.argtype(1)
+    def _set_imag(self, value):
+        from pypy.module.micronumpy.interp_dtype import W_ComplexDtype
+        assert isinstance(self.dtype, W_ComplexDtype)
+        dtype = self.dtype.float_type
+        self.value.imag = value.convert_to(dtype)
 
     def descr_getitem(self, space, _, w_idx):
         raise OperationError(space.w_IndexError,
diff --git a/pypy/module/micronumpy/interp_dtype.py 
b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -11,6 +11,8 @@
 from rpython.rtyper.lltypesystem import rffi
 from rpython.rlib import jit
 
+from pypy.module.micronumpy.arrayimpl.concrete import SliceArray
+
 
 UNSIGNEDLTR = "u"
 SIGNEDLTR = "i"
@@ -192,6 +194,16 @@
     def is_complex_type(self):
         return True
 
+    def _writable_imag_array(self, w_arr):
+        """helper for BaseConcreteArray.set_imag"""
+        impl = w_arr.implementation
+        strides = impl.get_strides()
+        backstrides = impl.get_backstrides()
+        float_type = self.float_type
+        return SliceArray(impl.start + float_type.get_size(), strides, 
backstrides,
+                impl.get_shape(), impl, w_arr, dtype=float_type)
+
+
 def dtype_from_list(space, w_lst):
     lst_w = space.listview(w_lst)
     fields = {}
@@ -252,7 +264,7 @@
 
 def dtype_from_spec(space, name):
         raise OperationError(space.w_NotImplementedError, space.wrap(
-            "dtype from spec"))    
+            "dtype from spec"))
 
 def descr__new__(space, w_subtype, w_dtype):
     cache = get_dtype_cache(space)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to