sympy / sympy

A computer algebra system written in pure Python
https://sympy.org/
Other
13.01k stars 4.45k forks source link

autowrap and ufuncify "helpers" arguments are inconsistent and poorly documented #10572

Open ronanpaixao opened 8 years ago

ronanpaixao commented 8 years ago

utilities.autowrap.ufuncify() doesn't explain properly how the helpers argument should be used. The best documentation, of course, is an example. Maybe one can include this in the docstring (it can also work as a test if using doctest):

from sympy.utilities import autowrap
from sympy.abc import x, t
expr = 3*x+f(t)
func_ufunc = autowrap.ufuncify([x, t], expr, helpers=[['f', 4*x, [x]]])
func_ufunc(1, 0.125)
#3.5

It took a long time for me to find the proper "format" for the helpers, which really is like iterable_of(3-tuple(str, SymPy expression, list)).

utilities.autowrap.autowrap(), however, expects only a single helper function!

autowrap.autowrap(expr, args=[x, t], helpers=[['f', 4*x, [x]]])
Traceback (most recent call last):

  File "<ipython-input-105-729cbaf02a5a>", line 1, in <module>
    autowrap.autowrap(expr, args=[x, t], helpers=[['f', 4*x, [x]]])

  File "D:\Anaconda\lib\site-packages\sympy\utilities\autowrap.py", line 510, in autowrap
    for name_h, expr_h, args_h in helpers:

ValueError: need more than 1 value to unpack
func_autow = autowrap.autowrap(expr, args=[x, t], helpers=['f', 4*x, [x]])
func_autow(1, 0.1)
#3.4
ronanpaixao commented 8 years ago

An important note: since autowrap doesn't allow for more helpers and the C/Cython backend doesn't support (out-of-the-box) some builtin function like sympy.Max, this pretty much blocks using C/Cython for expressions with more than one function, any function.

moorepants commented 8 years ago

We recently fixed this #8889 and added an extensive addition with code gen examples. I think the helpers is now in the master branch. It will be released with the 1.0 release that will happen soon.

moorepants commented 8 years ago

This was also recently merged: https://github.com/sympy/sympy/pull/10282

moorepants commented 8 years ago

@ronanpaixao Would you mind submitting a pull request with your docstring additions?