问题描述
从,Numba在计算机上(几周后)终于最终工作,没有任何奇怪的压痕错误.
Following up from here, Numba is finally working (after weeks) on my machine, without any weird indentation errors.
我已将其实现为链接问题的解决方案.
I've implemented it as in the solution to the linked question.
但是,我现在从Numba得到了这串错误,最后一行是它不能coerce to or from object in nopython context
:
However, I now get this string of errors from Numba, the last line being that it can't 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
--------------------------------------------------------------------------------
这是什么意思?我希望这并不意味着我不能使用对象!
What does this mean? I hope it doesn't mean I can't use objects!
我已经编辑了所有相关代码,以便不再传递任何对象,并且定义现在看起来像这样:
I've edited all relevant code so that I'm no longer passing any objects around, and the definition now looks like this:
@jit(float_[:,:,:](float_[:,:], int_[:], int_))
def train_function(X, y, H):
但是我仍然遇到该错误,除了现在不是Error:133:22
,而是:
But I'm still getting that error, except now it's not Error:133:22
, but:
Error 176:22: Cannot coerce to or from object in nopython context
推荐答案
我发现Numba无法直接识别np.dot()
,并且Error: 176:22
指向第176行,我正在使用np.dot()
.这是相关的行:
I found out somewhere that Numba doesn't recognize np.dot()
directly, and the Error: 176:22
was pointing to line 176, where I was using np.dot()
. This was the relevant line:
dot = 1. + np.dot(X1, g1) - np.dot(X1,gc)
所以我将点乘积转换为浮点数,并且有效:
So I cast the dot products it into floats, and it worked:
dot = 1. + float(np.dot(X1, g1)) - float(np.dot(X1,gc))
这篇关于无法在nopython上下文中强制到对象或从对象强制执行:python之后出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!