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]
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With