6
// a faire ensuite marcher pour vecteur complexes
11
// a random permutation
13
[ax,perm]=sort(rand(1,N*P,'u'));
21
[a1,ind]=gsort(a,'g');
24
if norm(a1- matrix(N*P:-1:1,N,P)) > %eps then bugmes();quit;end;
26
if norm(a1- matrix(a(ind),N,P)) > %eps then bugmes();quit;end;
32
[a1,ind]=gsort(a,'g','i');
35
if norm(a1- matrix(1:N*P,N,P)) > %eps then bugmes();quit;end;
37
if norm(a1- matrix(a(ind),N,P)) > %eps then bugmes();quit;end;
41
//----sort each column of a ('r' means that the row indice is used for sorting)
44
[a1,ind]=gsort(a,'r');
51
test= [test, matrix(a(ind(:,i),i),N,1)];
54
if norm(a1- test) > %eps then bugmes();quit;end;
60
[a1,ind]=gsort(a,'r','i');
67
test= [test, matrix(a(ind(:,i),i),N,1)];
70
if norm(a1- test) > %eps then bugmes();quit;end;
74
//----sort each row of a ('c' means that the column indice is used for sorting)
77
[a1,ind]=gsort(a,'c') ;
84
test= [test; matrix(a(i,ind(i,:)),1,P)];
87
if norm(a1- test) > %eps then bugmes();quit;end;
93
[a1,ind]=gsort(a,'c','i') ;
100
test= [test; matrix(a(i,ind(i,:)),1,P)];
103
if norm(a1- test) > %eps then bugmes();quit;end;
107
//----sort the rows of a in lexicographic order
109
// i.e a(k,:) < a(l,:) if there's a number j
111
// such that a(k,j) < a(l,j) and a(k,p)=a(l,p) for p in [1,j-1];
122
// a random permutation
124
[ax,perm]=sort(rand(1,N,'u'));
129
[a1,ind]=gsort(a,'lr');
132
if norm(a1- alr) > %eps then bugmes();quit;end;
134
if norm(a1- matrix(a(ind,:),N,P)) > %eps then bugmes();quit;end;
137
[a2,ind2]=gsort(a*[100;10;1],'g');
139
if norm(ind2-ind) > %eps then bugmes();quit;end;
145
[a1,ind]=gsort(a,'lr','i');
147
if norm(a1- alr(N:-1:1,:)) > %eps then bugmes();quit;end;
149
if norm(a1- matrix(a(ind,:),N,P)) > %eps then bugmes();quit;end;
151
[a2,ind2]=gsort(a*[100;10;1],'g','i');
153
if norm(ind2-ind) > %eps then bugmes();quit;end;
156
//----sort the columns of a in lexicographic order
162
// a random permutation
164
[ax,perm]=sort(rand(1,P,'u'));
169
[a1,ind]=gsort(a,'lc');
172
if norm(a1- alr) > %eps then bugmes();quit;end;
174
if norm(a1- matrix(a(:,ind),N,P)) > %eps then bugmes();quit;end;
177
[a2,ind2]=gsort([100,10,1]*a,'g');
179
if norm(ind2-ind) > %eps then bugmes();quit;end;
185
[a1,ind]=gsort(a,'lc','i');
188
if norm(a1- alr(:,P:-1:1)) > %eps then bugmes();quit;end;
190
if norm(a1- matrix(a(:,ind),N,P)) > %eps then bugmes();quit;end;
193
[a2,ind2]=gsort([100,10,1]*a,'g','i');
195
if norm(ind2-ind) > %eps then bugmes();quit;end;
198
//========================String sorts ================
202
a=int(10*rand(N,P,'u'));
207
[a1,ind]=gsort(string(a),'g');
209
[a2,ind2]=gsort(a,'g');
211
if norm(evstr(a1)- matrix(a(ind),N,P)) > %eps then bugmes();quit;end;
213
// a and string(a) are in the same order in the previous example
215
if norm(evstr(a1)- a2 ) > %eps then bugmes();quit;end;
220
[a1,ind1]=gsort(string(a),'r');
222
[a2,ind2]=gsort(a,'r');
224
if norm(ind1-ind2) > %eps then bugmes();quit;end;
226
// a and string(a) are in the same order in the previous example
228
if norm(evstr(a1)- a2 ) > %eps then bugmes();quit;end;
233
[a1,ind1]=gsort(string(a),'c') ;
235
[a2,ind2]=gsort(a,'c');
237
if norm(ind1-ind2) > %eps then bugmes();quit;end;
239
// a and string(a) are in the same order in the previous example
241
if norm(evstr(a1)- a2 ) > %eps then bugmes();quit;end;
244
//----sort the rows of a in lexicographic order
254
// a random permutation
256
[ax,perm]=sort(rand(1,N,'u'));
260
[a1,ind]=gsort(string(a),'lr') ;
262
[a2,ind]=gsort(a,'lr') ;
266
if norm(evstr(a1)- matrix(a(ind,:),N,P)) > %eps then bugmes();quit;end;
268
// a and string(a) are in the same order in the previous example
270
if norm(evstr(a1)- a2 ) > %eps then bugmes();quit;end;
274
//----sort the columns of a in lexicographic order
280
// a random permutation
282
[ax,perm]=sort(rand(1,P,'u'));
287
[a1,ind]=gsort(string(a),'lc');
289
[a2,ind]=gsort(a,'lc') ;
293
if norm(evstr(a1)- matrix(a(:,ind),N,P)) > %eps then bugmes();quit;end;
295
// a and string(a) are in the same order in the previous example
297
if norm(evstr(a1)- a2 ) > %eps then bugmes();quit;end;