[Numpy-discussion] sorting -inf, nan, inf

Charles R Harris charlesr.harris at gmail.com
Tue Sep 19 19:55:17 CDT 2006

On 9/19/06, A. M. Archibald <peridot.faceted at gmail.com> wrote:
> On 19/09/06, Charles R Harris <charlesr.harris at gmail.com> wrote:
> >
> >
> >
> > For floats we could use something like:
> >
> > lessthan(a,b) := a < b || (a == nan && b != nan)
> >
> > Which would put all the nans at one end and might not add too much
> overhead.
> You could put an any(isnan()) out front and run this slower version
> only if there are any NaNs (also, you can't use == for NaNs, you have
> to use C isNaN). But I'm starting to see the wisdom in simply throwing
> an exception, since sorting is not well-defined with NaNs.

Looks like mergesort can be modified to sort around the NaNs without too
much trouble if there is a good isnan function available: just cause the
pointers to skip over them. I see that most of the isnan stuff seems to be
in the ufunc source and isn't terribly simple. Could be broken out into a
separate include, I suppose.

I still wonder if it is worth the trouble. As to raising an exception, I
seem to recall reading somewhere that exception code tends to be expensive,
I haven't done any benchmarks myself.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20060919/a9ae46bf/attachment.html 

More information about the Numpy-discussion mailing list