I am trying to optimize some code, more specifically a function using Numba, @jit. However, I am running into some errors, that I cannot overcome. Please find the code and output error below. The input is uint8 and 2 dimensions. I am running on Mac OS Catalina 10.15.4, Numpy 1.15.2, Numba 0.39.0. Code:
@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
output:
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__'