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