- 14
- 0
- 约3.67千字
- 约 2页
- 2023-03-10 发布于湖北
- 举报
使使⽤⽤numba对对numpy加加速速遇遇到到的的坑坑
问题⼀:
numba.errors.UntypedAttributeError: Failed at nopython (nopython frontend)
Unknow n attribute fill of type array(float64 2d C)
经过查阅以下⽂档: /numba-doc/latest/reference/numpysupported.html
发现numba并不⽀持 np.fill()。因此将 码改成:
background = np.zeros((sourceIm.shape[0] sourceIm.shape[1])) # supported
for i j in np.ndindex (background.shape): # np.fill not supported by numba
background[i j] = threshold
background=background.astype(np.float32)
问题⼆:
numba.errors.TypingError: Failed at nopython (nopython frontend)
Internal error at numba.typeinfer.CallConstraint object at 0x7f726d5ba8:
numba.errors.InternalError: Integer object has no attribute ndim
[1] During: resolving callee type: Function(function w here at 0x7f86f67bf8)
[2] During: typing of call at test_depth_ im.py (24)
查看错误出现位置,发现在np.w here(),但查询上述⽂档,发现numba是⽀持np.w here()的。于是怀疑是数据类型未指明导致nopython模式
⽆法启动。
在np.w here()之前添加如下两⾏ 码,以检查numba推断出的类型:
@nj it(float32[: : :](float32[: : :] float32) parallel=True fastmath=True)
def depthFilter(depthInfo threshold):
#print(numba.typeof(depthInfo))
#print(numba.typeof(threshold))
不料竟然⼜报错:
numba.errors.TypingError: Failed at nopython (nopython frontend)
Untyped global name numba: cannot determine Numba type of class object
numba.errors.UntypedAttributeError: Failed at nopython (nopython frontend)
Unknow n attribute typeof of type Module(module numba from /usr/lib/python3/dist-packages/numba/__ init__ .py)
解决⽅法: 将函数上⽅的nj it装饰器注释掉即可 ()
数据类型为:
array(int32 3d C)
float64
于是考虑将数据类型转化⼀致
1. 数组需要⽤np.astype()转换: x=x.astype(np.float32)
2. 标量通过加点: 7300 - 7300. 并在装饰器中指明signature为 float32
否则可能遇到如下错误:
Traceback (most recent call last):
File test_depth_ im.py line 47 in module
depthFilter(float(x) 7300.)
TypeError: only size-1 arrays can be converted to Python scalars
或者:
numba.errors.TypingError: Failed at nopython (nopyth
您可能关注的文档
最近下载
- 抢救的配合PPT课件.pptx VIP
- 2026-2030中国粪便菌群移植(FMT)行业发展现状及趋势前景预判研究报告.docx
- (2026春新版)青岛版三年级数学下册全册PPT课件(六三制).pptx
- DBJ50T392-2021 城市综合管廊结构工程施工及质量验收标准.pdf VIP
- 重庆巴蜀中学高一生物模拟试卷含解析.docx VIP
- 天一大联考2026届高一化学第一学期期末预测试题含解析.doc
- 2026年护理部年度工作计划.docx
- 《医用微网雾化器技术要求》.pdf VIP
- (最新版)2025年11月《 美利坚合众国国家安全战略 》.pdf VIP
- 重庆巴蜀中学高二生物下学期期末试卷含解析.docx VIP
原创力文档

文档评论(0)