问题
Is it possible for Numba to read a file?
I tried using the standard Numpy method save and load and got a not-supported error.
Is there any other format Numba can handle? If not, what should one do when one needs to read from a file and still wants to use the power of Numba?
Here is what I tried:
import numpy as np
from numba import njit
a = np.random.randn(400, 400)
np.save('test', a)
@njit
def f():
a = np.load('test.npy')
return a
b = f()
> TypingError: Failed at nopython (nopython frontend)
> Unknown attribute 'load' of type Module(<module 'numpy'
回答1:
You will gain no benefit from reading the file within numba and np.load
is not supported (see here for the complete list of supported functions). Numba functions should, to get full benefit of the jit, just operate on scalars and arrays. Read the data in during your setup and then pass the arrays contained in the file into the numba-jitted function.
来源:https://stackoverflow.com/questions/50911063/how-to-read-file-with-numba