1 | // check-plug.i script for SOY, 18 Nov 2004 |
---|
2 | |
---|
3 | /* |
---|
4 | SOY: Sparse Operations with Yorick |
---|
5 | Copyright (C) 2004 Ralf Flicker (rflicker@mac.com) |
---|
6 | Copyright (C) 2010-2012 Marcos van Dam (marcos@flatwavefronts.com) |
---|
7 | |
---|
8 | This program is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU General Public License |
---|
10 | as published by the Free Software Foundation; either version 2 |
---|
11 | of the License, or (at your option) any later version. |
---|
12 | |
---|
13 | This program is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | GNU General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with this program; if not, write to the Free Software |
---|
20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
21 | */ |
---|
22 | |
---|
23 | require,"soy.i"; |
---|
24 | require,"random.i"; |
---|
25 | |
---|
26 | extern MR,MN,errors,errflg; |
---|
27 | MR = 50000; |
---|
28 | MN = 500000; |
---|
29 | |
---|
30 | errors = []; |
---|
31 | errflg = []; |
---|
32 | |
---|
33 | ftol = 1.e-6; |
---|
34 | dtol = 1.e-12; |
---|
35 | |
---|
36 | write,"\nSetting error tolerances : "; |
---|
37 | write,format=" >> single precision: %5.0e\n",ftol; |
---|
38 | write,format=" >> double precision: %5.0e\n\n",dtol; |
---|
39 | |
---|
40 | |
---|
41 | // Random rectangular matrices |
---|
42 | A = float(random([2,200,100])-0.5); |
---|
43 | A = A*(abs(A)<0.2); |
---|
44 | B = double(random([2,200,100])-0.5); |
---|
45 | B = B*(abs(B)<0.2); |
---|
46 | |
---|
47 | // Random symmetrix matrices |
---|
48 | S = float(random([2,100,100])-0.5); |
---|
49 | S = S(,+)*S(,+); |
---|
50 | S = S*(S>0.5); |
---|
51 | T = double(random([2,100,100])-0.5); |
---|
52 | T = T(,+)*T(,+); |
---|
53 | T = T*(T>0.5); |
---|
54 | |
---|
55 | // Random vectors |
---|
56 | v = float(random(200)); |
---|
57 | w = double(random(200)); |
---|
58 | s = float(random(100)); |
---|
59 | t = double(random(100)); |
---|
60 | |
---|
61 | // Test1: sprco/spruo and rcoinf/ruoinf |
---|
62 | write,format="testing sprco(a) and rcoinf (float)...%s","."; |
---|
63 | a = sprco(A); |
---|
64 | AA = rcoinf(a); |
---|
65 | err = max(abs(AA-A)); |
---|
66 | grow,errors,err; |
---|
67 | grow,errflg,(err != 0); |
---|
68 | if ((err != 0)) { |
---|
69 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
70 | } else { |
---|
71 | write,format="OK%s\n","."; |
---|
72 | } |
---|
73 | write,format="testing sprco(a) and rcoinf (double)...%s","."; |
---|
74 | a = sprco(B); |
---|
75 | AA = rcoinf(a); |
---|
76 | err = max(abs(AA-B)); |
---|
77 | grow,errors,err; |
---|
78 | grow,errflg,(err != 0); |
---|
79 | if ( (err != 0)) { |
---|
80 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
81 | } else { |
---|
82 | write,format="OK%s\n","."; |
---|
83 | } |
---|
84 | write,format="testing sprco(a,ur=200,un=10000) and rcoinf (float)...%s","."; |
---|
85 | a = sprco(A,ur=200,un=10000); |
---|
86 | AA = rcoinf(a); |
---|
87 | err = max(abs(AA-A)); |
---|
88 | grow,errors,err; |
---|
89 | grow,errflg,(err != 0); |
---|
90 | if ( (err != 0)) { |
---|
91 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
92 | } else { |
---|
93 | write,format="OK%s\n","."; |
---|
94 | } |
---|
95 | write,format="testing sprco(a,ur=200,un=10000) and rcoinf (double)...%s","."; |
---|
96 | a = sprco(B,ur=200,un=10000); |
---|
97 | AA = rcoinf(a); |
---|
98 | err = max(abs(AA-B)); |
---|
99 | grow,errors,err; |
---|
100 | grow,errflg,(err != 0); |
---|
101 | if ( (err != 0)) { |
---|
102 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
103 | } else { |
---|
104 | write,format="OK%s\n","."; |
---|
105 | } |
---|
106 | write,format="testing spruo(s) and ruoinf (float)...%s","."; |
---|
107 | a = spruo(S); |
---|
108 | AA = ruoinf(a); |
---|
109 | err = max(abs(AA-S)); |
---|
110 | grow,errors,err; |
---|
111 | grow,errflg,(err != 0); |
---|
112 | if ( (err != 0)) { |
---|
113 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
114 | } else { |
---|
115 | write,format="OK%s\n","."; |
---|
116 | } |
---|
117 | write,format="testing sprco(a) and rcoinf (double)...%s","."; |
---|
118 | a = spruo(T); |
---|
119 | AA = ruoinf(a); |
---|
120 | err = max(abs(AA-T)); |
---|
121 | grow,errors,err; |
---|
122 | grow,errflg,(err != 0); |
---|
123 | if ( (err != 0)) { |
---|
124 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
125 | } else { |
---|
126 | write,format="OK%s\n","."; |
---|
127 | } |
---|
128 | write,format="testing sprco(a,ur=200,un=10000) and rcoinf (float)...%s","."; |
---|
129 | a = spruo(S,ur=200,un=10000); |
---|
130 | AA = ruoinf(a); |
---|
131 | err = max(abs(AA-S)); |
---|
132 | grow,errors,err; |
---|
133 | grow,errflg,(err != 0); |
---|
134 | if ( (err != 0)) { |
---|
135 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
136 | } else { |
---|
137 | write,format="OK%s\n","."; |
---|
138 | } |
---|
139 | write,format="testing sprco(a,ur=200,un=10000) and rcoinf (double)...%s","."; |
---|
140 | a = spruo(T,ur=200,un=10000); |
---|
141 | AA = ruoinf(a); |
---|
142 | err = max(abs(AA-T)); |
---|
143 | grow,errors,err; |
---|
144 | grow,errflg,(err != 0); |
---|
145 | if ( (err != 0)) { |
---|
146 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
147 | } else { |
---|
148 | write,format="OK%s\n","."; |
---|
149 | } |
---|
150 | |
---|
151 | |
---|
152 | |
---|
153 | // Test 2: rcoxv and ruoxv |
---|
154 | write,format="testing rcoxv(a,v) (float)...%s","."; |
---|
155 | vv = A(+,)*v(+); |
---|
156 | a = sprco(A,ur=200,un=10000); |
---|
157 | uu = rcoxv(a,v); |
---|
158 | err = max(abs(vv-uu)); |
---|
159 | grow,errors,err; |
---|
160 | grow,errflg,(err > ftol); |
---|
161 | if ( (err > ftol)) { |
---|
162 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
163 | } else { |
---|
164 | write,format="OK%s\n","."; |
---|
165 | } |
---|
166 | write,format="testing rcoxv(a,v) (double)...%s","."; |
---|
167 | a = sprco(B,ur=200,un=10000); |
---|
168 | vv = B(+,)*w(+); |
---|
169 | uu = rcoxv(a,w); |
---|
170 | err = max(abs(vv-uu)); |
---|
171 | grow,errors,err; |
---|
172 | grow,errflg,(err > dtol); |
---|
173 | if ( (err > dtol)) { |
---|
174 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
175 | } else { |
---|
176 | write,format="OK%s\n","."; |
---|
177 | } |
---|
178 | write,format="testing ruoxv(a,v) (float)...%s","."; |
---|
179 | vv = S(+,)*s(+); |
---|
180 | a = spruo(S,ur=200,un=10000); |
---|
181 | uu = ruoxv(a,s); |
---|
182 | err = max(abs(vv-uu)); |
---|
183 | grow,errors,err; |
---|
184 | grow,errflg,(err > ftol); |
---|
185 | if ( (err > ftol)) { |
---|
186 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
187 | } else { |
---|
188 | write,format="OK%s\n","."; |
---|
189 | } |
---|
190 | write,format="testing ruoxv(a,v) (double)...%s","."; |
---|
191 | a = spruo(T,ur=200,un=10000); |
---|
192 | vv = T(+,)*t(+); |
---|
193 | uu = ruoxv(a,t); |
---|
194 | err = max(abs(vv-uu)); |
---|
195 | grow,errors,err; |
---|
196 | grow,errflg,(err > dtol); |
---|
197 | if ( (err > dtol)) { |
---|
198 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
199 | } else { |
---|
200 | write,format="OK%s\n","."; |
---|
201 | } |
---|
202 | |
---|
203 | |
---|
204 | // Test 3: rcoadd and ruoadd |
---|
205 | write,format="testing rcoadd(a,b) (float)...%s","."; |
---|
206 | C = float(B); |
---|
207 | D = A+C; |
---|
208 | a = sprco(A,ur=200,un=10000); |
---|
209 | c = sprco(C,ur=200,un=10000); |
---|
210 | d = rcoadd(a,c); |
---|
211 | dd = rcoinf(d); |
---|
212 | err = max(abs(D-dd)); |
---|
213 | grow,errors,err; |
---|
214 | grow,errflg,(err > ftol); |
---|
215 | if ( (err > ftol)) { |
---|
216 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
217 | } else { |
---|
218 | write,format="OK%s\n","."; |
---|
219 | } |
---|
220 | write,format="testing rcoadd(a,b) (double)...%s","."; |
---|
221 | C = double(A); |
---|
222 | D = B+C; |
---|
223 | b = sprco(B,ur=200,un=10000); |
---|
224 | c = sprco(C,ur=200,un=10000); |
---|
225 | d = rcoadd(b,c); |
---|
226 | dd = rcoinf(d); |
---|
227 | err = max(abs(D-dd)); |
---|
228 | grow,errors,err; |
---|
229 | grow,errflg,(err > dtol); |
---|
230 | if ( (err > dtol)) { |
---|
231 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
232 | } else { |
---|
233 | write,format="OK%s\n","."; |
---|
234 | } |
---|
235 | write,format="testing ruoadd(a,b) (float)...%s","."; |
---|
236 | U = float(T); |
---|
237 | V = S+U; |
---|
238 | a = spruo(S,ur=200,un=10000); |
---|
239 | c = spruo(U,ur=200,un=10000); |
---|
240 | d = ruoadd(a,c); |
---|
241 | dd = ruoinf(d); |
---|
242 | err = max(abs(V-dd)); |
---|
243 | grow,errors,err; |
---|
244 | grow,errflg,(err > ftol); |
---|
245 | if ( (err > ftol)) { |
---|
246 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
247 | } else { |
---|
248 | write,format="OK%s\n","."; |
---|
249 | } |
---|
250 | write,format="testing ruoadd(a,b) (double)...%s","."; |
---|
251 | U = double(S); |
---|
252 | V = U+T; |
---|
253 | a = spruo(T,ur=200,un=10000); |
---|
254 | c = spruo(U,ur=200,un=10000); |
---|
255 | d = ruoadd(a,c); |
---|
256 | dd = ruoinf(d); |
---|
257 | err = max(abs(V-dd)); |
---|
258 | grow,errors,err; |
---|
259 | grow,errflg,(err > dtol); |
---|
260 | if ( (err > dtol)) { |
---|
261 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
262 | } else { |
---|
263 | write,format="OK%s\n","."; |
---|
264 | } |
---|
265 | write,format="testing rcoadd(a,b,ur=200,un=20000) (float)...%s","."; |
---|
266 | C = float(B); |
---|
267 | D = A+C; |
---|
268 | a = sprco(A,ur=200,un=10000); |
---|
269 | c = sprco(C,ur=200,un=10000); |
---|
270 | d = rcoadd(a,c,ur=200,un=20000); |
---|
271 | dd = rcoinf(d); |
---|
272 | err = max(abs(D-dd)); |
---|
273 | grow,errors,err; |
---|
274 | grow,errflg,(err > ftol); |
---|
275 | if ( (err > ftol)) { |
---|
276 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
277 | } else { |
---|
278 | write,format="OK%s\n","."; |
---|
279 | } |
---|
280 | write,format="testing rcoadd(a,b,ur=200,un=20000) (double)...%s","."; |
---|
281 | C = double(A); |
---|
282 | D = B+C; |
---|
283 | b = sprco(B,ur=200,un=10000); |
---|
284 | c = sprco(C,ur=200,un=10000); |
---|
285 | d = rcoadd(b,c,ur=200,un=20000); |
---|
286 | dd = rcoinf(d); |
---|
287 | err = max(abs(D-dd)); |
---|
288 | grow,errors,err; |
---|
289 | grow,errflg,(err > dtol); |
---|
290 | if ( (err > dtol)) { |
---|
291 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
292 | } else { |
---|
293 | write,format="OK%s\n","."; |
---|
294 | } |
---|
295 | write,format="testing ruoadd(a,b,ur=200,un=20000) (float)...%s","."; |
---|
296 | U = float(T); |
---|
297 | V = S+U; |
---|
298 | a = spruo(S,ur=200,un=10000); |
---|
299 | c = spruo(U,ur=200,un=10000); |
---|
300 | d = ruoadd(a,c,ur=200,un=20000); |
---|
301 | dd = ruoinf(d); |
---|
302 | err = max(abs(V-dd)); |
---|
303 | grow,errors,err; |
---|
304 | grow,errflg,(err > ftol); |
---|
305 | if ( (err > ftol)) { |
---|
306 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
307 | } else { |
---|
308 | write,format="OK%s\n","."; |
---|
309 | } |
---|
310 | write,format="testing ruoadd(a,b,ur=200,un=20000) (double)...%s","."; |
---|
311 | U = double(S); |
---|
312 | V = U+T; |
---|
313 | a = spruo(T,ur=200,un=10000); |
---|
314 | c = spruo(U,ur=200,un=10000); |
---|
315 | d = ruoadd(a,c,ur=200,un=20000); |
---|
316 | dd = ruoinf(d); |
---|
317 | err = max(abs(V-dd)); |
---|
318 | grow,errors,err; |
---|
319 | grow,errflg,(err > dtol); |
---|
320 | if ( (err > dtol)) { |
---|
321 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
322 | } else { |
---|
323 | write,format="OK%s\n","."; |
---|
324 | } |
---|
325 | |
---|
326 | |
---|
327 | // Test 4: rcoata |
---|
328 | write,format="testing rcoata(a) (float)...%s","."; |
---|
329 | ATA = A(+,)*A(+,); |
---|
330 | a = sprco(A,ur=200,un=10000); |
---|
331 | d = rcoata(a); |
---|
332 | dd = ruoinf(d); |
---|
333 | err = max(abs(ATA-dd)); |
---|
334 | grow,errors,err; |
---|
335 | grow,errflg,(err > ftol); |
---|
336 | if ( (err > ftol)) { |
---|
337 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
338 | } else { |
---|
339 | write,format="OK%s\n","."; |
---|
340 | } |
---|
341 | write,format="testing rcoata(a) (double)...%s","."; |
---|
342 | BTB = B(+,)*B(+,); |
---|
343 | a = sprco(B,ur=200,un=10000); |
---|
344 | d = rcoata(a); |
---|
345 | dd = ruoinf(d); |
---|
346 | err = max(abs(BTB-dd)); |
---|
347 | grow,errors,err; |
---|
348 | grow,errflg,(err > dtol); |
---|
349 | if ( (err > dtol)) { |
---|
350 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
351 | } else { |
---|
352 | write,format="OK%s\n","."; |
---|
353 | } |
---|
354 | write,format="testing rcoata(a,ur=200,un=10000) (float)...%s","."; |
---|
355 | ATA = A(+,)*A(+,); |
---|
356 | a = sprco(A,ur=200,un=10000); |
---|
357 | d = rcoata(a,ur=200,un=10000); |
---|
358 | dd = ruoinf(d); |
---|
359 | err = max(abs(ATA-dd)); |
---|
360 | grow,errors,err; |
---|
361 | grow,errflg,(err > ftol); |
---|
362 | if ( (err > ftol)) { |
---|
363 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
364 | } else { |
---|
365 | write,format="OK%s\n","."; |
---|
366 | } |
---|
367 | write,format="testing rcoata(a,ur=200,un=10000) (double)...%s","."; |
---|
368 | BTB = B(+,)*B(+,); |
---|
369 | a = sprco(B,ur=200,un=10000); |
---|
370 | d = rcoata(a,ur=200,un=10000); |
---|
371 | dd = ruoinf(d); |
---|
372 | err = max(abs(BTB-dd)); |
---|
373 | grow,errors,err; |
---|
374 | grow,errflg,(err > dtol); |
---|
375 | if ( (err > dtol)) { |
---|
376 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
377 | } else { |
---|
378 | write,format="OK%s\n","."; |
---|
379 | } |
---|
380 | |
---|
381 | |
---|
382 | |
---|
383 | // Test 5: rcoatb |
---|
384 | write,format="testing rcoatb(a,b) (float)...%s","."; |
---|
385 | C = float(B); |
---|
386 | ATC = C(+,)*A(+,); |
---|
387 | a = sprco(A,ur=200,un=10000); |
---|
388 | c = sprco(C,ur=200,un=10000); |
---|
389 | d = rcoatb(a,c); |
---|
390 | dd = rcoinf(d); |
---|
391 | err = max(abs(ATC-dd)); |
---|
392 | grow,errors,err; |
---|
393 | grow,errflg,(err > ftol); |
---|
394 | if ( (err > ftol)) { |
---|
395 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
396 | } else { |
---|
397 | write,format="OK%s\n","."; |
---|
398 | } |
---|
399 | write,format="testing rcoatb(a,b) (double)...%s","."; |
---|
400 | C = double(A); |
---|
401 | ATC = C(+,)*B(+,); |
---|
402 | a = sprco(B,ur=200,un=10000); |
---|
403 | c = sprco(C,ur=200,un=10000); |
---|
404 | d = rcoatb(a,c); |
---|
405 | dd = rcoinf(d); |
---|
406 | err = max(abs(ATC-dd)); |
---|
407 | grow,errors,err; |
---|
408 | grow,errflg,(err > dtol); |
---|
409 | if ( (err > dtol)) { |
---|
410 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
411 | } else { |
---|
412 | write,format="OK%s\n","."; |
---|
413 | } |
---|
414 | write,format="testing rcoatb(a,b,ur=200,un=10000) (float)...%s","."; |
---|
415 | C = float(B); |
---|
416 | ATC = C(+,)*A(+,); |
---|
417 | a = sprco(A,ur=200,un=10000); |
---|
418 | c = sprco(C,ur=200,un=10000); |
---|
419 | d = rcoatb(a,c,ur=200,un=10000); |
---|
420 | dd = rcoinf(d); |
---|
421 | err = max(abs(ATC-dd)); |
---|
422 | grow,errors,err; |
---|
423 | grow,errflg,(err > ftol); |
---|
424 | if ( (err > ftol)) { |
---|
425 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
426 | } else { |
---|
427 | write,format="OK%s\n","."; |
---|
428 | } |
---|
429 | write,format="testing rcoatb(a,b,ur=200,un=10000) (double)...%s","."; |
---|
430 | C = double(A); |
---|
431 | ATC = C(+,)*B(+,); |
---|
432 | a = sprco(B,ur=200,un=10000); |
---|
433 | c = sprco(C,ur=200,un=10000); |
---|
434 | d = rcoatb(a,c,ur=200,un=10000); |
---|
435 | dd = rcoinf(d); |
---|
436 | err = max(abs(ATC-dd)); |
---|
437 | grow,errors,err; |
---|
438 | grow,errflg,(err > dtol); |
---|
439 | if ( (err > dtol)) { |
---|
440 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
441 | } else { |
---|
442 | write,format="OK%s\n","."; |
---|
443 | } |
---|
444 | |
---|
445 | |
---|
446 | |
---|
447 | // Test 6: rcoatb |
---|
448 | write,format="testing rcotr(a) (float)...%s","."; |
---|
449 | AT = transpose(A); |
---|
450 | a = sprco(A,ur=210,un=10000); |
---|
451 | at = rcotr(a); |
---|
452 | dd = rcoinf(at); |
---|
453 | err = max(abs(AT-dd)); |
---|
454 | grow,errors,err; |
---|
455 | grow,errflg,(err > ftol); |
---|
456 | if ( (err > ftol)) { |
---|
457 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
458 | } else { |
---|
459 | write,format="OK%s\n","."; |
---|
460 | } |
---|
461 | write,format="testing rcotr(a) (double)...%s","."; |
---|
462 | BT = transpose(B); |
---|
463 | a = sprco(B,ur=210,un=10000); |
---|
464 | at = rcotr(a); |
---|
465 | dd = rcoinf(at); |
---|
466 | err = max(abs(BT-dd)); |
---|
467 | grow,errors,err; |
---|
468 | grow,errflg,(err > ftol); |
---|
469 | if ( (err > ftol)) { |
---|
470 | write,format="ERROR OVERFLOW%s","!\n"; |
---|
471 | } else { |
---|
472 | write,format="OK%s\n","."; |
---|
473 | } |
---|
474 | |
---|
475 | |
---|
476 | write,"\nFinished!\n"; |
---|
477 | |
---|
478 | if (anyof(errflg)) { |
---|
479 | write,format="The script encountered %i (recoverable) error(s).\n",sum(errflg); |
---|
480 | write,format="The largest error by absolute value was %5.3e.\n",max(errors); |
---|
481 | write,"If this is much greater than the single precision error"; |
---|
482 | write,format=" tolerance (%4.0e), then something went seriously wrong.\n",ftol; |
---|
483 | write,"(if it is close, then no worries)\n" |
---|
484 | write,"To submit a bug report, email: rflicker@mac.com.\n"; |
---|
485 | } else { |
---|
486 | write,"All functions returned without errors.\n"; |
---|
487 | } |
---|