如何使用Numba读取文件 [英] How to read file with Numba

查看:131
本文介绍了如何使用Numba读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Numba 是否可以读取文件?

Is it possible for Numba to read a file?

我尝试使用标准的 Numpy 方法保存和加载,但遇到了不支持的错误.

I tried using the standard Numpy method save and load and got a not-supported error.

Numba 是否还有其他格式可以处理?如果不是,当一个人需要读取一个文件并且仍然想使用 Numba 的强大功能时,应该怎么做?

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?

这是我尝试过的:

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'

推荐答案

在 numba 中读取文件不会有任何好处,并且不支持 np.load(请参阅 此处 获取支持功能的完整列表).为了充分利用 jit,Numba 函数应该只对标量和数组进行操作.在设置过程中读取数据,然后将文件中包含的数组传递给 numba-jitted 函数.

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.

这篇关于如何使用Numba读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆