Hi, On Fri, Aug 27, 2021 at 1:23 PM William Stein <wst...@gmail.com> wrote:
> Hello Isuru -- thanks for popping in to comment! > > On Fri, Aug 27, 2021 at 10:56 AM Isuru Fernando <isu...@gmail.com> wrote: > > > > Hi, > > > > A SymEngine maintainer here. > > > > > Pynac has a lot of I think nontrivial efficient hooks back into Sage > > for working with various data types, and doing things like equality > > testing, fast evaluation of expression (fast_float, etc.), > > > > With SymEngine, we do have fast evaluation of expressions with > > several backends. One backend is LLVM, where we compile the function > > using LLVM and generate a callable C function using that. > > Wow, that's very cool. Do you know how it compares to Sage's > fast_float and fast_callable "compilers" in terms of speed? Sage's > don't actually depend on having LLVM installed (they aren't compiling > to machine code), so I assume might be significantly slower, except > that the people (=Robert Bradshaw) who wrote them are very clever, so > you never know. It's probably also interesting to benchmark the > compile time itself. > I've attached a small script that I put together just now. Note how we can pass sage expressions in symbolic ring to symengine functions. Timings are below. First one is sage and the second is symengine. one element 625 loops, best of 3: 68 μs per loop 625 loops, best of 3: 12.9 μs per loop create an output numpy array of 1000 elements 5 loops, best of 3: 175 ms per loop 625 loops, best of 3: 18.1 μs per loop compile time 625 loops, best of 3: 478 μs per loop 125 loops, best of 3: 2.69 ms per loop SymEngine LLVM backend has optimization levels (0, 1, 2, 3). 3 is the default. By setting to optimization level 0, compile time is half with a performance penalty of around 10%. Isuru -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/CA%2B01voPC7KbXXzxhrjztPynBeNs0fNyUj%2BCJkfYY5LX-4p95hQ%40mail.gmail.com.
wilk = prod((x-i) for i in [1 .. 20]); fc_wilk = fast_callable(wilk, vars=[x]) import numpy as np N = 1000 arr = np.random.rand(N) def run(): arr2 = np.empty_like(arr) for i in range(N): arr2[i] = fc_wilk(arr[i]) return arr2 import symengine fc_wilk_se = symengine.Lambdify([x], [wilk_se], backend="llvm") def run_se(): return fc_wilk_se(arr).reshape(N) assert np.allclose(run(), run_se()) print('one element') timeit('fc_wilk(0.0)') timeit('fc_wilk_se(0.0)') print('create an output numpy array of 1000 elements') timeit('run()') timeit('run_se()') print('compile time') timeit('fc_wilk = fast_callable(wilk, vars=[x])') timeit('fc_wilk_se = symengine.Lambdify([x], [wilk_se], backend="llvm")')