Fast plotting

17 views
Skip to first unread message

Tom Bachmann

unread,
Apr 26, 2011, 4:45:10 PM4/26/11
to mpmath
Hello,

I like to explore special functions by plotting them in the complex
plane. In fact I like it so much I have written a program to do only
that [1] ^^. Now I will be working over the summer with sympy, and it
would be nice to have plotting integrated into my normal workflow.
Moreover mpmath supports many more special functions than I do.

But: anything I try is just very very slow. The best I can do is this:

>>> from sympy.mpmath import fp as c
>>> c.cplot(c.loggamma, [-2,2],[-2,2],points=100000,verbose=True)

this takes about 15 seconds! My program (written admittedly in c++
using a fortran library) renders the function at a much higher
resolution in under one second. Clearly waiting 15 seconds for a not
even very crisp plot is not really an option if I'm "exploring" - I
want to zoom around etc.

Now I understand mpmath is firstly about high precision, not speed at
low precision. But still, maybe I'm missing something and there is a
way to make this awesomely fast :-).

[1] https://bitbucket.org/ness/fz

Fredrik Johansson

unread,
Apr 26, 2011, 5:21:57 PM4/26/11
to mpm...@googlegroups.com

Python unsurprisingly has a huge overhead for double precision
function evaluation. If you have a fast compiled version at hand, you
can of course use that with the mpmath plotting functions instead (and
maybe fall back to mpmath for the unsupported cases).

It's possible to get some decent speedups on this kind of code with
psyco and pypy (you'll need a recent svn checkout of both mpmath and
pypy), but probably not close to C/C++/fortran. The fp versions of
some special functions in mpmath would be reasonable candidates for
adding optional Cython type annotations though, if anyone has an
interest in that.

When I need to plot mpmath functions, I usually just settle for a
smaller number of points until I find something interesting enough to
render at a higher resolution. 5000-10000 is usually sufficient to see
the features of a function (though not very pretty).

Fredrik

Ondrej Certik

unread,
Apr 27, 2011, 8:54:37 PM4/27/11
to mpm...@googlegroups.com

It's hard to beat f77 though, that's for sure. We should also probably
update mpmath in sympy (I don't know if that is an issue with regards
to speed).

Ondrej

Reply all
Reply to author
Forward
0 new messages