From: Ray Speth <speth@MIT.EDU>  20090630 16:53:24

I believe I have found a simple change that improves the rendering speed of quiver plots, which can be quite slow for large vector fields. Based on some profiling, the problem appears to stem from the use of numpy's MaskedArrays in PolyCollection.set_verts. If I add the following line to the top of the PolyCollection.set_verts function in collections.py: verts = np.asarray(verts) I find that quiver plots are drawn about 3 times as quickly, going from 2.6 seconds for a 125x125 field to 0.65 seconds. This does not seem to break the use of MaskedArrays as inputs, and masked regions are still hidden in the final plot. I do not know if this has any adverse effects in other classes that inherit from PolyCollection. Using: python 2.6.2 on Windows XP numpy 1.3.0 matplotlib 0.98.5.3, Qt4Agg backend I do not know why iterating over MaskedArrays is so slow, but perhaps this information can be used to speed up some other functions as well. Ray Speth 
From: Eric Firing <efiring@ha...>  20090630 17:17:23

Ray Speth wrote: > I believe I have found a simple change that improves the rendering speed > of quiver plots, which can be quite slow for large vector fields. Based > on some profiling, the problem appears to stem from the use of numpy's > MaskedArrays in PolyCollection.set_verts. If I add the following line to > the top of the PolyCollection.set_verts function in collections.py: > > verts = np.asarray(verts) > > I find that quiver plots are drawn about 3 times as quickly, going from > 2.6 seconds for a 125x125 field to 0.65 seconds. This does not seem to > break the use of MaskedArrays as inputs, and masked regions are still > hidden in the final plot. I do not know if this has any adverse effects > in other classes that inherit from PolyCollection. > > Using: > python 2.6.2 on Windows XP > numpy 1.3.0 > matplotlib 0.98.5.3, Qt4Agg backend > > I do not know why iterating over MaskedArrays is so slow, but perhaps > this information can be used to speed up some other functions as well. > Ray, I was not aware of this particular slowdown, but yes, masked arrays are frustratingly slow in many ways. There is no inherent reason they can't be nearly as fast as ndarrays for almost everything, but it will take quite a bit of work at the C level to get there. In the meantime, there are often other ways of getting around critical slowdowns. Thanks for the quiver tip; I will look into it. Offhand, I suspect a modified version of your suggestion will be needed, but we should be able to get the speedup you found one way or another. I think that your suggested change would effectively disable all masked array support in PolyCollection, and I don't want to do that. Eric > Ray Speth > >  > _______________________________________________ > Matplotlibdevel mailing list > Matplotlibdevel@... > https://lists.sourceforge.net/lists/listinfo/matplotlibdevel 
From: Eric Firing <efiring@ha...>  20090728 22:51:26

Ray Speth wrote: > I believe I have found a simple change that improves the rendering speed > of quiver plots, which can be quite slow for large vector fields. Based > on some profiling, the problem appears to stem from the use of numpy's > MaskedArrays in PolyCollection.set_verts. If I add the following line to > the top of the PolyCollection.set_verts function in collections.py: > > verts = np.asarray(verts) > > I find that quiver plots are drawn about 3 times as quickly, going from > 2.6 seconds for a 125x125 field to 0.65 seconds. This does not seem to > break the use of MaskedArrays as inputs, and masked regions are still > hidden in the final plot. I do not know if this has any adverse effects > in other classes that inherit from PolyCollection. I made a change in PolyCollection.set_verts that has the effect of your suggestion but without affecting masked argument inputs in general. I also made a bunch of other changes in quiver.py to speed things up with or without masked inputs, but their net effect is minimal in practice; your suggestion was the key. I get a factor of 2, not 3; I think this must be a difference in our machines, though. In any case, I'm glad you found the time sink. Eric > > Using: > python 2.6.2 on Windows XP > numpy 1.3.0 > matplotlib 0.98.5.3, Qt4Agg backend > > I do not know why iterating over MaskedArrays is so slow, but perhaps > this information can be used to speed up some other functions as well. > > Ray Speth > >  > _______________________________________________ > Matplotlibdevel mailing list > Matplotlibdevel@... > https://lists.sourceforge.net/lists/listinfo/matplotlibdevel 