如何避免递归错误?

2024-09-24 02:20:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我设置了一个函数,该函数迭代字符组合以形成字符串。 它本身是递归的,递归调用如下所示:

testG(charNum - 1, arr2)

但是当我调用整个函数时,我得到了以下错误:

>>> testSpeedGPU()
Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    testSpeedGPU()
  File "F:\Script Projects#\HASHFinder.py", line 90, in testSpeedGPU
    testG(4, [''])
  File "D:\Python\lib\site-packages\numba\cuda\dispatcher.py", line 40, in __call__
    return self.compiled(*args, **kws)
  File "D:\Python\lib\site-packages\numba\cuda\compiler.py", line 758, in __call__
    kernel = self.specialize(*args)
  File "D:\Python\lib\site-packages\numba\cuda\compiler.py", line 769, in specialize
    kernel = self.compile(argtypes)
  File "D:\Python\lib\site-packages\numba\cuda\compiler.py", line 784, in compile
    kernel = compile_kernel(self.py_func, argtypes,
  File "D:\Python\lib\site-packages\numba\core\compiler_lock.py", line 32, in _acquire_compile_lock
    return func(*args, **kwargs)
TypeError: compile_kernel() got an unexpected keyword argument 'boundscheck'

这是函数的主体:

@jit(target ="cuda")
def testG(charNum, inpArray) -> null:
    if charNum == 1:
        arr2 = []
        for s in range(len(inpArray)):
            for i in range(len(alp)):
                arr2.append(alp[i] + inpArray[s])
        return
    else:
         print("more than 1")
         arr2 = []
         for s in range(len(inpArray)):
             for i in range(len(alp)):
                 arr2.append(alp[i] + inpArray[s])
         testG(charNum - 1, arr2)

我想这确实和递归有关,但我真的不知道。 谢谢你的帮助

PS:该函数在未标记@jit(target=“cuda”)时工作


Tags: 函数inpylibpackageslinesitekernel