Error using lambda function with Cython

I am trying to use Cython to speed up a piece of code. Cython gives an error that reads "Expected Identifier or Literal" when I use lambda functions. As far as I can tell, lambda functions should be supported in Cython 0.13. Am I wrong in this question? If they are really supported, do I need to do something else besides what I have to implement them?

def f(e_1, e_2, rho):
    """Bivariate Normal pdf with mean zero, unit variances, and correlation coefficient rho."""
    return (1.0 / (2.0 * pi * sqrt(1 - rho**2))) * exp(-(1.0 / (2*(1 - rho**2))) * (e_1**2 + e_2**2 - 2*rho*e_1*e_2))

def P_zero(b_10, b_11, b_20, b_21, rho, gamma, x):
    """Returns the probability of observing zero entrants in a market by numerically
    integrating out the unobserved firm-specific profit shocks."""
    h_z = lambda e_1: -inf
    g_z = lambda e_1: -b_10 - b_11*x[0] - gamma*x[1]
    I   = lambda e_1, e_2: f(e_1, e_2, rho)
    return dblquad(I, -inf, (-b_20 - b_21*x[0] - gamma*x[2]), h_z, g_z)[0]
+5
source share
2 answers

In my opinion, you should change h_z = lambda e_1: -infto h_z = lambda e_1: -float('inf')if you have not defined infelsewhere.

+1
source

Cython- Cython 0.14.1 OS X 10.6.6. , 0,13. - Cython, .

def f(e_1, e_2, rho):
    return e_1 + e_2 + rho

def dummy(a, b, c, d, e):
    return [a(1,2) + b + c + d(1) + e(3)]

def P_zero(b_10, b_11, b_20, b_21, rho, gamma, x):
    h_z = lambda e_1: -1000
    g_z = lambda e_1: -b_10 - b_11 * x[0] - gamma * x[1]
    I   = lambda e_1, e_2: f(e_1, e_2, rho)
    return dummy(I, -1000, (-b_20 - b_21 * x[0] - gamma * x[2]), h_z, g_z)[0]

print P_zero(1, 2, 3, 4, 5, 6, [6, 7, 8]) 
# outputs "-2122"
0

All Articles