-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.i
325 lines (267 loc) · 8.84 KB
/
check.i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/*
* Author: Francois Rigaut
*
* check file for imutil
*
* Copyright (c) 2003-2011, Francois Rigaut
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details (to receive a copy of the GNU
* General Public License, write to the Free Software Foundation, Inc., 675
* Mass Ave, Cambridge, MA 02139, USA).
*
*/
require,"imutil.i";
require,"util_fr.i";
require,"random_et.i";
func chk_bilinear(void)
{
// removed the following lines as it introduced an
// unnecessary dependancy to yorick-z
// im = img_read("crane.jpg");
// im = float(im);
// f = openb("crane.dat");
// restore,f,im;
// close,f;
dim = 512; sdim=32;
im = gaussdev([2,dim,dim]);
star = exp(-(dist(sdim)/2.)^2.);
for (i=1;i<=1000;i++) {
xs = long(dim/2.+gaussdev()*dim/5.);
ys = long(dim/2.+gaussdev()*dim/5.);
if (min(_(xs,ys)) < 1) continue;
if (max(_(xs,ys)+sdim-1) > dim) continue;
im(xs:xs+sdim-1,ys:ys+sdim-1) += star/(0.01+random());
}
// im = float(jpeg_read("polarbear.jpg"))(sum,,)(,::-1);
// palette,"gray.gp";
time = 100;
// tests of speed:
xi=1; yi=1; dim=100; nreb=2;
sim = im(xi:xi+dim-1,yi:yi+dim-1);
tic; tmp=bilinear(sim,nreb); eltime=tac()*1000.;
write,format="bilinear(im,nreb) (%d,%d) -> (%d,%d) : %.1fms, %.2fus/pixel\n",dim,dim,
nreb*dim,nreb*dim,eltime,eltime*1000/(nreb*dim)^2.;
dim = 512;
tic; tmp=bilinear(im,nreb); eltime=tac()*1000.;
write,format="bilinear(im,nreb) (%d,%d) -> (%d,%d) : %.1fms, %.2fus/pixel\n",dim,dim,
nreb*dim,nreb*dim,eltime,eltime*1000/(nreb*dim)^2.;
xi=1; yi=1; dim=100;
sim = im(xi:xi+dim-1,yi:yi+dim-1);
xy = indices(100);
tic; tmp=bilinear(sim,xy(,,1),xy(,,2)); eltime=tac()*1000.;
write,format="bilinear(im,xarray,yarray) (%d,%d) -> (%d,%d) : %.1fms, %.2fus/pixel\n",
dim,dim,nreb*dim,nreb*dim,eltime,eltime*1000/(nreb*dim)^2.;
//test of equality:
if (allof(sim == bilinear(sim,1))) {
write,"Checking that bilinear(im,1) = im ... Yes";
} else { error,"bilinear(im,1) != im"; }
//displays and check of functionalities:
xi=50; yi=200; dim=200;
// xi=220; yi=300; dim=200;
sim = im(xi:xi+dim-1,yi:yi+dim-1);
// window,wait=1;
palette,"earth.gp";
pli,sim;
pltitle,"Original";
write,"Original";
//pause,time;
fma; pli,bilinear(sim,2);
pltitle,"bilinear(im,2)";
write,"bilinear(im,2)";
//pause,time;
fma; pli,bilinear(sim,355,401);
pltitle,"bilinear(im,355,401)";
write,"bilinear(im,355,401)";
//pause,time;
fma; pli,bilinear(sim,401,355);
pltitle,"bilinear(im,401,355)";
write,"bilinear(im,401,355)";
//pause,time;
x = indgen(2*dim)/2.;
y = indgen(2*dim)/2.;
fma; pli,bilinear(sim,x,y,grid=1);
pltitle,"bilinear(im,x,y,grid=1)";
write,"bilinear(im,x,y,grid=1)";
//pause,time;
x = indgen(2*dim)/2.;
y = indgen(2*dim)/3.;
fma; plg,bilinear(im,x,y);
pltitle,"bilinear(im,vector!_x,vector!_y)";
write,"bilinear(im,vector_x,vector_y)";
//pause,time;
//speed test:
// window,style="nobox.gs",wait=1;
animate,1;
for (i=10;i<=dim;i+=4) {fma;pli,bilinear(sim,i,i),cmin=0,cmax=255;}
for (i=dim/2-1;i>=2;i-=4) {
fma;
pli,bilinear(sim(dim/2-i:dim/2+i,dim/2-i:dim/2+i),dim,dim),cmin=0,cmax=255;
}
animate,0;
//pause,time;
// check of other possibilities for errors:
// window,style="work.gs";
tmp = bilinear(sim,10,300);
tmp = bilinear(sim,300,10);
tmp = bilinear(sim,300,300,minus_one=1);
tmp = bilinear(sim,3,minus_one=1);
xy = indices(512)-256;
animate,1;
for (a=0;a<=180;a+=20) {
x = cos(a*pi/180)*xy(,,1) + sin(a*pi/180)*xy(,,2) + 256;
y = -sin(a*pi/180)*xy(,,1) + cos(a*pi/180)*xy(,,2) + 256;
fma; pli,bilinear(im,x,y,outside=10);
}
animate,0;
//pause,time;
}
func chk_spline2(void)
{
// removed the following lines as it introduced an
// unnecessary dependancy to yorick-z
// im = img_read("crane.jpg");
// im = float(im);
//f = openb("crane.dat");
//restore,f,im;
//close,f;
dim = 512; sdim=32;
im = gaussdev([2,dim,dim]);
star = exp(-(dist(sdim)/2.)^2.);
for (i=1;i<=1000;i++) {
xs = long(dim/2.+gaussdev()*dim/5.);
ys = long(dim/2.+gaussdev()*dim/5.);
if (min(_(xs,ys)) < 1) continue;
if (max(_(xs,ys)+sdim-1) > dim) continue;
im(xs:xs+sdim-1,ys:ys+sdim-1) += star/(0.01+random());
}
// im = float(jpeg_read("polarbear.jpg"))(sum,,)(,::-1);
// palette,"gray.gp";
time = 100;
// tests of speed:
xi=1; yi=1; dim=100; nreb=2;
sim = im(xi:xi+dim-1,yi:yi+dim-1);
tic; tmp=spline2(sim,nreb); eltime=tac()*1000.;
write,format="spline2(im,nreb) (%d,%d) -> (%d,%d) : %.1fms, %.2fus/pixel\n",dim,dim,
nreb*dim,nreb*dim,eltime,eltime*1000/(nreb*dim)^2.;
dim = 512;
tic; tmp=spline2(im,nreb); eltime=tac()*1000.;
write,format="spline2(im,nreb) (%d,%d) -> (%d,%d) : %.1fms, %.2fus/pixel\n",dim,dim,
nreb*dim,nreb*dim,eltime,eltime*1000/(nreb*dim)^2.;
xi=1; yi=1; dim=100;
sim = im(xi:xi+dim-1,yi:yi+dim-1);
xy = indices(100);
tic; tmp=spline2(sim,xy(,,1),xy(,,2)); eltime=tac()*1000.;
write,format="spline2(im,xarray,yarray) (%d,%d) -> (%d,%d) : %.1fms, %.2fus/pixel\n",
dim,dim,nreb*dim,nreb*dim,eltime,eltime*1000/(nreb*dim)^2.;
//test of equality:
if (allof(sim == spline2(sim,1))) {
write,"Checking that spline2(im,1) = im ... Yes";
} else { error,"spline2(im,1) != im"; }
//displays and check of functionalities:
xi=50; yi=200; dim=200;
// xi=220; yi=300; dim=200;
sim = im(xi:xi+dim-1,yi:yi+dim-1);
// window,wait=1;
fma;
pli,sim;
pltitle,"Original";
write,"Original";
//pause,time;
fma; pli,spline2(sim,2);
pltitle,"spline2(im,2)";
write,"spline2(im,2)";
//pause,time;
fma; pli,spline2(sim,355,401);
pltitle,"spline2(im,355,401)";
write,"spline2(im,355,401)";
//pause,time;
fma; pli,spline2(sim,401,355);
pltitle,"spline2(im,401,355)";
write,"spline2(im,401,355)";
//pause,time;
x = indgen(2*dim)/2.;
y = indgen(2*dim)/2.;
fma; pli,spline2(sim,x,y,grid=1);
pltitle,"spline2(im,x,y,grid=1)";
write,"spline2(im,x,y,grid=1)";
//pause,time;
return;
x = indgen(2*dim)/2.;
y = indgen(2*dim)/3.;
fma; plg,spline2(im,x,y);
pltitle,"spline2(im,vector!_x,vector!_y)";
write,"spline2(im,vector_x,vector_y)";
//pause,time;
//speed test:
// window,style="nobox.gs";
animate,1;
for (i=10;i<=dim;i+=4) {fma;pli,spline2(sim,i,i),cmin=0,cmax=255;}
for (i=dim/2-1;i>=2;i-=4) {
fma;
pli,spline2(sim(dim/2-i:dim/2+i,dim/2-i:dim/2+i),dim,dim),cmin=0,cmax=255;
}
animate,0;
//pause,time;
// check of other possibilities for errors:
// window,style="work.gs";
tmp = spline2(sim,10,300);
tmp = spline2(sim,300,10);
tmp = spline2(sim,300,300,minus_one=1);
tmp = spline2(sim,3,minus_one=1);
xy = indices(50)-25;
animate,1;
for (a=0;a<=180;a+=20) {
x = cos(a*pi/180)*xy(,,1) + sin(a*pi/180)*xy(,,2) + 100;
y = -sin(a*pi/180)*xy(,,1) + cos(a*pi/180)*xy(,,2) + 100;
fma; pli,spline2(sim,x,y);
}
animate,0;
//pause,time;
}
window,wait=1;
tic; g = dist(512); t1=tac();
tic; g = __dist(512); t2=tac();
write,format="Create dist(512): %fs (with interpreted function %f)\n",t1,t2;
tic; gc = clip(g,10,50); t1=tac();
tic; gc = min(max(g,10),50); t2=tac();
write,format="clip image 512x512: %fs (with Buildin yorick function %f)\n",t1,t2;
tic; gc = eclat(g); t1=tac();
tic; gc = roll(g); t2=tac();
write,format="Roll image 512x512: %fs (with Buildin yorick function %f)\n",t1,t2;
tic; greb = bin2(g); t=tac();
write,format="rebin 512x512 -> 256x256: %fs\n",t;
tic; x = gaussdev(100000); t1=tac();
tic; x = random_n(100000); t2=tac();
write,format="100000 normal random numbers: %fs (interpreted function %fs)\n",t1,t2;
v = array(10,100000);
tic; x = poidev(v); t1=tac();
tic; x = random_poisson(v); t2=tac();
write,format="Poisson of array(10,100000): %fs (interpreted function %fs)\n",t1,t2;
//Interpolation tests
chk_bilinear;
chk_spline2;
write,"Image interpolation tests OK";
// Sedgesort tests:
n = 500000;
write,format="Sorting %d numbers with sedgesort\n",n;
a = long(10000*random(n));
tic; v = a(sort(a)); t1=tac();
tic; v = sedgesort(a); t2=tac();
write,format="Long: Regular sort: %fs / sedgesort: %fs\n",t1,t2;
a = float(10000*random(n));
tic; v = a(sort(a)); t1=tac();
tic; v = sedgesort(a); t2=tac();
write,format="Float: Regular sort: %fs / sedgesort: %fs\n",t1,t2;
a = double(10000*random(n));
tic; v = a(sort(a)); t1=tac();
tic; v = sedgesort(a); t2=tac();
write,format="Double: Regular sort: %fs / sedgesort: %fs\n",t1,t2;
write,"All tests OK";