How to read file with Numba

主宰稳场 提交于 2020-01-16 17:46:18

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!