- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在尝试对定义的函数启用 numba 优化时遇到错误。
这是简化的函数:
@jit
def monte_carlo(iterations):
key1 = []
key2 = []
score = []
for i in range(iterations):
random.seed(i)
temp_matrix = random.sample(matrix, length)
for j in range(iterations):
random.seed(j)
key2.append(i)
key1.append(j)
for x in range(...):
try: temp_matrix[x] = random.sample(matrix[x], len(matrix[x]))
except: continue
scores.append(...)
return scores, keyA, keyB
monte_carlo(1000)
然后我收到此错误,在使用 Cuda 而不是 Jit 时也遇到了问题。
Traceback (most recent call last):
File "..."
File ...\numba\dispatcher.py", line 404, in _compile_for_args
error_rewrite(e, 'unsupported_error')
File "...\numba\dispatcher.py", line 344, in error_rewrite
reraise(type(e), e, None)
File "...\numba\six.py", line 668, in reraise
raise value.with_traceback(tb)
numba.errors.UnsupportedError: Failed in nopython mode pipeline (step: analyzing bytecode)
**Use of unsupported opcode (CONTINUE_LOOP) found**
File "...py", line 32:
def monte_carlo(iterations):
<source elided>
try: temp_qa_matrix[x] = random.sample(input.qa_matrix[x], len(input.qa_matrix[x]))
except: continue
^
因此,尽管它是受支持的构造,但它并不真正喜欢循环中的 continue。
最佳答案
我认为 Numba 的文档有点不完整。它可以处理普通的 continue
语句,该语句在底层使用 Python 操作码 JUMP_ABSOLUTE
,但不能处理 try/except block 内的 continue
语句,该语句使用Python 操作码 CONTINUE_LOOP
。
这是一个简单函数的示例,该函数(不必要)使用 continue
并与 Numba 配合使用。它将数组中大于 0.5 的元素减半。
def halve(x):
for i in range(len(x)):
if x[i] <= 0.5:
continue
x[i] /= 2
如果我们导入 Python dis
模块并查看 dis.dis(halve)
的输出,我们会看到有两个 JUMP_ABSOLUTE
操作码。这是 Python 通常用于 continue
语句的内容。如果我们使用 Numba jit 这个函数并在数组中运行它,我们会发现它工作没有问题。
但是如果我们重写half
来使用try/except:
def halve(x):
for i in range(len(x)):
try:
assert x[i] > 0.5
except:
continue
x[i] /= 2
然后查看 dis.dis(halve)
,我们看到其中一个 JUMP_ABSOLUTE
操作码已被 CONTINUE_LOOP
替换。我不知道底层的 Python 细节,但可以肯定的是,如果我们尝试 jit 这个函数,那么 Numba 会提示有一个不受支持的操作码。
所以,TLDR:看起来你不能在 Numba 的 try/except 中使用 continue,因为与 Python 实现相关的不明原因。
我怀疑几乎总是有解决方法,但由于您的代码不是完全独立的,所以我很难知道。
(旁注:如果您使用 NumPy 数组而不是列表,通常 Numba 会做得更好。)
关于python - 在 for 循环中使用 continue 时出现 Numba "Use of unsupported opcode (CONTINUE_LOOP) found"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62109830/
Apple M1 芯片上的 Mac OS 11.6 节点版本是17.0.1 % node -v v17.0.1 这个错误似乎真的来 self 无法辨别的任何地方。 (我检查了我的软件更新,没有最近的操
运行 cv2.getRectSubPix(img, (5,5), (0,0)) 抛出错误: OpenCV Error: Unsupported format or combination of for
不可能在 itunesconnect 中发送应用程序的新版本。虽然上周,同样的版本发送发生了。在代码中,我只是改了一个按钮的名字,没有再改哪里。 但总是报错: 错误 ITMS-9000:“不支持的架构
鉴于下面的 HTML,我尝试使用 jQuery 来匹配所有具有类“foo”的跨度的列表项,并且该跨度应包含文本“relevant”。 Some text relevant Some more
Azure 开始出现以下错误: Unsupported token. Unable to initialize the authorization context. 每当我尝试更改我的应用程序时,我都
尝试安装friday软件包时,出现错误 Preprocessing library friday-0.2.2.0... src/Vision/Detector/Edge.hs:3:14: Unsupp
Azure 开始出现以下错误: Unsupported token. Unable to initialize the authorization context. 每当我尝试更改我的应用程序时,我都
我的代码抛出此错误 Failed to load resource: unsupported url在以下行: self.$el.find('.capturedImage').attr('src',
首先,请原谅它已经被问过或者可以很容易地通过谷歌找到。我发布这个是因为我的时间有限。这是录制音频和视频的代码。 stopPreview(); Log.d("stream
我正在尝试在 Android 上实现应用索引。 我有一个 Intent 过滤器,如下:
对于在 WAS 8.5 中运行的应用程序客户端,我们有代码创建套接字失败并出现以下错误。 SSLSocketFactory factory = (SSLSocketFactory) SSLSo
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
我正在尝试从序列中获取生成的 key 。(使用 Servlet 和 Oracle10) 以下是我的代码: query ="insert into TABLE_NAME(COL1,COL2,COL3)
我的项目中有这个功能: def clean(self): if self.id_document_type == 'BC': now = date.today()
我在尝试 ARKit 时出现黑屏并显示以下错误消息。 WWDC 2017 示例 PlacingObjects 在同一设备上运行没有问题。 [] >>> FigVirtualFramebufferGet
ffmpeg 缺乏对 AAC 的默认支持真的很烦人: 我的 ffmpeg 版本: ffmpeg version git-2020-05-02-0d81edc Copyright (c) 2000-20
以下 config.xml 导致错误: ... ... ... 错误信息: Error Image 代码库是继承的,据我所知
创建位图上下文时出现此错误: CGBitmapContextCreate:不支持的参数组合:8 个整数位/组件; 24 位/像素;三分量色彩空间; kCGImageAlphaNone; 7936 字节
使用 pandas 读取 .xlsx 文件时出错。看起来它正在打开文件,因为它能够读取列名的前 8 个字符,即 员工编号 但因此错误而失败。我看到很多关于这个的帖子,但最后一部分从来都不是这些错误
我尝试执行下面的代码,但它抛出以下错误消息: Error: Syntax error, unrecognized expression: unsupported pseudo: really-good
我是一名优秀的程序员,十分优秀!