Commits

Romain Guillebert committed 145ff82

Move call_prepare to loop.py

  • Participants
  • Parent commits d18c417
  • Branches numpypy-array_prepare_-array_wrap

Comments (0)

Files changed (2)

File pypy/module/micronumpy/interp_ufuncs.py

             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

File pypy/module/micronumpy/loop.py

                              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: