2daa9b2fb8e8b1c8d2ba86c923cf7be80a67c1b9
[scilab.git] / scilab / modules / ast / tests / unit_tests / sparse.dia.ref
1 //
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2012 - DIGITEO - Antoine ELIAS
4 // Copyright (C) 2012 - Scilab Enterprises - Cedric Delamarre
5 //
6 // Copyright (C) 2012 - 2016 - Scilab Enterprises
7 //
8 // This file is hereby licensed under the terms of the GNU GPL v2.0,
9 // pursuant to article 5.3.4 of the CeCILL v.2.1.
10 // This file was originally licensed under the terms of the CeCILL v2.1,
11 // and continues to be available under such terms.
12 // For more information, see the COPYING file which you should have received
13 // along with this program.
14 //
15 //
16 // <-- CLI SHELL MODE -->
17 // sparse function
18 //from dense form
19 s=[ 1,0,0,0,0,0,0;
20 0,1,0,0,0,0,0;
21 0,0,1,0,0,0,0;
22 0,0,1,1,0,0,0;
23 0,0,1,1,1,0,0;
24 0,0,1,1,0,1,0;
25 0,0,1,1,0,1,1];
26 sp=sparse(s);
27 assert_checkequal(size(s), size(sp));
28 assert_checkequal(full(sp), s);
29 //from coord
30 sp = sparse([1 1;2 2;3 3;4 3;4 4;5 3;5 4;5 5;6 3;6 4;6 6;7 3;7 4;7 6;7 7], [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]);
31 assert_checkequal(size(s), size(sp));
32 assert_checkequal(full(sp), s);
33 //with size
34 newsp = sparse([], [], [10,20]);
35 assert_checkequal(size(newsp), [10,20]);
36 //concatenation
37 spc = [sp [1; 0; 1; 0; 1; 0; 1]];
38 sc = [s [1; 0; 1; 0; 1; 0; 1]];
39 assert_checkequal(full(spc), sc);
40 spc = [sp ;[1 0 1 0 1 0 1]];
41 sc = [s ;[1 0 1 0 1 0 1]];
42 assert_checkequal(full(spc), sc);
43 spc = [[1; 0; 1; 0; 1; 0; 1] sp];
44 sc = [[1; 0; 1; 0; 1; 0; 1] s];
45 assert_checkequal(full(spc), sc);
46 spc = [[1 0 1 0 1 0 1]; sp];
47 sc = [[1 0 1 0 1 0 1]; s];
48 assert_checkequal(full(spc), sc);
49 sc = [s s];
50 spc = [sp sp];
51 assert_checkequal(full(spc), sc);
52 sc = [s; s];
53 spc = [sp; sp];
54 assert_checkequal(full(spc), sc);
55 sc = [s s];
56 spc = [sp sp];
57 assert_checkequal(full(spc), sc);
58 A = sparse(1);
59 A = [A 0];
60 A = [A 0];
61 A = [A 0];
62 assert_checkequal(full(A), [1 0 0 0]);
63 assert_checkequal(size(A, "c"), 4);
64 //extraction
65 assert_checkequal(full(sp(:)), s(:));
66 assert_checkequal(size(sp(:)), size(s(:)));
67 assert_checkequal(full(sp(1:7, 1:7)), s(1:7, 1:7));
68 assert_checkequal(size(sp(1:7, 1:7)), size(s(1:7, 1:7)));
69 assert_checkequal(full(sp(1:4, :)), s(1:4, :));
70 assert_checkequal(size(sp(1:4, :)), size(s(1:4, :)));
71 assert_checkequal(full(sp(:, 2:6)), s(:, 2:6));
72 assert_checkequal(size(sp(:, 2:6)), size(s(:, 2:6)));
73 assert_checkequal(full(sp(:, $)), s(:, $));
74 assert_checkequal(size(sp(:, $)), size(s(:, $)));
75 //next tests get from old module sparse (Scilab 5.4)
76 ij=[1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6];
77 v=[1;2;3;4;5;6;7;8;9];
78 ij1=[1 6;1 2;6 5];
79 v1=[-1;-1;-1];
80 vc=v+%i*(21:29)';
81 v1c=v1+%i*[0;0.3;-1.2];
82 zer=sparse([],[],[6,6]);
83 a=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],1:9,[6 6]);
84 b=sparse([1 6;1 2;6 5],[-1;-1;-1],[6 6]);
85 ma=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],-(1:9),[6 6]);
86 mb=sparse([1 6;1 2;6 5],-[-1;-1;-1],[6 6]);
87 ac=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],(1:9)+%i*(21:29),[6 6]);
88 bc=sparse([1 6;1 2;6 5],[-1;-1;-1]+%i*[0;0.3;-1.2],[6 6]);
89 mac=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],-(1:9)-%i*(21:29),[6 6]);
90 mbc=sparse([1 6;1 2;6 5],[1;1;1]+%i*[0;-0.3;1.2],[6 6]);
91 //-------------------------------------------------------------
92 //test des primitives sparse, full
93 //--------------------------------------------------------------
94 //  -- for real matrix
95 assert_checkequal(full(sparse(0.3)), 0.3);
96 v= zeros(1,3);v(3)=5;v(1)=1;
97 assert_checkequal(full(sparse([1 1;1 3],[1 5])), v);
98 v= zeros(1,300);v(300)=5;v(1)=1;
99 assert_checkequal(full(sparse([1 1;1 300],[1 5])), v);
100 v= zeros(3,1);v(3)=5;v(1)=1;
101 assert_checkequal(full(sparse([1 1;3 1],[1 5])), v);
102 v= zeros(300,1);v(300)=5;v(1)=1;
103 assert_checkequal(full(sparse([1 1;300 1],[1 5])), v);
104 sp=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],1:9,[6 6]);
105 a=[0,0,3,0,2,1;;5,0,0,4,0,0;0,0,0,0,0,0;0,0,7,6,0,0;8,0,0,0,0,0;0,0,0,0,0,9];
106 assert_checkequal(full(sp), a);
107 sp=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],1:9,[8 6]);a(8,6)=0;
108 assert_checkequal(full(sp), a);
109 assert_checkequal(full(sparse([],[],[4 10])),  zeros(4,10));
110 v=sparse([2 1;3 1;4 1;6 1],[10;11;12;13],[6,1]);
111 a=[0;10;11;12;0;13];
112 assert_checkequal(full(v), a);
113 v=sparse([1 2;1 3;1 4;1 6],[10;11;12;13],[1,6]);
114 a=[0,10,11,12,0,13];
115 assert_checkequal(full(v), a);
116 //  -- for complex matrix
117 sp=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],(1:9)+%i*(21:29),[6 6]);
118 a=[0,0,3+%i*23,0,2+%i*22,1+%i*21
119 5+%i*25,0,0,4+%i*24,0,0
120 0,0,0,0,0,0
121 0,0,7+%i*27,6+%i*26,0,0
122 8+%i*28,0,0,0,0,0
123 0,0,0,0,0,9+%i*29];
124 assert_checkequal(full(sp), a);
125 sp=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],(1:9)+%i*(21:29),[8 6]);
126 a(8,6)=0;
127 assert_checkequal(full(sp), a);
128 v=sparse([2 1;3 1;4 1;6 1],[10-3*%i;11;12+5*%i;13+0.5*%i],[6,1]);
129 a=[0;10-%i*3;11;12+%i*5;0;13+%i*0.5];
130 assert_checkequal(full(v), a);
131 v=sparse([1 2;1 3;1 4;1 6],[10-3*%i;11;12+5*%i;13+0.5*%i],[1,6]);
132 a=[0,10-%i*3,11,12+%i*5,0,13+%i*0.5];
133 assert_checkequal(full(v), a);
134 //-----------------------------------------------
135 // addition and substraction tests
136 //-----------------------------------------------
137 // -- real real
138 a=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],1:9,[6 6]);
139 b=sparse([1 6;1 2;6 5],[-1;-1;-1],[6 6]);
140 v=sparse([2 1;3 1;4 1;6 1],[10;11;12;13],[6,1]);
141 vt=sparse([1 2;1 3;1 4;1 6],[10;11;12;13],[1,6]);
142 ma=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],-(1:9),[6 6]);
143 mb=sparse([1 6;1 2;6 5],-[-1;-1;-1],[6 6]);
144 zer=sparse([],[],[6,6]);
145 ac=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],(1:9)+%i*(21:29),[6 6]);
146 bc=sparse([1 6;1 2;6 5],[-1;-1;-1]+%i*[0;0.3;-1.2],[6 6]);
147 vc=sparse([2 1;3 1;4 1;6 1],[10-3*%i;11;12+5*%i;13+0.5*%i],[6,1]);
148 vct=sparse([1 2;1 3;1 4;1 6],[10-3*%i;11;12+5*%i;13+0.5*%i],[1,6]);
149 mac=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],-(1:9)-%i*(21:29),[6 6]);
150 mbc=sparse([1 6;1 2;6 5],[1;1;1]+%i*[0;-0.3;1.2],[6 6]);
151 assert_checkequal(full(v+sparse([],[],[6,1])), full(v));
152 assert_checkequal(full(sparse([],[],[6,1])+v), full(v));
153 assert_checkequal(full(v+v), full(v)+full(v));
154 assert_checkequal(full(v-v), full(v)-full(v));
155 assert_checkequal(full(vt+sparse([],[],[1,6])), full(vt));
156 assert_checkequal(full(vt+vt), full(vt)+full(vt));
157 assert_checkequal(full(vt-vt), full(vt)-full(vt));
158 assert_checkequal(full(zer+zer),  zeros(6,6));
159 assert_checkequal(full(a+a), full(a)+full(a));
160 assert_checkequal(full(b+b), full(b)+full(b));
161 assert_checkequal(full(a+zer), full(a));
162 assert_checkequal(full(zer+a), full(a));
163 assert_checkequal(full(b+a), full(b)+full(a));
164 assert_checkequal(full(a+b), full(b)+full(a));
165 assert_checkequal(full(a+ma), full(a)+full(ma));
166 assert_checkequal(full(a-a), full(a)-full(a));
167 assert_checkequal(full(a-ma), full(a)-full(ma));
168 assert_checkequal(full(b-mb), full(b)-full(mb));
169 assert_checkequal(full(a-zer), full(a));
170 assert_checkequal(full(zer-a), -full(a));
171 assert_checkequal(full(a-mb), full(a)-full(mb));
172 //  -- real complex
173 assert_checkequal(full(sparse([],[],[6,1])+vc), full(vc));
174 assert_checkequal(full(v+vc), full(v)+full(vc));
175 assert_checkequal(full(v-vc), full(v)-full(vc));
176 assert_checkequal(full(vt+vct), full(vt)+full(vct));
177 assert_checkequal(full(vt-vct), full(vt)-full(vct));
178 assert_checkequal(full(a+ac), full(a)+full(ac));
179 assert_checkequal(full(b+bc), full(b)+full(bc));
180 assert_checkequal(full(a+bc), full(a)+full(bc));
181 assert_checkequal(full(zer+ac), full(zer)+full(ac));
182 assert_checkequal(full(b+ac), full(b)+full(ac));
183 assert_checkequal(full(a-ac), full(a)-full(ac));
184 assert_checkequal(full(b-bc), full(b)-full(bc));
185 assert_checkequal(full(a-bc), full(a)-full(bc));
186 assert_checkequal(full(zer-ac), full(zer)-full(ac));
187 assert_checkequal(full(b-ac), full(b)-full(ac));
188 // -- complex real
189 assert_checkequal(full(vc+v), full(vc)+full(v));
190 assert_checkequal(full(vc-v), full(vc)-full(v));
191 assert_checkequal(full(vct+vt), full(vct)+full(vt));
192 assert_checkequal(full(vct-vt), full(vct)-full(vt));
193 assert_checkequal(full(ac+a), full(ac)+full(a));
194 assert_checkequal(full(bc+b), full(bc)+full(b));
195 assert_checkequal(full(ac+b), full(ac)+full(b));
196 assert_checkequal(full(ac+zer), full(zer)+full(ac));
197 assert_checkequal(full(bc+a), full(bc)+full(a));
198 assert_checkequal(full(ac-a), full(ac)-full(a));
199 assert_checkequal(full(bc-b), full(bc)-full(b));
200 assert_checkequal(full(ac-b), full(ac)-full(b));
201 assert_checkequal(full(ac-zer), -full(zer)+full(ac));
202 assert_checkequal(full(bc-a), full(bc)-full(a));
203 // -- complex complex
204 assert_checkequal(full(vc+vc), full(vc)+full(vc));
205 assert_checkequal(full(vc-vc), full(vc)-full(vc));
206 assert_checkequal(full(vct+vct), full(vct)+full(vct));
207 assert_checkequal(full(vct-vct), full(vct)-full(vct));
208 assert_checkequal(full(ac+ac), full(ac)+full(ac));
209 assert_checkequal(full(bc+bc), full(bc)+full(bc));
210 assert_checkequal(full(ac+bc), full(ac)+full(bc));
211 assert_checkequal(full(bc+ac), full(bc)+full(ac));
212 assert_checkequal(real(full(ac-ac)), full(zer));
213 assert_checkequal(imag(full(ac-ac)), full(zer));
214 assert_checkequal(real(full(bc-bc)), full(zer));
215 assert_checkequal(imag(full(bc-bc)), full(zer));
216 assert_checkequal(full(ac-bc), full(ac)-full(bc));
217 assert_checkequal(full(bc-ac), full(bc)-full(ac));
218 // sparse full and full sparse operation (soft coded apoerations)
219 assert_checkequal(full(a+1), full(a)+1);
220 assert_checkequal(full(1+a), full(a)+1);
221 assert_checkequal(full(a+ones(6,6)), full(a)+ones(6,6));
222 assert_checkequal(full(ones(6,6)+a), full(a)+ones(6,6));
223 assert_checkequal(full(a+2*eye()), full(a)+2*eye());
224 assert_checkequal(full(2*eye()+a), full(a)+2*eye());
225 assert_checkequal(full(a-1), full(a)-1);
226 assert_checkequal(full(1-a), 1-full(a));
227 assert_checkequal(full(a-ones(6,6)), full(a)-ones(6,6));
228 assert_checkequal(full(ones(6,6)-a), ones(6,6)-full(a));
229 assert_checkequal(full(a-2*eye()), full(a)-2*eye());
230 assert_checkequal(full(2*eye()-a), 2*eye()-full(a));
231 assert_checkequal(full(ac+1), full(ac)+1);
232 assert_checkequal(full(1+ac), full(ac)+1);
233 assert_checkequal(full(ac+ones(6,6)), full(ac)+ones(6,6));
234 assert_checkequal(full(ones(6,6)+ac), full(ac)+ones(6,6));
235 assert_checkequal(full(ac+2*eye()), full(ac)+2*eye());
236 assert_checkequal(full(2*eye()+ac), full(ac)+2*eye());
237 assert_checkequal(full(ac-1), full(ac)-1);
238 assert_checkequal(full(1-ac), 1-full(ac));
239 assert_checkequal(full(ac-ones(6,6)), full(ac)-ones(6,6));
240 assert_checkequal(full(ones(6,6)-ac), ones(6,6)-full(ac));
241 assert_checkequal(full(ac-2*eye()), full(ac)-2*eye());
242 assert_checkequal(full(2*eye()-ac), 2*eye()-full(ac));
243 assert_checkequal(full(ac+full(bc)), full(ac)+full(bc));
244 assert_checkequal(full(ac-full(bc)), full(ac)-full(bc));
245 assert_checkequal(full(full(ac)+full(bc)), full(ac)+full(bc));
246 //-----------------------------------------------
247 // multiplication tests
248 //-----------------------------------------------
249 // real x real
250 // sparse scalar , saclar sparse
251 assert_checkequal(full(a*2), full(a)*2);
252 assert_checkequal(full(2*a), full(a)*2);
253 assert_checkequal(a*[], []);
254 assert_checkequal([]*a, []);
255 c=rand(6,6);
256 assert_checkequal(a*c, full(a)*c);
257 assert_checkequal(c*a, c*full(a));
258 // sparse sparse
259 assert_checkequal(full(zer*zer), full(zer));
260 assert_checkequal(full(a*zer), full(zer));
261 assert_checkequal(full(zer*a), full(zer));
262 assert_checkequal(full(a*a), full(a)*full(a));
263 assert_checkequal(full(b*b), full(b)*full(b));
264 assert_checkequal(full(a*b), full(a)*full(b));
265 assert_checkequal(full(b*a), full(b)*full(a));
266 // complex x real real x complex
267 // sparse scalar , scalar sparse
268 assert_checkequal(full(ac*2), full(ac)*2);
269 assert_checkequal(full(2*ac), full(ac)*2);
270 assert_checkequal(full((2+%i)*a), (2+%i)*full(a));
271 assert_checkequal(full(a*(2+%i)), (2+%i)*full(a));
272 assert_checkequal(ac*[], []);
273 assert_checkequal([]*ac, []);
274 c=rand(6,6);
275 cc=c+rand(6,6)*%i;
276 assert_checkequal(ac*c, full(ac)*c);
277 assert_checkequal(cc*a, cc*full(a));
278 // sparse sparse
279 assert_checkequal(real(full(ac*zer)), full(zer));
280 assert_checkequal(imag(full(ac*zer)), full(zer));
281 assert_checkequal(real(full(zer*ac)), full(zer));
282 assert_checkequal(imag(full(zer*ac)), full(zer));
283 assert_checkequal(full(ac*a), full(ac)*full(a));
284 assert_checkequal(full(ac*a), full(ac)*full(a));
285 assert_checkequal(full(bc*b), full(bc)*full(b));
286 assert_checkequal(full(a*bc), full(a)*full(bc));
287 assert_checkequal(full(b*ac), full(b)*full(ac));
288 // // complex x complex
289 assert_checkequal(ac*cc, full(ac)*cc);
290 assert_checkequal(cc*ac, cc*full(ac));
291 // sparse sparse
292 assert_checkequal(full(ac*ac), full(ac)*full(ac));
293 assert_checkequal(full(bc*bc), full(bc)*full(bc));
294 assert_checkequal(full(bc*ac), full(bc)*full(ac));
295 //----------------------------------------------------------
296 // element wise multiplication tests
297 //----------------------------------------------------------
298 assert_checkequal(full(ac.*2), full(ac)*2);
299 assert_checkequal(full((2).*ac), full(ac)*2);
300 assert_checkequal(a.*[], []);
301 assert_checkequal([].*a, []);
302 c=rand(6,6);
303 //if norm(a*c-full(a)*c) >100*%eps then bugmes();quit;end
304 //if norm(c*a-c*full(a)) >100*%eps then bugmes();quit;end
305 // sparse sparse
306 assert_checkequal(full(zer.*zer), full(zer));
307 assert_checkequal(full(a.*zer), full(zer));
308 assert_checkequal(full(zer.*a), full(zer));
309 assert_checkequal(full(a.*a), full(a).*full(a));
310 assert_checkequal(full(b.*b), full(b).*full(b));
311 assert_checkequal(full(a.*b), full(a).*full(b));
312 assert_checkequal(full(b.*a), full(b).*full(a));
313 // complex x real real x complex
314 // sparse scalar , scalar sparse
315 assert_checkequal(full((2+%i).*a), (2+%i).*full(a));
316 assert_checkequal(full(a.*(2+%i)), (2+%i).*full(a));
317 assert_checkequal(ac.*[], []);
318 assert_checkequal([].*ac, []);
319 c=rand(6,6);
320 cc=c+rand(6,6)*%i;
321 assert_checkequal(full(ac.*c), full(ac).*c);
322 assert_checkequal(full(cc.*a), cc.*full(a));
323 // sparse sparse
324 assert_checkequal(full(ac.*zer), full(zer)*%i);
325 assert_checkequal(full(zer.*ac), full(zer)*%i);
326 assert_checkequal(full(ac.*a), full(ac).*full(a));
327 assert_checkequal(full(bc.*b), full(bc).*full(b));
328 assert_checkequal(full(a.*bc), full(a).*full(bc));
329 assert_checkequal(full(b.*ac), full(b).*full(ac));
330 // // complex x complex
331 assert_checkequal(full(ac.*cc), full(ac).*cc);
332 assert_checkequal(full(cc.*ac), cc.*full(ac));
333 // sparse sparse
334 assert_checkequal(full(ac.*ac), full(ac).*full(ac));
335 assert_checkequal(full(bc.*bc), full(bc).*full(bc));
336 assert_checkequal(full(bc.*ac), full(bc).*full(ac));
337 // ----------------------------------------------------------
338 // test de la transposition
339 //-----------------------------------------------------------
340 assert_checkequal(full(a'), full(a)');
341 assert_checkequal(full(ac'), full(ac)');
342 assert_checkequal(full(zer'), full(zer)' );
343 v=sparse([2 1;3 1;4 1;6 1],[10;11;12;13],[6,1]);
344 assert_checkequal(full(v'), full(v)');
345 assert_checkequal(full((v')'), full(v));
346 vc=sparse([2 1;3 1;4 1;6 1],[10-3*%i;11;12+5*%i;13+0.5*%i],[6,1]);
347 assert_checkequal(full(vc'), full(vc)');
348 assert_checkequal(full((vc')'), full(vc));
349 // ----------------------------------------------------------
350 // test des concatenation
351 //-----------------------------------------------------------
352 assert_checkequal(full([a]), full(a));
353 assert_checkequal(full([a b]), [full(a) full(b)]);
354 assert_checkequal(full([a;b]), [full(a);full(b)]);
355 assert_checkequal(full([a []]), full(a));
356 assert_checkequal(full([a;[]]), full(a));
357 assert_checkequal(full([a zer]), [full(a) full(zer)]);
358 assert_checkequal(full([zer;b]), [full(zer);full(b)]);
359 assert_checkequal(full([ac]), full(ac));
360 assert_checkequal(full([ac b]), [full(ac) full(b)]);
361 assert_checkequal(full([ac;b]), [full(ac);full(b)]);
362 assert_checkequal(full([ac []]), full(ac));
363 assert_checkequal(full([ac;[]]), full(ac));
364 assert_checkequal(full([a bc]), [full(a) full(bc)]);
365 assert_checkequal(full([a;bc]), [full(a);full(bc)]);
366 assert_checkequal(full([ac bc]), [full(ac) full(bc)]);
367 assert_checkequal(full([ac;bc]), [full(ac);full(bc)]);
368 // ----------------------------------------------------------
369 // test des extractions
370 //-----------------------------------------------------------
371 af=full(a);
372 assert_checkequal(full(a(1,3)), af(1,3));
373 assert_checkequal(full(a(1,4)), af(1,4));
374 assert_checkequal(full(a(1,:)), af(1,:));
375 v=sparse([2 1;3 1;4 1;6 1],[10;11;12;13],[6,1]);vf=full(v);
376 assert_checkequal(full(v(:)), vf(:));
377 assert_checkequal(full(v(3:4)), vf(3:4));
378 assert_checkequal(full(v([1 5])), vf([1 5]));
379 assert_checkequal(full(v([4 3])), vf([4 3]));
380 assert_checkequal(full(v([4 4])), vf([4 4]));
381 assert_checkequal(full(v([1 1])), vf([1 1]));
382 v=v';vf=vf';
383 assert_checkequal(full(v(:)), vf(:));
384 assert_checkequal(full(v(3:4)), vf(3:4));
385 assert_checkequal(full(v([1 5])), vf([1 5]));
386 assert_checkequal(full(v([4 3])), vf([4 3]));
387 assert_checkequal(full(v([4 4])), vf([4 4]));
388 assert_checkequal(full(v([1 1])), vf([1 1]));
389 acff=full(ac);
390 assert_checkequal(full(ac(1,3)), acff(1,3));
391 assert_checkequal(full(ac(1,4)), acff(1,4));
392 assert_checkequal(full(ac(1,:)), acff(1,:));
393 vc=sparse([2 1;3 1;4 1;6 1],[10-3*%i;11;12+5*%i;13+0.5*%i],[6,1]);vcf=full(vc);
394 assert_checkequal(full(vc(:)), vcf(:));
395 assert_checkequal(full(vc(3:4)), vcf(3:4));
396 assert_checkequal(full(vc([1 5])), vcf([1 5]));
397 assert_checkequal(full(vc([4 3])), vcf([4 3]));
398 assert_checkequal(full(vc([4 4])), vcf([4 4]));
399 assert_checkequal(full(vc([1 1])), vcf([1 1]));
400 vc=vc';vcf=vcf';
401 assert_checkequal(full(vc(:)), vcf(:));
402 assert_checkequal(full(vc(3:4)), vcf(3:4));
403 assert_checkequal(full(vc([1 5])), vcf([1 5]));
404 assert_checkequal(full(vc([4 3])), vcf([4 3]));
405 assert_checkequal(full(vc([4 4])), vcf([4 4]));
406 assert_checkequal(full(vc([1 1])), vcf([1 1]));
407 // ----------------------------------------------------------
408 // test des insertions
409 //-----------------------------------------------------------
410 a=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],1:9,[6 6]);
411 vt=sparse([1 2;1 3;1 4;1 6],[10;11;12;13],[1,6]);
412 // full line insertion
413 //----------------------
414 a1=a;a1(1,:)=vt;A=full(a);Vt=full(vt);A(1,:)=Vt;
415 assert_checkequal(full(a1), A);
416 a1=a;a1(3,:)=vt;A=full(a);Vt=full(vt);A(3,:)=Vt;
417 assert_checkequal(full(a1), A);
418 a1=a;a1(1,:)=vt;A=full(a);Vt=full(vt);A(1,:)=Vt;
419 assert_checkequal(full(a1), A);
420 a1=a;a1(3,:)=vt;A=full(a);Vt=full(vt);A(3,:)=Vt;
421 assert_checkequal(full(a1), A);
422 a1=a;a1(7,:)=vt;A=full(a);Vt=full(vt);A(7,:)=Vt;
423 assert_checkequal(full(a1), A);
424 a1=a;a1(8,:)=vt;A=full(a);Vt=full(vt);A(8,:)=Vt;
425 assert_checkequal(full(a1), A);
426 a1=a;a1([1 3],:)=[vt;2*vt];A=full(a);Vt=full(vt);A([1 3],:)=[Vt;2*Vt];
427 assert_checkequal(full(a1), A);
428 a1=a;a1([3 1],:)=[vt;2*vt];A=full(a);Vt=full(vt);A([3 1],:)=[Vt;2*Vt];
429 assert_checkequal(full(a1), A);
430 a1=a;a1([1 3 1],:)=[vt;2*vt;3*vt];A=full(a);Vt=full(vt);A([1 3 1],:)=[Vt;2*Vt;3*Vt];
431 assert_checkequal(full(a1), A);
432 //  insert zero vector
433 vt=sparse([],[],[1,6]);
434 a1=a;a1(1,:)=vt;A=full(a);Vt=full(vt);A(1,:)=Vt;
435 assert_checkequal(full(a1), A);
436 a1=a;a1(3,:)=vt;A=full(a);Vt=full(vt);A(3,:)=Vt;
437 assert_checkequal(full(a1), A);
438 a1=a;a1(1,:)=vt;A=full(a);Vt=full(vt);A(1,:)=Vt;
439 assert_checkequal(full(a1), A);
440 a1=a;a1(3,:)=vt;A=full(a);Vt=full(vt);A(3,:)=Vt;
441 assert_checkequal(full(a1), A);
442 a1=a;a1(7,:)=vt;A=full(a);Vt=full(vt);A(7,:)=Vt;
443 assert_checkequal(full(a1), A);
444 a1=a;a1(8,:)=vt;A=full(a);Vt=full(vt);A(8,:)=Vt;
445 assert_checkequal(full(a1), A);
446 a1=a;a1([1 3],:)=[vt;2*vt];A=full(a);Vt=full(vt);A([1 3],:)=[Vt;2*Vt];
447 assert_checkequal(full(a1), A);
448 a1=a;a1([3 1],:)=[vt;2*vt];A=full(a);Vt=full(vt);A([3 1],:)=[Vt;2*Vt];
449 assert_checkequal(full(a1), A);
450 a1=a;a1([1 3 1],:)=[vt;2*vt;3*vt];A=full(a);Vt=full(vt);A([1 3 1],:)=[Vt;2*Vt;3*Vt];
451 assert_checkequal(full(a1), A);
452 a=sparse([],[],[6,6]);
453 a1=a;a1(1,:)=vt;A=full(a);Vt=full(vt);A(1,:)=Vt;
454 assert_checkequal(full(a1), A);
455 a1=a;a1(3,:)=vt;A=full(a);Vt=full(vt);A(3,:)=Vt;
456 assert_checkequal(full(a1), A);
457 a1=a;a1(1,:)=vt;A=full(a);Vt=full(vt);A(1,:)=Vt;
458 assert_checkequal(full(a1), A);
459 a1=a;a1(3,:)=vt;A=full(a);Vt=full(vt);A(3,:)=Vt;
460 assert_checkequal(full(a1), A);
461 a1=a;a1(7,:)=vt;A=full(a);Vt=full(vt);A(7,:)=Vt;
462 assert_checkequal(full(a1), A);
463 a1=a;a1(8,:)=vt;A=full(a);Vt=full(vt);A(8,:)=Vt;
464 assert_checkequal(full(a1), A);
465 b=sparse([1 1;1 3;1 6;2 1;2 2;2 4],10:15,[2,6]);
466 a1=a;a1([1 3],:)=b;A=full(a);B=full(b);A([1 3],:)=B;
467 assert_checkequal(full(a1), A);
468 a1=a;a1([3 1],:)=b;A=full(a);B=full(b);A([3 1],:)=B;
469 assert_checkequal(full(a1), A);
470 b=sparse([1 1;1 3;1 6;2 1;2 2;2 4;3 3;3 5],10:17,[3,6]);
471 a1=a;a1([1 3 1],:)=b;A=full(a);B=full(b);A([1 3 1],:)=B;
472 assert_checkequal(full(a1), A);
473 //  insert zero vector
474 vt=sparse([],[],[1,6]);
475 a1=a;a1(1,:)=vt;A=full(a);Vt=full(vt);A(1,:)=Vt;
476 assert_checkequal(full(a1), A);
477 a1=a;a1(3,:)=vt;A=full(a);Vt=full(vt);A(3,:)=Vt;
478 assert_checkequal(full(a1), A);
479 a1=a;a1(1,:)=vt;A=full(a);Vt=full(vt);A(1,:)=Vt;
480 assert_checkequal(full(a1), A);
481 a1=a;a1(3,:)=vt;A=full(a);Vt=full(vt);A(3,:)=Vt;
482 assert_checkequal(full(a1), A);
483 a1=a;a1(7,:)=vt;A=full(a);Vt=full(vt);A(7,:)=Vt;
484 assert_checkequal(full(a1), A);
485 a1=a;a1(8,:)=vt;A=full(a);Vt=full(vt);A(8,:)=Vt;
486 assert_checkequal(full(a1), A);
487 b=sparse([1 1;1 3;1 6;2 1;2 2;2 4],10:15,[2,6]);
488 a1=a;a1([1 3],:)=b;A=full(a);B=full(b);A([1 3],:)=B;
489 assert_checkequal(full(a1), A);
490 a1=a;a1([3 1],:)=b;A=full(a);B=full(b);A([3 1],:)=B;
491 assert_checkequal(full(a1), A);
492 b=sparse([1 1;1 3;1 6;2 1;2 2;2 4;3 3;3 5],10:17,[3,6]);
493 a1=a;a1([1 3 1],:)=b;A=full(a);B=full(b);A([1 3 1],:)=B;
494 assert_checkequal(full(a1), A);
495 // full column insertion
496 //----------------------
497 a=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],1:9,[6 6]);
498 v=sparse([2 1;3 1;4 1;6 1],[10;11;12;13],[6,1]);
499 a1=a;a1(:,1)=v;A=full(a);V=full(v);A(:,1)=V;
500 assert_checkequal(full(a1), A);
501 a1=a;a1(:,2)=v;A=full(a);V=full(v);A(:,2)=V;
502 assert_checkequal(full(a1), A);
503 a1=a;a1(:,1)=v;A=full(a);V=full(v);A(:,1)=V;
504 assert_checkequal(full(a1), A);
505 a1=a;a1(:,2)=v;A=full(a);V=full(v);A(:,2)=V;
506 assert_checkequal(full(a1), A);
507 a1=a;a1(:,3)=v;A=full(a);V=full(v);A(:,3)=V;
508 assert_checkequal(full(a1), A);
509 //
510 a1=a;a1(:,7)=v;A=full(a);V=full(v);A(:,7)=V;
511 assert_checkequal(full(a1), A);
512 a1=a;a1(:,8)=v;A=full(a);V=full(v);A(:,8)=V;
513 assert_checkequal(full(a1), A);
514 b=sparse([1 2;2 1;3 1;3 2;4 1;6 2],10:15,[6,2]);
515 a1=a;a1(:,[1 3])=b;A=full(a);B=full(b);A(:,[1 3])=B;
516 assert_checkequal(full(a1), A);
517 a1=a;a1(:,[3 1])=b;A=full(a);B=full(b);A(:,[3 1])=B;
518 assert_checkequal(full(a1), A);
519 b=sparse([1 2;2 1;2 3;3 1;3 2;4 1;5 3;6 2],10:17,[6,3]);
520 a1=a;a1(:,[1 3 1])=b;A=full(a);B=full(b);A(:,[1 3 1])=B;
521 assert_checkequal(full(a1), A);
522 v=sparse([],[],[6,1]);
523 a1=a;a1(:,1)=v;A=full(a);V=full(v);A(:,1)=V;
524 assert_checkequal(full(a1), A);
525 a1=a;a1(:,2)=v;A=full(a);V=full(v);A(:,2)=V;
526 assert_checkequal(full(a1), A);
527 a1=a;a1(:,1)=v;A=full(a);V=full(v);A(:,1)=V;
528 assert_checkequal(full(a1), A);
529 a1=a;a1(:,2)=v;A=full(a);V=full(v);A(:,2)=V;
530 assert_checkequal(full(a1), A);
531 a1=a;a1(:,3)=v;A=full(a);V=full(v);A(:,3)=V;
532 assert_checkequal(full(a1), A);
533 //
534 a1=a;a1(:,7)=v;A=full(a);V=full(v);A(:,7)=V;
535 assert_checkequal(full(a1), A);
536 a1=a;a1(:,8)=v;A=full(a);V=full(v);A(:,8)=V;
537 assert_checkequal(full(a1), A);
538 b=sparse([],[],[6,2]);
539 a1=a;a1(:,[1 3])=b;A=full(a);B=full(b);A(:,[1 3])=B;
540 assert_checkequal(full(a1), A);
541 a1=a;a1(:,[3 1])=b;A=full(a);B=full(b);A(:,[3 1])=B;
542 assert_checkequal(full(a1), A);
543 b=sparse([],[],[6,3]);
544 a1=a;a1(:,[1 3 1])=b;A=full(a);B=full(b);A(:,[1 3 1])=B;
545 assert_checkequal(full(a1), A);
546 a=sparse([],[],[6,6]);
547 a1=a;a1(:,1)=v;A=full(a);V=full(v);A(:,1)=V;
548 assert_checkequal(full(a1), A);
549 a1=a;a1(:,2)=v;A=full(a);V=full(v);A(:,2)=V;
550 assert_checkequal(full(a1), A);
551 a1=a;a1(:,1)=v;A=full(a);V=full(v);A(:,1)=V;
552 assert_checkequal(full(a1), A);
553 a1=a;a1(:,2)=v;A=full(a);V=full(v);A(:,2)=V;
554 assert_checkequal(full(a1), A);
555 a1=a;a1(:,3)=v;A=full(a);V=full(v);A(:,3)=V;
556 assert_checkequal(full(a1), A);
557 //
558 a1=a;a1(:,7)=v;A=full(a);V=full(v);A(:,7)=V;
559 assert_checkequal(full(a1), A);
560 a1=a;a1(:,8)=v;A=full(a);V=full(v);A(:,8)=V;
561 assert_checkequal(full(a1), A);
562 b=sparse([1 2;2 1;3 1;3 2;4 1;6 2],10:15,[6,2]);
563 a1=a;a1(:,[1 3])=b;A=full(a);B=full(b);A(:,[1 3])=B;
564 assert_checkequal(full(a1), A);
565 a1=a;a1(:,[3 1])=b;A=full(a);B=full(b);A(:,[3 1])=B;
566 assert_checkequal(full(a1), A);
567 b=sparse([1 2;2 1;2 3;3 1;3 2;4 1;5 3;6 2],10:17,[6,3]);
568 a1=a;a1(:,[1 3 1])=b;A=full(a);B=full(b);A(:,[1 3 1])=B;
569 assert_checkequal(full(a1), A);
570 v=sparse([],[],[6,1]);
571 a1=a;a1(:,1)=v;A=full(a);V=full(v);A(:,1)=V;
572 assert_checkequal(full(a1), A);
573 a1=a;a1(:,2)=v;A=full(a);V=full(v);A(:,2)=V;
574 assert_checkequal(full(a1), A);
575 a1=a;a1(:,1)=v;A=full(a);V=full(v);A(:,1)=V;
576 assert_checkequal(full(a1), A);
577 a1=a;a1(:,2)=v;A=full(a);V=full(v);A(:,2)=V;
578 assert_checkequal(full(a1), A);
579 a1=a;a1(:,3)=v;A=full(a);V=full(v);A(:,3)=V;
580 assert_checkequal(full(a1), A);
581 //
582 a1=a;a1(:,7)=v;A=full(a);V=full(v);A(:,7)=V;
583 assert_checkequal(full(a1), A);
584 a1=a;a1(:,8)=v;A=full(a);V=full(v);A(:,8)=V;
585 assert_checkequal(full(a1), A);
586 b=sparse([1 2;2 1;3 1;3 2;4 1;6 2],10:15,[6,2]);
587 a1=a;a1(:,[1 3])=b;A=full(a);B=full(b);A(:,[1 3])=B;
588 assert_checkequal(full(a1), A);
589 a1=a;a1(:,[3 1])=b;A=full(a);B=full(b);A(:,[3 1])=B;
590 assert_checkequal(full(a1), A);
591 b=sparse([1 2;2 1;2 3;3 1;3 2;4 1;5 3;6 2],10:17,[6,3]);
592 a1=a;a1(:,[1 3 1])=b;A=full(a);B=full(b);A(:,[1 3 1])=B;
593 assert_checkequal(full(a1), A);
594 v=sparse([],[],[6,1]);
595 a1=a;a1(:,1)=v;A=full(a);V=full(v);A(:,1)=V;
596 assert_checkequal(full(a1), A);
597 a1=a;a1(:,2)=v;A=full(a);V=full(v);A(:,2)=V;
598 assert_checkequal(full(a1), A);
599 a1=a;a1(:,1)=v;A=full(a);V=full(v);A(:,1)=V;
600 assert_checkequal(full(a1), A);
601 a1=a;a1(:,2)=v;A=full(a);V=full(v);A(:,2)=V;
602 assert_checkequal(full(a1), A);
603 a1=a;a1(:,3)=v;A=full(a);V=full(v);A(:,3)=V;
604 assert_checkequal(full(a1), A);
605 //
606 a1=a;a1(:,7)=v;A=full(a);V=full(v);A(:,7)=V;
607 assert_checkequal(full(a1), A);
608 a1=a;a1(:,8)=v;A=full(a);V=full(v);A(:,8)=V;
609 assert_checkequal(full(a1), A);
610 b=sparse([],[],[6,2]);
611 a1=a;a1(:,[1 3])=b;A=full(a);B=full(b);A(:,[1 3])=B;
612 assert_checkequal(full(a1), A);
613 a1=a;a1(:,[3 1])=b;A=full(a);B=full(b);A(:,[3 1])=B;
614 assert_checkequal(full(a1), A);
615 b=sparse([],[],[6,3]);
616 a1=a;a1(:,[1 3 1])=b;A=full(a);B=full(b);A(:,[1 3 1])=B;
617 assert_checkequal(full(a1), A);
618 // row column insertion
619 a=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],1:9,[6 6]);
620 b=sparse([1 2;1 3;3 3],-(1:3),[3,3]);
621 a1=a;a1(1,1)=sparse(30);A=full(a);A(1,1)=30;
622 assert_checkequal(full(a1), A);
623 a1=a;a1(1,6)=sparse(30);A=full(a);A(1,6)=30;
624 assert_checkequal(full(a1), A);
625 a1=a;a1(1,8)=sparse(30);A=full(a);A(1,8)=30;
626 assert_checkequal(full(a1), A);
627 a1=a;a1(1:3,1:3)=b;A=full(a);A(1:3,1:3)=full(b);
628 assert_checkequal(full(a1), A);
629 a1=a;a1(1:3,6:8)=b;A=full(a);A(1:3,6:8)=full(b);
630 assert_checkequal(full(a1), A);
631 a1=a;a1(6:8,1:3)=b;A=full(a);A(6:8,1:3)=full(b);
632 assert_checkequal(full(a1), A);
633 a1=a;a1([3 2 1],1:3)=b;A=full(a);A([3 2 1],1:3)=full(b);
634 assert_checkequal(full(a1), A);
635 a1=a;a1([1 2 1],1:3)=b;A=full(a);A([1 2 1],1:3)=full(b);
636 assert_checkequal(full(a1), A);
637 a1=a;a1([3 2 1],[3 2 1])=b;A=full(a);A([3 2 1],[3 2 1])=full(b);
638 assert_checkequal(full(a1), A);
639 a1=a;a1([1 2 1],[3 2 1])=b;A=full(a);A([1 2 1],[3 2 1])=full(b);
640 assert_checkequal(full(a1), A);
641 a1=a;a1([1 2 1],[1 2 1])=b;A=full(a);A([1 2 1],[1 2 1])=full(b);
642 assert_checkequal(full(a1), A);
643 //sparse full
644 a=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],1:9,[6 6]);
645 vt=11:16;
646 // full line insertion
647 //----------------------
648 a1=a;a1(1,:)=vt;A=full(a);A(1,:)=vt;
649 assert_checkequal(full(a1), A);
650 a1=a;a1(3,:)=vt;A=full(a);A(3,:)=vt;
651 assert_checkequal(full(a1), A);
652 a1=a;a1(1,:)=vt;A=full(a);A(1,:)=vt;
653 assert_checkequal(full(a1), A);
654 a1=a;a1(3,:)=vt;A=full(a);A(3,:)=vt;
655 assert_checkequal(full(a1), A);
656 a1=a;a1(7,:)=vt;A=full(a);A(7,:)=vt;
657 assert_checkequal(full(a1), A);
658 a1=a;a1(8,:)=vt;A=full(a);A(8,:)=vt;
659 assert_checkequal(full(a1), A);
660 a1=a;a1([1 3],:)=[vt;2*vt];A=full(a);A([1 3],:)=[vt;2*vt];
661 assert_checkequal(full(a1), A);
662 a1=a;a1([3 1],:)=[vt;2*vt];A=full(a);A([3 1],:)=[vt;2*vt];
663 assert_checkequal(full(a1), A);
664 a1=a;a1([1 3 1],:)=[vt;2*vt;3*vt];A=full(a);A([1 3 1],:)=[vt;2*vt;3*vt];
665 assert_checkequal(full(a1), A);
666 a=sparse([],[],[6,6]);
667 a1=a;a1(1,:)=vt;A=full(a);A(1,:)=vt;
668 assert_checkequal(full(a1), A);
669 a1=a;a1(3,:)=vt;A=full(a);A(3,:)=vt;
670 assert_checkequal(full(a1), A);
671 a1=a;a1(1,:)=vt;A=full(a);A(1,:)=vt;
672 assert_checkequal(full(a1), A);
673 a1=a;a1(3,:)=vt;A=full(a);A(3,:)=vt;
674 assert_checkequal(full(a1), A);
675 a1=a;a1(7,:)=vt;A=full(a);A(7,:)=vt;
676 assert_checkequal(full(a1), A);
677 a1=a;a1(8,:)=vt;A=full(a);A(8,:)=vt;
678 assert_checkequal(full(a1), A);
679 b=[1:6;11:16];
680 a1=a;a1([1 3],:)=b;A=full(a);A([1 3],:)=b;
681 assert_checkequal(full(a1), A);
682 a1=a;a1([3 1],:)=b;A=full(a);A([3 1],:)=b;
683 assert_checkequal(full(a1), A);
684 b=[1:6;11:16;21:26];
685 a1=a;a1([1 3 1],:)=b;A=full(a);A([1 3 1],:)=b;
686 assert_checkequal(full(a1), A);
687 // full column insertion
688 //----------------------
689 a=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],1:9,[6 6]);
690 v=(1:6)';
691 a1=a;a1(:,1)=v;A=full(a);A(:,1)=v;
692 assert_checkequal(full(a1), A);
693 a1=a;a1(:,2)=v;A=full(a);A(:,2)=v;
694 assert_checkequal(full(a1), A);
695 a1=a;a1(:,1)=v;A=full(a);A(:,1)=v;
696 assert_checkequal(full(a1), A);
697 a1=a;a1(:,2)=v;A=full(a);A(:,2)=v;
698 assert_checkequal(full(a1), A);
699 a1=a;a1(:,3)=v;A=full(a);A(:,3)=v;
700 assert_checkequal(full(a1), A);
701 //
702 a1=a;a1(:,7)=v;A=full(a);A(:,7)=v;
703 assert_checkequal(full(a1), A);
704 a1=a;a1(:,8)=v;A=full(a);A(:,8)=v;
705 assert_checkequal(full(a1), A);
706 b=[(1:6)' (11:16)'];
707 a1=a;a1(:,[1 3])=b;A=full(a);A(:,[1 3])=b;
708 assert_checkequal(full(a1), A);
709 a1=a;a1(:,[3 1])=b;A=full(a);A(:,[3 1])=b;
710 assert_checkequal(full(a1), A);
711 b=[(1:6)' (11:16)' (21:26)'];
712 a1=a;a1(:,[1 3 1])=b;A=full(a);A(:,[1 3 1])=b;
713 assert_checkequal(full(a1), A);
714 //********
715 // row column insertion
716 a=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],1:9,[6 6]);
717 b=-[1 2 3;4 5 6;7 8 9];
718 a1=a;a1(1,1)=30;A=full(a);A(1,1)=30;
719 assert_checkequal(full(a1), A);
720 a1=a;a1(1,6)=30;A=full(a);A(1,6)=30;
721 assert_checkequal(full(a1), A);
722 a1=a;a1(1,8)=30;A=full(a);A(1,8)=30;
723 assert_checkequal(full(a1), A);
724 a1=a;a1(1:3,1:3)=b;A=full(a);A(1:3,1:3)=b;
725 assert_checkequal(full(a1), A);
726 a1=a;a1(1:3,6:8)=b;A=full(a);A(1:3,6:8)=b;
727 assert_checkequal(full(a1), A);
728 a1=a;a1(6:8,1:3)=b;A=full(a);A(6:8,1:3)=b;
729 assert_checkequal(full(a1), A);
730 a1=a;a1([3 2 1],1:3)=b;A=full(a);A([3 2 1],1:3)=b;
731 assert_checkequal(full(a1), A);
732 a1=a;a1([1 2 1],1:3)=b;A=full(a);A([1 2 1],1:3)=b;
733 assert_checkequal(full(a1), A);
734 a1=a;a1([3 2 1],[3 2 1])=b;A=full(a);A([3 2 1],[3 2 1])=b;
735 assert_checkequal(full(a1), A);
736 a1=a;a1([1 2 1],[3 2 1])=b;A=full(a);A([1 2 1],[3 2 1])=b;
737 assert_checkequal(full(a1), A);
738 a1=a;a1([1 2 1],[1 2 1])=b;A=full(a);A([1 2 1],[1 2 1])=b;
739 assert_checkequal(full(a1), A);
740 // vector insertion
741 v=sparse([1 1;3 1;6 1],[10 11 12],[6 1]);
742 v1=v;v1(1)=33;V=full(v);V(1)=33;
743 assert_checkequal(full(v1), V);
744 v1=v;v1(2)=33;V=full(v);V(2)=33;
745 assert_checkequal(full(v1), V);
746 v1=v;v1(8)=33;V=full(v);V(8)=33;
747 assert_checkequal(full(v1), V);
748 v1=v;v1([1 2 8])=[5;10;33];V=full(v);V([1 2 8])=[5;10;33];
749 assert_checkequal(full(v1), V);
750 v1=v;v1(:)=[];
751 assert_checkequal(full(v1), []);
752 v1=v;v1(1)=sparse(33);V=full(v);V(1)=33;
753 assert_checkequal(full(v1), V);
754 v1=v;v1(2)=sparse(33);V=full(v);V(2)=33;
755 assert_checkequal(full(v1), V);
756 v1=v;v1(8)=sparse(33);V=full(v);V(8)=33;
757 assert_checkequal(full(v1), V);
758 v1=v;v1([1 2 8])=sparse([5;10;33]);V=full(v);V([1 2 8])=[5;10;33];
759 assert_checkequal(full(v1), V);
760 v1=v;v1([1 2 1])=sparse([5;10;33]);V=full(v);V([1 2 1])=[5;10;33];
761 assert_checkequal(full(v1), V);
762 v1=v;v1(:)=[];
763 assert_checkequal(full(v1), []);
764 v1=v;v1(:)=sparse([2 1],44,[6 1]);V=full(v);V(:)=[0;44;0;0;0;0];
765 assert_checkequal(full(v1), V);
766 v=v';
767 v1=v;v1(1)=33;V=full(v);V(1)=33;
768 assert_checkequal(full(v1), V);
769 v1=v;v1(2)=33;V=full(v);V(2)=33;
770 assert_checkequal(full(v1), V);
771 v1=v;v1(8)=33;V=full(v);V(8)=33;
772 assert_checkequal(full(v1), V);
773 v1=v;v1([1 2 8])=[5 10 33];V=full(v);V([1 2 8])=[5 10 33];
774 assert_checkequal(full(v1), V);
775 v1=v;v1(1)=sparse(33);V=full(v);V(1)=33;
776 assert_checkequal(full(v1), V);
777 v1=v;v1(2)=sparse(33);V=full(v);V(2)=33;
778 assert_checkequal(full(v1), V);
779 v1=v;v1(8)=sparse(33);V=full(v);V(8)=33;
780 assert_checkequal(full(v1), V);
781 v1=v;v1([1 2 8])=sparse([5 10 33]);V=full(v);V([1 2 8])=[5 10 33];
782 assert_checkequal(full(v1), V);
783 v1=v;v1([1 2 1])=sparse([5 10 33]);V=full(v);V([1 2 1])=[5 10 33];
784 assert_checkequal(full(v1), V);
785 v1=v;v1(:)=sparse([1 2],44,[1,6]);V=full(v);V(:)=[0 44 0 0 0 0];
786 assert_checkequal(full(v1), V);
787 v1=v;v1(1)=[];V=full(v);V(1)=[];
788 assert_checkequal(full(v1), V);
789 //test des comparaisons
790 a=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],1:9,[6 6]);
791 b=sparse([1 6;1 2;6 5],[10;-1;-1],[6 6]);
792 assert_checkequal(full(a==a), full(a)==full(a));
793 assert_checkequal(full(a<>a), (full(a)<>full(a)));
794 assert_checkequal(full(a>sparse(5)), (full(a)>5));
795 assert_checkequal(full(a<sparse(5)), (full(a)<5));
796 assert_checkequal(full(a>=sparse(5)), (full(a)>=5));
797 assert_checkequal(full(a<=sparse(5)), (full(a)<=5));
798 assert_checkequal(full(sparse(5)>a), (5>full(a)));
799 assert_checkequal(full(sparse(5)<a), (5<full(a)));
800 assert_checkequal(full(sparse(5)>=a), (5>=full(a)));
801 assert_checkequal(full(sparse(5)<=a), (5<=full(a)));
802 assert_checkequal(full(b>a), (full(b)>full(a)));
803 assert_checkequal(full(b<a), (full(b)<full(a)));
804 assert_checkequal(full(b>=a), (full(b)>=full(a)));
805 assert_checkequal(full(b<=a), (full(b)<=full(a)));
806 assert_checkequal(full(a==full(a)), full(a)==full(a));
807 assert_checkequal(full(a<>full(a)), (full(a)<>full(a)));
808 assert_checkequal(full(a>5), (full(a)>5));
809 assert_checkequal(full(a<5), (full(a)<5));
810 assert_checkequal(full(a>=5), (full(a)>=5));
811 assert_checkequal(full(a<=5), (full(a)<=5));
812 assert_checkequal(full(5>a), (5>full(a)));
813 assert_checkequal(full(5<a), (5<full(a)));
814 assert_checkequal(full(5>=a), (5>=full(a)));
815 assert_checkequal(full(5<=a), (5<=full(a)));
816 assert_checkequal(full(b>full(a)), (full(b)>full(a)));
817 assert_checkequal(full(b<full(a)), (full(b)<full(a)));
818 assert_checkequal(full(b>=full(a)), (full(b)>=full(a)));
819 assert_checkequal(full(b<=full(a)), (full(b)<=full(a)));
820 assert_checkequal(full(full(a)==a), full(a)==full(a));
821 assert_checkequal(full(full(a)<>a), (full(a)<>full(a)));
822 assert_checkequal(full(full(a)>sparse(5)), (full(a)>5));
823 assert_checkequal(full(full(a)<sparse(5)), (full(a)<5));
824 assert_checkequal(full(full(a)>=sparse(5)), (full(a)>=5));
825 assert_checkequal(full(full(a)<=sparse(5)), (full(a)<=5));
826 assert_checkequal(full(full(b)>a), (full(b)>full(a)));
827 assert_checkequal(full(full(b)<a), (full(b)<full(a)));
828 assert_checkequal(full(full(b)>=a), (full(b)>=full(a)));
829 assert_checkequal(full(full(b)<=a), (full(b)<=full(a)));
830 a=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],-(1:9),[6 6]);
831 b=sparse([1 6;1 2;6 5],[10;-1;-1],[6 6]);
832 assert_checkequal(full(a==a), full(a)==full(a));
833 assert_checkequal(full(a<>a), (full(a)<>full(a)));
834 assert_checkequal(full(a>sparse(5)), (full(a)>5));
835 assert_checkequal(full(a<sparse(5)), (full(a)<5));
836 assert_checkequal(full(a>=sparse(5)), (full(a)>=5));
837 assert_checkequal(full(a<=sparse(5)), (full(a)<=5));
838 assert_checkequal(full(sparse(5)>a), (5>full(a)));
839 assert_checkequal(full(sparse(5)<a), (5<full(a)));
840 assert_checkequal(full(sparse(5)>=a), (5>=full(a)));
841 assert_checkequal(full(sparse(5)<=a), (5<=full(a)));
842 assert_checkequal(full(b>a), (full(b)>full(a)));
843 assert_checkequal(full(b<a), (full(b)<full(a)));
844 assert_checkequal(full(b>=a), (full(b)>=full(a)));
845 assert_checkequal(full(b<=a), (full(b)<=full(a)));
846 assert_checkequal(full(a==full(a)), full(a)==full(a));
847 assert_checkequal(full(a<>full(a)), (full(a)<>full(a)));
848 assert_checkequal(full(a>5), (full(a)>5));
849 assert_checkequal(full(a<5), (full(a)<5));
850 assert_checkequal(full(a>=5), (full(a)>=5));
851 assert_checkequal(full(a<=5), (full(a)<=5));
852 assert_checkequal(full(5>a), (5>full(a)));
853 assert_checkequal(full(5<a), (5<full(a)));
854 assert_checkequal(full(5>=a), (5>=full(a)));
855 assert_checkequal(full(5<=a), (5<=full(a)));
856 assert_checkequal(full(b>full(a)), (full(b)>full(a)));
857 assert_checkequal(full(b<full(a)), (full(b)<full(a)));
858 assert_checkequal(full(b>=full(a)), (full(b)>=full(a)));
859 assert_checkequal(full(b<=full(a)), (full(b)<=full(a)));
860 assert_checkequal(full(full(a)==a), full(a)==full(a));
861 assert_checkequal(full(full(a)<>a), (full(a)<>full(a)));
862 assert_checkequal(full(full(a)>sparse(5)), (full(a)>5));
863 assert_checkequal(full(full(a)<sparse(5)), (full(a)<5));
864 assert_checkequal(full(full(a)>=sparse(5)), (full(a)>=5));
865 assert_checkequal(full(full(a)<=sparse(5)), (full(a)<=5));
866 assert_checkequal(full(full(b)>a), (full(b)>full(a)));
867 assert_checkequal(full(full(b)<a), (full(b)<full(a)));
868 assert_checkequal(full(full(b)>=a), (full(b)>=full(a)));
869 assert_checkequal(full(full(b)<=a), (full(b)<=full(a)));
870 a=sparse([1 1;3 1;6 1],[10 11 12],[6 1]);
871 assert_checkequal(full(a==a), full(a)==full(a));
872 assert_checkequal(full(a<>a), (full(a)<>full(a)));
873 assert_checkequal(full(a>sparse(5)), (full(a)>5));
874 assert_checkequal(full(a<sparse(5)), (full(a)<5));
875 assert_checkequal(full(a>=sparse(5)), (full(a)>=5));
876 assert_checkequal(full(a<=sparse(5)), (full(a)<=5));
877 assert_checkequal(full(sparse(5)>a), (5>full(a)));
878 assert_checkequal(full(sparse(5)<a), (5<full(a)));
879 assert_checkequal(full(sparse(5)>=a), (5>=full(a)));
880 assert_checkequal(full(sparse(5)<=a), (5<=full(a)));
881 assert_checkequal(full(a==full(a)), full(a)==full(a));
882 assert_checkequal(full(a<>full(a)), (full(a)<>full(a)));
883 assert_checkequal(full(a>5), (full(a)>5));
884 assert_checkequal(full(a<5), (full(a)<5));
885 assert_checkequal(full(a>=5), (full(a)>=5));
886 assert_checkequal(full(a<=5), (full(a)<=5));
887 assert_checkequal(full(5>a), (5>full(a)));
888 assert_checkequal(full(5<a), (5<full(a)));
889 assert_checkequal(full(5>=a), (5>=full(a)));
890 assert_checkequal(full(5<=a), (5<=full(a)));
891 assert_checkequal(full(full(a)==a), full(a)==full(a));
892 assert_checkequal(full(full(a)<>a), (full(a)<>full(a)));
893 assert_checkequal(full(full(a)>sparse(5)), (full(a)>5));
894 assert_checkequal(full(full(a)<sparse(5)), (full(a)<5));
895 assert_checkequal(full(full(a)>=sparse(5)), (full(a)>=5));
896 assert_checkequal(full(full(a)<=sparse(5)), (full(a)<=5));
897 a=a';
898 assert_checkequal(full(a==a), full(a)==full(a));
899 assert_checkequal(full(a<>a), (full(a)<>full(a)));
900 assert_checkequal(full(a>sparse(5)), (full(a)>5));
901 assert_checkequal(full(a<sparse(5)), (full(a)<5));
902 assert_checkequal(full(a>=sparse(5)), (full(a)>=5));
903 assert_checkequal(full(a<=sparse(5)), (full(a)<=5));
904 assert_checkequal(full(sparse(5)>a), (5>full(a)));
905 assert_checkequal(full(sparse(5)<a), (5<full(a)));
906 assert_checkequal(full(sparse(5)>=a), (5>=full(a)));
907 assert_checkequal(full(sparse(5)<=a), (5<=full(a)));
908 assert_checkequal(full(a==full(a)), full(a)==full(a));
909 assert_checkequal(full(a<>full(a)), (full(a)<>full(a)));
910 assert_checkequal(full(a>5), (full(a)>5));
911 assert_checkequal(full(a<5), (full(a)<5));
912 assert_checkequal(full(a>=5), (full(a)>=5));
913 assert_checkequal(full(a<=5), (full(a)<=5));
914 assert_checkequal(full(5>a), (5>full(a)));
915 assert_checkequal(full(5<a), (5<full(a)));
916 assert_checkequal(full(5>=a), (5>=full(a)));
917 assert_checkequal(full(5<=a), (5<=full(a)));
918 assert_checkequal(full(full(a)==a), full(a)==full(a));
919 assert_checkequal(full(full(a)<>a), (full(a)<>full(a)));
920 assert_checkequal(full(full(a)>sparse(5)), (full(a)>5));
921 assert_checkequal(full(full(a)<sparse(5)), (full(a)<5));
922 assert_checkequal(full(full(a)>=sparse(5)), (full(a)>=5));
923 assert_checkequal(full(full(a)<=sparse(5)), (full(a)<=5));
924 a=sparse([1 1;3 1;6 1],[-10 -11 -12],[6 1]);
925 assert_checkequal(full(a==a), full(a)==full(a));
926 assert_checkequal(full(a<>a), (full(a)<>full(a)));
927 assert_checkequal(full(a>sparse(5)), (full(a)>5));
928 assert_checkequal(full(a<sparse(5)), (full(a)<5));
929 assert_checkequal(full(a>=sparse(5)), (full(a)>=5));
930 assert_checkequal(full(a<=sparse(5)), (full(a)<=5));
931 assert_checkequal(full(sparse(5)>a), (5>full(a)));
932 assert_checkequal(full(sparse(5)<a), (5<full(a)));
933 assert_checkequal(full(sparse(5)>=a), (5>=full(a)));
934 assert_checkequal(full(sparse(5)<=a), (5<=full(a)));
935 assert_checkequal(full(a==full(a)), full(a)==full(a));
936 assert_checkequal(full(a<>full(a)), (full(a)<>full(a)));
937 assert_checkequal(full(a>5), (full(a)>5));
938 assert_checkequal(full(a<5), (full(a)<5));
939 assert_checkequal(full(a>=5), (full(a)>=5));
940 assert_checkequal(full(a<=5), (full(a)<=5));
941 assert_checkequal(full(5>a), (5>full(a)));
942 assert_checkequal(full(5<a), (5<full(a)));
943 assert_checkequal(full(5>=a), (5>=full(a)));
944 assert_checkequal(full(5<=a), (5<=full(a)));
945 assert_checkequal(full(full(a)==a), full(a)==full(a));
946 assert_checkequal(full(full(a)<>a), (full(a)<>full(a)));
947 assert_checkequal(full(full(a)>sparse(5)), (full(a)>5));
948 assert_checkequal(full(full(a)<sparse(5)), (full(a)<5));
949 assert_checkequal(full(full(a)>=sparse(5)), (full(a)>=5));
950 assert_checkequal(full(full(a)<=sparse(5)), (full(a)<=5));
951 a=a';
952 assert_checkequal(full(a==a), full(a)==full(a));
953 assert_checkequal(full(a<>a), (full(a)<>full(a)));
954 assert_checkequal(full(a>sparse(5)), (full(a)>5));
955 assert_checkequal(full(a<sparse(5)), (full(a)<5));
956 assert_checkequal(full(a>=sparse(5)), (full(a)>=5));
957 assert_checkequal(full(a<=sparse(5)), (full(a)<=5));
958 assert_checkequal(full(sparse(5)>a), (5>full(a)));
959 assert_checkequal(full(sparse(5)<a), (5<full(a)));
960 assert_checkequal(full(sparse(5)>=a), (5>=full(a)));
961 assert_checkequal(full(sparse(5)<=a), (5<=full(a)));
962 assert_checkequal(full(a==full(a)), full(a)==full(a));
963 assert_checkequal(full(a<>full(a)), (full(a)<>full(a)));
964 assert_checkequal(full(a>5), (full(a)>5));
965 assert_checkequal(full(a<5), (full(a)<5));
966 assert_checkequal(full(a>=5), (full(a)>=5));
967 assert_checkequal(full(a<=5), (full(a)<=5));
968 assert_checkequal(full(5>a), (5>full(a)));
969 assert_checkequal(full(5<a), (5<full(a)));
970 assert_checkequal(full(5>=a), (5>=full(a)));
971 assert_checkequal(full(5<=a), (5<=full(a)));
972 assert_checkequal(full(full(a)==a), full(a)==full(a));
973 assert_checkequal(full(full(a)<>a), (full(a)<>full(a)));
974 assert_checkequal(full(full(a)>sparse(5)), (full(a)>5));
975 assert_checkequal(full(full(a)<sparse(5)), (full(a)<5));
976 assert_checkequal(full(full(a)>=sparse(5)), (full(a)>=5));
977 assert_checkequal(full(full(a)<=sparse(5)), (full(a)<=5));
978 a=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],1:9,[6 6]);
979 b=sparse([1 6;1 2;5 5],[10;-1;-1],[5 6]);
980 assert_checkfalse(a==b);
981 assert_checktrue(a<>b);
982 // Sparse does not accept hypermatrices as input arguments
983 A = matrix(1:12, [2 2 3]);
984 msg = _("%s: Wrong size for input argument #%d: A m-by-n matrix expected.\n");
985 funcname = "sparse";
986 assert_checkerror("sparse(A)", msprintf(msg, funcname, 1));
987 assert_checkerror("sparse(1, A, 1)", msprintf(msg, funcname, 2));
988 assert_checkerror("sparse(1, 1, A)", msprintf(msg, funcname, 3));