gpt4 book ai didi

Python Numba jit NotImplementedError 列表理解

转载 作者:太空宇宙 更新时间:2023-11-03 15:13:37 26 4
gpt4 key购买 nike

我想加快使用 Numba 执行列表理解的公式的计算速度。

from numba import jit

# General function to generate overlapping windows from a dataframe
@jit
def overlapping_windows(index, wl=256, noverlap=128):
l = len(index)
res = [[s,s+wl] for s in xrange(0, l, noverlap) if s+wl < l]
return res

overlapping_windows([1,2,3,4,5,6,7,8,9,10],4,2)

但是我得到了一个 NotImplementedError。不知道为什么。

---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-45-ce0579185abe> in <module>()
6 return res
7
----> 8 overlapping_windows([1,2,3,4,5,6,7,8,9,10],4,2)

~/anaconda/lib/python2.7/site-packages/numba/dispatcher.pyc in _compile_and_call(self, *args, **kws)
123 assert not kws
124 sig = tuple([typeof_pyval(a) for a in args])
--> 125 self.jit(sig)
126 return self(*args, **kws)
127

~/anaconda/lib/python2.7/site-packages/numba/dispatcher.pyc in jit(self, sig, **kws)
118 """Alias of compile(sig, **kws)
119 """
--> 120 return self.compile(sig, **kws)
121
122 def _compile_and_call(self, *args, **kws):

~/anaconda/lib/python2.7/site-packages/numba/dispatcher.pyc in compile(self, sig, locals, **targetoptions)
106 cres = compiler.compile_extra(typingctx, targetctx, self.py_func,
107 args=args, return_type=return_type,
--> 108 flags=flags, locals=locs)
109
110 # Check typing error if object mode is used

~/anaconda/lib/python2.7/site-packages/numba/compiler.pyc in compile_extra(typingctx, targetctx, func, args, return_type, flags, locals)
85 Use ``None`` to indicate
86 """
---> 87 bc = bytecode.ByteCode(func=func)
88 if config.DEBUG:
89 print(bc.dump())

~/anaconda/lib/python2.7/site-packages/numba/bytecode.pyc in __init__(self, func)
275 raise ByteCodeSupportError("does not support cellvars")
276
--> 277 table = utils.SortedMap(ByteCodeIter(code))
278 labels = set(dis.findlabels(code.co_code))
279 labels.add(0)

~/anaconda/lib/python2.7/site-packages/numba/utils.pyc in __init__(self, seq)
44 self._values = []
45 self._index = {}
---> 46 for i, (k, v) in enumerate(sorted(seq)):
47 self._index[k] = i
48 self._values.append((k, v))

~/anaconda/lib/python2.7/site-packages/numba/bytecode.pyc in next(self)
195 ts = "offset=%d opcode=%x opname=%s"
196 tv = offset, opcode, dis.opname[opcode]
--> 197 raise NotImplementedError(ts % tv)
198 if info.argsize:
199 arg = self.read_arg(info.argsize)

NotImplementedError: offset=66 opcode=5e opname=LIST_APPEND

最佳答案

这很可能意味着您正在使用的 numba 版本不支持具有列表理解的函数。

关于Python Numba jit NotImplementedError 列表理解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23601220/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com