数值内核的即时编译器
项目描述
https://pythran.readthedocs.io
这是什么?
Pythran是针对Python语言子集的即时编译器,重点在于科学计算。它将带有一些接口描述的Python模块注释转换为具有相同接口的本地Python模块,但(希望)更快。
它旨在高效编译 科学程序,并利用多核和SIMD指令单元。
直到0.9.5(包括),Pythran支持Python 3和Python 2.7。现在它只支持Python 3。
安装
Pythran源代码托管在 https://github.com/serge-sans-paille/pythran。
Pythran版本托管在 https://pypi.python.org/pypi/pythran。
Pythran可在conda-forge上使用 https://anaconda.org/conda-forge/pythran。
Debian/Ubuntu
使用 pip
收集依赖项
Pythran依赖于几个Python模块和几个C++库。在类似Debian的平台,运行
$> sudo apt-get install libatlas-base-dev $> sudo apt-get install python-dev python-ply python-numpy
使用 pip 安装
$> pip install pythran
使用 mamba 或 conda
使用 mamba (https://github.com/conda-forge/miniforge#mambaforge) 或 conda (https://github.com/conda-forge/miniforge)
运行
$> mamba install -c conda-forge pythran
或
$> conda install -c conda-forge pythran
Mac OSX
使用 brew (https://brew.sh.cn/)
$> pip install pythran $> brew install openblas $> printf '[compiler]\nblas=openblas\ninclude_dirs=/usr/local/opt/openblas/include\nlibrary_dirs=/usr/local/opt/openblas/lib' > ~/.pythranrc
根据您的配置,您可能需要将以下内容添加到您的 ~/.pythranrc 文件中
[compiler] CXX=g++-4.9 CC=gcc-4.9
ArchLinux
使用 pacman
$> pacman -S python-pythran
Fedora
使用 dnf
$> dnf install pythran
Windows
Windows 支持正在进行中,仅针对 Python 3.5+ 且需要 Visual Studio 2017 或更好的 clang-cl
$> pip install pythran
注意,使用 clang-cl.exe 是默认设置。可以通过 CXX 和 CC 环境变量进行更改。
其他平台
请参阅 MANUAL 文件。
基本用法
一个简单的 pythran 输入可以是 dprod.py
"""
Naive dotproduct! Pythran supports numpy.dot
"""
#pythran export dprod(int list, int list)
def dprod(l0,l1):
"""WoW, generator expression, zip and sum."""
return sum(x * y for x, y in zip(l0, l1))
要将它转换为本地模块,运行
$> pythran dprod.py
这将生成一个本地 dprod.so,可以像之前的模块一样导入
$> python -c 'import dprod' # this imports the native module instead
文档
用户文档在 doc 目录中的 MANUAL 文件中可用。
开发者文档在 doc 目录中的 DEVGUIDE 文件中可用。还有一个 TUTORIAL 文件,供不喜欢阅读文档的人使用。
CLI 文档可通过 pythran 帮助命令获取
$> pythran --help
还可以使用 pydoc 获取一些额外的开发者文档。请注意,这是著名游戏 Where’s Waldo? 的计算机科学版本
$> pydoc pythran $> pydoc pythran.typing $> pydoc -b # in the browser
示例
请参阅源代码中的 pythran/tests/cases/ 目录。
联系
赞扬、批评和饼干
pythran@freelists.org – 首先在 https://www.freelists.org/list/pythran 注册!
#pythran 在 OFTC, https://oftc.net
邮件列表存档可在 https://www.freelists.org/archive/pythran/ 获取。
引用
如果您需要引用 Pythran 论文,请自由使用
@article{guelton2015pythran,
title={Pythran: Enabling static optimization of scientific python programs},
author={Guelton, Serge and Brunet, Pierrick and Amini, Mehdi and Merlini,
Adrien and Corbillon, Xavier and Raynaud, Alan},
journal={Computational Science \& Discovery},
volume={8},
number={1},
pages={014001},
year={2015},
publisher={IOP Publishing}
}
许可证
请参阅 LICENSE 文件。
项目详情
pythran-0.16.1.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 861748c0f9c7d422b32724b114b3817d818ed4eab86c09781aa0a3f7ceabb7f9 |
|
MD5 | 106497787546f3538db7bb1a9e48d88a |
|
BLAKE2b-256 | 7332f892675c5009cd4c1895ded3d6153476bf00adb5ad1634d03635620881f5 |