简体   繁体   中英

python, numba: adding a function reference to a typed list

I am trying to build a list of functions that can be used inside jitted numba code. Since reflected lists are deprecated, I use numba's typed lists. Appending to the typed list works as long as I keep adding the same function. However, adding a second function will fail. Is there a way to achieve this with numba?

from numba.typed import List
from numba import njit
@njit()
def foo(b):
    b = b * 2.0
    return b

@njit()
def bar(a):
    a = a + 1.0
    return a

l = List()
l.append(foo) # this works
l.append(foo) # this will also work
l.append(bar) # this will fail

the full error message is here [https://pastebin.com/pBciXhGL][1]

this solution works at least with the trivial case above

https://numba.discourse.group/t/typed-list-of-jitted-functions-in-jitclass/413/4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM