Is there a way to get the actual expression once the ufunc is complied?

52 views
Skip to first unread message

Tanu Hari Dixit

unread,
Dec 25, 2015, 7:41:34 AM12/25/15
to sympy
I tried out this to get the expression

>>> from sympy import symbols
>>> from sympy.utilities.autowrap import ufuncify
>>> x=symbols('x')
>>> expr=x**2 +x**4 +1
>>> binary_fu=ufuncify(x, expr)
>>> binary_fu(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: ufunc 'wrapper_module_0' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

This is expected because a ufunc will expect an array. Is there a way to get the expression once one has ufuncified it?
(This is trivial in case of lambify)
>>> lambdified_poly=lambdify(x,expr)
>>> lambdified_poly(x)
x**4 + x**2 + 1
 
Please help me.

Jason Moore

unread,
Dec 25, 2015, 12:07:05 PM12/25/15
to sy...@googlegroups.com
lambdify works in this case because it, by default, generates sympy expressions. Lambdify is unique in this case. All of the others based on autowrap will not accept sympy types.

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/9b653989-d049-442a-9e2d-78abd92a8ab0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tanu Hari Dixit

unread,
Dec 25, 2015, 12:14:26 PM12/25/15
to sympy

Thank you!

Aaron Meurer

unread,
Dec 25, 2015, 4:41:07 PM12/25/15
to sy...@googlegroups.com
lambdify generates numpy functions by default. This only works because
there are no functions in the expression (just multiplication,
addition, and powers).

To answer the original question, as far as I can tell, the original
expression is not saved anywhere in the ufuncified function.

Aaron Meurer
> https://groups.google.com/d/msgid/sympy/CAP7f1AhRxHHxr%2B6H%2BO1iv5fQJVhnOW%3D8%2BRDahzEQdAGP_%2BCWEQ%40mail.gmail.com.

Tanu Hari Dixit

unread,
Dec 26, 2015, 6:28:18 AM12/26/15
to sympy
Thank you!

On Friday, December 25, 2015 at 6:11:34 PM UTC+5:30, Tanu Hari Dixit wrote:
Reply all
Reply to author
Forward
0 new messages