[Numpy-discussion] Medians that ignore values
David Cournapeau
david at ar.media.kyoto-u.ac.jp
Sun Sep 21 02:56:38 EDT 2008
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);
}
cheers,
David
More information about the NumPy-Discussion
mailing list