Sage: Ticket #15030: Switch standard 2D plotting from `fast_float` to `fast_callable`
https://trac.sagemath.org/ticket/15030
<p>
Switch the <code>plot</code> command to use <code>fast_callable</code> instead of <code>fast_float</code>. This will make commands like <code>plot(abs(log(x)), x)</code> work.
</p>
en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/15030
Trac 1.1.6eviatarbachSat, 10 Aug 2013 09:55:54 GMTattachment set
https://trac.sagemath.org/ticket/15030
https://trac.sagemath.org/ticket/15030
<ul>
<li><strong>attachment</strong>
set to <em>trac15030.patch</em>
</li>
</ul>
TicketeviatarbachSat, 10 Aug 2013 10:04:48 GMTstatus changed
https://trac.sagemath.org/ticket/15030#comment:1
https://trac.sagemath.org/ticket/15030#comment:1
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>needs_review</em>
</li>
</ul>
<p>
The patch changes <code>plot</code> to use <code>fast_callable</code>. It doesn't fix <code>contour_plot</code> or <code>plot3d</code>, for example, since that seems to be more involved, and should be fixed in a future patch.
</p>
<p>
Patchbot apply trac15030.patch
</p>
TickettkluckFri, 16 Aug 2013 07:11:58 GMT
https://trac.sagemath.org/ticket/15030#comment:2
https://trac.sagemath.org/ticket/15030#comment:2
<p>
Thanks for looking into this important issue!
</p>
<p>
Did you check to see what the performance implications of your patch are? I assume that <code>fast_float</code> is faster than <code>fast_callable</code>, but that is not based on any data.
</p>
TicketeviatarbachFri, 16 Aug 2013 23:20:54 GMT
https://trac.sagemath.org/ticket/15030#comment:3
https://trac.sagemath.org/ticket/15030#comment:3
<p>
Yes, <code>fast_float</code> is slightly faster in my tests. However, I think the plan is to deprecate <code>fast_float</code> anyway; see <a class="needs_work ticket" href="https://trac.sagemath.org/ticket/5572" title="defect: fast_callable improvements (followup for #5093) (needs_work)">#5572</a>.
</p>
TicketppurkaWed, 25 Sep 2013 14:16:15 GMT
https://trac.sagemath.org/ticket/15030#comment:4
https://trac.sagemath.org/ticket/15030#comment:4
<p>
This doesn't really fix <a class="new ticket" href="https://trac.sagemath.org/ticket/13559" title="defect: fast_float yields infinity when Python does, but should handle bigger ... (new)">#13559</a>. Do you have an idea why? I thought this change to <code>fast_callable</code> should take care of that other ticket too.
</p>
TicketeviatarbachThu, 26 Sep 2013 05:16:50 GMT
https://trac.sagemath.org/ticket/15030#comment:5
https://trac.sagemath.org/ticket/15030#comment:5
<p>
I think it's because <code>plot</code> (look at the function <code>generate_plot_points</code> in <code>sage.plot.plot</code>) generates float points, and
</p>
<pre class="wiki">sage: exp(1e5r)
OverflowError: math range error
</pre><p>
Maybe it should generate <a class="missing wiki">RealNumber?</a> points instead (I guess they should also be faster than floats for many functions, because MPFR functions are functions are fast)? In any case, that doesn't affect this ticket.
</p>
TicketppurkaSat, 28 Sep 2013 11:59:40 GMT
https://trac.sagemath.org/ticket/15030#comment:6
https://trac.sagemath.org/ticket/15030#comment:6
<p>
Hmm.. so, you are changing only the plots for symbolic expressions. This patch makes the symbolic expression plots about five times slower.
</p>
<pre class="wiki">sage: timeit('plot(abs(log(x)), (x, -20, 20))') # with patch
25 loops, best of 3: 18.5 ms per loop
sage: timeit('plot(abs(log(x)), (x, -20, 20))') # without patch
125 loops, best of 3: 3.58 ms per loop
</pre><p>
What do you think of the following change which introduces only a factor of two slowdown? The main problem seems to be that the fast float stuff does not handle complex numbers, and so we can explicitly specify the domain as CDF. I am not sure what is the default domain.
</p>
<pre class="wiki">+ from sage.ext.fast_callable import fast_callable
+ from sage.rings.all import CDF
+ return fast_callable(self, vars=vars, expect_one_var=True,
+ domain=CDF)
</pre><p>
The timeit results are as follows:
</p>
<pre class="wiki">sage: timeit('plot(abs(log(x)), (x, -20, 20))')
125 loops, best of 3: 6 ms per loop
</pre><p>
A few doctests in <code>expression.pyx</code> fail, but they can be fixed (by changing their output).
</p>
Ticketvbraun_spamThu, 30 Jan 2014 21:20:52 GMTmilestone changed
https://trac.sagemath.org/ticket/15030#comment:7
https://trac.sagemath.org/ticket/15030#comment:7
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.1</em> to <em>sage-6.2</em>
</li>
</ul>
TicketrwsThu, 03 Apr 2014 09:12:49 GMTstatus changed; work_issues set
https://trac.sagemath.org/ticket/15030#comment:8
https://trac.sagemath.org/ticket/15030#comment:8
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>needs_work</em>
</li>
<li><strong>work_issues</strong>
set to <em>compare patch with alternative by ppurka</em>
</li>
</ul>
TicketrwsSun, 13 Apr 2014 16:08:02 GMTbranch set
https://trac.sagemath.org/ticket/15030#comment:9
https://trac.sagemath.org/ticket/15030#comment:9
<ul>
<li><strong>branch</strong>
set to <em>u/rws/switch_standard_2d_plotting_from__fast_float__to__fast_callable_</em>
</li>
</ul>
TicketrwsSun, 13 Apr 2014 16:09:19 GMTstatus changed; keywords, reviewer, commit, author set
https://trac.sagemath.org/ticket/15030#comment:10
https://trac.sagemath.org/ticket/15030#comment:10
<ul>
<li><strong>keywords</strong>
<em>plot</em> added
</li>
<li><strong>reviewer</strong>
set to <em>Ralf Stephan</em>
</li>
<li><strong>commit</strong>
set to <em>7a9e07abeaf14171706e407173a342810031e200</em>
</li>
<li><strong>status</strong>
changed from <em>needs_work</em> to <em>positive_review</em>
</li>
<li><strong>author</strong>
set to <em>Eviatar Bach</em>
</li>
</ul>
<pre class="wiki"> this patch before
sage: timeit('plot(abs(log(x)), (x, -20, 20))') 11.4 ms 2.4
sage: timeit('circle((1,1), 1) + plot(x^2, (x,0,5))') 2.7 ms 2.3
sage: timeit('plot(x^2,(x,300,500),ticks=[None,50000])') 10.8 ms 9.4
sage: i = CDF.0 # define i this way for maximum speed.
sage: timeit('plot(lambda t: arg(zeta(0.5+t*i)), 1,27,rgbcolor=(0.8,0,0))')
52.2 ms 52.2
sage: timeit('plot([sin(n*x) for n in [1..4]], (0, pi))') 10.4 ms 10.2
sage: f = (2*x^3+2*x-1)/((x-2)*(x+1))
sage: timeit('plot([f, 2*x+2], -7,7, fill = {0: [1]})') 11.2 ms 11.1
</pre><p>
so, in my opinion, there is only a slowdown where the original behaviour was incorrect. It is not correct to say "This patch makes the symbolic expression plots about five times slower."
</p>
<p>
I rebased the patch on 6.2.beta7. LGTM and tests fine in <code>plot/</code> and <code>symbolic/</code>.
</p>
<hr />
<p>
New commits:
</p>
<table class="wiki">
<tr><td><a class="ext-link" href="http://git.sagemath.org/sage.git/commit/?id=7a9e07abeaf14171706e407173a342810031e200"><span class="icon"></span>7a9e07a</a></td><td><code>Trac 15030: replace fast_float with fast_callable in 2D plotting</code>
</td></tr></table>
TicketvbraunMon, 14 Apr 2014 19:57:29 GMTstatus, branch changed; resolution set
https://trac.sagemath.org/ticket/15030#comment:11
https://trac.sagemath.org/ticket/15030#comment:11
<ul>
<li><strong>status</strong>
changed from <em>positive_review</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
<li><strong>branch</strong>
changed from <em>u/rws/switch_standard_2d_plotting_from__fast_float__to__fast_callable_</em> to <em>7a9e07abeaf14171706e407173a342810031e200</em>
</li>
</ul>
TicketkcrismanMon, 21 Apr 2014 13:36:57 GMTcommit deleted
https://trac.sagemath.org/ticket/15030#comment:12
https://trac.sagemath.org/ticket/15030#comment:12
<ul>
<li><strong>commit</strong>
<em>7a9e07abeaf14171706e407173a342810031e200</em> deleted
</li>
</ul>
<p>
Note that <a class="closed ticket" href="https://trac.sagemath.org/ticket/13355" title="defect: doctest proper handling of domain in evalf functions (closed: fixed)">#13355</a> which is related, if not the same...
</p>
<p>
Also, anyone know how this impacts 3d plots?
</p>
TicketppurkaSun, 11 May 2014 07:10:00 GMT
https://trac.sagemath.org/ticket/15030#comment:13
https://trac.sagemath.org/ticket/15030#comment:13
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/15030#comment:12" title="Comment 12">kcrisman</a>:
</p>
<blockquote class="citation">
<p>
Also, anyone know how this impacts 3d plots?
</p>
</blockquote>
<p>
I believe this has no impact on 3d plots. 3d plots from 2d objects goes via <code>.plot3d()</code> methods which usually just take the already generated data points. 3d plots created directly are not affected by this patch.
</p>
Ticket