On Tue, Nov 16, 2010 at 5:20 PM, J P <jpsc...@gmail.com> wrote:
> Hi all, here's my first patch for matplotlib. Someone noticed at Stack
> Overflow that the plot_surface function in mplot3d wasn't especially fast
> for a lot of points (and small rstrides/cstrides) and using shading and a
> single color. I found some parts of the code that weren't vectorized. These
> are my changes so far.
>
> Summary of changes:
> 1. Changed from double looping over aranges to using xrange
> 2. Made the normalization of the normals and their dot product with the
> vector [-1,-1,0.5] to find the shading a vectorized operation.
> 3. Changed a list comprehension which calculated the colors using an
> iterative approach to using the already built-in vectorization of the
> Normalization class and using the np.outer function. The result is a numpy
> array rather than a list which actually speeds up things down the line.
> 4. removed the corners array from plot_surface which wasn't ever used or
> returned. It didn't really slow things down, but I'm thinking that it is
> cruft.
>
> For change number two, I made a separate function that generates the
> shades, but feel free to move that around if you prefer.. or maybe it should
> be a function that begins with a _ because it shouldn't be used externally.
> These changes give varying levels of speed improvement depending on the
> number of points and the rstrides/cstrides arguments. With larger numbers of
> points and small rstrides/cstrides, these changes can more than halve the
> running time. I have found no difference in output after my changes.
>
> I know there is more work to be done within the plot_surface function and
> I'll submit more changes soon.
>
> Justin
>
>
Justin,
Thank you for your efforts to improve the performance of mplot3d. I will
take a look at the patches you have submitted and test them out. What I am
probably going to do is break down the patches into smaller pieces and
incorporate them piece-by-piece.
I tried refactoring plot_surface once before to mixed results. The key
feature I was trying to gain was compatibility with masked arrays. I wanted
to duplicate the behavior of contourf and pcolor where masked out portions
of the surface would not be created. I managed to get it to work for that
particular use-case, but I broke a bunch of other use-cases along the way.
I am curious to see if your patches make this easier/harder to do.
Thank you for your efforts and thank you for using matplotlib!
Ben Root
------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3.
Spend less time writing and rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel