1. Pypy
  2. Untitled project
  3. pypy

Commits

mattip  committed d3b4a27

typo, fix if clause, actually set return value

  • Participants
  • Parent commits 5c0ec11
  • Branches numpypy-array_prepare_-array_wrap

Comments (0)

Files changed (5)

File pypy/module/micronumpy/interp_numarray.py

View file
     # ----------------------- reduce -------------------------------
 
     def _reduce_ufunc_impl(ufunc_name, promote_to_largest=False,
-                           cumultative=False):
+                           cumulative=False):
         def impl(self, space, w_axis=None, w_out=None, w_dtype=None):
             if space.is_none(w_out):
                 out = None
                 out = w_out
             return getattr(interp_ufuncs.get(space), ufunc_name).reduce(
                 space, self, True, promote_to_largest, w_axis,
-                False, out, w_dtype, cumultative=cumultative)
+                False, out, w_dtype, cumulative=cumulative)
         return func_with_new_name(impl, "reduce_%s_impl_%d_%d" % (ufunc_name,
-                    promote_to_largest, cumultative))
+                    promote_to_largest, cumulative))
 
     descr_sum = _reduce_ufunc_impl("add")
     descr_sum_promote = _reduce_ufunc_impl("add", True)
     descr_all = _reduce_ufunc_impl('logical_and')
     descr_any = _reduce_ufunc_impl('logical_or')
 
-    descr_cumsum = _reduce_ufunc_impl('add', cumultative=True)
-    descr_cumprod = _reduce_ufunc_impl('multiply', cumultative=True)
+    descr_cumsum = _reduce_ufunc_impl('add', cumulative=True)
+    descr_cumprod = _reduce_ufunc_impl('multiply', cumulative=True)
 
     def descr_mean(self, space, w_axis=None, w_out=None):
         if space.is_none(w_axis):

File pypy/module/micronumpy/interp_ufuncs.py

View file
                            w_dtype)
 
     def reduce(self, space, w_obj, multidim, promote_to_largest, w_axis,
-               keepdims=False, out=None, dtype=None, cumultative=False):
+               keepdims=False, out=None, dtype=None, cumulative=False):
         if self.argcount != 2:
             raise OperationError(space.w_ValueError, space.wrap("reduce only "
                 "supported for binary functions"))
                     "%s.reduce without identity", self.name)
         if shapelen > 1 and axis < shapelen:
             temp = None
-            if cumultative:
+            if cumulative:
                 shape = obj_shape[:]
                 temp_shape = obj_shape[:axis] + obj_shape[axis + 1:]
                 if out:
             else:
                 out = W_NDimArray.from_shape(space, shape, dtype, w_instance=obj)
             return loop.do_axis_reduce(shape, self.func, obj, dtype, axis, out,
-                                       self.identity, cumultative, temp)
-        if cumultative:
+                                       self.identity, cumulative, temp)
+        if cumulative:
             if out:
                 if out.get_shape() != [obj.get_size()]:
                     raise OperationError(space.w_ValueError, space.wrap(
         if out:
             out.set_scalar_value(res)
             return out
-        if space.type(obj) != W_NDimArray:
+        if not type(obj) == W_NDimArray:
             #If obj is a subtype of W_NDimArray, return a empty-shape instance
-            return W_NDimArray.from_shape(space, [], dtype, w_instance=obj)
+            out = W_NDimArray.from_shape(space, [], dtype, w_instance=obj)
+            out.set_scalar_value(res)
+            return out
         return res
 
     def call_prepare(self, space, w_out, w_obj, w_result):

File pypy/module/micronumpy/iter.py

View file
         return self.indexes[d]
 
 class AxisIterator(base.BaseArrayIterator):
-    def __init__(self, array, shape, dim, cumultative):
+    def __init__(self, array, shape, dim, cumulative):
         self.shape = shape
         strides = array.get_strides()
         backstrides = array.get_backstrides()
-        if cumultative:
+        if cumulative:
             self.strides = strides
             self.backstrides = backstrides
         elif len(shape) == len(strides):

File pypy/module/micronumpy/loop.py

View file
                                             'func', 'dtype'],
                                     reds='auto')
 
-def do_axis_reduce(shape, func, arr, dtype, axis, out, identity, cumultative,
+def do_axis_reduce(shape, func, arr, dtype, axis, out, identity, cumulative,
                    temp):
-    out_iter = out.create_axis_iter(arr.get_shape(), axis, cumultative)
-    if cumultative:
+    out_iter = out.create_axis_iter(arr.get_shape(), axis, cumulative)
+    if cumulative:
         temp_iter = temp.create_axis_iter(arr.get_shape(), axis, False)
     else:
         temp_iter = out_iter # hack
             cur = temp_iter.getitem()
             w_val = func(dtype, cur, w_val)
         out_iter.setitem(w_val)
-        if cumultative:
+        if cumulative:
             temp_iter.setitem(w_val)
             temp_iter.next()
         arr_iter.next()

File pypy/module/micronumpy/test/test_numarray.py

View file
         a = array(range(5))
         assert a.all() == False
         a[0] = 3.0
-        assert a.all() == True
+        b = a.all()
+        assert b == True
         b = array([])
         assert b.all() == True
 
         b = a[1:, 1::2]
         c = b + b
         assert c.sum() == (6 + 8 + 10 + 12) * 2
-        assert isinstance(c.sum(dtype='f8'), float)
+        d = c.sum(dtype='f8')
+        assert isinstance(d, float)
 
     def test_transpose(self):
         from numpypy import array