Updates:
Status: Accepted
Comment #1 on issue 2543 by asmeurer: lambdify of constant functions
http://code.google.com/p/sympy/issues/detail?id=2543
I can confirm this issue.
I think we could fix the issue better than using the ways that you
suggest. Remember that you can edit the lambdify code to fix this (that's
why you reported the issue to us, isn't it). lambdify(x, 2) basically
returns a wrapper around lambda x: 2 (see lambdastr in
sympy.utilities.lambdify). Thus, I think we could add vectorization in the
constant case to the lambda expression itself. Something like
lambdastr(x, x**2, printer=numpy_lambdastr)
lambda x: (x**2)
lambdastr(x, 2, printer=numpy_lambdastr)
lambda x: numpy.vectorize(lambda x: 2)(x)
where printer=numpy_lambdastr would be sent to lambdastr when numpy is used
in lambdify. I hope I am using vectorize properly here. It seems to work:
In [45]: (lambda x: numpy.vectorize(lambda x: 2)(x))(u)
Out[45]: [2 2 2 2 2 2 2 2 2 2]
numpy_lambdastr would recursively call the normal lambdastr for the
internal lambda. I don't know much about numpy, so you or someone else
should look to see if this looks like a good solution.
Also, I admit I don't know much about lambdify (I basically just read the
code for the first time just now, and I've never used it in practice).
Would it be better to have a lambda inside the vectorize (outer) lambda, or
to have a lambdified function in there? The latter would involve
recursively calling lambdify() instead of recursively calling lambdastr().
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy-issues?hl=en.