Using the flag
, it is possible to use the
numpy implementation for numpy related operations. One advantage to use this backend is that the Pythran implementation uses C++ expression templates to save memory transfers and can benefit from SIMD instructions of modern CPU.
This can lead to really interesting speedup in some cases, going from 2 up to 16, depending on the targeted CPU architecture and the original algorithm.
Please note that this feature is experimental.
You first need to install Pythran. See its 文档编制 了解更多信息。
Then, simply add a
directive at the top of the Python files that needs to be compiled using Pythran numpy support.
Here is an example of a simple
file using distutils:
from distutils.core import setup from Cython.Build import cythonize setup( name = "My hello app", ext_modules = cythonize('hello_pythran.pyx') )
Then, with the following header in
# cython: np_pythran=True
will be compiled using Pythran numpy support.