从here跟进,Numba在我的机器上终于工作(几周后),没有任何奇怪的缩进错误。
我已经在链接问题的解决方案中实现了它。
但是,我现在从Numba那里得到这一系列错误,最后一行是它不能coerce to or from object in nopython context
:
Traceback (most recent call last):
File "C:\Users\app\Documents\Python Scripts\gbc_classifier_train.py", line 19, in <module>
import gentleboost_c_class_jit_v6_nolimit as gbc
File "C:\Users\app\Documents\Python Scripts\gentleboost_c_class_jit_v6_nolimit.py", line 26, in <module>
@jit(void(object_, float_[:,:], int_[:], int_))
File "C:\Users\app\Anaconda\lib\site-packages\numba\decorators.py", line 224, in _jit_decorator
nopython=nopython, func_ast=func_ast, **kwargs)
File "C:\Users\app\Anaconda\lib\site-packages\numba\decorators.py", line 133, in compile_function
func_env = pipeline.compile2(env, func, restype, argtypes, func_ast=func_ast, **kwds)
File "C:\Users\app\Anaconda\lib\site-packages\numba\pipeline.py", line 144, in compile2
post_ast = pipeline(func_ast, env)
File "C:\Users\app\Anaconda\lib\site-packages\numba\pipeline.py", line 191, in __call__
ast = self.transform(ast, env)
File "C:\Users\app\Anaconda\lib\site-packages\numba\pipeline.py", line 656, in transform
ast = stage(ast, env)
File "C:\Users\app\Anaconda\lib\site-packages\numba\pipeline.py", line 641, in _stage
return _check_stage_object(stage_obj)(ast, env)
File "C:\Users\app\Anaconda\lib\site-packages\numba\pipeline.py", line 194, in __call__
ast = self.transform(ast, env)
File "C:\Users\app\Anaconda\lib\site-packages\numba\pipeline.py", line 474, in transform
return transformer.visit(ast)
File "C:\Users\app\Anaconda\lib\ast.py", line 241, in visit
return visitor(node)
File "C:\Users\app\Anaconda\lib\ast.py", line 297, in generic_visit
value = self.visit(value)
File "C:\Users\app\Anaconda\lib\ast.py", line 241, in visit
return visitor(node)
File "C:\Users\app\Anaconda\lib\ast.py", line 297, in generic_visit
value = self.visit(value)
File "C:\Users\app\Anaconda\lib\ast.py", line 241, in visit
return visitor(node)
File "C:\Users\app\Anaconda\lib\ast.py", line 297, in generic_visit
value = self.visit(value)
File "C:\Users\app\Anaconda\lib\ast.py", line 241, in visit
return visitor(node)
File "C:\Users\app\Anaconda\lib\site-packages\numba\visitors.py", line 311, in visit_ControlBlock
self.visitlist(node.body)
File "C:\Users\app\Anaconda\lib\site-packages\numba\visitors.py", line 286, in visitlist
list[:] = _flatmap(self.visit, list)
File "C:\Users\app\Anaconda\lib\site-packages\numba\visitors.py", line 33, in _flatmap
res = func(elem)
File "C:\Users\app\Anaconda\lib\ast.py", line 241, in visit
return visitor(node)
File "C:\Users\app\Anaconda\lib\ast.py", line 306, in generic_visit
new_node = self.visit(old_value)
File "C:\Users\app\Anaconda\lib\ast.py", line 241, in visit
return visitor(node)
File "C:\Users\app\Anaconda\lib\ast.py", line 297, in generic_visit
value = self.visit(value)
File "C:\Users\app\Anaconda\lib\ast.py", line 241, in visit
return visitor(node)
File "C:\Users\app\Anaconda\lib\ast.py", line 297, in generic_visit
value = self.visit(value)
File "C:\Users\app\Anaconda\lib\ast.py", line 241, in visit
return visitor(node)
File "C:\Users\app\Anaconda\lib\ast.py", line 297, in generic_visit
value = self.visit(value)
File "C:\Users\app\Anaconda\lib\ast.py", line 241, in visit
return visitor(node)
File "C:\Users\app\Anaconda\lib\site-packages\numba\visitors.py", line 311, in visit_ControlBlock
self.visitlist(node.body)
File "C:\Users\app\Anaconda\lib\site-packages\numba\visitors.py", line 286, in visitlist
list[:] = _flatmap(self.visit, list)
File "C:\Users\app\Anaconda\lib\site-packages\numba\visitors.py", line 33, in _flatmap
res = func(elem)
File "C:\Users\app\Anaconda\lib\ast.py", line 241, in visit
return visitor(node)
File "C:\Users\app\Anaconda\lib\ast.py", line 306, in generic_visit
new_node = self.visit(old_value)
File "C:\Users\app\Anaconda\lib\ast.py", line 241, in visit
return visitor(node)
File "C:\Users\app\Anaconda\lib\ast.py", line 297, in generic_visit
value = self.visit(value)
File "C:\Users\app\Anaconda\lib\ast.py", line 241, in visit
return visitor(node)
File "C:\Users\app\Anaconda\lib\ast.py", line 297, in generic_visit
value = self.visit(value)
File "C:\Users\app\Anaconda\lib\ast.py", line 241, in visit
return visitor(node)
File "C:\Users\app\Anaconda\lib\ast.py", line 297, in generic_visit
value = self.visit(value)
File "C:\Users\app\Anaconda\lib\ast.py", line 241, in visit
return visitor(node)
File "C:\Users\app\Anaconda\lib\site-packages\numba\visitors.py", line 311, in visit_ControlBlock
self.visitlist(node.body)
File "C:\Users\app\Anaconda\lib\site-packages\numba\visitors.py", line 286, in visitlist
list[:] = _flatmap(self.visit, list)
File "C:\Users\app\Anaconda\lib\site-packages\numba\visitors.py", line 33, in _flatmap
res = func(elem)
File "C:\Users\app\Anaconda\lib\ast.py", line 241, in visit
return visitor(node)
File "C:\Users\app\Anaconda\lib\ast.py", line 306, in generic_visit
new_node = self.visit(old_value)
File "C:\Users\app\Anaconda\lib\ast.py", line 241, in visit
return visitor(node)
File "C:\Users\app\Anaconda\lib\ast.py", line 297, in generic_visit
value = self.visit(value)
File "C:\Users\app\Anaconda\lib\ast.py", line 241, in visit
return visitor(node)
File "C:\Users\app\Anaconda\lib\site-packages\numba\array_expressions.py", line 100, in visit_Assign
node.value = self.visit(node.value)
File "C:\Users\app\Anaconda\lib\ast.py", line 241, in visit
return visitor(node)
File "C:\Users\app\Anaconda\lib\ast.py", line 306, in generic_visit
new_node = self.visit(old_value)
File "C:\Users\app\Anaconda\lib\ast.py", line 241, in visit
return visitor(node)
File "C:\Users\app\Anaconda\lib\site-packages\numba\array_expressions.py", line 136, in visit_BinOp
return self.visit_elementwise(elementwise, node)
File "C:\Users\app\Anaconda\lib\site-packages\numba\array_expressions.py", line 84, in visit_elementwise
return self.register_array_expression(node)
File "C:\Users\app\Anaconda\lib\site-packages\numba\array_expressions.py", line 272, in register_array_expression
wrap=False, link=False, nopython=True,
File "C:\Users\app\Anaconda\lib\site-packages\numba\pipeline.py", line 90, in run_pipeline2
post_ast = pipeline(func_ast, env)
File "C:\Users\app\Anaconda\lib\site-packages\numba\pipeline.py", line 191, in __call__
ast = self.transform(ast, env)
File "C:\Users\app\Anaconda\lib\site-packages\numba\pipeline.py", line 656, in transform
ast = stage(ast, env)
File "C:\Users\app\Anaconda\lib\site-packages\numba\pipeline.py", line 641, in _stage
return _check_stage_object(stage_obj)(ast, env)
File "C:\Users\app\Anaconda\lib\site-packages\numba\pipeline.py", line 202, in __call__
reporting.report(env, exc=e)
File "C:\Users\app\Anaconda\lib\site-packages\numba\reporting.py", line 181, in report
raise exc
numba.error.NumbaError: (see below)
--------------------- Numba Encountered Errors or Warnings ---------------------
Error 133:22: Cannot coerce to or from object in nopython context
--------------------------------------------------------------------------------
这是什么意思?我希望这并不意味着我不能使用对象!
我编辑了所有相关代码,以便我不再传递任何对象,现在定义如下:
@jit(float_[:,:,:](float_[:,:], int_[:], int_))
def train_function(X, y, H):
但是我仍然会收到这个错误,除非它现在不是Error:133:22
,而是:
Error 176:22: Cannot coerce to or from object in nopython context
答案 0 :(得分:2)
我发现某个地方Numba无法直接识别np.dot()
,Error: 176:22
指向第176行,我在那里使用np.dot()
。这是相关的一行:
dot = 1. + np.dot(X1, g1) - np.dot(X1,gc)
所以我把它们的点产品转换成浮点数,它起作用了:
dot = 1. + float(np.dot(X1, g1)) - float(np.dot(X1,gc))