~ubuntu-branches/ubuntu/karmic/scilab/karmic

« back to all changes in this revision

Viewing changes to tests/gsort.dia.ref

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-21 16:57:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020321165743-e9mv12c1tb1plztg
Tags: upstream-2.6
ImportĀ upstreamĀ versionĀ 2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
// Copyright INRIA
 
3
 
 
4
// test de gsort :
 
5
 
 
6
// a faire ensuite marcher pour vecteur complexes
 
7
 
 
8
 
 
9
N=4;P=5;
 
10
 
 
11
// a random permutation
 
12
 
 
13
[ax,perm]=sort(rand(1,N*P,'u'));
 
14
 
 
15
a=matrix(perm,N,P);
 
16
 
 
17
 
 
18
//-----Global sort
 
19
 
 
20
 
 
21
[a1,ind]=gsort(a,'g');
 
22
 
 
23
 
 
24
if norm(a1- matrix(N*P:-1:1,N,P)) > %eps then bugmes();quit;end;
 
25
 
 
26
if norm(a1- matrix(a(ind),N,P)) > %eps then bugmes();quit;end;
 
27
 
 
28
 
 
29
//increasing values
 
30
 
 
31
 
 
32
[a1,ind]=gsort(a,'g','i');
 
33
 
 
34
 
 
35
if norm(a1- matrix(1:N*P,N,P)) > %eps then bugmes();quit;end;
 
36
 
 
37
if norm(a1- matrix(a(ind),N,P)) > %eps then bugmes();quit;end;
 
38
 
 
39
 
 
40
 
 
41
//----sort each column of a ('r' means that the row indice is used for sorting)
 
42
 
 
43
 
 
44
[a1,ind]=gsort(a,'r');
 
45
 
 
46
nc=size(a,'c');
 
47
 
 
48
test=[];
 
49
 
 
50
for i=1:nc ;
 
51
   test= [test, matrix(a(ind(:,i),i),N,1)];
 
52
end
 
53
 
 
54
if norm(a1- test) > %eps then bugmes();quit;end;
 
55
 
 
56
 
 
57
//increasing values
 
58
 
 
59
 
 
60
[a1,ind]=gsort(a,'r','i');
 
61
 
 
62
nc=size(a,'c');
 
63
 
 
64
test=[];
 
65
 
 
66
for i=1:nc ;
 
67
   test= [test, matrix(a(ind(:,i),i),N,1)];
 
68
end
 
69
 
 
70
if norm(a1- test) > %eps then bugmes();quit;end;
 
71
 
 
72
 
 
73
 
 
74
//----sort each row of a ('c' means that the column indice is used for sorting)
 
75
 
 
76
 
 
77
[a1,ind]=gsort(a,'c')   ;
 
78
 
 
79
nr=size(a,'r');
 
80
 
 
81
test=[];
 
82
 
 
83
for i=1:nr ;
 
84
   test= [test; matrix(a(i,ind(i,:)),1,P)];
 
85
end
 
86
 
 
87
if norm(a1- test) > %eps then bugmes();quit;end;
 
88
 
 
89
 
 
90
//increasing
 
91
 
 
92
 
 
93
[a1,ind]=gsort(a,'c','i')   ;
 
94
 
 
95
nr=size(a,'r');
 
96
 
 
97
test=[];
 
98
 
 
99
for i=1:nr ;
 
100
   test= [test; matrix(a(i,ind(i,:)),1,P)];
 
101
end
 
102
 
 
103
if norm(a1- test) > %eps then bugmes();quit;end;
 
104
 
 
105
 
 
106
 
 
107
//----sort the rows of a in lexicographic order
 
108
 
 
109
//    i.e a(k,:) < a(l,:) if there's a number j
 
110
 
 
111
//    such that a(k,j) < a(l,j) and a(k,p)=a(l,p) for p in [1,j-1];
 
112
 
 
113
//
 
114
 
 
115
N=4;P=3;
 
116
 
 
117
alr=[1,2,2;
 
118
     1,2,1;
 
119
     1,1,2;
 
120
     1,1,1];
 
121
 
 
122
// a random permutation
 
123
 
 
124
[ax,perm]=sort(rand(1,N,'u'));
 
125
 
 
126
a=alr(perm,:);
 
127
 
 
128
 
 
129
[a1,ind]=gsort(a,'lr');
 
130
 
 
131
 
 
132
if norm(a1- alr) > %eps then bugmes();quit;end;
 
133
 
 
134
if norm(a1- matrix(a(ind,:),N,P)) > %eps then bugmes();quit;end;
 
135
 
 
136
 
 
137
[a2,ind2]=gsort(a*[100;10;1],'g');
 
138
 
 
139
if norm(ind2-ind) > %eps then bugmes();quit;end;
 
140
 
 
141
 
 
142
// increasing
 
143
 
 
144
 
 
145
[a1,ind]=gsort(a,'lr','i');
 
146
 
 
147
if norm(a1- alr(N:-1:1,:)) > %eps then bugmes();quit;end;
 
148
 
 
149
if norm(a1- matrix(a(ind,:),N,P)) > %eps then bugmes();quit;end;
 
150
 
 
151
[a2,ind2]=gsort(a*[100;10;1],'g','i');
 
152
 
 
153
if norm(ind2-ind) > %eps then bugmes();quit;end;
 
154
 
 
155
 
 
156
//----sort the columns of a in lexicographic order
 
157
 
 
158
N=3;P=4;
 
159
 
 
160
alr=alr';
 
161
 
 
162
// a random permutation
 
163
 
 
164
[ax,perm]=sort(rand(1,P,'u'));
 
165
 
 
166
a=alr(:,perm);
 
167
 
 
168
 
 
169
[a1,ind]=gsort(a,'lc');
 
170
 
 
171
 
 
172
if norm(a1- alr) > %eps then bugmes();quit;end;
 
173
 
 
174
if norm(a1- matrix(a(:,ind),N,P)) > %eps then bugmes();quit;end;
 
175
 
 
176
 
 
177
[a2,ind2]=gsort([100,10,1]*a,'g');
 
178
 
 
179
if norm(ind2-ind) > %eps then bugmes();quit;end;
 
180
 
 
181
 
 
182
//increasing
 
183
 
 
184
 
 
185
[a1,ind]=gsort(a,'lc','i');
 
186
 
 
187
 
 
188
if norm(a1- alr(:,P:-1:1)) > %eps then bugmes();quit;end;
 
189
 
 
190
if norm(a1- matrix(a(:,ind),N,P)) > %eps then bugmes();quit;end;
 
191
 
 
192
 
 
193
[a2,ind2]=gsort([100,10,1]*a,'g','i');
 
194
 
 
195
if norm(ind2-ind) > %eps then bugmes();quit;end;
 
196
 
 
197
 
 
198
//========================String sorts ================
 
199
 
 
200
N=10;P=20;
 
201
 
 
202
a=int(10*rand(N,P,'u'));
 
203
 
 
204
 
 
205
//-----Global sort
 
206
 
 
207
[a1,ind]=gsort(string(a),'g');
 
208
 
 
209
[a2,ind2]=gsort(a,'g');
 
210
 
 
211
if norm(evstr(a1)- matrix(a(ind),N,P)) > %eps then bugmes();quit;end;
 
212
 
 
213
// a and string(a) are in the same order in the previous example
 
214
 
 
215
if norm(evstr(a1)- a2 ) > %eps then bugmes();quit;end;
 
216
 
 
217
 
 
218
//-- rows
 
219
 
 
220
[a1,ind1]=gsort(string(a),'r');
 
221
 
 
222
[a2,ind2]=gsort(a,'r');
 
223
 
 
224
if norm(ind1-ind2) > %eps then bugmes();quit;end;
 
225
 
 
226
// a and string(a) are in the same order in the previous example
 
227
 
 
228
if norm(evstr(a1)- a2 ) > %eps then bugmes();quit;end;
 
229
 
 
230
 
 
231
//--columns
 
232
 
 
233
[a1,ind1]=gsort(string(a),'c')   ;
 
234
 
 
235
[a2,ind2]=gsort(a,'c');
 
236
 
 
237
if norm(ind1-ind2) > %eps then bugmes();quit;end;
 
238
 
 
239
// a and string(a) are in the same order in the previous example
 
240
 
 
241
if norm(evstr(a1)- a2 ) > %eps then bugmes();quit;end;
 
242
 
 
243
 
 
244
//----sort the rows of a in lexicographic order
 
245
 
 
246
 
 
247
N=4;P=3;
 
248
 
 
249
alr=[1,2,2;
 
250
     1,2,1;
 
251
     1,1,2;
 
252
     1,1,1];
 
253
 
 
254
// a random permutation
 
255
 
 
256
[ax,perm]=sort(rand(1,N,'u'));
 
257
 
 
258
a=alr(perm,:);
 
259
 
 
260
[a1,ind]=gsort(string(a),'lr') ;
 
261
 
 
262
[a2,ind]=gsort(a,'lr') ;
 
263
 
 
264
//
 
265
 
 
266
if norm(evstr(a1)- matrix(a(ind,:),N,P)) > %eps then bugmes();quit;end;
 
267
 
 
268
// a and string(a) are in the same order in the previous example
 
269
 
 
270
if norm(evstr(a1)- a2 ) > %eps then bugmes();quit;end;
 
271
 
 
272
 
 
273
 
 
274
//----sort the columns of a in lexicographic order
 
275
 
 
276
N=3;P=4;
 
277
 
 
278
alr=alr';
 
279
 
 
280
// a random permutation
 
281
 
 
282
[ax,perm]=sort(rand(1,P,'u'));
 
283
 
 
284
a=alr(:,perm);
 
285
 
 
286
 
 
287
[a1,ind]=gsort(string(a),'lc');
 
288
 
 
289
[a2,ind]=gsort(a,'lc') ;
 
290
 
 
291
//
 
292
 
 
293
if norm(evstr(a1)- matrix(a(:,ind),N,P)) > %eps then bugmes();quit;end;
 
294
 
 
295
// a and string(a) are in the same order in the previous example
 
296
 
 
297
if norm(evstr(a1)- a2 ) > %eps then bugmes();quit;end;
 
298
 
 
299
 
 
300