I have the following code in python to calculate the Mandelbrot set. It works fine, but when I try to compile it with JIT by adding @jit
decorator before the function def, it doesn't work any more. Can anybody tell me why? I would appreciate if you don't criticize my Mandelbrot calculation (I am guessing it could be optimized) and just let me know why JIT doesn't work with this function. By the way, the code is indented after the def. It just didn't appear that way when I inserted it here.
def mandelbrot(xmin,xmax,ymin,ymax,width,height,maxiter):
points=[]
x=np.linspace(xmin,xmax,width)
y=np.linspace(ymin,ymax,height)
for ix,re in enumerate(x):
points.append([])
for iy,im in enumerate(y):
cx=re
cy=im
zx=0
zy=0
for n in range(maxiter):
if zx*zx+zy*zy>4.0:
iters=n
break
else:
oldzx=zx
oldzy=zy
zy = 2*oldzx*oldzy+cy
zx = oldzx*oldzx-oldzy*oldzy+cx
iters=n
points[ix].append(int(iters))
return points
I get the following error report with the final line being LoweringError
runfile('D:/python programs/mandelbrot/mandelbrot.py', wdir='D:/python programs/mandelbrot') Traceback (most recent call last):
File "", line 1, in runfile('D:/python programs/mandelbrot/mandelbrot.py', wdir='D:/python programs/mandelbrot')
File "C:\Users\Matthew\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 786, in runfile execfile(filename, namespace)
File "C:\Users\Matthew\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile exec(compile(f.read(), filename, 'exec'), namespace)
File "D:/python programs/mandelbrot/mandelbrot.py", line 41, in mandelbrot_set=mandelbrot(-2.0,1.0,-1.5,1.5,500,500,50)
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\dispatcher.py", line 368, in _compile_for_args raise e
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\dispatcher.py", line 325, in _compile_for_args return self.compile(tuple(argtypes))
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\dispatcher.py", line 653, in compile cres = self._compiler.compile(args, return_type)
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\dispatcher.py", line 83, in compile pipeline_class=self.pipeline_class)
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\compiler.py", line 873, in compile_extra return pipeline.compile_extra(func)
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\compiler.py", line 367, in compile_extra return self._compile_bytecode()
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\compiler.py", line 804, in _compile_bytecode return self._compile_core()
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\compiler.py", line 791, in _compile_core res = pm.run(self.status)
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\compiler.py", line 253, in run raise patched_exception
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\compiler.py", line 245, in run stage()
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\compiler.py", line 438, in stage_objectmode_frontend cres = self.frontend_looplift()
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\compiler.py", line 428, in frontend_looplift lifted=tuple(loops), lifted_from=None)
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\compiler.py", line 887, in compile_ir lifted_from=lifted_from)
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\compiler.py", line 375, in compile_ir return self._compile_ir()
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\compiler.py", line 811, in _compile_ir return self._compile_core()
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\compiler.py", line 791, in _compile_core res = pm.run(self.status)
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\compiler.py", line 253, in run raise patched_exception
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\compiler.py", line 245, in run stage()
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\compiler.py", line 652, in stage_objectmode_backend self._backend(lowerfn, objectmode=True)
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\compiler.py", line 628, in _backend lowered = lowerfn()
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\compiler.py", line 601, in backend_object_mode self.flags)
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\compiler.py", line 1018, in py_lowering_stage lower.lower()
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\lowering.py", line 173, in lower self.lower_normal_function(self.fndesc)
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\lowering.py", line 214, in lower_normal_function entry_block_tail = self.lower_function_body()
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\lowering.py", line 239, in lower_function_body self.lower_block(block)
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\lowering.py", line 254, in lower_block self.lower_inst(inst)
File "C:\Users\Matthew\Anaconda3\lib\contextlib.py", line 130, in exit self.gen.throw(type, value, traceback)
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\errors.py", line 585, in new_error_context six.reraise(type(newerr), newerr, tb)
File "C:\Users\Matthew\Anaconda3\lib\site-packages\numba\six.py", line 659, in reraise raise value
LoweringError: iters
File "mandelbrot.py", line 17: def mandelbrot(xmin,xmax,ymin,ymax,width,height,maxiter): for ix,re in enumerate(x): points.append([]) ^