这是我的代码,用于从图像构造最小树(f
是由scipy提供的图像)
这是我正在编写的一个接缝雕刻程序的基础。
此代码段在普通python中按预期工作。当我在不使用nopython=True
的情况下使用@numba.jit
时,它也可以工作(性能提高了大约200%!),但那是在对象模式下。
当我尝试使用nopython=True
模式时,它不能编译,并且我得到错误:
Failed at nopython (nopython frontend)
Undefined variable '$313.3'
我不明白为什么这个不能编译,因为我没有看到任何可能是未定义的东西。
from numba import jit
from scipy import misc
import numba
f = misc.face()
@jit(nopython=True)
def explorethisx(inar, x):
places = []
places.append((x,0))
x1,y1 = x,0
s = numba.int64(0)
co = 0
#for _ in range( 799):
while co != numba.int16(799):
co += 1
a1,a2,a3 = 999,999,999
a1 = inar[y1 + 1][x1-1][1]
a2 = inar[y1 + 1][x1][1]
a3 = inar[y1 + 1][x1 + 1][1]
m = a1
ch = -1
if m > a2:
m = a2
ch = 0
if m > a3:
m = a3
ch = 1
x1 = x1 + ch
y1 = y1 + 1
s += inar[y1][x1][1]
places.append((x1,y1))
return([s, places])
explorethisx(f,3)
explorethisx.inspect_types()
Numba是一个非常酷的项目,即使是在python对象模式下,性能的提升也给我留下了深刻的印象。
https://stackoverflow.com/questions/41558683
复制