Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when using lambda function with Cython

Tags:

python

cython

I am trying to use Cython to speed up a piece of code. Cython is giving an error that reads "Expected an identifier or literal" when I use lambda functions. As far as I can tell, lambda functions are meant to be supported in Cython 0.13. Am I incorrect on this point? If they are, indeed, supported, do I need to do something other than what I have here 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]
like image 599
Randall J Avatar asked Nov 28 '10 06:11

Randall J


1 Answers

In my opinion you should change h_z = lambda e_1: -inf with h_z = lambda e_1: -float('inf') unless you have defined inf somewhere else.

like image 194
razpeitia Avatar answered Oct 17 '22 09:10

razpeitia