我正在使用numba来加速我的代码,这种代码在没有numba的情况下正常工作。但在使用@jit后,它崩溃了这个错误:
Traceback (most recent call last):
File "C:\work_asaaki\code\gbc_classifier_train_7.py", line 54, in <module>
gentlebooster.train(X_train, y_train, boosting_rounds)
File "C:\work_asaaki\code\gentleboost_c_class_jit_v7_nolimit.py", line 298, in train
self.g_per_round, self.g = train_function(X, y, H)
File "C:\Anaconda\lib\site-packages\numba\dispatcher.py", line 152, in _compile_for_args
return self.jit(sig)
File "C:\Anaconda\lib\site-packages\numba\dispatcher.py", line 143, in jit
return self.compile(sig, **kws)
File "C:\Anaconda\lib\site-packages\numba\dispatcher.py", line 250, in compile
locals=self.locals)
File "C:\Anaconda\lib\site-packages\numba\compiler.py", line 183, in compile_bytecode
flags.no_compile)
File "C:\Anaconda\lib\site-packages\numba\compiler.py", line 323, in native_lowering_stage
lower.lower()
File "C:\Anaconda\lib\site-packages\numba\lowering.py", line 219, in lower
self.lower_block(block)
File "C:\Anaconda\lib\site-packages\numba\lowering.py", line 254, in lower_block
raise LoweringError(msg, inst.loc)
numba.lowering.LoweringError: Internal error:
NotImplementedError: ('cast', <llvm.core.Instruction object at 0x000000001801D320>, slice3_type, int64)
File "gentleboost_c_class_jit_v7_nolimit.py", line 103
第103行位于循环中:
weights = np.empty([n,m])
for curr_n in range(n):
weights[curr_n,:] = 1.0/(n) # this is line 103
其中n
是我的代码中已经定义的常量。
如何删除错误?什么&#34;降低&#34;正在进行?我在64位计算机上使用带有Numba 0.13.x和Numpy 1.8.x的Anaconda 2.0.1。
答案 0 :(得分:4)
基于此:https://gist.github.com/cc7768/bc5b8b7b9052708f0c0a,
我想出了如何避免这个问题。我没有使用冒号:
来引用任何行/列,而是将循环打开成两个循环,以显式引用数组每个维度中的索引:
weights = np.empty([n,m])
for curr_n in range(n):
for curr_m in range (m):
weights[curr_n,curr_m] = 1.0/(n)
我的代码中有其他实例,在此之后我使用了冒号,但它们没有导致错误进一步下降,不确定原因。