Author: Romain Guillebert <romain...@gmail.com>
Branch: numpypy-array_prepare_-array_wrap
Changeset: r68215:145ff824d697
Date: 2013-11-18 17:42 +0100
http://bitbucket.org/pypy/pypy/changeset/145ff824d697/

Log:    Move call_prepare to loop.py

diff --git a/pypy/module/micronumpy/interp_ufuncs.py 
b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -256,38 +256,6 @@
             return out
         return res
 
-    def call_prepare(self, space, w_out, w_obj, w_result):
-        if isinstance(w_out, W_NDimArray):
-            w_array = space.lookup(w_out, "__array_prepare__")
-            w_caller = w_out
-        else:
-            w_array = space.lookup(w_obj, "__array_prepare__")
-            w_caller = w_obj
-        if w_array:
-            w_retVal = space.get_and_call_function(w_array, w_caller, 
w_result, None)
-            if not isinstance(w_retVal, W_NDimArray) and \
-               not isinstance(w_retVal, interp_boxes.Box):
-                raise OperationError(space.w_ValueError,
-                    space.wrap( "__array_prepare__ must return an "
-                                "ndarray or subclass thereof"))
-            if isinstance(w_result, interp_boxes.Box) or \
-                w_result.is_scalar():
-                if not isinstance(w_retVal, interp_boxes.Box) and not 
w_retVal.is_scalar():
-                    raise OperationError(space.w_TypeError,
-                        space.wrap( "__array_prepare__ must return an "
-                                    "ndarray or subclass thereof which is "
-                                    "otherwise identical to its input"))
-            elif w_result.get_shape() != w_retVal.get_shape() or \
-               w_result.implementation.get_strides() != \
-                    w_retVal.implementation.get_strides():
-                raise OperationError(space.w_TypeError,
-                    space.wrap( "__array_prepare__ must return an "
-                                "ndarray or subclass thereof which is "
-                                "otherwise identical to its input"))
-            return w_retVal
-        return w_result
-
-
 class W_Ufunc1(W_Ufunc):
     _immutable_fields_ = ["func", "bool_result"]
     argcount = 1
diff --git a/pypy/module/micronumpy/loop.py b/pypy/module/micronumpy/loop.py
--- a/pypy/module/micronumpy/loop.py
+++ b/pypy/module/micronumpy/loop.py
@@ -19,6 +19,37 @@
                              reds = ['shape', 'w_lhs', 'w_rhs', 'out',
                                      'left_iter', 'right_iter', 'out_iter'])
 
+def call_prepare(self, space, w_out, w_obj, w_result):
+    if isinstance(w_out, W_NDimArray):
+        w_array = space.lookup(w_out, "__array_prepare__")
+        w_caller = w_out
+    else:
+        w_array = space.lookup(w_obj, "__array_prepare__")
+        w_caller = w_obj
+    if w_array:
+        w_retVal = space.get_and_call_function(w_array, w_caller, w_result, 
None)
+        if not isinstance(w_retVal, W_NDimArray) and \
+            not isinstance(w_retVal, interp_boxes.Box):
+            raise OperationError(space.w_ValueError,
+                space.wrap( "__array_prepare__ must return an "
+                            "ndarray or subclass thereof"))
+        if isinstance(w_result, interp_boxes.Box) or \
+            w_result.is_scalar():
+            if not isinstance(w_retVal, interp_boxes.Box) and not 
w_retVal.is_scalar():
+                raise OperationError(space.w_TypeError,
+                    space.wrap( "__array_prepare__ must return an "
+                                "ndarray or subclass thereof which is "
+                                "otherwise identical to its input"))
+        elif w_result.get_shape() != w_retVal.get_shape() or \
+            w_result.implementation.get_strides() != \
+                w_retVal.implementation.get_strides():
+            raise OperationError(space.w_TypeError,
+                space.wrap( "__array_prepare__ must return an "
+                            "ndarray or subclass thereof which is "
+                            "otherwise identical to its input"))
+        return w_retVal
+    return w_result
+
 def call2(space, shape, func, calc_dtype, res_dtype, w_lhs, w_rhs, out):
     # handle array_priority
     # w_lhs and w_rhs could be of different ndarray subtypes. Numpy does:
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to