标签: pypy

如何在双精度算术中正确舍入到最接近的整数

我必须使用 Python3(PyPy 实现)分析大量数据,其中我对相当大的浮点数进行一些操作,并且必须检查结果是否足够接近整数。

举个例子,假设我正在生成随机的数字对,并检查它们是否形成毕达哥拉斯三元组(是具有整数边的直角三角形的边):

from math import hypot
from pprint import pprint
from random import randrange
from time import time

def gen_rand_tuples(start, stop, amount):
    '''
    Generates random integer pairs and converts them to tuples of floats.
    '''
    for _ in range(amount):
        yield (float(randrange(start, stop)), float(randrange(start, stop)))

t0 = time()
## Results are those pairs that results in integer hypothenuses, or
## at least very close, to within 1e-12.
results = [t for t in gen_rand_tuples(1, 2**32, 10_000_000) if …
Run Code Online (Sandbox Code Playgroud)

python precision pypy floating-accuracy double-double-arithmetic

6
推荐指数
1
解决办法
213
查看次数

单个Web服务器上的PyPy + PHP

我正在从头开始设置一个Web服务器,主要用于使用Python编写webapps.在查看Apache + mod_wsgi的替代方案时,看起来pypy在我打算用于我自己的应用程序的几乎所有内容中都表现得非常好.没有真正有机会正确使用PyPy,我觉得这是一个很好的机会来使用它,因为我不需要服务器是防弹的.

但是,我想在Web服务器上运行一些PHP应用程序以用于管理目的(例如,PHPPgAdmin).是否有一个优雅的解决方案,允许我在像Apache这样的PHP兼容的网络服务器中使用PyPy?或者我将不得不运行CherryPy/Paste或其他WSGI服务器之一,Apache和mod_wsgi在一个单独的端口上提供管理服务?

php python apache pypy wsgi

5
推荐指数
1
解决办法
779
查看次数

如何在PyPy中安装/使用cx_Oracle

我似乎无法在Google或SO上找到任何关于让cx_Oracle与PyPy一起工作的信息.有人可以告诉我是否有可能,如果是的话,我怎么能做到这一点?

python cx-oracle pypy

5
推荐指数
1
解决办法
1277
查看次数

使用PyPy或Shedskin加速现有Python App的部分内容

我希望为现有应用程序带来速度提升,我正在寻找有关可能选项的建议.该应用程序是用Python编写的,使用wxPython,并与之打包py2exe(我只针对Windows平台).应用程序的某些部分是计算密集型的,在解释Py​​thon中运行得太慢.我不熟悉C,所以移植部分代码并不是我的选择.

所以我的问题基本上是我清楚地了解我的选项,如下所示,或者我是从错误的方向接近这个?

  • 与pypy一起运行:今天我开始尝试Pypy - 结果令人兴奋,因为我可以从pypy解释器运行大部分代码,我看到5x +速度改进而没有代码更改.但是,如果我理解正确的话,(a)具有wxpython支持的Pypy 仍然是一项正在进行中的工作,并且(b)我无法将其编译为exe以进行分发.所以,除非我弄错了,这对我来说似乎是不合适的?没有办法打包,所以部分内容是用pypy执行的?
  • 将代码转换为RPython,使用pypy进行翻译所以下一个选项似乎实际上是将代码的一部分重写为pypy受限语言,这似乎是一项非常大的工作.但是,如果我这样做,部分代码可以编译成可执行文件(?),然后我可以通过ctypes(?)访问代码.
  • 其他限制选项 Shedskin似乎是一个受欢迎的选择,这是否更符合我的要求?其他选项似乎是Cpython,Psyco和Unladen,但它们都被取代或不再维护.

python pypy

5
推荐指数
1
解决办法
1636
查看次数

什么样的Python开始?

我想学习python所以我从python站点下载它,我看到其他4种蟒蛇出现:

  • Python(正常)
  • IronPython的
  • Jython的
  • PyPy
  • 无堆叠的Python

我真的可以找到它们之间的差异.还有哪一个是最好的开始.

python ironpython pypy jython python-stackless

5
推荐指数
1
解决办法
583
查看次数

如何禁用pypy assert语句?

$ ./pypy -O
Python 2.7.2 (a3e1b12d1d01, Dec 04 2012, 13:33:26)
[PyPy 1.9.1-dev0 with GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: `` amd64 and ppc are only
available in enterprise version''
>>>> assert 1==2
Traceback (most recent call last):
  File "", line 1, in 
AssertionError
>>>> 

但是当我执行时

$ python -O
Python 2.7.3 (default, Aug  1 2012, 05:14:39) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> assert …

python pypy

5
推荐指数
1
解决办法
235
查看次数

如何在PyCharm 4.5.2中使用PyPy作为标准/默认解释器?

如何在PyCharm 4.5.2中使用PyPy作为标准/默认解释器?一切都在Ubunutu 14.10下运行,并且已经安装了pypy.

python pypy pycharm

5
推荐指数
1
解决办法
6164
查看次数

将matplotlib安装到pypy

当我尝试使用pip安装matplotlib时,抛出异常:

In file included from /usr/include/numpy/ndarrayobject.h:26:0,
                 from src/file_compat.h:7,
                 from src/ft2font_wrapper.cpp:3:
/usr/include/numpy/__multiarray_api.h: In function ‘int _import_array()’:
/usr/include/numpy/__multiarray_api.h:1686:13: error: ‘NPY_CPU_UNKNOWN_ENDIAN’ was not declared in this scope
   if (st == NPY_CPU_UNKNOWN_ENDIAN) {
             ^
/usr/include/numpy/__multiarray_api.h:1697:13: error: ‘NPY_CPU_LITTLE’ was not declared in this scope
   if (st != NPY_CPU_LITTLE) {
             ^
error: command 'cc' failed with exit status 1

----------------------------------------
Command "/usr/bin/pypy -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-vGxrsz/matplotlib/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-oB9gVW-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-vGxrsz/matplotlib
Run Code Online (Sandbox Code Playgroud)

如果我正确理解它的问题在numpy中。我使用以下命令安装它:

pypy …

python pypy numpy pip matplotlib

5
推荐指数
1
解决办法
2925
查看次数

在树莓派上安装pypy3

我有一个需要更快运行的python3脚本,因此我试图在运行raspbian Stretch 4.14的raspberry pi上安装pypy3。

看起来pypy已经预装了,但它的版本是2.7.12,并且无法与我的python3代码一起使用。

我在Google上搜索了很多,但找不到适合我的安装pypy3的说明,很多人建议从二进制文件中进行构建,但是我不确定这意味着什么....或在哪里可以找到正确的ARM体系结构二进制文件。

请帮忙!

python pypy python-3.x raspberry-pi

5
推荐指数
1
解决办法
671
查看次数

pypy3在10 ** 10循环时间内发生了什么

代码简单

@count_run_time
def test_while(l: int=0) -> (int, int):
    y = 0
    x = 0
    while x < l:
        y += x
        x += 1
    return x, y
Run Code Online (Sandbox Code Playgroud)

当我使用cpython(Python 3.6.8(v3.6.8:3c6b436a57,Dec 24 2018,02:04:31))运行时

test_while(10**5)
[func: test_while] cost @0.008665s
(100000, 4999950000)

test_while(10**6)
[func: test_while] cost @0.080222s
(1000000, 499999500000)

test_while(10**7)
[func: test_while] cost @0.814199s
(10000000, 49999995000000)

test_while(10**8)
[func: test_while] cost @7.944017s
(100000000, 4999999950000000)

test_while(10**9)
[func: test_while] cost @80.063558s
(1000000000, 499999999500000000)

test_while(10**10)
[func: test_while] cost @851.572578s
(10000000000, 49999999995000000000)
Run Code Online (Sandbox Code Playgroud)

从结果可以看出,随着循环次数的增加,消耗的时间也呈线性增加。

接下来,我尝试在pypy3(Python 3.6.1(784b254d6699,Apr 14 2019,10:22:55),[PyPy 7.1.1-beta0与GCC 4.2.1兼容Apple …

pypy python-3.x

5
推荐指数
1
解决办法
43
查看次数