So indeed things become much much faster using GMPY ground types. Another speed related question is doing expression substituion, i.e expr.subs(dict). This subs operation is very slow comparing to Sage. In my case I often have to do this task which instantiates an expression with hundred of thousand of data and this takes lots of time. For example, [(x**3 + y**2 + z + 3).subs(d) for d in big_data_set]. Is there some way to do this more efficiently ? Like using different data structure than Expression ?
Thanks, In [2]: %time bench_solvers.time_solve_lin_sys_165x165() CPU times: user 4.02 s, sys: 0.15 s, total: 4.17 s Wall time: 4.08 s In [3]: %time bench_solvers.time_eqs_165x165() CPU times: user 0.94 s, sys: 0.09 s, total: 1.03 s Wall time: 0.96 s In [4]: %time bench_solvers.time_verify_sol_165x165() CPU times: user 7.04 s, sys: 0.04 s, total: 7.09 s Wall time: 7.08 s In [5]: %time bench_solvers.time_to_expr_eqs_165x165() CPU times: user 6.34 s, sys: 0.14 s, total: 6.49 s Wall time: 6.41 s On Tuesday, April 9, 2013 12:15:33 AM UTC-6, Aaron Meurer wrote: > > These are my timings: > > gmpy ground types: > > In [19]: from sympy.polys.benchmarks import bench_solvers > > In [20]: %time _ = bench_solvers.time_eqs_165x165() > CPU times: user 590 ms, sys: 86.9 ms, total: 677 ms > Wall time: 625 ms > > In [21]: %time _ = bench_solvers.time_to_expr_eqs_165x165() > CPU times: user 4.01 s, sys: 149 ms, total: 4.16 s > Wall time: 4.08 s > > In [22]: %time _ = bench_solvers.time_verify_sol_165x165() > CPU times: user 4.66 s, sys: 106 ms, total: 4.76 s > Wall time: 4.69 s > > In [23]: %time _ = bench_solvers.time_solve_lin_sys_165x165() > CPU times: user 2.95 s, sys: 192 ms, total: 3.15 s > Wall time: 3.02 s > > Python ground types > > In [1]: from sympy.polys.benchmarks import bench_solvers > > In [2]: %time _ = bench_solvers.time_eqs_165x165() > CPU times: user 975 ms, sys: 154 ms, total: 1.13 s > Wall time: 1.03 s > > In [3]: %time _ = bench_solvers.time_to_expr_eqs_165x165() > CPU times: user 4.98 s, sys: 113 ms, total: 5.09 s > Wall time: 5.03 s > > In [4]: %time _ = bench_solvers.time_verify_sol_165x165() > CPU times: user 6.73 s, sys: 64.7 ms, total: 6.79 s > Wall time: 6.75 s > > In [5]: %time _ = bench_solvers.time_solve_lin_sys_165x165() > CPU times: user 26.2 s, sys: 112 ms, total: 26.4 s > Wall time: 26.3 s > > So the ground types do make a difference, especially in the solve > times. Note that if gmpy is not installed, it just uses Python ints > and Fraction for integers and rational numbers (it's likely Fraction > that is so slow, since it has basic operations like addition and gcd > implemented in Python loops). > > Aaron Meurer > > On Tue, Apr 9, 2013 at 12:05 AM, ThanhVu Nguyen > <[email protected] <javascript:>> wrote: > > If you want to try it out you have to use > >> > >> sparse-polys branch from #1840 pull request. Here is a sample code: > >> > >> In [1]: from sympy.polys.benchmarks.bench_solvers import * > >> > >> In [2]: %time eqs = eqs_165x165() > >> CPU times: user 2.12 s, sys: 0.01 s, total: 2.13 s > >> Wall time: 2.12 s > >> > >> In [3]: %time sol = solve_lin_sys(eqs, R_165) > >> CPU times: user 1.60 s, sys: 0.01 s, total: 1.60 s > >> Wall time: 1.59 s > >> > >> > > >> > > > > > > > > > Hi, I just tried the benchmark file from the latest git pull but was > not > > able to achieve such good performance . I don't have GMP installed > so > > using whatever that sympy uses by default. My test below shows solving > > these equations takes 32 secs, which is 27 times longer than generating > > them 1.2 s. This contrasts with your stats above which indicates > solving > > these equations takes 1.6 s, which is even faster than generating them > in > > 2.12s (is it even possible ??). > > > > Your solve_lin_sy() function is indeed much faster than the default > > solve(), taking over 600 s. However when I've tried size 248x248 and > Sage's > > solve() still solves under two min but your solve_lin_sys() takes over > 20 > > mins, at which point I just gave up and kill the process. (If you need > > these data let me know) > > > > > > All the tests below were done on my MacBook in 2011, 2.3 Ghz i3 with 8 > GB > > Ram . Perhaps I should install GMP and try again ? > > > > In [1]: import bench_solvers > > > > In [2]: %time _ = bench_solvers.time_eqs_165x165() > > CPU times: user 1.18 s, sys: 0.09 s, total: 1.27 s > > Wall time: 1.21 s > > > > In [3]: %time _ = bench_solvers.time_to_expr_eqs_165x165() > > CPU times: user 6.10 s, sys: 0.12 s, total: 6.22 s > > Wall time: 6.16 s > > > > In [4]: %time _ = bench_solvers.time_verify_sol_165x165() > > CPU times: user 8.07 s, sys: 0.05 s, total: 8.12 s > > Wall time: 8.10 s > > > > In [5]: %time _ = bench_solvers.time_solve_lin_sys_165x165() > > CPU times: user 32.52 s, sys: 0.11 s, total: 32.63 s > > Wall time: 32.62 s > > > > > > In [7]: eqs = bench_solvers.eqs_165x165() > > > > In [8]: eqs_ = [eqt.as_expr() for eqt in eqs] > > > > In [11]: from sympy import solve > > > > In [9]: %time _ = solve(eqs_,as_dict=True) #default solve() > > CPU times: user 610.49 s, sys: 2.05 s, total: 612.54 s > > Wall time: 614.68 s > > > > -- > > 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] <javascript:>. > > To post to this group, send email to [email protected]<javascript:>. > > > Visit this group at http://groups.google.com/group/sympy?hl=en-US. > > > > For more options, visit https://groups.google.com/groups/opt_out. > > > > > -- 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 post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sympy?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
