Eric Firing wrote: > David, > > I have made some changes in svn that address all but one of the points > you made: > > [....] >> if self.clip: >> mask = ma.getmaskorNone(val) >> if mask == None: >> val = ma.array(clip(val.filled(vmax), vmin, vmax)) >> else: >> val = ma.array(clip(val.filled(vmax), vmin, vmax), >> mask=mask) > > The real problem here is that I should not have been using > getmaskorNone(). In numpy.ma, we need nomask, not None, so we want an > ordinary getmask() call. ma.array(...., mask=ma.nomask) is very fast, > so the problem goes away. > >> >> Actually, the problem is in ma.array: with a value of mask to None, >> it should not make a difference between mask = None or no mask arg, >> right ? > But it does, because for numpy it needs to be nomask; it does > something with None, but whatever it is, it is very slow. > >> I didn't change ma.array to keep my change as local as possible. To >> change only this operation as above gives a speed up from 1.8 s to ~ >> 1.0 s for to_rgba, which means calling show goes from ~ 2.2 s to ~1.4 >> s. I also changed result = (val-vmin)/float(vmax-vmin) >> >> to >> >> invcache = 1.0 / (vmax - vmin) >> result = (val-vmin) * invcache > > This is the one I did not address. I don't understand how this could > be making much difference, and some testing using ipython and %prun > with 1-line operations showed little difference with variations on > this theme. The fastest would appear to be (and logically should be, > I think) result = (val-vmin)*(1.0/(vmax-vmin)), but I don't think it > makes much difference--it looks to me like maybe 10-20 msec, not 100, > on my Pentium M 1.6 Ghz. Maybe still worthwhile, so I may yet make > the change after more careful testing. > > >> >> which gives a moderate speed up (around 100 ms for a 8000x256 points >> array). Once you make both those changes, the clip call is by far the >> most expensive operation in normalize functor, but the functor is not >> really expensive anymore compared to the rest, so this is not where I >> looked at. >> >> For the where calls in Colormap functor, I was wondering if they are >> necessary in all cases: some of those calls seem redundant, and it >> may be possible to detect that before calling them. This should be >> both easier and faster, at least in this case, than having a fast >> where ? >> > > You hit the nail squarely: where() is the wrong function to use, and I > have eliminated it from colors.py. The much faster replacement is > putmask, which does as well as direct indexing with a Boolean but > works with all three numerical packages. I think that using the fast > putmask is better than trying to figure out special cases in which > there would be nothing to put, although I could be convinced otherwise. > > >> I understand that support of multiple array backend, support of mask >> arrays have cost consequences. But it looks like it may be possible >> to speed things up for cases where an array has only meaningful >> values/no mask. > > The big gains here were essentially bug fixes--picking the appropriate > function (getmask versus getmaskorNone and putmask versus where). Ok, I've installed last svn, and now, there is still one function which is much slower than a direct numpy implementation, so I would like to know if this is inherent to the multiple backend nature of matplotlib or not. The functor Normalize uses the clip function, and a direct numpy would be 3 times faster (giving the show call a 20 % speed in my really limited benchmarks):
if clip: mask = ma.getmask(val) #val = ma.array(nx.clip(val.filled(vmax), vmin, vmax), # mask=mask) def myclip(a, m, M): a[a<m] = m a[a>M] = M return a val = ma.array(myclip(val.filled(vmax), vmin, vmax), mask=mask) I am a bit lost in the matplotlib code to see where clip is implemented (is it in numerix and as such using the numpy function clip ?). Still, I must confess that all this looks quite good, because it was possible to speed things up quite considerably without too much effort, cheers, David ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users