Numba v0.44:无法反映反射容器的元素 [英] Numba v0.44: cannot reflect element of reflected container
问题描述
我是 numba
的新手,我在每一个转折点都在努力获得我认为在 nopython
模式下工作很简单的东西.
例如,受到这个问题的启发 coalescing-ranges 我写了以下函数:
@njit# @jitdef合并(范围):合并 = []对于 i, (label_a, start_a, stop_a) 在 enumerate(ranges) 中:append_flag = 真对于 enumerate(coalesced) 中的 j, (label_b, start_b, stop_b):if label_a != label_b: # 类型不同继续elif stop_a
它假定它是在列表列表中传递的.每个子列表仅包含整数 [type, start, stop]
并且提到此功能以合并重叠的类似类型范围,例如
这个函数与 @jit
一起工作(尽管它会发出大量警告).当使用 @njit
和上面的列表调用这个函数时:
TypeError: Failed in nopython mode pipeline (step: nopython mode backend)无法反映反射容器的元素:反射列表(反射列表(int64))
我不知道这是什么意思,也不知道为什么会失败.
Numba 现在提供 类型列表,这些接受列表列表.据我所知,它们仍然需要单独附加(因为 TypedList.extend 方法不接受 LofL).这导致:
from numba.typed import List # 根据文档,由于是测试版,需要明确导入大声笑 = [[1, 10, 100], [0, 50, 75], [1, 50, 150], [0, 10, 100], [0, 200, 300], [0, 15, 150]]nb_list = 列表()对于 lst 来说:nb_list.append(lst)合并(nb_list)
I am new to numba
and am struggling at every turn to get what I think is simple to work in nopython
mode.
For example, inspired by this question coalescing-ranges I have written the following function:
@njit
# @jit
def coalesce(ranges):
coalesced = []
for i, (label_a, start_a, stop_a) in enumerate(ranges):
append_flag = True
for j, (label_b, start_b, stop_b) in enumerate(coalesced):
if label_a != label_b: # not of same type
continue
elif stop_a < start_b: # a does not start and then overlap b
continue
elif stop_b < start_a: # b does not start and then overlap a
continue
else:
# same type and overlap, merge into i, do not append
append_flag = False
coalesced[j] = [label_a, min([start_a, start_b]), max([stop_a, stop_b])]
break
if append_flag:
coalesced.append([label_a, start_a, stop_a])
return coalesced
It assumes that it is passed in a list of lists. Each sub list consists of only integers [type, start, stop]
and this function is mention to merge similar typed ranges which overlap e.g.
[
[1, 10, 100],
[0, 50, 75],
[1, 50, 150],
[0, 10, 100],
[0, 200, 300],
[0, 15, 150]
]
# becomes
[
[0, 10, 150],
[0, 200, 300],
[1, 10, 150]
]
This function works with @jit
(although it spits out a ton of warnings).
When calling this function with @njit
and the above list:
TypeError: Failed in nopython mode pipeline (step: nopython mode backend)
cannot reflect element of reflected container: reflected list(reflected list(int64))
I have no idea what this means or why this fails.
Numba now offers Typed Lists, these accept a list of lists. As far as I can see they still need to be appended individually though (because the TypedList.extend method doesn't accept LofL). This leads to:
from numba.typed import List # As per the docs, since it's in beta, it needs to be imported explicitly
lol = [[1, 10, 100], [0, 50, 75], [1, 50, 150], [0, 10, 100], [0, 200, 300], [0, 15, 150]]
nb_list = List()
for lst in lol:
nb_list.append(lst)
coalesce(nb_list)
这篇关于Numba v0.44:无法反映反射容器的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!