Невозможно привести к объекту или из него в контексте nopython: ошибка после python

После этого 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

1 ответ

Я где-то узнал, что Нумба не узнает 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))
Другие вопросы по тегам