James,
this contribution is just awesome! Great work!

Assuming that no serious issues show up, I'd vote that from 0.7.6, ufuncify 
should use your new backend by default.

Øyvind

On Thursday, August 28, 2014 5:07:07 AM UTC+2, James Crist wrote:
>
> I still need to do some cleanups and add tests, but I finally have this 
> working and thought I'd share. I'm really happy with this:
>
> In [1]: from sympy import *
>
> In [2]: a, b, c = symbols('a, b, c')
>
> In [3]: expr = (sin(a) + sqrt(b)*c**2)/2 
>
> In [4]: from sympy.utilities.autowrap import ufuncify
>
> In [5]: func = ufuncify((a, b, c), expr)
>
> In [6]: func(1, 2, 3)
> Out[6]: 6.7846965230828769
>
> In [7]: func([1, 2, 3, 4, 5], [6, 7, 8, 9, 10], 3)
> Out[7]: array([ 11.44343933,  12.36052961,  12.79848207,  13.12159875,  
> 13.75078733])
>
> In [8]: from numpy import arange
>
> In [9]: a = arange(10).reshape((2, 5))
>
> In [10]: c = arange(10, 20).reshape((2, 5))
>
> In [11]: b = 25
>
> In [12]: func(a, b, c)
> Out[12]: 
> array([[ 250.        ,  302.92073549,  360.45464871,  422.57056   ,
>          489.62159875],
>        [ 562.02053786,  639.86029225,  722.8284933 ,  810.49467912,
>          902.70605924]])
>
> In [13]: type(func)
> Out[13]: numpy.ufunc
>
> This now does everything a numpy `ufunc` does normally, as it *is* a 
> ufunc. Codegen is hooked up to numpy api. Type conversion and broadcasting 
> are done automagically.
>
> Caveats: only functions with a single output are accepted (this could be 
> changed to accept multi-output without much effort though). Also, as with 
> all unfuncs, input/outputs must all be scalars (no matrix/Indexed 
> operations allowed).
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/9fb3217b-c2c6-455a-8eca-3ca791bed0f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to