1 * Routines for selecting the k largest or smallest values could use
2 heapsort for speed O(N log k) rather than insertion O(N k).
4 * Sorting of complex arrarys without using additional memory. We try
5 to avoid allocating memory internally in GSL, so internally computing
6 the magnitudes and storing them in a temporary array is undesirable.
8 Obviously a complex array can be sorted using sqrt(x*x + y*y) <=>
9 sqrt(u*u + v*v) (written in a numerically stable way) for every
10 comparison, but this may be unacceptably slow. Maybe not? It is just a
11 constant factor. The square roots could sometimes be avoided by
14 (x,y) = (MAX(|x|,|y|), MIN(|x|,|y|))
15 (u,v) = (MAX(|u|,|v|), MIN(|u|,|v|))
17 if (x < u/sqrt(2)) /* This part is optional optimization */
22 if (x == 0 && u == 0) ...
26 t = u*sqrt((1+(v/u)^2)/(1+(y/x)^2))
35 but this does depend on the data having sufficient range for the
36 optimization to be worthwhile, otherwise it is an extra cost.