[Numpy-discussion] Medians that ignore values

Charles R Harris charlesr.harris@gmail....
Sun Sep 21 02:28:21 CDT 2008


On Sun, Sep 21, 2008 at 12:56 AM, David Cournapeau <
david@ar.media.kyoto-u.ac.jp> wrote:

> David Cournapeau wrote:
> > Anne Archibald wrote:
> >> If users are concerned about performance, it's worth noting that on
> >> some machines nans force a fallback to software floating-point
> >> handling, with a corresponding very large performance hit. This
> >> includes some but not all x86 (and I think x86-64) CPUs. How this
> >> compares to the performance of masked arrays is not clear.
> >
> > I spent some time on this. In particular, for max.min, I did the
> > following for the core loop (always return nan if nan is in the array):
> >
> >  /* nan + x and x + nan are nan, where x can be anything:
> > normal,
> >   * denormal, nan, infinite
> > */
> >   tmp = *((@typ@ *)i1) + *((@typ@
> > *)i2);
> >   if(isnan(tmp))
> > {
> >             *((@typ@ *)op) =
> > tmp;
> >   } else
> > {
> >             *((@typ@ *)op)=*((@typ@ *)i1) @OP@ *((@typ@ *)i2) ? *((@typ@
> > *)i1) : *((@typ@ *)i2);
> >   }
>
> Grr, sorry for the mangling:
>
> /* nan + x and x + nan are nan, where x can be anything: normal,
>  * denormal, nan, infinite */
> tmp = *((@typ@ *)i1) + *((@typ@*)i2);
> if(isnan(tmp)) {
>    *((@typ@ *)op) = tmp;
> } else {
>    *((@typ@ *)op) = *((@typ@ *)i1) @OP@ *((@typ@ *)i2) ? *((@typ@*)i1) :
> *((@typ@ *)i2);
> }
>

You can use type instead of typ so the code is a bit easier to read. It's
one of the changes I've made.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080921/69874174/attachment-0001.html 


More information about the Numpy-discussion mailing list