David Cournapeau wrote:
[...]
> 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 ?).

There is a clip function in all three numeric packages, so a native clip 
is being used.

If numpy.clip is actually slower than your version, that sounds like a 
problem with the implementation in numpy.  By all logic a single clip 
function should either be the same (if it is implemented like yours) or 
faster (if it is a single loop in C-code, as I would expect).  This 
warrants a little more investigation before changing the mpl code.  The 
best thing would be if you could make a simple standalone numpy test 
case profiling both versions and post the results as a question to the 
numpy-discussion list.  Many such questions in the past have resulted in 
big speedups in numpy.

One more thought: it is possible that the difference is because myclip 
operates on the array in place while clip generates a new array.  If 
this is the cause of the difference then changing your last line to 
"return a.copy()"  probably would slow it down to the numpy clip speed 
or slower.

Eric

-------------------------------------------------------------------------
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

Reply via email to