python - 如何编译 numba python 代码并存储它?

标签 python numba

我一直在使用 numba 来加速一些 for 循环,获得了很好的结果。我如何预编译代码而不是及时编译代码(这需要一些时间)?

这是一个例子:

import numba as nb
import numpy as np
import time.time()

Nk = 5
Nl = 6
Nx = 7
Ny = 8
A = np.random.rand(Nk, Nl, Nx, Ny)

@nb.jit(nopython=True)
def Loop( A, X, Y ):
    Nk = A.shape[0]
    Nl = A.shape[1]
    Nx = A.shape[2]
    Ny = A.shape[3]
    for ik in range(Nk):
        for il in range(Nl):
            for ix in range(Nx):
                for iy in range(Ny):
                    Y[ik, il] += A[ik, il, ix, iy]*X[ix,iy]
    return Y

Y = np.zeros([Nk, Nl])
X = np.random.rand(Nx, Ny)
Y = Loop( A, X , Y )

我想要的是以某种方式保存已编译的函数,这样我就不需要每次都编译它。

最佳答案

原则上你有 pycc,但截至今天 (numba 0.17) the API is not stable :

The API for ahead of time compilation isn’t stabilized. Adventurous users can still try the pycc utility which is installed as part of Numba.

但是熟练的读者可以提取一些信息from the source itself .

关于python - 如何编译 numba python 代码并存储它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27473307/

相关文章:

python - 在 Python 中计算蛋白质接触顺序

python - Zabbix Action - 如何在自定义脚本中使用默认字段

python - 将 .whl Python 包安装到默认目录以外的特定目录中

python - 如何使用 PIL 从图像中剪切自定义形状?

用于向量化函数的 Python 和 Numba

python - 将 numpy.bmat 与 numba 一起使用

python - close() 或 join() 等效于 celery 作业(python)?

python - 如何在 python 中创建 OR 语句?

python - 将自定义 numba njit 函数应用于 pandas 滚动对象

python - Numba jit nopython 模式 : tell numba the signature of an external arbitrary function