#11837: Make Newton basin plotting fun and easy
---------------------------+------------------------------------------------
   Reporter:  kcrisman     |          Owner:  jason, was                     
       Type:  enhancement  |         Status:  new                            
   Priority:  major        |      Milestone:                                 
  Component:  graphics     |       Keywords:  fractal newton complex plot    
Work_issues:               |       Upstream:  N/A                            
   Reviewer:               |         Author:  Karl-Dieter Crisman, SImon King
     Merged:               |   Dependencies:                                 
---------------------------+------------------------------------------------
Changes (by newvalueoldvalue):

  * author:  Karl-Dieter Crisman => Karl-Dieter Crisman, SImon King


Comment:

 I just attached [attachment:newton_basins_more_cython.spyx], which
 improves the timing by a factor of almost 100:

 With the original version of the code together with the `2./3`, I get
 {{{
 sage: %time basin_plot([-1,i,1],(-3,3),(-3,3),plot_points=100,figsize=7)
 CPU times: user 13.70 s, sys: 0.00 s, total: 13.70 s
 Wall time: 13.74 s
 }}}

 With the code that I just attached, I get
 {{{
 sage: %time basin_plot([-1,i,1],(-3,3),(-3,3),plot_points=100,figsize=7)
 CPU times: user 0.15 s, sys: 0.00 s, total: 0.15 s
 Wall time: 0.15 s
 }}}

 How is that done?

 Apparently, the optimization should mainly take place in `which_root`.
 Since it is not possible to turn it into a fast_callable, I cythonised it
 instead. More precisely, I introduced a cdef'd class `RootFinder`, that
 carries all relevant data (the list of roots, the function newtf and also
 the cutoff 2/3) as a cdef'd attribute.

 Originally, the function f1 is a lambda function (slow!) that calls the
 Python function `which_root` (slow!) by providing two arguments, where the
 first argument is always the same (redundant!). I replaced it by the
 method `Finder.which_root`, where `Finder` is an appropriate instance of
 `RootFinder`.

 Inside `which_root`, further improvements happened:
  * First of all, the list of roots is transformed into a list of complex
 doubles (because, in your original example, the complex unit `i` is a
 symbolic expression, not a complex double, which was responsible for the
 slowness).
  * Moreover, Cython is informed that the list of roots is a list, and that
 both the root and "varia" are complex doubles.
  * We know that all our complex doubles have the same parent. Hence, we
 avoid the parental tests that are part of `__sub__` and call `_sub_`
 instead (single underscore).
  * Since the `counter` loop is rather tight, `counter` is declared as an
 int.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11837#comment:7>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to