On Tue, Sep 14, 2021 at 4:13 PM [email protected]
<[email protected]> wrote:
>
> Hello,
> let's say I'd like to numerically evaluate a single sympy function over an 
> array using sympy as the module. Curiously, passing in regular Python's float 
> numbers makes the evaluation much faster then passing in Sympy's Float 
> instances. I tried several sympy functions, they tend to follow this trend.
>
> Why does this happen? Considering that the following lambda function always 
> return Float instances,  I thought that the input was sympified inside a 
> sympy function, thus making the actual python's float evaluation slower due 
> to casting...
>
> from sympy import *
> import numpy as np
> from mpmath import mpf
>
> func = sin(x)
> f = np.frompyfunc(lambdify(x, func, "sympy"), 1, 1)
> domain = np.linspace(0, 100, 1000)
> domain_mpf = [mpf(str(t)) for t in domain]
> domain_sympy = [Float(t) for t in domain]
>
> %timeit f(domain)
> %timeit f(domain_mpf)
> %timeit f(domain_sympy)

What are the results you get from these? For me the last one is
slightly faster, which makes sense because the inputs don't have to be
converted to SymPy Floats first.

Aaron Meurer

>
> --
> 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 [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/0bac1ecd-52b2-4256-a1e6-90fa7c502030n%40googlegroups.com.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2BK0nwW%3DQ4PA-JHJFGNG1smMuk2ZQmdYC%2B91LMfeo8ykg%40mail.gmail.com.

Reply via email to