Reputation: 3743
I have been using numba to speed up some for loops getting pretty good results. Instead of having code compile just in time (which takes some time) how do I pre compile the code?
here is an example:
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 )
What I'd like is to somehow save the compiled function so I don't need to compile it each time.
Upvotes: 2
Views: 1262
Reputation: 39
Ahead-of-Time compilation (AOT) maybe too heavy for this purpose(I don't need to compile it each time). Just use @jit(cache=True) is sufficient.
Upvotes: -1
Reputation:
In principle you have pycc
, but as of today (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.
However a skilled reader can extract some information from the source itself.
Upvotes: 1