Ticket #33904: check.i

File check.i, 11.5 KB (added by paumard, 12 years ago)

"yorick -batch check.i" with the package installed

Line 
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
23require,"soy.i";
24require,"random.i";
25
26extern MR,MN,errors,errflg;
27MR = 50000;
28MN = 500000;
29
30errors = [];
31errflg = [];
32
33ftol = 1.e-6;
34dtol = 1.e-12;
35
36write,"\nSetting error tolerances : ";
37write,format="  >> single precision: %5.0e\n",ftol;
38write,format="  >> double precision: %5.0e\n\n",dtol;
39
40
41// Random rectangular matrices
42A = float(random([2,200,100])-0.5);
43A = A*(abs(A)<0.2);
44B = double(random([2,200,100])-0.5);
45B = B*(abs(B)<0.2);
46
47// Random symmetrix matrices
48S = float(random([2,100,100])-0.5);
49S = S(,+)*S(,+);
50S = S*(S>0.5);
51T = double(random([2,100,100])-0.5);
52T = T(,+)*T(,+);
53T = T*(T>0.5);
54
55// Random vectors
56v = float(random(200));
57w = double(random(200));
58s = float(random(100));
59t = double(random(100));
60
61// Test1: sprco/spruo and rcoinf/ruoinf
62write,format="testing sprco(a) and rcoinf (float)...%s",".";
63a = sprco(A);
64AA = rcoinf(a);
65err = max(abs(AA-A));
66grow,errors,err;
67grow,errflg,(err != 0);
68if ((err != 0)) {
69  write,format="ERROR OVERFLOW%s","!\n";
70} else {
71  write,format="OK%s\n",".";
72}
73write,format="testing sprco(a) and rcoinf (double)...%s",".";
74a = sprco(B);
75AA = rcoinf(a);
76err = max(abs(AA-B));
77grow,errors,err;
78grow,errflg,(err != 0);
79if ( (err != 0)) {
80  write,format="ERROR OVERFLOW%s","!\n";
81} else {
82  write,format="OK%s\n",".";
83}
84write,format="testing sprco(a,ur=200,un=10000) and rcoinf (float)...%s",".";
85a = sprco(A,ur=200,un=10000);
86AA = rcoinf(a);
87err = max(abs(AA-A));
88grow,errors,err;
89grow,errflg,(err != 0);
90if ( (err != 0)) {
91  write,format="ERROR OVERFLOW%s","!\n";
92} else {
93  write,format="OK%s\n",".";
94}
95write,format="testing sprco(a,ur=200,un=10000) and rcoinf (double)...%s",".";
96a = sprco(B,ur=200,un=10000);
97AA = rcoinf(a);
98err = max(abs(AA-B));
99grow,errors,err;
100grow,errflg,(err != 0);
101if ( (err != 0)) {
102  write,format="ERROR OVERFLOW%s","!\n";
103} else {
104  write,format="OK%s\n",".";
105}
106write,format="testing spruo(s) and ruoinf (float)...%s",".";
107a = spruo(S);
108AA = ruoinf(a);
109err = max(abs(AA-S));
110grow,errors,err;
111grow,errflg,(err != 0);
112if ( (err != 0)) {
113  write,format="ERROR OVERFLOW%s","!\n";
114} else {
115  write,format="OK%s\n",".";
116}
117write,format="testing sprco(a) and rcoinf (double)...%s",".";
118a = spruo(T);
119AA = ruoinf(a);
120err = max(abs(AA-T));
121grow,errors,err;
122grow,errflg,(err != 0);
123if ( (err != 0)) {
124  write,format="ERROR OVERFLOW%s","!\n";
125} else {
126  write,format="OK%s\n",".";
127}
128write,format="testing sprco(a,ur=200,un=10000) and rcoinf (float)...%s",".";
129a = spruo(S,ur=200,un=10000);
130AA = ruoinf(a);
131err = max(abs(AA-S));
132grow,errors,err;
133grow,errflg,(err != 0);
134if ( (err != 0)) {
135  write,format="ERROR OVERFLOW%s","!\n";
136} else {
137  write,format="OK%s\n",".";
138}
139write,format="testing sprco(a,ur=200,un=10000) and rcoinf (double)...%s",".";
140a = spruo(T,ur=200,un=10000);
141AA = ruoinf(a);
142err = max(abs(AA-T));
143grow,errors,err;
144grow,errflg,(err != 0);
145if ( (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
154write,format="testing rcoxv(a,v) (float)...%s",".";
155vv = A(+,)*v(+);
156a = sprco(A,ur=200,un=10000);
157uu = rcoxv(a,v);
158err = max(abs(vv-uu));
159grow,errors,err;
160grow,errflg,(err > ftol);
161if ( (err > ftol)) {
162  write,format="ERROR OVERFLOW%s","!\n";
163} else {
164  write,format="OK%s\n",".";
165}
166write,format="testing rcoxv(a,v) (double)...%s",".";
167a = sprco(B,ur=200,un=10000);
168vv = B(+,)*w(+);
169uu = rcoxv(a,w);
170err = max(abs(vv-uu));
171grow,errors,err;
172grow,errflg,(err > dtol);
173if ( (err > dtol)) {
174  write,format="ERROR OVERFLOW%s","!\n";
175} else {
176  write,format="OK%s\n",".";
177}
178write,format="testing ruoxv(a,v) (float)...%s",".";
179vv = S(+,)*s(+);
180a = spruo(S,ur=200,un=10000);
181uu = ruoxv(a,s);
182err = max(abs(vv-uu));
183grow,errors,err;
184grow,errflg,(err > ftol);
185if ( (err > ftol)) {
186  write,format="ERROR OVERFLOW%s","!\n";
187} else {
188  write,format="OK%s\n",".";
189}
190write,format="testing ruoxv(a,v) (double)...%s",".";
191a = spruo(T,ur=200,un=10000);
192vv = T(+,)*t(+);
193uu = ruoxv(a,t);
194err = max(abs(vv-uu));
195grow,errors,err;
196grow,errflg,(err > dtol);
197if ( (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
205write,format="testing rcoadd(a,b) (float)...%s",".";
206C = float(B);
207D = A+C;
208a = sprco(A,ur=200,un=10000);
209c = sprco(C,ur=200,un=10000);
210d = rcoadd(a,c);
211dd = rcoinf(d);
212err = max(abs(D-dd));
213grow,errors,err;
214grow,errflg,(err > ftol);
215if ( (err > ftol)) {
216  write,format="ERROR OVERFLOW%s","!\n";
217} else {
218  write,format="OK%s\n",".";
219}
220write,format="testing rcoadd(a,b) (double)...%s",".";
221C = double(A);
222D = B+C;
223b = sprco(B,ur=200,un=10000);
224c = sprco(C,ur=200,un=10000);
225d = rcoadd(b,c);
226dd = rcoinf(d);
227err = max(abs(D-dd));
228grow,errors,err;
229grow,errflg,(err > dtol);
230if ( (err > dtol)) {
231  write,format="ERROR OVERFLOW%s","!\n";
232} else {
233  write,format="OK%s\n",".";
234}
235write,format="testing ruoadd(a,b) (float)...%s",".";
236U = float(T);
237V = S+U;
238a = spruo(S,ur=200,un=10000);
239c = spruo(U,ur=200,un=10000);
240d = ruoadd(a,c);
241dd = ruoinf(d);
242err = max(abs(V-dd));
243grow,errors,err;
244grow,errflg,(err > ftol);
245if ( (err > ftol)) {
246  write,format="ERROR OVERFLOW%s","!\n";
247} else {
248  write,format="OK%s\n",".";
249}
250write,format="testing ruoadd(a,b) (double)...%s",".";
251U = double(S);
252V = U+T;
253a = spruo(T,ur=200,un=10000);
254c = spruo(U,ur=200,un=10000);
255d = ruoadd(a,c);
256dd = ruoinf(d);
257err = max(abs(V-dd));
258grow,errors,err;
259grow,errflg,(err > dtol);
260if ( (err > dtol)) {
261  write,format="ERROR OVERFLOW%s","!\n";
262} else {
263  write,format="OK%s\n",".";
264}
265write,format="testing rcoadd(a,b,ur=200,un=20000) (float)...%s",".";
266C = float(B);
267D = A+C;
268a = sprco(A,ur=200,un=10000);
269c = sprco(C,ur=200,un=10000);
270d = rcoadd(a,c,ur=200,un=20000);
271dd = rcoinf(d);
272err = max(abs(D-dd));
273grow,errors,err;
274grow,errflg,(err > ftol);
275if ( (err > ftol)) {
276  write,format="ERROR OVERFLOW%s","!\n";
277} else {
278  write,format="OK%s\n",".";
279}
280write,format="testing rcoadd(a,b,ur=200,un=20000) (double)...%s",".";
281C = double(A);
282D = B+C;
283b = sprco(B,ur=200,un=10000);
284c = sprco(C,ur=200,un=10000);
285d = rcoadd(b,c,ur=200,un=20000);
286dd = rcoinf(d);
287err = max(abs(D-dd));
288grow,errors,err;
289grow,errflg,(err > dtol);
290if ( (err > dtol)) {
291  write,format="ERROR OVERFLOW%s","!\n";
292} else {
293  write,format="OK%s\n",".";
294}
295write,format="testing ruoadd(a,b,ur=200,un=20000) (float)...%s",".";
296U = float(T);
297V = S+U;
298a = spruo(S,ur=200,un=10000);
299c = spruo(U,ur=200,un=10000);
300d = ruoadd(a,c,ur=200,un=20000);
301dd = ruoinf(d);
302err = max(abs(V-dd));
303grow,errors,err;
304grow,errflg,(err > ftol);
305if ( (err > ftol)) {
306  write,format="ERROR OVERFLOW%s","!\n";
307} else {
308  write,format="OK%s\n",".";
309}
310write,format="testing ruoadd(a,b,ur=200,un=20000) (double)...%s",".";
311U = double(S);
312V = U+T;
313a = spruo(T,ur=200,un=10000);
314c = spruo(U,ur=200,un=10000);
315d = ruoadd(a,c,ur=200,un=20000);
316dd = ruoinf(d);
317err = max(abs(V-dd));
318grow,errors,err;
319grow,errflg,(err > dtol);
320if ( (err > dtol)) {
321  write,format="ERROR OVERFLOW%s","!\n";
322} else {
323  write,format="OK%s\n",".";
324}
325
326
327// Test 4: rcoata
328write,format="testing rcoata(a) (float)...%s",".";
329ATA = A(+,)*A(+,);
330a = sprco(A,ur=200,un=10000);
331d = rcoata(a);
332dd = ruoinf(d);
333err = max(abs(ATA-dd));
334grow,errors,err;
335grow,errflg,(err > ftol);
336if ( (err > ftol)) {
337  write,format="ERROR OVERFLOW%s","!\n";
338} else {
339  write,format="OK%s\n",".";
340}
341write,format="testing rcoata(a) (double)...%s",".";
342BTB = B(+,)*B(+,);
343a = sprco(B,ur=200,un=10000);
344d = rcoata(a);
345dd = ruoinf(d);
346err = max(abs(BTB-dd));
347grow,errors,err;
348grow,errflg,(err > dtol);
349if ( (err > dtol)) {
350  write,format="ERROR OVERFLOW%s","!\n";
351} else {
352  write,format="OK%s\n",".";
353}
354write,format="testing rcoata(a,ur=200,un=10000) (float)...%s",".";
355ATA = A(+,)*A(+,);
356a = sprco(A,ur=200,un=10000);
357d = rcoata(a,ur=200,un=10000);
358dd = ruoinf(d);
359err = max(abs(ATA-dd));
360grow,errors,err;
361grow,errflg,(err > ftol);
362if ( (err > ftol)) {
363  write,format="ERROR OVERFLOW%s","!\n";
364} else {
365  write,format="OK%s\n",".";
366}
367write,format="testing rcoata(a,ur=200,un=10000) (double)...%s",".";
368BTB = B(+,)*B(+,);
369a = sprco(B,ur=200,un=10000);
370d = rcoata(a,ur=200,un=10000);
371dd = ruoinf(d);
372err = max(abs(BTB-dd));
373grow,errors,err;
374grow,errflg,(err > dtol);
375if ( (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
384write,format="testing rcoatb(a,b) (float)...%s",".";
385C = float(B);
386ATC = C(+,)*A(+,);
387a = sprco(A,ur=200,un=10000);
388c = sprco(C,ur=200,un=10000);
389d = rcoatb(a,c);
390dd = rcoinf(d);
391err = max(abs(ATC-dd));
392grow,errors,err;
393grow,errflg,(err > ftol);
394if ( (err > ftol)) {
395  write,format="ERROR OVERFLOW%s","!\n";
396} else {
397  write,format="OK%s\n",".";
398}
399write,format="testing rcoatb(a,b) (double)...%s",".";
400C = double(A);
401ATC = C(+,)*B(+,);
402a = sprco(B,ur=200,un=10000);
403c = sprco(C,ur=200,un=10000);
404d = rcoatb(a,c);
405dd = rcoinf(d);
406err = max(abs(ATC-dd));
407grow,errors,err;
408grow,errflg,(err > dtol);
409if ( (err > dtol)) {
410  write,format="ERROR OVERFLOW%s","!\n";
411} else {
412  write,format="OK%s\n",".";
413}
414write,format="testing rcoatb(a,b,ur=200,un=10000) (float)...%s",".";
415C = float(B);
416ATC = C(+,)*A(+,);
417a = sprco(A,ur=200,un=10000);
418c = sprco(C,ur=200,un=10000);
419d = rcoatb(a,c,ur=200,un=10000);
420dd = rcoinf(d);
421err = max(abs(ATC-dd));
422grow,errors,err;
423grow,errflg,(err > ftol);
424if ( (err > ftol)) {
425  write,format="ERROR OVERFLOW%s","!\n";
426} else {
427  write,format="OK%s\n",".";
428}
429write,format="testing rcoatb(a,b,ur=200,un=10000) (double)...%s",".";
430C = double(A);
431ATC = C(+,)*B(+,);
432a = sprco(B,ur=200,un=10000);
433c = sprco(C,ur=200,un=10000);
434d = rcoatb(a,c,ur=200,un=10000);
435dd = rcoinf(d);
436err = max(abs(ATC-dd));
437grow,errors,err;
438grow,errflg,(err > dtol);
439if ( (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
448write,format="testing rcotr(a) (float)...%s",".";
449AT = transpose(A);
450a = sprco(A,ur=210,un=10000);
451at = rcotr(a);
452dd = rcoinf(at);
453err = max(abs(AT-dd));
454grow,errors,err;
455grow,errflg,(err > ftol);
456if ( (err > ftol)) {
457  write,format="ERROR OVERFLOW%s","!\n";
458} else {
459  write,format="OK%s\n",".";
460}
461write,format="testing rcotr(a) (double)...%s",".";
462BT = transpose(B);
463a = sprco(B,ur=210,un=10000);
464at = rcotr(a);
465dd = rcoinf(at);
466err = max(abs(BT-dd));
467grow,errors,err;
468grow,errflg,(err > ftol);
469if ( (err > ftol)) {
470  write,format="ERROR OVERFLOW%s","!\n";
471} else {
472  write,format="OK%s\n",".";
473}
474
475
476write,"\nFinished!\n";
477
478if (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}