1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2020 - Samuel GOUGEON
4 // This file is hereby licensed under the terms of the GNU GPL v2.0,
5 // pursuant to article 5.3.4 of the CeCILL v.2.1.
6 // This file was originally licensed under the terms of the CeCILL v2.1,
7 // and continues to be available under such terms.
8 // For more information, see the COPYING file which you should have
9 // received along with this program.
11 function [sorted, indin] = %s_gsort(array, method, sortdir, criteria)
12 // Sorting complex numbers.
13 // This overload sorts only dense matrices.
14 // For hypermatrices, %hm_gsort() is called upstream
15 // For sparse matrices, %sp_gsort() is called upstream.
17 // method : "g" "r" "c" "lr" "lc"
18 // sortdir : [], or 1 or 2 elements in ["i" "d"]. Default = "d"
19 // criteria: list() of functions handles: real, imag, abs, atan
24 i = grand(10,3,"uin",-1,1);
25 r = grand(10,3,"uin",-1,1);
27 [cs, k] = %s_gsort(c, "g", ["d" "i"], list(abs, atan));
28 a = atand(imag(cs),real(cs));
29 disp(cs, abs(cs) + a*%i)
35 // CHECKING INPUT PARAMETERS
36 // -------------------------
38 // This overload is called only when array is defined and are complex numbers
41 // method: checked in the gateway (and initialized when default)
42 if ~isdef("method", "l") | method==[] | (type(method)==10 & method(1)=="")
46 // sortdir: checked in %gsort_multilevel. Only setting the default:
47 if ~isdef("sortdir", "l") | sortdir==[] | (type(sortdir)==10 & sortdir(1)=="")
48 sortdir = "d" // for back-compatibility
50 //criteria: checked in %gsort_multilevel. Only setting the default:
51 if ~isdef("criteria", "l") | (type(criteria)==1 & criteria==[])
52 if size(sortdir,"*")==2
53 criteria = list(abs, atan)
61 // Indices are computed anyway.
62 [sorted, indin] = %gsort_multilevel(array, method, sortdir, criteria)