【发布时间】:2020-05-15 00:47:55
【问题描述】:
我正在尝试使用 Numba 的 @jitclass 装饰器,显然是为了加快我的代码速度。我收到的错误似乎是为了对@jitclass 有基本的理解
ss 装饰器。
import numba
from numba import jitclass
spec = [('raster',numba.float32[:,:]),('height', numba.int32),
('width', numba.int32),('azis', numba. int64[:]),('grid',numba.int32),('rough',numba.float32[:,:])]#,('maxrange',numba.float32[:,:]),('azir atio',numba.float32[:,:]),('labels',numba.int32[:,:])]
@jitclass(spec)
class raster_class(object):
def __init__(self,raster):
self.raster = raster
self.height =self.raster.shape[0]
self.width = self.raster.shape[1]
self.azis = np.arange(0,170,10)
self.grid = 500
x,y = numba.int32(self.height/self.grid),numba.int32(self.width/self.grid)
self.rough = np.zeros((x,y),dtype=np.float32)
self.maxrange = np.zeros((self.height/self.grid),(self.width/self.grid))
self.aziratio = self.rough.copy()
self.labels = self.rough.copy()
if __name__ == '__main__':
raster = np.zeros(1000,1000)
raster_class = raster_class(raster)
导致的错误:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Internal error at <numba.typeinfer.CallConstraint object at 0x7f19b3ce5128>:
File "processraster.py", line 24:
def __init__(self,raster):
<source elided>
self.azis = np.arange(0,170,10)
self.grid = 500
^
[1] During: lowering "$0.45 = call $0.41($0.44, func=$0.41, args=[Var($0.44, /home/dunbar/DEM/processraster.py (24))], kws=(), vararg=None)" at /home/dunbar/DEM/processraster.py (24)
[2] During: resolving callee type: jitclass.raster_class#7f19a049f828<raster:array(float32, 2d, A),height:int32,width:int32,azis:array(int64, 1d, A),grid:int32,rough:array(float32, 2d, A)>
[3] During: typing of call at <string> (3)
--%<----------------------------------------------------------------------------
File "<string>", line 3:
<source missing, REPL/exec in use?>
【问题讨论】:
-
请重新阅读How to ask,因为您似乎在第一次阅读时错过了一些关键点,即“请勿发布代码、数据、错误消息的图像等。 - 将文本复制或输入到问题中”(强调原文)。