【问题标题】:How can I get the stable version of numpy for PyPy?如何获得 PyPy 的稳定版 numpy?
【发布时间】:2015-01-17 23:36:22
【问题描述】:

我已经从链接 https://bitbucket.org/pypy/pypy/downloads/pypy-2.4.0-src.tar.bz2 下载了 PyPy 便携式版本,并且我已经使用命令 pip install git+https://bitbucket.org/pypy/numpy.git 为 PyPy 安装了 numpy

安装成功,但是我不能使用numpy.min这样的功能。

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

所以,我运行了numpy.test(),结果是

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

我安装的 numpy 似乎是不稳定版本。如何获得 PyPy 的稳定版 numpy?

我也试过pip install numpy(不是pip install git+https://bitbucket.org/pypy/numpy.git

但是,我遇到了链接PIP Install Numpy throws an error "ascii codec can't decode byte 0xe2"中讨论的另一个问题

答案是使用apt-get 安装numpy,但是,这个答案仅适用于CPython。 PyPy 有什么好的解决方案吗?

【问题讨论】:

  • 你确定有一个numpy 版本可以和pypy 一起使用吗?我能找到的关于它的最后一篇 pypy 博客文章是从 4 月开始的,它似乎仍在进行中。

标签: python numpy pypy


【解决方案1】:

我刚刚下载了 Pypy 2.4 及其 numpy(通过 git install)。 ufunc 功能似乎有错误或不完整。

x = numpy.arange(10)
x.sum()  # 45
x.min()  # 0
numpy.min(x)  # TypeError: expected integer, got NoneType object
numpy.sum(x)  # same error

但如果我给它一个out 属性,这些ufunc 版本可以工作(排序)

numpy.sum(x, out=1)  # returns 45
numpy.min(x, out=1)  # returns 0
numpy.min(x, out=None)  # gets the above error

但在out参数中没有返回值

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

常规的numpy 会反对y 不是数组(或维度错误)。


np.min(x)np.core.umath.minimum.reduce(x,None,None,None) 相同,其中reduce 参数为(variable, axis, dtype, out)np.core.umath.minimum.reduce(x) 工作正常。

np.core.umath.add.accumulateout 参数方面按预期工作,因此问题似乎与 reduce 无关。

如果您使用 git clone 安装,您将在您的机器上获得完整的存储库,您可以对其进行探索。该信息也可在线获取。我仍在尝试找出 ufunc reduce 的定义位置,以及它是否功能齐全。该模块仍处于开发阶段。


http://buildbot.pypy.org/numpy-status/latest.html 是一个 numpy 状态表。它引用pypy/module/micronumpy 目录。我还没有弄清楚这与https://bitbucket.org/pypy/numpy.git 存储库有什么关系(在下载页面上)。我可以在micronumpy 树中找到ufunc.reduce 代码,但在numpy.git 树中找不到。


core/_methods.py 中,sum 被定义为对add.reduce 的调用。 minmax 类似。关键字参数变为位置参数。

def _sum(a, axis=None, dtype=None, out=None, keepdims=False):
    return um.add.reduce(a, axis, dtype, out, keepdims)

但看起来这些参数的顺序是错误的。 out 是第 4 个,但是当我直接尝试 add.reduce 时,我必须成为第 6 个。

>>>> 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)

我顺便看到micronumpy 树中有一个commit 处理reduce 的错误参数顺序。这可能正在修复这个错误。

在常规 numpy 中,sum 调用是:

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

效果很好。显然有人试图通过最小化关键字参数来挤出一点性能。

module/micronumpy/ufuncs.pyreduce 定义为:

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

【讨论】:

    猜你喜欢
    • 2015-04-30
    • 2013-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-31
    • 1970-01-01
    • 2011-02-25
    • 1970-01-01
    相关资源
    最近更新 更多