[pypy-commit] pypy numpy-back-to-applevel: import var/std, figure out extra kwargs for reduce

fijal noreply at buildbot.pypy.org
Sat Jan 21 20:12:14 CET 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-back-to-applevel
Changeset: r51606:1c6f3a721515
Date: 2012-01-21 21:02 +0200
http://bitbucket.org/pypy/pypy/changeset/1c6f3a721515/

Log:	import var/std, figure out extra kwargs for reduce

diff --git a/lib_pypy/numpypy/core/_methods.py b/lib_pypy/numpypy/core/_methods.py
--- a/lib_pypy/numpypy/core/_methods.py
+++ b/lib_pypy/numpypy/core/_methods.py
@@ -36,7 +36,7 @@
                             skipna=skipna, keepdims=keepdims)
     if isinstance(ret, mu.ndarray):
         ret = um.true_divide(ret, rcount,
-                        out=ret, casting='unsafe', subok=False)
+                        casting='unsafe', subok=False)
     else:
         ret = ret / float(rcount)
     return ret
@@ -79,7 +79,7 @@
     rcount -= ddof
     if isinstance(ret, mu.ndarray):
         ret = um.true_divide(ret, rcount,
-                        out=ret, casting='unsafe', subok=False)
+                        casting='unsafe', subok=False)
     else:
         ret = ret / float(rcount)
 
@@ -91,7 +91,7 @@
                                 skipna=skipna, keepdims=keepdims)
 
     if isinstance(ret, mu.ndarray):
-        ret = um.sqrt(ret, out=ret)
+        ret = um.sqrt(ret)
     else:
         ret = um.sqrt(ret)
 
diff --git a/lib_pypy/numpypy/core/fromnumeric.py b/lib_pypy/numpypy/core/fromnumeric.py
--- a/lib_pypy/numpypy/core/fromnumeric.py
+++ b/lib_pypy/numpypy/core/fromnumeric.py
@@ -2324,13 +2324,12 @@
     0.44999999925552653
 
     """
-    assert axis is None
     assert dtype is None
     assert out is None
     assert ddof == 0
     if not hasattr(a, "std"):
         a = numpypy.array(a)
-    return a.std()
+    return a.std(axis=axis)
 
 
 def var(a, axis=None, dtype=None, out=None, ddof=0):
@@ -2421,10 +2420,9 @@
     0.20250000000000001
 
     """
-    assert axis is None
     assert dtype is None
     assert out is None
     assert ddof == 0
     if not hasattr(a, "var"):
         a = numpypy.array(a)
-    return a.var()
+    return a.var(axis=axis)
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
@@ -46,18 +46,27 @@
         return self.identity
 
     def descr_call(self, space, __args__):
-        # XXX do something with strange keywords
-        if len(__args__.arguments_w) < self.argcount:
+        args_w, kwds_w = __args__.unpack()
+        # it occurs to me that we don't support any datatypes that
+        # require casting, change it later when we do
+        kwds_w.pop('casting', None)
+        w_subok = kwds_w.pop('subok', None)
+        w_out = kwds_w.pop('out', space.w_None)
+        if ((w_subok is not None and space.is_true(w_subok)) or
+            not space.is_w(w_out, space.w_None)):
+            raise OperationError(space.w_NotImplementedError,
+                                 space.wrap("parameters unsupported"))
+        if kwds_w or len(args_w) < self.argcount:
             raise OperationError(space.w_ValueError,
                 space.wrap("invalid number of arguments")
             )
-        elif len(__args__.arguments_w) > self.argcount:
+        elif len(args_w) > self.argcount:
             # The extra arguments should actually be the output array, but we
             # don't support that yet.
             raise OperationError(space.w_TypeError,
                 space.wrap("invalid number of arguments")
             )
-        return self.call(space, __args__.arguments_w)
+        return self.call(space, args_w)
 
     @unwrap_spec(skipna=bool, keepdims=bool)
     def descr_reduce(self, space, w_obj, w_axis=NoneNotWrapped, w_dtype=None,
diff --git a/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py b/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py
--- a/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py
+++ b/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py
@@ -98,15 +98,15 @@
         from numpypy import array, var
         a = array([[1,2],[3,4]])
         assert var(a) == 1.25
-        #assert (var(a,0) == array([ 1.,  1.])).all()
-        #assert (var(a,1) == array([ 0.25,  0.25])).all()
+        assert (var(a,0) == array([ 1.,  1.])).all()
+        assert (var(a,1) == array([ 0.25,  0.25])).all()
 
     def test_std(self):
         from numpypy import array, std
         a = array([[1, 2], [3, 4]])
         assert std(a) ==  1.1180339887498949
-        #assert (std(a, axis=0) == array([ 1.,  1.])).all()
-        #assert (std(a, axis=1) == array([ 0.5,  0.5])).all()
+        assert (std(a, axis=0) == array([ 1.,  1.])).all()
+        assert (std(a, axis=1) == array([ 0.5,  0.5])).all()
 
     def test_mean(self):
         from numpypy import array, mean, arange


More information about the pypy-commit mailing list