这个错误发生在定义函数*
时。我可以从三个函数定义案例开始,前两个案例通过了,第三个是第二个测试案例的小修改失败了。也许 * 不支持,但错误很有趣,想了解原因。
Numba版本:'0.56.4' Python版本:'3.9.17'
通过测试1
import numba as nb
def test_1(a, b, c, d, e, f, g):
return a + b + c + d + e + f + g
test_1 = nb.njit(test_1)
def test_2(a, b, c, d, e, f, g):
return test_1(a, b, c, d, e, f, g)
test_2 = nb.njit(test_2)
test_2(1, 2, 3, 4, 5, 6, 7)
通过测试2
import numba as nb
def test_1(a, b, c, *, d, e, f):
return a + b + c + d + e + f
test_1 = nb.njit(test_1)
def test_2(a, b, c, d, e, f, g):
return test_1(a, b, c, d, e, f)
test_2 = nb.njit(test_2)
test_2(1, 2, 3, 4, 5, 6, 7)
测试3失败
import numba as nb
def test_1(a, b, c, *, d, e, f, g):
return a + b + c + d + e + f
test_1 = nb.njit(test_1)
def test_2(a, b, c, d, e, f, g):
return test_1(a, b, c, d, e, f, g)
test_2 = nb.njit(test_2)
test_2(1, 2, 3, 4, 5, 6, 7)
错误追溯
---------------------------------------------------------------------------
TypingError Traceback (most recent call last)
Cell In[10], line 9
7 test_2 = nb.njit(test_2)
8 # test_1(1, 2, 3, 4, 5, 6, 7)
----> 9 test_2(1, 2, 3, 4, 5, 6, 7)
File ~/.cache/pypoetry/virtualenvs/indices-ldm-post-process-danSbNDA-py3.9/lib/python3.9/site-packages/numba/core/dispatcher.py:467, in _DispatcherBase._compile_for_args(self, *args, **kws)
464 msg = (f"{str(e).rstrip()} \n\nThis error may have been caused "
465 f"by the following argument(s):\n{args_str}\n")
466 e.patch_message(msg)
--> 467 error_rewrite(e, 'typing')
468 except errors.UnsupportedError as e:
469 # Something unsupported is present in the user code, add help info
470 error_rewrite(e, 'unsupported_error')
File ~/.cache/pypoetry/virtualenvs/indices-ldm-post-process-danSbNDA-py3.9/lib/python3.9/site-packages/numba/core/dispatcher.py:409, in _DispatcherBase._compile_for_args..error_rewrite(e, issue_type)
407 raise e
408 else:
--> 409 raise e.with_traceback(None)
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Internal error at .
tuple index out of range
During: resolving callee type: type(CPUDispatcher())
During: typing of call at /tmp/ipykernel_3435313/3644502072.py (6)
Enable logging at debug level for details.
我在Numba github上提出了一个问题
1条答案
按热度按时间q9rjltbz1#
错误似乎与
test_1
函数定义中使用*args
语法有关。Numba不支持此语法。要修复错误,您可以使用
**kwargs
语法。下面是如何修改test_1
和test_2
函数的示例:这段代码应该没有任何错误。