How can I get a stable numpy version for PyPy?

I downloaded the portable version of PyPy from the link https://bitbucket.org/pypy/pypy/downloads/pypy-2.4.0-src.tar.bz2 and I installed numpy for PyPy with the commandpip install git+https://bitbucket.org/pypy/numpy.git

The installation was successful, but I cannot use a function numpy.min

like this.

>>>> numpy.min([1,2,3])    
Traceback (most recent call last):
...
TypeError: expected integer, got NoneType object

      

So I ran numpy.test()

and the result is

FAILED (KNOWNFAIL=5, SKIP=24, errors=886, failures=152)
<nose.result.TextTestResult run=3367 errors=886 failures=152>

      

It seems to be the unstable version of numpy I have installed. How can I get a stable numpy version for PyPy?

Also I tried just pip install numpy

(not pip install git+https://bitbucket.org/pypy/numpy.git

)

However, I ran into another issue discussed in the link PIP Install Numpy gives an error message. "ascii codec cannot decode byte 0xe2"

The answer is used apt-get

to install numpy, but this answer is for CPython only. is there a good solution for PyPy?

+3


source to share


1 answer


I just downloaded Pypy 2.4 and its numpy (via git install). It looks like the function ufunc

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 attribute out

these versions ufunc

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 doesn't return a value in the parameter out

y = 0
numpy.sum(x, out=y)  # returns 45, but does not change y

      

Plain numpy

will prevent y

it from not being an array (or having the wrong dimensions).




np.min(x)

matches np.core.umath.minimum.reduce(x,None,None,None)

where arguments reduce

(variable, axis, dtype, out)

. np.core.umath.minimum.reduce(x)

works fine.

np.core.umath.add.accumulate

works as expected for the argument out

, so the problem seems to be isolated from reduce

.

If you install with git clone, you get the complete repository on your machine, which you can explore. This information is also available on the Internet. I'm still trying to figure out where the ufunc abbreviation is defined and whether it was fully functional or not. This module is still under development.




http://buildbot.pypy.org/numpy-status/latest.html - numpy state table. It links to a directory pypy/module/micronumpy

. I didn't understand how this relates to the https://bitbucket.org/pypy/numpy.git repository (on the download page). I can find the code ufunc.reduce

in the tree micronumpy

, but not in the tree numpy.git

.




B core/_methods.py

is sum

defined as a challenge add.reduce

. min

and max

similarly. Keyword parameters become positional.

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 these parameters is wrong. out

is the 4th, but when I try add.reduce

directly I have to do 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 note in passing that in the tree micronumpy

there commit

that has an incorrect order of the parameters for reduce

. This could be a fix for this error.

In a regular numpy

call sum

:

um.add.reduce(a, axis=axis, dtype=dtype, out=out, keepdims=keepdims)

      

which works great. Apparently someone was trying to squeeze out some performance by minimizing the keyword parameters.

module/micronumpy/ufuncs.py

defines reduce

how:

reduce(self, space, w_obj, w_axis, keepdims=False, out=None, dtype=None,
    cumulative=False)

      

+3


source







All Articles