python - Numba 错误,AttributeError:“数组”对象没有属性“__defaults__”
问题描述
我正在尝试优化一些代码,更具体地说是使用 Numba 的函数,@jit。但是,我遇到了一些我无法克服的错误。请在下面找到代码和输出错误。输入是 uint8 和 2 维。我在 Mac OS Catalina 10.15.4、Numpy 1.15.2、Numba 0.39.0 上运行。代码:
@jit(numba.uint8[:,:],parallel=True, nopython=True, nogil=True)
def flowaccumulation(flowdir):
nr=flowdir.shape[0]
nc=flowdir.shape[1]
shape=(nr,nc)
accumulation=np.zeros(shape)
for i in prange(nr):
for j in range(nc):
if flowdir[i,j]==0:
accumulation[i,j]=0
else:
tempi=i
tempj=j
while tempj!=-1 and tempj!=nc and tempi!=-1 and tempi!=nr and flowdir[tempi,tempj]!=0:
if flowdir[tempi,tempj]==1:
movej=1
movei=0
accumulation[tempi,tempj]=accumulation[tempi,tempj]+1
if flowdir[tempi+movei,tempj+movej]==16:
break
elif flowdir[tempi,tempj]==2:
movej=1
movei=1
accumulation[tempi,tempj]=accumulation[tempi,tempj]+1
if flowdir[tempi+movei,tempj+movej]==32:
break
elif flowdir[tempi,tempj]==4:
movej=0
movei=1
accumulation[tempi,tempj]=accumulation[tempi,tempj]+1
if flowdir[tempi+movei,tempj+movej]==64:
break
elif flowdir[tempi,tempj]==8:
movej=-1
movei=1
accumulation[tempi,tempj]=accumulation[tempi,tempj]+1
if flowdir[tempi+movei,tempj+movej]==128:
break
elif flowdir[tempi,tempj]==16:
movej=-1
movei=0
accumulation[tempi,tempj]=accumulation[tempi,tempj]+1
if flowdir[tempi+movei,tempj+movej]==1:
break
elif flowdir[tempi,tempj]==32:
movej=-1
movei=-1
accumulation[tempi,tempj]=accumulation[tempi,tempj]+1
if flowdir[tempi+movei,tempj+movej]==2:
break
elif flowdir[tempi,tempj]==64:
movej=0
movei=-1
accumulation[tempi,tempj]=accumulation[tempi,tempj]+1
if flowdir[tempi+movei,tempj+movej]==4:
break
elif flowdir[tempi,tempj]==128:
movej=1
movei=-1
accumulation[tempi,tempj]=accumulation[tempi,tempj]+1
if flowdir[tempi+movei,tempj+movej]==8:
break
tempi=tempi+movei
tempj=tempj+movej
return accumulation
输出:
File "/Users/nina/opt/anaconda3/envs/floods/lib/python3.5/site-packages/numba/dispatcher.py", line 183, in __init__
default_values = self.py_func.__defaults__ or ()
AttributeError: 'Array' object has no attribute '__defaults__'
解决方案
推荐阅读
- java - 为什么 List.contains(Object) 的行为不同?
- r - 如何在同一个数据帧上做colsum和average
- powerbi - 使用 DAX 生成日期系列
- javascript - 仅在服务器上需要一个包
- java - Intellij IDEA 仅针对所有未提交的更改运行测试
- regex - 在换行符之前匹配字符,不包括空格?
- macos - MacOS - 使用带有launchd的脚本 - 启动,登录,注销,关闭?
- service-worker - Workbox 的服务人员在更改时未更新
- python - AllenNLP 共指分辨率的多 GPU 训练
- reactjs - 事件处理程序中带有 [name] 的 PrevState