From: Charles R H. <cha...@gm...> - 2006-09-20 00:55:20
|
On 9/19/06, A. M. Archibald <per...@gm...> wrote: > > On 19/09/06, Charles R Harris <cha...@gm...> 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. Chuck |