简体   繁体   English

Python:PyPy:SciPy /卡方分布?

[英]Python: PyPy: SciPy/Chi-square distribution?

I have a Python project where performance is fairly important. 我有一个Python项目,其中性能非常重要。 Honestly, I know Python (at least pure Python) isn't the best tool for the job, but I'm using it anyhow because I want to distribute a very simple pure python version of some research code so that people can modify it, etc. without having to set up a complicated environment. 老实说,我知道Python(至少是纯Python)不是最好的工具,但无论如何我都在使用它,因为我想分发一些非常简单的纯python版本的一些研究代码,以便人们可以修改它,等,而不必设置复杂的环境。 (I also have an alternative implementation, written in D, which is much faster but harder to hack.) (我还有一个替代实现,用D编写,速度更快但更难破解。)

I was using PyPy as my interpreter and recommending it to anyone who usd this code. 我使用PyPy作为我的翻译,并向任何使用此代码的人推荐它。 This was giving me reasonable speed. 这给了我合理的速度。 I then decided to tweak the algorithm and needed to access to some functions from SciPy (all I need is the CDF, survival function and inverse CDF for the Chi-square distribution). 然后我决定调整算法并需要从SciPy访问一些函数(我需要的只是CDF,生存函数和卡方阵的逆CDF)。 I tried running my code in CPython to get access to SciPy and it's slow as molasses. 我尝试在CPython中运行我的代码来访问SciPy,它作为糖蜜很慢。

Can someone suggest one of three things: 有人可以建议三件事之一:

  1. A kludge that will allow me to use some bits and pieces of SciPy from PyPy. 一个kludge,允许我使用PyPy的一些片段SciPy。

  2. Even better, pure python implementations of the chi-square distribution functions I need, under a liberal license? 在自由主义许可下,我需要更纯粹的python实现卡方分布功能吗?

  3. A way to JIT the bottlenecks from CPython? 一种JIT CPython瓶颈的方法? I'm aware of Psyco, but it appears unmaintained and only works on 32-bit systems. 我知道Psyco,但它似乎没有维护,只适用于32位系统。

SciPy does not work on PyPy yet, although there is some work to make it happen relatively soonish, provided you're willing to use nightly and make little adjustments so you use only the supported subset of numpy (that expands rapidly anyway). SciPy还没有在PyPy上运行,虽然有一些工作可以让它相对较快地发生,只要你愿意每晚使用并做一些调整,这样你只使用支持的numpy子集(无论如何都会迅速扩展)。 I would suggest you simply try porting the SciPy functions to Python for now if time rushes you (they should be relatively simple, but still work). 我建议你现在只是尝试将SciPy函数移植到Python,如果时间紧迫你(它们应该相对简单,但仍然有效)。 There is also a numpy fundraising on PyPy website to make this happen even sooner :) 在PyPy网站上还有一个numpy筹款活动,以便更快地实现这一目标:)

EDIT: This is matplotlib running on pypy by embedding CPython: http://baroquesoftware.com/~fijal/extreme_hacks.png 编辑:这是通过嵌入CPython在pypy上运行的matplotlib: http ://baroquesoftware.com/~fijal/extreme_hacks.png

EDIT2: read http://morepypy.blogspot.com/2011/12/plotting-using-matplotlib-from-pypy.html for an example. EDIT2:阅读http://morepypy.blogspot.com/2011/12/plotting-using-matplotlib-from-pypy.html以获取示例。

Cheers, fijal 干杯,fijal

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM