What is causing Numba's AttributeError: 'NoneType' object has no attribute 'pysig'?
What is causing Numba's AttributeError: 'NoneType' object has no attribute 'pysig'?
当我尝试运行这个代码时:
from numba import njit, int64
from numba.types import List
@njit(int64(List(int64, True)))
def f(a):
a[0] = 0
return a[0]
@njit(List(int64)())
def g(): return [f([0])]
我得到以下信息。为什么是这样?我如何让它正确识别类型?
Traceback (most recent call last):
File "Temp.py", line 9, in <module>
@njit(List(int64)())
File "numba\decorators.py", line 172, in wrapper
disp.compile(sig)
File "numba\dispatcher.py", line 350, in compile
flags=flags, locals=self.locals)
File "numba\compiler.py", line 644, in compile_extra
return pipeline.compile_extra(func)
File "numba\compiler.py", line 361, in compile_extra
return self.compile_bytecode(bc, func_attr=self.func_attr)
File "numba\compiler.py", line 370, in compile_bytecode
return self._compile_bytecode()
File "numba\compiler.py", line 631, in _compile_bytecode
return pm.run(self.status)
File "numba\compiler.py", line 251, in run
raise patched_exception
numba.errors.TypingError: Caused By:
Traceback (most recent call last):
File "numba\compiler.py", line 243, in run
res = stage()
File "numba\compiler.py", line 458, in stage_nopython_frontend
self.locals)
File "numba\compiler.py", line 759, in type_inference_stage
infer.propagate()
File "numba\typeinfer.py", line 510, in propagate
raise errors[0]
TypingError: Internal error at <numba.typeinfer.CallConstraint object at 0x00000000071C82E8>:
--%<-----------------------------------------------------------------
Traceback (most recent call last):
File "numba\typeinfer.py", line 111, in propagate
constraint(typeinfer)
File "numba\typeinfer.py", line 270, in __call__
self.resolve(typeinfer, typevars, fnty)
File "numba\typeinfer.py", line 297, in resolve
sig = context.resolve_function_type(fnty, pos_args, kw_args)
File "numba\typing\context.py", line 113, in resolve_function_type
return func.get_call_type(self, args, kws)
File "numba\types.py", line 334, in get_call_type
sig.pysig = self.pysig
AttributeError: 'NoneType' object has no attribute 'pysig'
--%<-----------------------------------------------------------------
File "Temp.py", line 10
将 f
的装饰器签名从 @njit(int64(List(int64, True)))
更改为 @njit(int64(List(int64)))
让我在 Numba 0.31.0 上工作。
对于 f
,a
不是反射列表,因此将该标志设置为 True
似乎会导致问题。对于 Numba 0.31.0,我收到一条不同的错误消息。
不过,总的来说,我会允许 Numba 对输入和输出进行自己的类型推断。我不确定您使用的是什么版本,但在最近的版本中,很少有理由在装饰器签名中定义类型。如果你对类型推断器在做什么感到好奇,只需使用 nb.njit
或 nb.jit(nopython=True)
,用你想要的输入调用函数,然后检查 f.inspect_types()
(如果你的 jitted 函数是 f
).
当我尝试运行这个代码时:
from numba import njit, int64
from numba.types import List
@njit(int64(List(int64, True)))
def f(a):
a[0] = 0
return a[0]
@njit(List(int64)())
def g(): return [f([0])]
我得到以下信息。为什么是这样?我如何让它正确识别类型?
Traceback (most recent call last):
File "Temp.py", line 9, in <module>
@njit(List(int64)())
File "numba\decorators.py", line 172, in wrapper
disp.compile(sig)
File "numba\dispatcher.py", line 350, in compile
flags=flags, locals=self.locals)
File "numba\compiler.py", line 644, in compile_extra
return pipeline.compile_extra(func)
File "numba\compiler.py", line 361, in compile_extra
return self.compile_bytecode(bc, func_attr=self.func_attr)
File "numba\compiler.py", line 370, in compile_bytecode
return self._compile_bytecode()
File "numba\compiler.py", line 631, in _compile_bytecode
return pm.run(self.status)
File "numba\compiler.py", line 251, in run
raise patched_exception
numba.errors.TypingError: Caused By:
Traceback (most recent call last):
File "numba\compiler.py", line 243, in run
res = stage()
File "numba\compiler.py", line 458, in stage_nopython_frontend
self.locals)
File "numba\compiler.py", line 759, in type_inference_stage
infer.propagate()
File "numba\typeinfer.py", line 510, in propagate
raise errors[0]
TypingError: Internal error at <numba.typeinfer.CallConstraint object at 0x00000000071C82E8>:
--%<-----------------------------------------------------------------
Traceback (most recent call last):
File "numba\typeinfer.py", line 111, in propagate
constraint(typeinfer)
File "numba\typeinfer.py", line 270, in __call__
self.resolve(typeinfer, typevars, fnty)
File "numba\typeinfer.py", line 297, in resolve
sig = context.resolve_function_type(fnty, pos_args, kw_args)
File "numba\typing\context.py", line 113, in resolve_function_type
return func.get_call_type(self, args, kws)
File "numba\types.py", line 334, in get_call_type
sig.pysig = self.pysig
AttributeError: 'NoneType' object has no attribute 'pysig'
--%<-----------------------------------------------------------------
File "Temp.py", line 10
将 f
的装饰器签名从 @njit(int64(List(int64, True)))
更改为 @njit(int64(List(int64)))
让我在 Numba 0.31.0 上工作。
对于 f
,a
不是反射列表,因此将该标志设置为 True
似乎会导致问题。对于 Numba 0.31.0,我收到一条不同的错误消息。
不过,总的来说,我会允许 Numba 对输入和输出进行自己的类型推断。我不确定您使用的是什么版本,但在最近的版本中,很少有理由在装饰器签名中定义类型。如果你对类型推断器在做什么感到好奇,只需使用 nb.njit
或 nb.jit(nopython=True)
,用你想要的输入调用函数,然后检查 f.inspect_types()
(如果你的 jitted 函数是 f
).