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

//full

x=rand(); // scalar
i1=ones(1,4);
i2=ones(2,4);
i3=ones(2,2,2);
assert_checkequal(size(x(i1)), [1 4]);
assert_checkequal(size(x(i1')), [4 1]);
assert_checkequal(size(x(i2)), [2 4]);
assert_checkequal(size(x(i3)), [2 2 2]);

x=rand(1,4); // row vector
i1=ones(1,4);
i2=ones(2,4);
i3=ones(2,2,2);
assert_checkequal(size(x(i1)), [1 4]);
assert_checkequal(size(x(i1')), [1 4]);
assert_checkequal(size(x(i2)), [2 4]);
assert_checkequal(size(x(i3)), [2 2 2]);

x=rand(4,1); // column vector
i1=ones(1,4);
i2=ones(2,4);
i3=ones(2,2,2);
assert_checkequal(size(x(i1)), [4 1]);
assert_checkequal(size(x(i1')), [4 1]);
assert_checkequal(size(x(i2)), [2 4]);
assert_checkequal(size(x(i3)), [2 2 2]);

x=rand(3,3); // matrix
i1=ones(1,4);
i2=ones(2,4);
i3=ones(2,2,2);
assert_checkequal(size(x(i1)), [1 4]);
assert_checkequal(size(x(i1')), [4 1]);
assert_checkequal(size(x(i2)), [2 4]);
assert_checkequal(size(x(i3)), [2 2 2]);

x=rand(3,3,3); // hypermatrix
i1=ones(1,4);
i2=ones(2,4);
i3=ones(2,2,2);
assert_checkequal(size(x(i1)), [1 4]);
assert_checkequal(size(x(i1')), [4 1]);
assert_checkequal(size(x(i2)), [2 4]);
assert_checkequal(size(x(i3)), [2 2 2]);

//sparse

x=sparse(rand());
i1=ones(1,4);
i2=ones(2,4);
i3=ones(2,2,2);
assert_checkequal(size(x(i1)), [1 4]);
assert_checkequal(size(x(i1')), [4 1]);
assert_checkequal(size(x(i2)), [2 4]);
assert_checkequal(size(x(i3)), [8 1]);

x=sparse(rand(1,4)); // row vector
i1=ones(1,4);
i2=ones(2,4);
i3=ones(2,2,2);
assert_checkequal(size(x(i1)), [1 4]);
assert_checkequal(size(x(i1')), [1 4]);
assert_checkequal(size(x(i2)), [2 4]);
assert_checkequal(size(x(i3)), [8 1]);

x=sparse(rand(4,1)); // column vector
i1=ones(1,4);
i2=ones(2,4);
i3=ones(2,2,2);
assert_checkequal(size(x(i1)), [4 1]);
assert_checkequal(size(x(i1')), [4 1]);
assert_checkequal(size(x(i2)), [2 4]);
assert_checkequal(size(x(i3)), [8 1]);

x=sparse(rand(3,3)); // matrix
i1=ones(1,4);
i2=ones(2,4);
i3=ones(2,2,2);
assert_checkequal(size(x(i1)), [1 4]);
assert_checkequal(size(x(i1')), [4 1]);
assert_checkequal(size(x(i2)), [2 4]);
assert_checkequal(size(x(i3)), [8 1]);


//sparse boolean

x=sparse(rand()>0.5);
i1=ones(1,4);
i2=ones(2,4);
i3=ones(2,2,2);
assert_checkequal(size(x(i1)), [1 4]);
assert_checkequal(size(x(i1')), [4 1]);
assert_checkequal(size(x(i2)), [2 4]);
assert_checkequal(size(x(i3)), [8 1]);

x=sparse(rand(1,4)>0.5); // row vector
i1=ones(1,4);
i2=ones(2,4);
i3=ones(2,2,2);
assert_checkequal(size(x(i1)), [1 4]);
assert_checkequal(size(x(i1')), [1 4]);
assert_checkequal(size(x(i2)), [2 4]);
assert_checkequal(size(x(i3)), [8 1]);

x=sparse(rand(4,1)>0.5); // column vector
i1=ones(1,4);
i2=ones(2,4);
i3=ones(2,2,2);
assert_checkequal(size(x(i1)), [4 1]);
assert_checkequal(size(x(i1')), [4 1]);
assert_checkequal(size(x(i2)), [2 4]);
assert_checkequal(size(x(i3)), [8 1]);

x=sparse(rand(3,3)>0.5); // matrix
i1=ones(1,4);
i2=ones(2,4);
i3=ones(2,2,2);
assert_checkequal(size(x(i1)), [1 4]);
assert_checkequal(size(x(i1')), [4 1]);
assert_checkequal(size(x(i2)), [2 4]);
assert_checkequal(size(x(i3)), [8 1]);