1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2010 - INRIA - Serge Steer
5 // This file is distributed under the same license as the Scilab package.
6 // =============================================================================
8 // <-- Non-regression test for bug 3842 -->
10 // <-- Bugzilla URL -->
11 // http://bugzilla.scilab.org/show_bug.cgi?id=3842
13 // <-- Short Description -->
14 // sum applyed to integer arrys can only procuce results computed using native operations.
15 exec SCI/modules/elementary_functions/tests/unit_tests/prod.tst
17 // =============================================================================
19 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
21 // Copyright (C) 2010 - INRIA - Serge Steer
25 // This file is distributed under the same license as the Scilab package.
27 // =============================================================================
36 T=list(list(),list('native'),list('double'));
39 if prod([],typ(:))<>1 then pause,end
40 if prod([],'*',typ(:))<>1 then pause,end
41 if prod([],1,typ(:))<>[] then pause,end
42 if prod([],2,typ(:))<>[] then pause,end
43 if prod([],3,typ(:))<>[] then pause,end
47 //=======================================================================
53 T=list(list(),list('native'),list('double'));
56 if prod(d,typ(:))<>22860 then pause,end
57 if prod(d,'*',typ(:))<>22860 then pause,end
58 if or(prod(d,1,typ(:))<>[254 90]) then pause,end
59 if or(prod(d,2,typ(:))<>[10;2286]) then pause,end
60 if or(prod(d,3,typ(:))<>d) then pause,end
65 //hypermatrices of floats
67 d=[1 10;254 9];d(:,:,2)=1;
69 T=list(list(),list('native'),list('double'));
72 if prod(d,typ(:))<>22860 then pause,end
73 if prod(d,'*',typ(:))<>22860 then pause,end
74 if or(prod(d,1,typ(:))<>hypermat([1,2,2],[254;90;1;1])) then pause,end
75 if or(prod(d,2,typ(:))<>hypermat([2,1,2],[10;2286;1;1])) then pause,end
76 if or(prod(d,3,typ(:))<>[1,10;254,9]) then pause,end
77 if or(prod(d,5,typ(:))<>d) then pause,end
81 //=======================================================================
83 //matrices of short integers
85 i=uint8([1 10;254 9]);
87 T=list(list(),list('native'));
90 if prod(i,typ(:))<>uint8(76) then pause,end
91 if prod(i,'*',typ(:))<>uint8(76) then pause,end
92 if or(prod(i,1,typ(:))<>uint8([254 90])) then pause,end
93 if or(prod(i,2,typ(:))<>uint8([10;238])) then pause,end
94 if or(prod(i,3,typ(:))<>i) then pause,end
98 if prod(i,'double')<>22860 then pause,end
100 if prod(i,'*','double')<>22860 then pause,end
102 if or(prod(i,1,'double')<>[254 90]) then pause,end
104 if or(prod(i,2,'double')<>[10;2286]) then pause,end
106 if or(prod(i,3,'double')<>double(i)) then pause,end
111 i=uint8([1 10;254 9]);i(:,:,2)=uint8(1);
113 for typ=list(list(),list('native'));
114 if prod(i,typ(:))<>uint8(76) then pause,end
115 if prod(i,'*',typ(:))<>uint8(76) then pause,end
116 if or(prod(i,1,typ(:))<>hypermat([1,2,2],uint8([254;90;1;1]))) then pause,end
117 if or(prod(i,2,typ(:))<>hypermat([2,1,2],uint8([10;238;1;1]))) then pause,end
118 if or(prod(i,3,typ(:))<>([1,10;254,9])) then pause,end
119 if or(prod(i,5,typ(:))<>i) then pause,end
123 if prod(i,'double')<>22860 then pause,end
125 if prod(i,'*','double')<>22860 then pause,end
127 if or(prod(i,1,'double')<>hypermat([1,2,2],[254;90;1;1])) then pause,end
129 if or(prod(i,2,'double')<>hypermat([2,1,2],[10;2286;1;1])) then pause,end
131 if or(prod(i,3,'double')<>[1,10;254,9]) then pause,end
133 if or(prod(i,5,'double')<>double(i)) then pause,end
139 s=%s;p=[s s+1;s^2 1];
141 T=list(list(),list('native'),list('double'));
144 if prod(p,typ(:))<>s^3+s^4 then pause,end
145 if prod(p,'*',typ(:))<>s^3+s^4 then pause,end
146 if or(prod(p,1,typ(:))<>[s^3,1+s]) then pause,end
147 if or(prod(p,2,typ(:))<>[s+s^2;s^2]) then pause,end
148 if or(prod(p,3,typ(:))<>p) then pause,end
153 s=%s;p=[s s+1;s^2 1];p(:,:,2)=[1 s;s+1 2];
155 T=list(list(),list('native'),list('double'));
158 if prod(p,typ(:))<>2*s^4+4*s^5+2*s^6 then pause,end
159 if prod(p,'*',typ(:))<>2*s^4+4*s^5+2*s^6 then pause,end
160 if or(prod(p,1,typ(:))<>hypermat([1,2,2],[s^3;1+s;1+s;2*s])) then pause,end
161 if or(prod(p,2,typ(:))<>hypermat([2,1,2],[s+s^2;s^2;s;2+2*s])) then pause,end
162 if or(prod(p,3,typ(:))<>[s,s+s^2;s^2+s^3,2]) then pause,end
163 if or(prod(p,5,typ(:))<>p) then pause,end
167 //=======================================================================
169 //Matrices of rationals
171 s=%s;r=1.0 ./[s s+1;s^2 1];
173 T=list(list(),list('native'),list('double'));
176 if prod(r,typ(:))<>1.0/(s^3+s^4) then pause,end
177 if prod(r,'*',typ(:))<>1.0/(s^3+s^4) then pause,end
178 if or(prod(r,1,typ(:))<>[1,1]./[s^3,1+s]) then pause,end
179 if or(prod(r,2,typ(:))<>[1;1]./[s+s^2;s^2]) then pause,end
180 if or(prod(r,3,typ(:))<>r) then pause,end
184 //=======================================================================
186 //Matrices of booleans
190 for typ=list(list(),list('double'));
191 if prod(b,typ(:))<>0 then pause,end
192 if prod(b,'*',typ(:))<>0 then pause,end
193 if or(prod(b,1,typ(:))<>[0 1]) then pause,end
194 if or(prod(b,2,typ(:))<>[1;0]) then pause,end
195 if or(prod(b,3,typ(:))<>double(b)) then pause,end
199 if prod(b,'native')<>%f then pause,end
201 if prod(b,'*','native')<>%f then pause,end
203 if or(prod(b,1,'native')<>[%f %t]) then pause,end
205 if or(prod(b,2,'native')<>[%t;%f]) then pause,end
207 if or(prod(b,3,'native')<>b) then pause,end
212 b=[%t %t;%f %t];b(1,1,2)=%t;
214 for typ=list(list(),list('double'));
215 if prod(b,typ(:))<>0 then pause,end
216 if prod(b,'*',typ(:))<>0 then pause,end
217 if or(prod(b,1,typ(:))<>hypermat([1,2,2],[0;1;0;0])) then pause,end
218 if or(prod(b,2,typ(:))<>hypermat([2,1,2],[1;0;0;0])) then pause,end
219 if or(prod(b,3,typ(:))<>[1,0;0,0]) then pause,end
220 if or(prod(b,5,typ(:))<>double(b)) then pause,end
224 if prod(b,'native')<>%f then pause,end
226 if prod(b,'*','native')<>%f then pause,end
228 if or(prod(b,1,'native')<>hypermat([1,2,2],[%f;%t;%f;%f])) then pause,end
230 if or(prod(b,2,'native')<>hypermat([2,1,2],[%t;%f;%f;%f])) then pause,end
232 if or(prod(b,3,'native')<>[%t,%f;%f,%f]) then pause,end
234 if or(prod(b,5,'native')<>b) then pause,end
236 //=======================================================================
238 //sparse matrices of floats
240 s=sparse([1 10 2;-1 254 9]);
242 T=list(list(),list('native'),list('double'));
245 if prod(s,typ(:))<>-45720 then pause,end
246 if prod(s,'*',typ(:))<>-45720 then pause,end
247 if or(prod(s,1,typ(:))<>sparse([-1 2540 18])) then pause,end
248 if or(prod(s,2,typ(:))<>sparse([20;-2286])) then pause,end
249 if or(prod(s,3,typ(:))<>s) then pause,end
253 //=======================================================================
255 //sparse matrices of boolean
257 bs=sparse([%t %t %f;%t %t %t]);
259 for typ=list(list(),list('double'));
260 if prod(bs,typ(:))<>0 then pause,end
261 if prod(bs,'*',typ(:))<>0 then pause,end
262 if or(prod(bs,1,typ(:))<>sparse([1,1,0])) then pause,end
263 if or(prod(bs,2,typ(:))<>sparse([0;1])) then pause,end
264 if or(prod(bs,3,typ(:))<>bool2s(bs)) then pause,end
268 if prod(bs,'native')<>%f then pause,end
270 if prod(bs,'*','native')<>%f then pause,end
272 if or(prod(bs,1,'native')<>sparse([%t,%t,%f])) then pause,end
274 if or(prod(bs,2,'native')<>sparse([%f;%t])) then pause,end
276 if or(prod(bs,3,'native')<>bs) then pause,end
279 // TODO : test the "m" option
281 exec SCI/modules/elementary_functions/tests/unit_tests/cumprod.tst
283 // =============================================================================
285 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
287 // Copyright (C) 2010 - INRIA - Serge Steer
289 // Copyright (C) 2012 - Scilab Enterprises - Cedric Delamarre
293 // This file is distributed under the same license as the Scilab package.
295 // =============================================================================
298 // <-- CLI SHELL MODE
305 T=list(list(),list('native'),list('double'));
308 assert_checkequal(cumprod([],typ(:)), []);
309 assert_checkequal(cumprod([],'*',typ(:)), []);
310 assert_checkequal(cumprod([],1,typ(:)), []);
311 assert_checkequal(cumprod([],2,typ(:)), []);
312 assert_checkequal(cumprod([],3,typ(:)), []);
316 //=======================================================================
322 T=list(list(),list('native'),list('double'));
325 assert_checkequal(cumprod(d,typ(:)), [1,2540;254,22860]);
326 assert_checkequal(cumprod(d,'*',typ(:)), [1,2540;254,22860]);
327 assert_checkequal(cumprod(d,1,typ(:)), [1,10;254,90]);
328 assert_checkequal(cumprod(d,2,typ(:)), [1,10;254,2286]);
329 assert_checkequal(cumprod(d,3,typ(:)), d);
333 //hypermatrices of floats
335 d=[1 10;254 9];d(1,1,2)=1;
337 T=list(list(),list('native'),list('double'));
340 assert_checkequal(cumprod(d,typ(:)), hypermat([2,2,2],[1;254;2540;22860;22860;0;0;0]));
341 assert_checkequal(cumprod(d,'*',typ(:)), hypermat([2,2,2],[1;254;2540;22860;22860;0;0;0]));
342 assert_checkequal(cumprod(d,1,typ(:)), hypermat([2,2,2],[1;254;10;90;1;0;0;0]));
343 assert_checkequal(cumprod(d,2,typ(:)), hypermat([2,2,2],[1;254;10;2286;1;0;0;0]));
344 assert_checkequal(cumprod(d,3,typ(:)), hypermat([2,2,2],[1;254;10;9;1;0;0;0]));
345 assert_checkequal(cumprod(d,5,typ(:)), d);
349 //=======================================================================
353 i=uint8([1 10;254 9]);
355 for typ=list(list(),list('native'));
356 assert_checkequal(cumprod(i,typ(:)), uint8([1,236;254,76]));
357 assert_checkequal(cumprod(i,'*',typ(:)), uint8([1,236;254,76]));
358 assert_checkequal(cumprod(i,1,typ(:)), uint8([1,10;254,90]));
359 assert_checkequal(cumprod(i,2,typ(:)), uint8([1,10;254,238]));
360 assert_checkequal(cumprod(i,3,typ(:)), double(i));
364 assert_checkequal(cumprod(i,'double'), [1,2540;254,22860]);
366 assert_checkequal(cumprod(i,'*','double'), [1,2540;254,22860]);
368 assert_checkequal(cumprod(i,1,'double'), [1,10;254,90]);
370 assert_checkequal(cumprod(i,2,'double'), [1,10;254,2286]);
372 assert_checkequal(cumprod(i,3,'double'), double(i));
377 i=uint8([1 10;254 9]);i(1,1,2)=uint8(1);
379 for typ=list(list(),list('native'));
380 assert_checkequal(cumprod(i,typ(:)), hypermat([2,2,2],uint8([1;254;236;76;76;0;0;0])));
381 assert_checkequal(cumprod(i,'*',typ(:)), hypermat([2,2,2],uint8([1;254;236;76;76;0;0;0])));
382 assert_checkequal(cumprod(i,1,typ(:)), hypermat([2,2,2],uint8([1;254;10;90;1;0;0;0])));
383 assert_checkequal(cumprod(i,2,typ(:)), hypermat([2,2,2],uint8([1;254;10;238;1;0;0;0])));
384 assert_checkequal(cumprod(i,3,typ(:)), hypermat([2,2,2],uint8([1;254;10;9;1;0;0;0])));
385 assert_checkequal(cumprod(i,5,typ(:)), double(i));
390 assert_checkequal(cumprod(i,'double'), hypermat([2,2,2],[1;254;2540;22860;22860;0;0;0]));
392 assert_checkequal(cumprod(i,'*','double'), hypermat([2,2,2],[1;254;2540;22860;22860;0;0;0]));
394 assert_checkequal(cumprod(i,1,'double'), hypermat([2,2,2],[1;254;10;90;1;0;0;0]));
396 assert_checkequal(cumprod(i,2,'double'), hypermat([2,2,2],[1;254;10;2286;1;0;0;0]));
398 assert_checkequal(cumprod(i,3,'double'), hypermat([2,2,2],[1;254;10;9;1;0;0;0]));
400 assert_checkequal(cumprod(i,5,'double'), double(i));
403 //=======================================================================
405 //Matrices of Polynomials
407 s=%s;p=[s s+1;s^2 0];
409 T=list(list(),list('native'),list('double'));
412 assert_checkequal(cumprod(p,typ(:)), [s,s^3+s^4;s^3,0*s]);
413 assert_checkequal(cumprod(p,'*',typ(:)), [s,s^3+s^4;s^3,0*s]);
414 assert_checkequal(cumprod(p,1,typ(:)), [s,1+s;s^3,0*s]);
415 assert_checkequal(cumprod(p,2,typ(:)), [s,s+s^2;s^2,0*s]);
416 assert_checkequal(cumprod(p,3,typ(:)), p);
422 s=%s;p=[s s+1;s^2 0];p(1,1,2)=-1;
424 T=list(list(),list('native'),list('double'));
427 assert_checkequal(cumprod(p,typ(:)), hypermat([2,2,2],[s;s^3;s^3+s^4;0*s;0*s;0*s;0*s;0*s]));
428 assert_checkequal(cumprod(p,'*',typ(:)), hypermat([2,2,2],[s;s^3;s^3+s^4;0*s;0*s;0*s;0*s;0*s]));
429 assert_checkequal(cumprod(p,1,typ(:)), hypermat([2,2,2],[s;s^3;1+s;0*s;-1;0*s;0*s;0*s]));
430 assert_checkequal(cumprod(p,2,typ(:)), hypermat([2,2,2],[s;s^2;s+s^2;0*s;-1;0*s;0*s;0*s]));
431 assert_checkequal(cumprod(p,3,typ(:)), hypermat([2,2,2],[s;s^2;1+s;0*s;-s;0*s;0*s;0*s]));
432 assert_checkequal(cumprod(p,5,typ(:)), p);
435 //=======================================================================
437 //Matrices of rationals
439 s=%s;r=1.0 ./[s s+1;s^2 1];
441 T=list(list(),list('native'),list('double'));
444 assert_checkequal(cumprod(r,typ(:)), [1,1;1,1]./[s,s^3+s^4;s^3,s^3+s^4]);
445 assert_checkequal(cumprod(r,'*',typ(:)), [1,1;1,1]./[s,s^3+s^4;s^3,s^3+s^4]);
446 assert_checkequal(cumprod(r,1,typ(:)), [1,1;1,1]./[s,1+s;s^3,1+s]);
447 assert_checkequal(cumprod(r,2,typ(:)), [1,1;1,1]./[s,s+s^2;s^2,s^2]);
448 assert_checkequal(cumprod(r,3,typ(:)), r);
452 //=======================================================================
454 ///Matrices of boolean
459 for typ=list(list(),list('double'));
460 assert_checkequal(cumprod(b,typ(:)), [1,0;0,0]);
461 assert_checkequal(cumprod(b,'*',typ(:)), [1,0;0,0]);
462 assert_checkequal(cumprod(b,1,typ(:)), [1,1;0,1]);
463 assert_checkequal(cumprod(b,2,typ(:)), [1,1;0,0]);
464 assert_checkequal(cumprod(b,3,typ(:)), double(b));
467 assert_checkequal(cumprod(b,'native'), [%t,%f;%f,%f]);
469 assert_checkequal(cumprod(b,'*','native'), [%t,%f;%f,%f]);
471 assert_checkequal(cumprod(b,1,'native'), [%t,%t;%f,%t]);
473 assert_checkequal(cumprod(b,2,'native'), [%t,%t;%f,%f]);
475 assert_checkequal(cumprod(b,3,'native'), b);
480 b=[%t %t;%f %t];b(1,1,2)=%f;
482 for typ=list(list(),list('double'));
483 assert_checkequal(cumprod(b,typ(:)), hypermat([2,2,2],[1;0;0;0;0;0;0;0]));
484 assert_checkequal(cumprod(b,'*',typ(:)), hypermat([2,2,2],[1;0;0;0;0;0;0;0]));
485 assert_checkequal(cumprod(b,1,typ(:)), hypermat([2,2,2],[1;0;1;1;0;0;0;0]));
486 assert_checkequal(cumprod(b,2,typ(:)), hypermat([2,2,2],[1;0;1;0;0;0;0;0]));
487 assert_checkequal(cumprod(b,3,typ(:)), hypermat([2,2,2],[1;0;1;1;0;0;0;0]));
488 assert_checkequal(cumprod(b,5,typ(:)), double(b));
492 assert_checkequal(cumprod(b,'native'), hypermat([2,2,2],[%t;%f;%f;%f;%f;%f;%f;%f]));
494 assert_checkequal(cumprod(b,'*','native'), hypermat([2,2,2],[%t;%f;%f;%f;%f;%f;%f;%f]));
496 assert_checkequal(cumprod(b,1,'native'), hypermat([2,2,2],[%t;%f;%t;%t;%f;%f;%f;%f]));
498 assert_checkequal(cumprod(b,2,'native'), hypermat([2,2,2],[%t;%f;%t;%f;%f;%f;%f;%f]));
500 assert_checkequal(cumprod(b,3,'native'), hypermat([2,2,2],[%t;%f;%t;%t;%f;%f;%f;%f]));
502 assert_checkequal(cumprod(b,5,'native'), b);
505 //=======================================================================
507 //sparse matrices of floats
509 s=sparse([1 10 0;-1 0 9]);
511 T=list(list(),list('native'),list('double'));
514 assert_checkequal(cumprod(s,typ(:)), sparse([1,1;1,2;2,1],[1;-10;-1],[2,3]));
515 assert_checkequal(cumprod(s,'*',typ(:)), sparse([1,1;1,2;2,1],[1;-10;-1],[2,3]));
516 assert_checkequal(cumprod(s,1,typ(:)), sparse([1,1;1,2;2,1],[1;10;-1],[2,3]));
517 assert_checkequal(cumprod(s,2,typ(:)), sparse([1,1;1,2;2,1],[1;10;-1],[2,3]));
518 assert_checkequal(cumprod(s,3,typ(:)), s);
522 //=======================================================================
524 //sparse matrices of boolean
526 bs=sparse([%t %t %f;%t %t %t]);
528 for typ=list(list(),list('double'));
529 assert_checkequal(cumprod(bs,typ(:)), sparse([1,1;1,2;2,1;2,2],[1;1;1;1],[2,3]));
530 assert_checkequal(cumprod(bs,'*',typ(:)), sparse([1,1;1,2;2,1;2,2],[1;1;1;1],[2,3]));
531 assert_checkequal(cumprod(bs,1,typ(:)), sparse([1,1;1,2;2,1;2,2],[1;1;1;1],[2,3]));
532 assert_checkequal(cumprod(bs,2,typ(:)), sparse([1,1;1,2;2,1;2,2;2,3],[1;1;1;1;1],[2,3]));
533 assert_checkequal(cumprod(bs,3,typ(:)), bool2s(bs));
537 assert_checkequal(cumprod(bs,'native'), sparse([1,1;1,2;2,1;2,2],[%t;%t;%t;%t],[2,3]));
539 assert_checkequal(cumprod(bs,'*','native'), sparse([1,1;1,2;2,1;2,2],[%t;%t;%t;%t],[2,3]));
542 assert_checkequal(cumprod(bs,1,'native'), sparse([1,1;1,2;2,1;2,2],[%t;%t;%t;%t],[2,3]));
544 assert_checkequal(cumprod(bs,2,'native'), sparse([1,1;1,2;2,1;2,2;2,3],[%t;%t;%t;%t;%t],[2,3]));
546 assert_checkequal(cumprod(bs,3,'native'), bs);
549 // TODO : test the "m" option
551 exec SCI/modules/elementary_functions/tests/unit_tests/prod.tst
553 // =============================================================================
555 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
557 // Copyright (C) 2010 - INRIA - Serge Steer
561 // This file is distributed under the same license as the Scilab package.
563 // =============================================================================
566 // <-- CLI SHELL MODE
572 T=list(list(),list('native'),list('double'));
575 if prod([],typ(:))<>1 then pause,end
576 if prod([],'*',typ(:))<>1 then pause,end
577 if prod([],1,typ(:))<>[] then pause,end
578 if prod([],2,typ(:))<>[] then pause,end
579 if prod([],3,typ(:))<>[] then pause,end
583 //=======================================================================
589 T=list(list(),list('native'),list('double'));
592 if prod(d,typ(:))<>22860 then pause,end
593 if prod(d,'*',typ(:))<>22860 then pause,end
594 if or(prod(d,1,typ(:))<>[254 90]) then pause,end
595 if or(prod(d,2,typ(:))<>[10;2286]) then pause,end
596 if or(prod(d,3,typ(:))<>d) then pause,end
601 //hypermatrices of floats
603 d=[1 10;254 9];d(:,:,2)=1;
605 T=list(list(),list('native'),list('double'));
608 if prod(d,typ(:))<>22860 then pause,end
609 if prod(d,'*',typ(:))<>22860 then pause,end
610 if or(prod(d,1,typ(:))<>hypermat([1,2,2],[254;90;1;1])) then pause,end
611 if or(prod(d,2,typ(:))<>hypermat([2,1,2],[10;2286;1;1])) then pause,end
612 if or(prod(d,3,typ(:))<>[1,10;254,9]) then pause,end
613 if or(prod(d,5,typ(:))<>d) then pause,end
617 //=======================================================================
619 //matrices of short integers
621 i=uint8([1 10;254 9]);
623 T=list(list(),list('native'));
626 if prod(i,typ(:))<>uint8(76) then pause,end
627 if prod(i,'*',typ(:))<>uint8(76) then pause,end
628 if or(prod(i,1,typ(:))<>uint8([254 90])) then pause,end
629 if or(prod(i,2,typ(:))<>uint8([10;238])) then pause,end
630 if or(prod(i,3,typ(:))<>i) then pause,end
634 if prod(i,'double')<>22860 then pause,end
636 if prod(i,'*','double')<>22860 then pause,end
638 if or(prod(i,1,'double')<>[254 90]) then pause,end
640 if or(prod(i,2,'double')<>[10;2286]) then pause,end
642 if or(prod(i,3,'double')<>double(i)) then pause,end
647 i=uint8([1 10;254 9]);i(:,:,2)=uint8(1);
649 for typ=list(list(),list('native'));
650 if prod(i,typ(:))<>uint8(76) then pause,end
651 if prod(i,'*',typ(:))<>uint8(76) then pause,end
652 if or(prod(i,1,typ(:))<>hypermat([1,2,2],uint8([254;90;1;1]))) then pause,end
653 if or(prod(i,2,typ(:))<>hypermat([2,1,2],uint8([10;238;1;1]))) then pause,end
654 if or(prod(i,3,typ(:))<>([1,10;254,9])) then pause,end
655 if or(prod(i,5,typ(:))<>i) then pause,end
659 if prod(i,'double')<>22860 then pause,end
661 if prod(i,'*','double')<>22860 then pause,end
663 if or(prod(i,1,'double')<>hypermat([1,2,2],[254;90;1;1])) then pause,end
665 if or(prod(i,2,'double')<>hypermat([2,1,2],[10;2286;1;1])) then pause,end
667 if or(prod(i,3,'double')<>[1,10;254,9]) then pause,end
669 if or(prod(i,5,'double')<>double(i)) then pause,end
675 s=%s;p=[s s+1;s^2 1];
677 T=list(list(),list('native'),list('double'));
680 if prod(p,typ(:))<>s^3+s^4 then pause,end
681 if prod(p,'*',typ(:))<>s^3+s^4 then pause,end
682 if or(prod(p,1,typ(:))<>[s^3,1+s]) then pause,end
683 if or(prod(p,2,typ(:))<>[s+s^2;s^2]) then pause,end
684 if or(prod(p,3,typ(:))<>p) then pause,end
689 s=%s;p=[s s+1;s^2 1];p(:,:,2)=[1 s;s+1 2];
691 T=list(list(),list('native'),list('double'));
694 if prod(p,typ(:))<>2*s^4+4*s^5+2*s^6 then pause,end
695 if prod(p,'*',typ(:))<>2*s^4+4*s^5+2*s^6 then pause,end
696 if or(prod(p,1,typ(:))<>hypermat([1,2,2],[s^3;1+s;1+s;2*s])) then pause,end
697 if or(prod(p,2,typ(:))<>hypermat([2,1,2],[s+s^2;s^2;s;2+2*s])) then pause,end
698 if or(prod(p,3,typ(:))<>[s,s+s^2;s^2+s^3,2]) then pause,end
699 if or(prod(p,5,typ(:))<>p) then pause,end
703 //=======================================================================
705 //Matrices of rationals
707 s=%s;r=1.0 ./[s s+1;s^2 1];
709 T=list(list(),list('native'),list('double'));
712 if prod(r,typ(:))<>1.0/(s^3+s^4) then pause,end
713 if prod(r,'*',typ(:))<>1.0/(s^3+s^4) then pause,end
714 if or(prod(r,1,typ(:))<>[1,1]./[s^3,1+s]) then pause,end
715 if or(prod(r,2,typ(:))<>[1;1]./[s+s^2;s^2]) then pause,end
716 if or(prod(r,3,typ(:))<>r) then pause,end
720 //=======================================================================
722 //Matrices of booleans
726 for typ=list(list(),list('double'));
727 if prod(b,typ(:))<>0 then pause,end
728 if prod(b,'*',typ(:))<>0 then pause,end
729 if or(prod(b,1,typ(:))<>[0 1]) then pause,end
730 if or(prod(b,2,typ(:))<>[1;0]) then pause,end
731 if or(prod(b,3,typ(:))<>double(b)) then pause,end
735 if prod(b,'native')<>%f then pause,end
737 if prod(b,'*','native')<>%f then pause,end
739 if or(prod(b,1,'native')<>[%f %t]) then pause,end
741 if or(prod(b,2,'native')<>[%t;%f]) then pause,end
743 if or(prod(b,3,'native')<>b) then pause,end
748 b=[%t %t;%f %t];b(1,1,2)=%t;
750 for typ=list(list(),list('double'));
751 if prod(b,typ(:))<>0 then pause,end
752 if prod(b,'*',typ(:))<>0 then pause,end
753 if or(prod(b,1,typ(:))<>hypermat([1,2,2],[0;1;0;0])) then pause,end
754 if or(prod(b,2,typ(:))<>hypermat([2,1,2],[1;0;0;0])) then pause,end
755 if or(prod(b,3,typ(:))<>[1,0;0,0]) then pause,end
756 if or(prod(b,5,typ(:))<>double(b)) then pause,end
760 if prod(b,'native')<>%f then pause,end
762 if prod(b,'*','native')<>%f then pause,end
764 if or(prod(b,1,'native')<>hypermat([1,2,2],[%f;%t;%f;%f])) then pause,end
766 if or(prod(b,2,'native')<>hypermat([2,1,2],[%t;%f;%f;%f])) then pause,end
768 if or(prod(b,3,'native')<>[%t,%f;%f,%f]) then pause,end
770 if or(prod(b,5,'native')<>b) then pause,end
772 //=======================================================================
774 //sparse matrices of floats
776 s=sparse([1 10 2;-1 254 9]);
778 T=list(list(),list('native'),list('double'));
781 if prod(s,typ(:))<>-45720 then pause,end
782 if prod(s,'*',typ(:))<>-45720 then pause,end
783 if or(prod(s,1,typ(:))<>sparse([-1 2540 18])) then pause,end
784 if or(prod(s,2,typ(:))<>sparse([20;-2286])) then pause,end
785 if or(prod(s,3,typ(:))<>s) then pause,end
789 //=======================================================================
791 //sparse matrices of boolean
793 bs=sparse([%t %t %f;%t %t %t]);
795 for typ=list(list(),list('double'));
796 if prod(bs,typ(:))<>0 then pause,end
797 if prod(bs,'*',typ(:))<>0 then pause,end
798 if or(prod(bs,1,typ(:))<>sparse([1,1,0])) then pause,end
799 if or(prod(bs,2,typ(:))<>sparse([0;1])) then pause,end
800 if or(prod(bs,3,typ(:))<>bool2s(bs)) then pause,end
804 if prod(bs,'native')<>%f then pause,end
806 if prod(bs,'*','native')<>%f then pause,end
808 if or(prod(bs,1,'native')<>sparse([%t,%t,%f])) then pause,end
810 if or(prod(bs,2,'native')<>sparse([%f;%t])) then pause,end
812 if or(prod(bs,3,'native')<>bs) then pause,end
815 // TODO : test the "m" option
817 exec SCI/modules/elementary_functions/tests/unit_tests/cumprod.tst
819 // =============================================================================
821 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
823 // Copyright (C) 2010 - INRIA - Serge Steer
825 // Copyright (C) 2012 - Scilab Enterprises - Cedric Delamarre
829 // This file is distributed under the same license as the Scilab package.
831 // =============================================================================
834 // <-- CLI SHELL MODE
841 T=list(list(),list('native'),list('double'));
844 assert_checkequal(cumprod([],typ(:)), []);
845 assert_checkequal(cumprod([],'*',typ(:)), []);
846 assert_checkequal(cumprod([],1,typ(:)), []);
847 assert_checkequal(cumprod([],2,typ(:)), []);
848 assert_checkequal(cumprod([],3,typ(:)), []);
852 //=======================================================================
858 T=list(list(),list('native'),list('double'));
861 assert_checkequal(cumprod(d,typ(:)), [1,2540;254,22860]);
862 assert_checkequal(cumprod(d,'*',typ(:)), [1,2540;254,22860]);
863 assert_checkequal(cumprod(d,1,typ(:)), [1,10;254,90]);
864 assert_checkequal(cumprod(d,2,typ(:)), [1,10;254,2286]);
865 assert_checkequal(cumprod(d,3,typ(:)), d);
869 //hypermatrices of floats
871 d=[1 10;254 9];d(1,1,2)=1;
873 T=list(list(),list('native'),list('double'));
876 assert_checkequal(cumprod(d,typ(:)), hypermat([2,2,2],[1;254;2540;22860;22860;0;0;0]));
877 assert_checkequal(cumprod(d,'*',typ(:)), hypermat([2,2,2],[1;254;2540;22860;22860;0;0;0]));
878 assert_checkequal(cumprod(d,1,typ(:)), hypermat([2,2,2],[1;254;10;90;1;0;0;0]));
879 assert_checkequal(cumprod(d,2,typ(:)), hypermat([2,2,2],[1;254;10;2286;1;0;0;0]));
880 assert_checkequal(cumprod(d,3,typ(:)), hypermat([2,2,2],[1;254;10;9;1;0;0;0]));
881 assert_checkequal(cumprod(d,5,typ(:)), d);
885 //=======================================================================
889 i=uint8([1 10;254 9]);
891 for typ=list(list(),list('native'));
892 assert_checkequal(cumprod(i,typ(:)), uint8([1,236;254,76]));
893 assert_checkequal(cumprod(i,'*',typ(:)), uint8([1,236;254,76]));
894 assert_checkequal(cumprod(i,1,typ(:)), uint8([1,10;254,90]));
895 assert_checkequal(cumprod(i,2,typ(:)), uint8([1,10;254,238]));
896 assert_checkequal(cumprod(i,3,typ(:)), double(i));
900 assert_checkequal(cumprod(i,'double'), [1,2540;254,22860]);
902 assert_checkequal(cumprod(i,'*','double'), [1,2540;254,22860]);
904 assert_checkequal(cumprod(i,1,'double'), [1,10;254,90]);
906 assert_checkequal(cumprod(i,2,'double'), [1,10;254,2286]);
908 assert_checkequal(cumprod(i,3,'double'), double(i));
913 i=uint8([1 10;254 9]);i(1,1,2)=uint8(1);
915 for typ=list(list(),list('native'));
916 assert_checkequal(cumprod(i,typ(:)), hypermat([2,2,2],uint8([1;254;236;76;76;0;0;0])));
917 assert_checkequal(cumprod(i,'*',typ(:)), hypermat([2,2,2],uint8([1;254;236;76;76;0;0;0])));
918 assert_checkequal(cumprod(i,1,typ(:)), hypermat([2,2,2],uint8([1;254;10;90;1;0;0;0])));
919 assert_checkequal(cumprod(i,2,typ(:)), hypermat([2,2,2],uint8([1;254;10;238;1;0;0;0])));
920 assert_checkequal(cumprod(i,3,typ(:)), hypermat([2,2,2],uint8([1;254;10;9;1;0;0;0])));
921 assert_checkequal(cumprod(i,5,typ(:)), double(i));
926 assert_checkequal(cumprod(i,'double'), hypermat([2,2,2],[1;254;2540;22860;22860;0;0;0]));
928 assert_checkequal(cumprod(i,'*','double'), hypermat([2,2,2],[1;254;2540;22860;22860;0;0;0]));
930 assert_checkequal(cumprod(i,1,'double'), hypermat([2,2,2],[1;254;10;90;1;0;0;0]));
932 assert_checkequal(cumprod(i,2,'double'), hypermat([2,2,2],[1;254;10;2286;1;0;0;0]));
934 assert_checkequal(cumprod(i,3,'double'), hypermat([2,2,2],[1;254;10;9;1;0;0;0]));
936 assert_checkequal(cumprod(i,5,'double'), double(i));
939 //=======================================================================
941 //Matrices of Polynomials
943 s=%s;p=[s s+1;s^2 0];
945 T=list(list(),list('native'),list('double'));
948 assert_checkequal(cumprod(p,typ(:)), [s,s^3+s^4;s^3,0*s]);
949 assert_checkequal(cumprod(p,'*',typ(:)), [s,s^3+s^4;s^3,0*s]);
950 assert_checkequal(cumprod(p,1,typ(:)), [s,1+s;s^3,0*s]);
951 assert_checkequal(cumprod(p,2,typ(:)), [s,s+s^2;s^2,0*s]);
952 assert_checkequal(cumprod(p,3,typ(:)), p);
958 s=%s;p=[s s+1;s^2 0];p(1,1,2)=-1;
960 T=list(list(),list('native'),list('double'));
963 assert_checkequal(cumprod(p,typ(:)), hypermat([2,2,2],[s;s^3;s^3+s^4;0*s;0*s;0*s;0*s;0*s]));
964 assert_checkequal(cumprod(p,'*',typ(:)), hypermat([2,2,2],[s;s^3;s^3+s^4;0*s;0*s;0*s;0*s;0*s]));
965 assert_checkequal(cumprod(p,1,typ(:)), hypermat([2,2,2],[s;s^3;1+s;0*s;-1;0*s;0*s;0*s]));
966 assert_checkequal(cumprod(p,2,typ(:)), hypermat([2,2,2],[s;s^2;s+s^2;0*s;-1;0*s;0*s;0*s]));
967 assert_checkequal(cumprod(p,3,typ(:)), hypermat([2,2,2],[s;s^2;1+s;0*s;-s;0*s;0*s;0*s]));
968 assert_checkequal(cumprod(p,5,typ(:)), p);
971 //=======================================================================
973 //Matrices of rationals
975 s=%s;r=1.0 ./[s s+1;s^2 1];
977 T=list(list(),list('native'),list('double'));
980 assert_checkequal(cumprod(r,typ(:)), [1,1;1,1]./[s,s^3+s^4;s^3,s^3+s^4]);
981 assert_checkequal(cumprod(r,'*',typ(:)), [1,1;1,1]./[s,s^3+s^4;s^3,s^3+s^4]);
982 assert_checkequal(cumprod(r,1,typ(:)), [1,1;1,1]./[s,1+s;s^3,1+s]);
983 assert_checkequal(cumprod(r,2,typ(:)), [1,1;1,1]./[s,s+s^2;s^2,s^2]);
984 assert_checkequal(cumprod(r,3,typ(:)), r);
988 //=======================================================================
990 ///Matrices of boolean
995 for typ=list(list(),list('double'));
996 assert_checkequal(cumprod(b,typ(:)), [1,0;0,0]);
997 assert_checkequal(cumprod(b,'*',typ(:)), [1,0;0,0]);
998 assert_checkequal(cumprod(b,1,typ(:)), [1,1;0,1]);
999 assert_checkequal(cumprod(b,2,typ(:)), [1,1;0,0]);
1000 assert_checkequal(cumprod(b,3,typ(:)), double(b));
1003 assert_checkequal(cumprod(b,'native'), [%t,%f;%f,%f]);
1005 assert_checkequal(cumprod(b,'*','native'), [%t,%f;%f,%f]);
1007 assert_checkequal(cumprod(b,1,'native'), [%t,%t;%f,%t]);
1009 assert_checkequal(cumprod(b,2,'native'), [%t,%t;%f,%f]);
1011 assert_checkequal(cumprod(b,3,'native'), b);
1014 //with hypermatrices
1016 b=[%t %t;%f %t];b(1,1,2)=%f;
1018 for typ=list(list(),list('double'));
1019 assert_checkequal(cumprod(b,typ(:)), hypermat([2,2,2],[1;0;0;0;0;0;0;0]));
1020 assert_checkequal(cumprod(b,'*',typ(:)), hypermat([2,2,2],[1;0;0;0;0;0;0;0]));
1021 assert_checkequal(cumprod(b,1,typ(:)), hypermat([2,2,2],[1;0;1;1;0;0;0;0]));
1022 assert_checkequal(cumprod(b,2,typ(:)), hypermat([2,2,2],[1;0;1;0;0;0;0;0]));
1023 assert_checkequal(cumprod(b,3,typ(:)), hypermat([2,2,2],[1;0;1;1;0;0;0;0]));
1024 assert_checkequal(cumprod(b,5,typ(:)), double(b));
1028 assert_checkequal(cumprod(b,'native'), hypermat([2,2,2],[%t;%f;%f;%f;%f;%f;%f;%f]));
1030 assert_checkequal(cumprod(b,'*','native'), hypermat([2,2,2],[%t;%f;%f;%f;%f;%f;%f;%f]));
1032 assert_checkequal(cumprod(b,1,'native'), hypermat([2,2,2],[%t;%f;%t;%t;%f;%f;%f;%f]));
1034 assert_checkequal(cumprod(b,2,'native'), hypermat([2,2,2],[%t;%f;%t;%f;%f;%f;%f;%f]));
1036 assert_checkequal(cumprod(b,3,'native'), hypermat([2,2,2],[%t;%f;%t;%t;%f;%f;%f;%f]));
1038 assert_checkequal(cumprod(b,5,'native'), b);
1041 //=======================================================================
1043 //sparse matrices of floats
1045 s=sparse([1 10 0;-1 0 9]);
1047 T=list(list(),list('native'),list('double'));
1050 assert_checkequal(cumprod(s,typ(:)), sparse([1,1;1,2;2,1],[1;-10;-1],[2,3]));
1051 assert_checkequal(cumprod(s,'*',typ(:)), sparse([1,1;1,2;2,1],[1;-10;-1],[2,3]));
1052 assert_checkequal(cumprod(s,1,typ(:)), sparse([1,1;1,2;2,1],[1;10;-1],[2,3]));
1053 assert_checkequal(cumprod(s,2,typ(:)), sparse([1,1;1,2;2,1],[1;10;-1],[2,3]));
1054 assert_checkequal(cumprod(s,3,typ(:)), s);
1058 //=======================================================================
1060 //sparse matrices of boolean
1062 bs=sparse([%t %t %f;%t %t %t]);
1064 for typ=list(list(),list('double'));
1065 assert_checkequal(cumprod(bs,typ(:)), sparse([1,1;1,2;2,1;2,2],[1;1;1;1],[2,3]));
1066 assert_checkequal(cumprod(bs,'*',typ(:)), sparse([1,1;1,2;2,1;2,2],[1;1;1;1],[2,3]));
1067 assert_checkequal(cumprod(bs,1,typ(:)), sparse([1,1;1,2;2,1;2,2],[1;1;1;1],[2,3]));
1068 assert_checkequal(cumprod(bs,2,typ(:)), sparse([1,1;1,2;2,1;2,2;2,3],[1;1;1;1;1],[2,3]));
1069 assert_checkequal(cumprod(bs,3,typ(:)), bool2s(bs));
1073 assert_checkequal(cumprod(bs,'native'), sparse([1,1;1,2;2,1;2,2],[%t;%t;%t;%t],[2,3]));
1075 assert_checkequal(cumprod(bs,'*','native'), sparse([1,1;1,2;2,1;2,2],[%t;%t;%t;%t],[2,3]));
1078 assert_checkequal(cumprod(bs,1,'native'), sparse([1,1;1,2;2,1;2,2],[%t;%t;%t;%t],[2,3]));
1080 assert_checkequal(cumprod(bs,2,'native'), sparse([1,1;1,2;2,1;2,2;2,3],[%t;%t;%t;%t;%t],[2,3]));
1082 assert_checkequal(cumprod(bs,3,'native'), bs);
1085 // TODO : test the "m" option