Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lambdify does not work with Integral #19641

Closed
oscarbenjamin opened this issue Jun 25, 2020 · 4 comments · Fixed by #20134
Closed

Lambdify does not work with Integral #19641

oscarbenjamin opened this issue Jun 25, 2020 · 4 comments · Fixed by #20134

Comments

@oscarbenjamin
Copy link
Contributor

In [36]: lambdify(z, Integral(1, (x, 0, z)))(1)                                                                                                
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-36-276a7bc694f7> in <module>
----> 1 lambdify(z, Integral(1, (x, 0, z)))(1)

<lambdifygenerated-3> in _lambdifygenerated(z)
      2     return (  # Not supported in Python with SciPy:
      3   # Integral
----> 4 Integral(1, (x, 0, z)))

NameError: name 'Integral' is not defined

This could use numerical integration routines from scipy, mpmath etc.

@sylee957
Copy link
Member

Does scipy support vectorization over parameters for integrals, or it only expects scalar arguments?

@ehren
Copy link
Contributor

ehren commented Sep 23, 2020

scipy.integrals.quad and scipy.integrals.nquad will always return a single float as the actual result of integration (so I think they will also only accept an integrand function that has scalar arguments even though multiple scalar arguments are supported by nquad). But I'm not sure whether there's a function in scipy that handles vectorizing in a more optimal way than just using numpy.vectorize. This seems to be asked in https://stackoverflow.com/questions/57350391/scipy-integrate-quad-quadrature-nquad-cannot-integrate-vector-parameterized (More discussion in the pull #20134).

@sylee957
Copy link
Member

It looks like we would have to document clearly about how some sympy functions can be vectorized or not with scipy lambdify. I find it confusing that some functions can be evaluated to grid and some functions cannot, and this have important application for developing plotting module.

@moorepants
Copy link
Member

I think it is reasonable to build in numpy.vectorize() into our lambdify printers for numpy/scipy functions that aren't vectorized by default. This would allow things to just work and is probably fine for the majority of use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants