我一直在制作一个涉及复数计算的程序,我正在使用的三个函数是:
import turtle
import cmath
import numpy as np
from numba import jit
@jit
def quadratics(arange=[0,10],brange=[0,100],crange=[0,100], step=2):
l = []
for a in range(arange[0],arange[1]+1,step):
for b in range(brange[0],brange[1]+1,step):
for c in range(crange[0],crange[1]+1,step):
if a != 0:
l.append((-b+cmath.sqrt(b**2-4*a*c))/(2*a))
l.append((-b-cmath.sqrt(b**2-4*a*c))/(2*a))
return l
def mindistance(point, roots):
return min(np.array([(point.real-i.real)**2+(point.imag-i.imag)**2 for i in roots]))
@jit
def drawing_matrix(imsz=500,xrange=[-5,5],yrange=[-5,5],poly=2,acc=0.01):
l = np.zeros((imsz, imsz))
roots = quadratics()
for x in range(0, imsz):
for y in range(0, imsz):
c = complex((x/imsz)*(xrange[1]-xrange[0])+xrange[0],(y/imsz)*(yrange[1]-yrange[0])+yrange[0])
if mindistance(c, roots) <= acc:
l[x,y] = 1
return l
现在,我一直在使用Numba来加快@jit
装饰器的速度,除了mindistance()
之外它还没什么问题。如果我将@jit
装饰器放在该函数上(这非常有用,因为它在程序运行期间被调用了数千次),它会产生最全能的错误消息,结尾于:
numba.errors.LoweringError: Failed at object (object mode backend)
make_function(code=<code object <listcomp> at 0x000001F460FAB540, file "C:\Users\Isky\Documents\IT\Programs\Mathematics\AlgebraicNumbers.py", line 19>, name=$const0.7, defaults=None, closure=$0.5)
File "AlgebraicNumbers.py", line 19
[1] During: lowering "$0.8 = make_function(code=<code object <listcomp> at 0x000001F460FAB540, file "C:\Users\Isky\Documents\IT\Programs\Mathematics\AlgebraicNumbers.py", line 19>, name=$const0.7, defaults=None, closure=$0.5)" at C:\Users\Isky\Documents\IT\Programs\Mathematics\AlgebraicNumbers.py (19)
是第19行(如def mindistance()
所示)。你能告诉我为什么Numba不喜欢这个功能吗?