Reputation: 13135
I am getting the error:
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Untyped global name 'sum_': cannot determine Numba type of <class 'function'>
for the following code:
import numba as nb
from numba.pycc import CC
cc = CC('yin')
@cc.export('sum_', nb.float32(nb.float32[:]))
def sum_(a):
s = 0
for i in a:
s += i
return s
@cc.export('average', nb.float32(nb.float32[:]))
def average(a):
return sum_(a)/len(a)
cc.compile()
What should I be doing?
Upvotes: 5
Views: 4785
Reputation: 4171
I've run into this problem once before. The ahead-of-time compilation mode doesn't help in type inference, for some reason, unlike jit
or njit
compiled functions. A workaround, as suggested here, would be to add an additional njit
decorator.
import numba as nb
from numba.pycc import CC
cc = CC('yin')
@nb.njit
@cc.export('sum_', nb.float32(nb.float32[:]))
def sum_(a):
s = 0
for i in a:
s += i
return s
@cc.export('average', nb.float32(nb.float32[:]))
def average(a):
return sum_(a)/len(a)
cc.compile()
Upvotes: 4