todo

来自「数学公式库--非常不错 The GNU Scientific Library 」· 代码 · 共 37 行

TXT
37
字号
* Routines for selecting the k largest or smallest values could useheapsort for speed O(N log k) rather than insertion O(N k).* Sorting of complex arrarys without using additional memory. We tryto avoid allocating memory internally in GSL, so internally computingthe magnitudes and storing them in a temporary array is undesirable. Obviously a complex array can be sorted using sqrt(x*x + y*y) <=>sqrt(u*u + v*v) (written in a numerically stable way) for everycomparison, but this may be unacceptably slow. Maybe not? It is just aconstant factor. The square roots could sometimes be avoided byoptimization,    (x,y) = (MAX(|x|,|y|), MIN(|x|,|y|))    (u,v) = (MAX(|u|,|v|), MIN(|u|,|v|))    if (x < u/sqrt(2))     /* This part is optional optimization */       return -1     if (x > u*sqrt(2))       return +1    if (x == 0 && u == 0) ...    if (x == 0) ...    if (u == 0) ...        t = u*sqrt((1+(v/u)^2)/(1+(y/x)^2))        if (x < t)       return -1    if (x > t)       return +1     else       return 0but this does depend on the data having sufficient range for theoptimization to be worthwhile, otherwise it is an extra cost.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?