1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2012 - Scilab Enterprises - Sylvestre Ledru
4 // Copyright (C) 2013, 2014 - Scilab Enterprises - Paul Bignier
5 // Copyright (C) 2019 - Samuel GOUGEON
7 // This file is distributed under the same license as the Scilab package.
8 // =============================================================================
10 // <-- CLI SHELL MODE -->
11 // <-- NO CHECK REF -->
12 // <-- ENGLISH IMPOSED -->
15 x = [1 2 3 4; 5 6 7 8];
18 assert_checkequal([5 6 7 8; 1 2 3 4], y);
23 assert_checkequal([4 3 2 1; 8 7 6 5], y);
26 x = matrix(1:24, [3 2 4]);
28 ref = matrix( [19;20;21;22;23;24;13;14;15;16;17;18;7;8;9;10;11;12;1;2;3;4;5;6], [3 2 4]);
30 assert_checkequal(y, ref);
33 y = flipdim(x*%i, dim);
34 assert_checkequal(y, ref*%i);
36 // Integer-encoded numbers:
37 y = flipdim(int16(x), dim);
38 assert_checkequal(y, int16(ref));
41 ref_bool = matrix([%T;%T;%T;%T;%T;%T;%T;%T;%T;%T;%T;%T;%F;%F;%F;%T;%T;%F;%F;%F;%F;%F;%F;%F], [3 2 4]);
42 y = flipdim(x < 15, 2);
43 assert_checkequal(y, ref_bool);
46 x_txt = matrix(strsplit("a":"x", 1:23), 4, 6);
47 x_txt = x_txt + x_txt;
48 ref_txt = ["uu" "qq" "mm" "ii" "ee" "aa"; "vv" "rr" "nn" "jj" "ff" "bb";
49 "ww" "ss" "oo" "kk" "gg" "cc";
50 "xx" "tt" "pp" "ll" "hh" "dd" ];
51 y = flipdim(x_txt, 2);
52 assert_checkequal(y, ref_txt);
55 x_pol = inv_coeff([x(:,:,1) x(:,:,2) x(:,:,3) x(:,:,4) [0;1;2]], 2);
57 ref_pol = [3+12*X+21*X^2 6+15*X+24*X^2 9+18*X+2*X^2;
58 2+11*X+20*X^2 5+14*X+23*X^2 8+17*X+X^2;
59 1+10*X+19*X^2 4+13*X+22*X^2 7+16*X ];
60 y = flipdim(x_pol, 1);
61 assert_checkequal(y, ref_pol);
67 assert_checkequal(y, ref_r);
70 x = matrix(1:48, [3 2 4 2]);
72 ref = matrix([19;20;21;22;23;24;13;14;15;16;17;18;7;8;9;10;11;12;1;2;3;4;5;6;43;44;45;46;47;48;37;38;39;40;41;42;31;32;33;34;35;36;25;26;27;28;29;30], [3 2 4 2]);
74 assert_checkequal(y, ref);
79 x = [0 1 2 3 4 5 6 7 8 9 10 11];
82 ref1 = [11 10 9 8 7 6 5 4 3 2 1 0];
84 y = flipdim(x, 2, 1); // Present action.
85 assert_checkequal(y, ref1);
87 ref2 = [10 11 8 9 6 7 4 5 2 3 0 1];
89 y = flipdim(x, 2, 2); // Block size = 2.
90 assert_checkequal(y, ref2);
92 ref3 = [9 10 11 6 7 8 3 4 5 0 1 2];
95 assert_checkequal(y, ref3);
97 ref4 = [8 9 10 11 4 5 6 7 0 1 2 3];
100 assert_checkequal(y, ref4);
102 ref5 = [6 7 8 9 10 11 0 1 2 3 4 5];
103 ref5 = [ref5 ; ref5];
104 y = flipdim(x, 2, 6);
105 assert_checkequal(y, ref5);
109 refMsg = msprintf(_("%s: Wrong value for input argument #%d: A divisor of the selected dimension size expected.\n"), "flipdim", 3);
110 assert_checkerror("y = flipdim(x, 2, 5)", refMsg); // size(x) = [2 12] and 5 does not divide 12.
112 // With an hypermatrix
113 // -------------------
114 h = matrix(1:16,2,4,2);
122 ref = cat(3, [5 7 1 3; 6 8 2 4], [13 15 9 11; 14 16 10 12]);
123 assert_checkequal(flipdim(h,2,2), ref);
125 h = permute(h,[2 1 3]);
137 ref = cat(3, [5 6; 7 8; 1 2; 3 4], [13 14; 15 16; 9 10; 11 12]);
138 assert_checkequal(flipdim(h,1,2), ref);
140 h = permute(h,[3 2 1]);
154 ref = cat(3,[5 6 ; 13 14], [7 8 ; 15 16], [1 2 ; 9 10], [3 4 ; 11 12]);
155 assert_checkequal(flipdim(h,3,2), ref);