[pypy-commit] pypy numpy-multidim: avoid exposing random parameters to python

alex_gaynor noreply at buildbot.pypy.org
Thu Nov 24 16:18:07 CET 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: numpy-multidim
Changeset: r49737:9abe1021b1c6
Date: 2011-11-24 09:17 -0600
http://bitbucket.org/pypy/pypy/changeset/9abe1021b1c6/

Log:	avoid exposing random parameters to python

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
@@ -401,7 +401,7 @@
 
     def _reduce_ufunc_impl(ufunc_name):
         def impl(self, space):
-            return getattr(interp_ufuncs.get(space), ufunc_name).descr_reduce(space, self, True)
+            return getattr(interp_ufuncs.get(space), ufunc_name).reduce(space, self, multidim=True)
         return func_with_new_name(impl, "reduce_%s_impl" % ufunc_name)
 
     descr_sum = _reduce_ufunc_impl("add")
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
@@ -44,10 +44,11 @@
             )
         return self.call(space, __args__.arguments_w)
 
-    @unwrap_spec(called_on_array=bool)
-    def descr_reduce(self, space, w_obj, called_on_array=False):
+    def descr_reduce(self, space, w_obj):
+        return self.reduce(space, w_obj, multidim=False)
+
+    def reduce(self, space, w_obj, multidim):
         from pypy.module.micronumpy.interp_numarray import convert_to_array, Scalar
-
         if self.argcount != 2:
             raise OperationError(space.w_ValueError, space.wrap("reduce only "
                 "supported for binary functions"))
@@ -65,10 +66,9 @@
         )
         start = obj.start_iter(obj.shape)
         shapelen = len(obj.shape)
-        if not called_on_array:
-            if shapelen > 1:
-                raise OperationError(space.w_NotImplementedError,
-                                     space.wrap("not implemented yet"))
+        if shapelen > 1 and not multidim:
+            raise OperationError(space.w_NotImplementedError,
+                space.wrap("not implemented yet"))
         if self.identity is None:
             if size == 0:
                 raise operationerrfmt(space.w_ValueError, "zero-size array to "
@@ -80,10 +80,10 @@
         new_sig = signature.Signature.find_sig([
             self.reduce_signature, obj.signature
         ])
-        return self.reduce(new_sig, shapelen, start, value, obj,
+        return self.reduce_loop(new_sig, shapelen, start, value, obj,
                            dtype).wrap(space)
 
-    def reduce(self, signature, shapelen, i, value, obj, dtype):
+    def reduce_loop(self, signature, shapelen, i, value, obj, dtype):
         while not i.done():
             reduce_driver.jit_merge_point(signature=signature,
                                           shapelen=shapelen, self=self,


More information about the pypy-commit mailing list