I define a function using numba @jit(nopython =True) which will call a normal cdf function via scipy.special, and I got this error message:
TypingError: Untyped global name 'norm'
The following is my code:
import numpy as np
from numba import *
from scipy.stats import *
timelst = np.random.randn(2083)
noncovlst = np.random.randn(2083)
lst = np.random.randint(30,size=127)
lst_num = 0
lst_num = np.append(lst_num,lst)
lst_num = np.cumsum(lst_num)
n = 127
agelst = np.random.randint(16,80,127)
edulst = np.random.randint(1,28,127)
incomelst = np.random.randn(127)
@jit(nopython=True)
def lamb(now,params):
b = params[0]
mu = params[1]
s = params[2]
beta1 = params[3]
beta3 = params[4]
beta4 = params[5]
beta5 = params[6]
beta6 = params[7]
L = 0.0
for i in range(n):
timez = timelst[lst_num[i]:lst_num[i+1]]
noncov = noncovlst[lst_num[i]:lst_num[i+1]]
timeq = timez[timez < now]
noncovq = noncov[timez < now]
L += (b*now + np.exp(beta3*agelst[i]+beta5*edulst[i]
+beta6*incomelst[i])*(norm.cdf((now-timeq-mu)/s)*np.exp(beta1*noncovq)).sum())/n
return L
res = [2.422855,16.320364,28.984707,-9.942004,-3.118748,-0.248391,1.903728,4.126649]
Type
lamb(0.2,res)
The error message:
TypingError: Failed at nopython (nopython frontend)
Untyped global name 'norm'
I know drop nopython keyword will probably fix the issue, however, it will covert to object mode, which can have a huge performance penalty.
Is any better way to include the normal cdf into numba nopython mode ?