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