[pypy-commit] pypy numpy-multidim: raise NotImplementedError in case we call reduce directly on a multidim array

fijal noreply at buildbot.pypy.org
Thu Nov 24 16:12:06 CET 2011


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-multidim
Changeset: r49735:62ddd31b5a52
Date: 2011-11-24 17:11 +0200
http://bitbucket.org/pypy/pypy/changeset/62ddd31b5a52/

Log:	raise NotImplementedError in case we call reduce directly on a
	multidim array

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
@@ -397,7 +397,7 @@
 
     def _reduce_ufunc_impl(ufunc_name):
         def impl(self, space):
-            return getattr(interp_ufuncs.get(space), ufunc_name).descr_reduce(space, self)
+            return getattr(interp_ufuncs.get(space), ufunc_name).descr_reduce(space, self, 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
@@ -1,6 +1,6 @@
 from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.gateway import interp2app
+from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.typedef import TypeDef, GetSetProperty, interp_attrproperty
 from pypy.module.micronumpy import interp_dtype, signature
 from pypy.rlib import jit
@@ -44,7 +44,8 @@
             )
         return self.call(space, __args__.arguments_w)
 
-    def descr_reduce(self, space, w_obj):
+    @unwrap_spec(called_on_array=bool)
+    def descr_reduce(self, space, w_obj, called_on_array=False):
         from pypy.module.micronumpy.interp_numarray import convert_to_array, Scalar
 
         if self.argcount != 2:
@@ -64,6 +65,10 @@
         )
         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 self.identity is None:
             if size == 0:
                 raise operationerrfmt(space.w_ValueError, "zero-size array to "


More information about the pypy-commit mailing list