[ast] upgrade sparse extraction after 5dc990d1
[scilab.git] / scilab / modules / ast / tests / nonreg_tests / bug_14487.tst
1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2018 - St├ęphane MOTTELET
4 //
5 //  This file is distributed under the same license as the Scilab package.
6 // =============================================================================
7 //
8 // <-- CLI SHELL MODE -->
9 // <-- NO CHECK REF -->
10 //
11 // <-- Non-regression test for bug 14487 -->
12 //
13 // <-- Bugzilla URL -->
14 // http://bugzilla.scilab.org/14487
15 //
16 // <-- Short Description -->
17 // Matrix indexing is not coherent with MATLAB convention
18
19 //full
20
21 x=rand(); // scalar
22 i1=ones(1,4);
23 i2=ones(2,4);
24 i3=ones(2,2,2);
25 assert_checkequal(size(x(i1)), [1 4]);
26 assert_checkequal(size(x(i1')), [4 1]);
27 assert_checkequal(size(x(i2)), [2 4]);
28 assert_checkequal(size(x(i3)), [2 2 2]);
29
30 x=rand(1,4); // row vector
31 i1=ones(1,4);
32 i2=ones(2,4);
33 i3=ones(2,2,2);
34 assert_checkequal(size(x(i1)), [1 4]);
35 assert_checkequal(size(x(i1')), [1 4]);
36 assert_checkequal(size(x(i2)), [2 4]);
37 assert_checkequal(size(x(i3)), [2 2 2]);
38
39 x=rand(4,1); // column vector
40 i1=ones(1,4);
41 i2=ones(2,4);
42 i3=ones(2,2,2);
43 assert_checkequal(size(x(i1)), [4 1]);
44 assert_checkequal(size(x(i1')), [4 1]);
45 assert_checkequal(size(x(i2)), [2 4]);
46 assert_checkequal(size(x(i3)), [2 2 2]);
47
48 x=rand(3,3); // matrix
49 i1=ones(1,4);
50 i2=ones(2,4);
51 i3=ones(2,2,2);
52 assert_checkequal(size(x(i1)), [1 4]);
53 assert_checkequal(size(x(i1')), [4 1]);
54 assert_checkequal(size(x(i2)), [2 4]);
55 assert_checkequal(size(x(i3)), [2 2 2]);
56
57 x=rand(3,3,3); // hypermatrix
58 i1=ones(1,4);
59 i2=ones(2,4);
60 i3=ones(2,2,2);
61 assert_checkequal(size(x(i1)), [1 4]);
62 assert_checkequal(size(x(i1')), [4 1]);
63 assert_checkequal(size(x(i2)), [2 4]);
64 assert_checkequal(size(x(i3)), [2 2 2]);
65
66 //sparse
67
68 x=sparse(rand());
69 i1=ones(1,4);
70 i2=ones(2,4);
71 i3=ones(2,2,2);
72 assert_checkequal(size(x(i1)), [1 4]);
73 assert_checkequal(size(x(i1')), [4 1]);
74 assert_checkequal(size(x(i2)), [2 4]);
75 assert_checkequal(size(x(i3)), [8 1]);
76
77 x=sparse(rand(1,4)); // row vector
78 i1=ones(1,4);
79 i2=ones(2,4);
80 i3=ones(2,2,2);
81 assert_checkequal(size(x(i1)), [1 4]);
82 assert_checkequal(size(x(i1')), [1 4]);
83 assert_checkequal(size(x(i2)), [2 4]);
84 assert_checkequal(size(x(i3)), [8 1]);
85
86 x=sparse(rand(4,1)); // column vector
87 i1=ones(1,4);
88 i2=ones(2,4);
89 i3=ones(2,2,2);
90 assert_checkequal(size(x(i1)), [4 1]);
91 assert_checkequal(size(x(i1')), [4 1]);
92 assert_checkequal(size(x(i2)), [2 4]);
93 assert_checkequal(size(x(i3)), [8 1]);
94
95 x=sparse(rand(3,3)); // matrix
96 i1=ones(1,4);
97 i2=ones(2,4);
98 i3=ones(2,2,2);
99 assert_checkequal(size(x(i1)), [1 4]);
100 assert_checkequal(size(x(i1')), [4 1]);
101 assert_checkequal(size(x(i2)), [2 4]);
102 assert_checkequal(size(x(i3)), [8 1]);
103
104
105 //sparse boolean
106
107 x=sparse(rand()>0.5);
108 i1=ones(1,4);
109 i2=ones(2,4);
110 i3=ones(2,2,2);
111 assert_checkequal(size(x(i1)), [1 4]);
112 assert_checkequal(size(x(i1')), [4 1]);
113 assert_checkequal(size(x(i2)), [2 4]);
114 assert_checkequal(size(x(i3)), [8 1]);
115
116 x=sparse(rand(1,4)>0.5); // row vector
117 i1=ones(1,4);
118 i2=ones(2,4);
119 i3=ones(2,2,2);
120 assert_checkequal(size(x(i1)), [1 4]);
121 assert_checkequal(size(x(i1')), [1 4]);
122 assert_checkequal(size(x(i2)), [2 4]);
123 assert_checkequal(size(x(i3)), [8 1]);
124
125 x=sparse(rand(4,1)>0.5); // column vector
126 i1=ones(1,4);
127 i2=ones(2,4);
128 i3=ones(2,2,2);
129 assert_checkequal(size(x(i1)), [4 1]);
130 assert_checkequal(size(x(i1')), [4 1]);
131 assert_checkequal(size(x(i2)), [2 4]);
132 assert_checkequal(size(x(i3)), [8 1]);
133
134 x=sparse(rand(3,3)>0.5); // matrix
135 i1=ones(1,4);
136 i2=ones(2,4);
137 i3=ones(2,2,2);
138 assert_checkequal(size(x(i1)), [1 4]);
139 assert_checkequal(size(x(i1')), [4 1]);
140 assert_checkequal(size(x(i2)), [2 4]);
141 assert_checkequal(size(x(i3)), [8 1]);
142
143
144
145
146
147