On Wed, Sep 15, 2021 at 2:36 AM Davide Sandona' <[email protected]>
wrote:

> 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.
>>
>
> This chart summarizes my findings. Each dot represents the evaluation time
> with the specified module + data type.
> I guess the results depend on the machine being used. This one has been
> generated on an old processor. I'll try
> to see what a modern processor is going to produce.
> [image: lambdify.png]
>

This seems consistent with what I would expect, although I'm a little
surprised that mpmath is slower than SymPy.

Aaron Meurer


> Davide.
>
>
> Il giorno mer 15 set 2021 alle ore 01:37 Aaron Meurer <[email protected]>
> ha scritto:
>
>> 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
>> .
>>
> --
> 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/CAO%3D1Z0-Bfgb2dG4BuV02%2BfPzYcu97DhOW%3DYonSuBa7FxOOdg5g%40mail.gmail.com
> <https://groups.google.com/d/msgid/sympy/CAO%3D1Z0-Bfgb2dG4BuV02%2BfPzYcu97DhOW%3DYonSuBa7FxOOdg5g%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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%3D6KHK3PhBndgtRgmNqDdbfqp9WStbo8AsH0JLnjYEZp8Pw%40mail.gmail.com.

Reply via email to