[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Inconsistency: "sort" on UNIX <-> Windows



Daniel Luebbert (luebbert@stanford.edu) writes:

> I've been using the "sort" routine to sort an 2D-array by increasing
> values of its first column.
> The "sort" routine seems to behave differently in the UNIX and the
> Windows versions of IDL5.3.
> 
> In other words: The "sort" routine on Windows doesn't preserve the
> original order of entries which have the same value (see the 3
> "1"-values in my test data), but apparently rearranges them in a random
> way.
> 
> What I'd like to know is:
> How can it be that such a basic routine behaves differently in differnet
> implementations of IDL?
> 
> And, more importantly: can anybody tell me how to make the
> Windows-version of "sort" behave correctly,
> without writing my own routine for sorting?

What makes you think the Windows version is behaving "incorrectly"? 
In fact, it could well be the UNIX version is screwy, as I prefer
to believe. :-)

But the truth of the matter is that you get different results because
IDL uses the system supplied qsort() routine on each platform, 
and as they are different implementations, they are free to 
return different sub-orders for the identical elements.
 
Why the Windows qsort is different from everyone else's
is a matter best taken up with Mr. Gates himself. If I
had to guess, I would guess that it's because the algorithm
used in the Windows qsort is an order of magnitude (at least)
faster than the qsort algorithm used in UNIX. :^)

Cheers,

David

P.S. There is not much that can be done, except sort
the other dimension by some consistent criteria (e.g.
the "order" in the original array). Ugly, but perhaps
necessary depending upon your application.

-- 
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155