Baz
Baz

Reputation: 13135

Untyped global name 'sum_': cannot determine Numba type of <class 'function'>

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

Answers (1)

Mercury
Mercury

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

Related Questions