我的函数必须进行jit编译,但是我收到以下弃用警告:
我该如何解决,因此问题已解决? (这样我就不必担心该功能将来无法正常工作)
SELECT DISTINCT
s.sid
FROM
suppliers s,
catalog c
WHERE
s.sid = c.sid
AND c.pid IN (SELECT
p1.pid
FROM
parts p1,
parts p2
WHERE
p1.color = 'red' AND p2.color = 'green');
它将创建第5个随机值数组e_labeling.py:418: NumbaWarning:
Compilation is falling back to object mode WITH looplifting enabled because Function "get_result" failed type inference due to: non-precise type array(pyobject, 1d, C)
During: typing of argument at D:/Arc/Arc_Project\Architecture\_3_Labeling\CRV_Weighted_Score_labeling.py (422)
File "..\_3_Labeling\CRV_Weighted_Score_labeling.py", line 422:
def get_result(RatiosUp, RatiosDown, UpPointsSlices, DownPointsSlices, shapes, result, len_result):
<source elided>
for i in prange(len_result):
^
@nb.jit
D:/Arc/Arc_Project\Architecture\_3_Labeling\CRV_Weighted_Score_labeling.py:418: NumbaWarning:
Compilation is falling back to object mode WITHOUT looplifting enabled because Function "get_result" failed type inference due to: cannot determine Numba type of <class 'numba.core.dispatcher.LiftedLoop'>
File "..\_3_Labeling\CRV_Weighted_Score_labeling.py", line 422:
def get_result(RatiosUp, RatiosDown, UpPointsSlices, DownPointsSlices, shapes, result, len_result):
<source elided>
for i in prange(len_result):
^
@nb.jit
c:\users\ben\appdata\local\programs\python\python38\lib\site-packages\numba\core\object_mode_passes.py:177: NumbaWarning: Function "get_result" was compiled in object mode without forceobj=True, but has lifted loops.
File "..\_3_Labeling\CRV_Weighted_Score_labeling.py", line 422:
def get_result(RatiosUp, RatiosDown, UpPointsSlices, DownPointsSlices, shapes, result, len_result):
<source elided>
for i in prange(len_result):
^
warnings.warn(errors.NumbaWarning(warn_msg,
c:\users\ben\appdata\local\programs\python\python38\lib\site-packages\numba\core\object_mode_passes.py:187: NumbaDeprecationWarning:
Fall-back from the nopython compilation path to the object mode compilation path has been detected, this is deprecated behaviour.
For more information visit https://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit
File "..\_3_Labeling\CRV_Weighted_Score_labeling.py", line 422:
def get_result(RatiosUp, RatiosDown, UpPointsSlices, DownPointsSlices, shapes, result, len_result):
<source elided>
for i in prange(len_result):
^
warnings.warn(errors.NumbaDeprecationWarning(msg,
D:/Arc/Arc_Project\Architecture\_3_Labeling\CRV_Weighted_Score_labeling.py:418: NumbaWarning:
Compilation is falling back to object mode WITHOUT looplifting enabled because Function "get_result" failed type inference due to: non-precise type pyobject
During: typing of argument at D:/Arc/Arc_Project\Architecture\_3_Labeling\CRV_Weighted_Score_labeling.py (422)
File "..\_3_Labeling\CRV_Weighted_Score_labeling.py", line 422:
def get_result(RatiosUp, RatiosDown, UpPointsSlices, DownPointsSlices, shapes, result, len_result):
<source elided>
for i in prange(len_result):
^
@nb.jit
c:\users\ben\appdata\local\programs\python\python38\lib\site-packages\numba\core\object_mode_passes.py:177: NumbaWarning: Function "get_result" was compiled in object mode without forceobj=True.
File "..\_3_Labeling\CRV_Weighted_Score_labeling.py", line 422:
def get_result(RatiosUp, RatiosDown, UpPointsSlices, DownPointsSlices, shapes, result, len_result):
<source elided>
for i in prange(len_result):
^
warnings.warn(errors.NumbaWarning(warn_msg,
c:\users\ben\appdata\local\programs\python\python38\lib\site-packages\numba\core\object_mode_passes.py:187: NumbaDeprecationWarning:
Fall-back from the nopython compilation path to the object mode compilation path has been detected, this is deprecated behaviour.
For more information visit https://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit
File "..\_3_Labeling\CRV_Weighted_Score_labeling.py", line 422:
def get_result(RatiosUp, RatiosDown, UpPointsSlices, DownPointsSlices, shapes, result, len_result):
<source elided>
for i in prange(len_result):
^
warnings.warn(errors.NumbaDeprecationWarning(msg,
,并根据条件设置result
或1
s :(是的,每个条件都有2个条件,但这是因为它们必须以其他顺序检查。
0
是对象的numpy数组(因为它的numpy数组是不同大小的numpy数组。(在同一索引下,这4个np.array的子数组长度相同)
这里是函数:(底部有一个可重现的样本)
RatiosUp, RatiosDown, UpPointsSlices, DownPointsSlices
可重现的样本:(具有正确的结果列表理解,以确保更改后的结果仍然正确)
from numba import prange
@nb.njit
def compare_size_filter(a,b):
return a > b
@nb.njit(parallel=True)
def loop_func(sub_RatiosUp, sub_RatiosDown, sub_UpPointsSlices, sub_DownPointsSlices, sub_result, len_shape):
for j in prange(len_shape):
if compare_size_filter(sub_RatiosUp[j],sub_RatiosDown[j]):
sub_result[j] = 1
elif compare_size_filter(sub_RatiosDown[j],sub_RatiosUp[j]):
sub_result[j] = 0
elif compare_size_filter(sub_DownPointsSlices[j], sub_UpPointsSlices[j]):
sub_result[j] = 0
else:
sub_result[j] = 1
@nb.jit
def get_result(RatiosUp, RatiosDown, UpPointsSlices, DownPointsSlices, shapes, result, len_result):
for i in prange(len_result):
loop_func(RatiosUp[i], RatiosDown[i], UpPointsSlices[i], DownPointsSlices[i], result[i], shapes[i])
return result
答案 0 :(得分:0)
您可以禁止弃用警告。从warnings filter
from numba.core.errors import NumbaDeprecationWarning, NumbaPendingDeprecationWarning
import warnings
warnings.simplefilter('ignore', category=NumbaDeprecationWarning)
warnings.simplefilter('ignore', category=NumbaPendingDeprecationWarning)
编辑:从下面的评论中,我看不到这对您有用。因此,我查看了您提供的内容,发现您没有发送Numba所需的数据类型。
您正在向其发送NumPy数组。
RatiosUp = np.array([np.random.uniform(size=rand) for rand in temp], dtype=object)
当数组需要更多类似的东西
>>> numba.float32[:]
array(float32, 1d, A)
同样,来自文档: