I just downloaded Pypy 2.4 and its numpy (via the git install). Looks like the ufunc functionality has a bug or is just incomplete.
x = numpy.arange(10)
x.sum() # 45
x.min() # 0
numpy.min(x) # TypeError: expected integer, got NoneType object
numpy.sum(x) # same error
but if I give it an out attribute these ufunc versions work (sortof)
numpy.sum(x, out=1) # returns 45
numpy.min(x, out=1) # returns 0
numpy.min(x, out=None) # gets the above error
But it does not return a value in the out parameter
y = 0
numpy.sum(x, out=y) # returns 45, but does not change y
Regular numpy would object about y not being an array (or having the wrong dimensions).
np.min(x) is that same as np.core.umath.minimum.reduce(x,None,None,None), where the reduce arguments are (variable, axis, dtype, out). np.core.umath.minimum.reduce(x) works fine.
np.core.umath.add.accumulate works as expected with respect to the out argument, so the problem seems to be isolated to the reduce.
If you install with git clone you get the full repository on your machine, which you can explore. That info is also available online. I'm still trying to figure out where the ufunc reduce is defined, and whether it was fully functional or not. This module is still very much in the development stage.
http://buildbot.pypy.org/numpy-status/latest.html is a numpy status table. It references a pypy/module/micronumpy directory. I haven't figured out how this relates to the https://bitbucket.org/pypy/numpy.git repository (on the download page). I can find the ufunc.reduce code in the micronumpy tree, but not in the numpy.git tree.
In core/_methods.py, sum is defined as a call to add.reduce. min and max similarly. Keyword parameters become positional ones.
def _sum(a, axis=None, dtype=None, out=None, keepdims=False):
return um.add.reduce(a, axis, dtype, out, keepdims)
But it looks like the order of those parameters is wrong. out is the 4th, but when I try add.reduce directly, I have to make the 6th.
>>>> x
array([[ 0., 1.],
[ 2., 3.],
[ 4., 5.]])
>>>> y=np.zeros((2,))
>>>> np.add.reduce(x, 0, float, False, False, y)
array([ 6., 9.])
# reduce(a, axis, dtype, ?, keepdims, out)
I saw in passing that there is a commit in the micronumpy tree dealing with a wrong parameter order for reduce. That may be fixing this error.
In regular numpy the sum call is:
um.add.reduce(a, axis=axis, dtype=dtype, out=out, keepdims=keepdims)
which works fine. Apparently someone was trying to squeeze out a bit of performance by minimizing keyword parameters.
module/micronumpy/ufuncs.py defines reduce as:
reduce(self, space, w_obj, w_axis, keepdims=False, out=None, dtype=None,
cumulative=False)