fix subtraction and addition on sparse 36/15136/5
Antoine ELIAS [Tue, 2 Sep 2014 09:05:29 +0000 (11:05 +0200)]
Change-Id: I68a21225280f95ebce30006161e7d1e5e244faea

scilab/modules/ast/src/cpp/operations/types_addition.cpp
scilab/modules/ast/src/cpp/operations/types_subtraction.cpp
scilab/modules/ast/tests/unit_tests/sparse.dia.ref
scilab/modules/ast/tests/unit_tests/sparse.tst

index d450eed..8d86010 100644 (file)
@@ -2427,7 +2427,7 @@ template<> InternalType* add_M_M<Sparse, Double, Sparse>(Sparse* _pL, Double* _p
 
             for (int i = 0 ; i < size ; i++)
             {
-                pOut->set(i, i, pOut->get(i, i) + cplx_add, false);
+                pOut->set(i, i, pOut->getImg(i, i) + cplx_add, false);
             }
         }
         else
index 430c65f..186db76 100644 (file)
@@ -2294,44 +2294,12 @@ template<> InternalType* sub_M_M<Double, Polynom, Polynom>(Double* _pL, Polynom*
 //sp - sp
 template<> InternalType* sub_M_M<Sparse, Sparse, Sparse>(Sparse* _pL, Sparse* _pR)
 {
-    Sparse* pOut = NULL;
     //check scalar hidden in a sparse ;)
-    if (_pL->getRows() == 1 && _pL->getCols() == 1)
+    if (_pL->isScalar() || _pR->isScalar())
     {
-        //do scalar - sp
-        Double* pDbl = NULL;
-        if (_pL->isComplex())
-        {
-            std::complex<double> dbl = _pL->getImg(0, 0);
-            pDbl = new Double(dbl.real(), dbl.imag());
-        }
-        else
-        {
-            pDbl = new Double(_pL->get(0, 0));
-        }
-
-        //AddSparseToDouble(_pR, pDbl, (GenericType**)pOut);
-        delete pDbl;
-        return pOut;
-    }
-
-    if (_pR->getRows() == 1 && _pR->getCols() == 1)
-    {
-        //do sp - scalar
-        Double* pDbl = NULL;
-        if (_pR->isComplex())
-        {
-            std::complex<double> dbl = _pR->getImg(0, 0);
-            pDbl = new Double(dbl.real(), dbl.imag());
-        }
-        else
-        {
-            pDbl = new Double(_pR->get(0, 0));
-        }
-
-        //AddSparseToDouble(_pL, pDbl, (GenericType**)pOut);
-        delete pDbl;
-        return 0;
+        // scalar - sp  or  sp - scalar
+        // call Overload
+        return NULL;
     }
 
     if (_pL->getRows() != _pR->getRows() || _pL->getCols() != _pR->getCols())
@@ -2340,18 +2308,6 @@ template<> InternalType* sub_M_M<Sparse, Sparse, Sparse>(Sparse* _pL, Sparse* _p
         throw ast::ScilabError(_W("Inconsistent row/column dimensions.\n"));
     }
 
-    if (_pL->nonZeros() == 0)
-    {
-        //sp([]) - sp
-        return _pR;
-    }
-
-    if (_pR->nonZeros() == 0)
-    {
-        //sp - sp([])
-        return _pL;
-    }
-
     return _pL->substract(*_pR);
 }
 
@@ -2367,7 +2323,7 @@ template<> InternalType* sub_M_M<Double, Sparse, Double>(Double* _pL, Sparse* _p
     {
         //d - sp
         pOut = (Double*)_pL->clone();
-        pOut->setComplex(bComplex1 | bComplex2);
+        pOut->setComplex(bComplex1 || bComplex2);
         if (bComplex2)
         {
             std::complex<double> dbl = _pR->getImg(0, 0);
@@ -2385,7 +2341,7 @@ template<> InternalType* sub_M_M<Double, Sparse, Double>(Double* _pL, Sparse* _p
     if (_pL->isScalar())
     {
         //d - SP
-        pOut = new Double(_pR->getRows(), _pR->getCols(), bComplex1 | bComplex2);
+        pOut = new Double(_pR->getRows(), _pR->getCols(), bComplex1 || bComplex2);
         int iSize = _pR->getSize();
         double dblVal = _pL->get(0);
         double dblValI = 0;
@@ -2434,11 +2390,11 @@ template<> InternalType* sub_M_M<Double, Sparse, Double>(Double* _pL, Sparse* _p
         return pOut;
     }
 
-    if (_pL->isScalar())
+    if (_pR->isScalar())
     {
         //D - sp
         pOut = (Double*)_pR->clone();
-        pOut->setComplex(bComplex1 | bComplex2);
+        pOut->setComplex(bComplex1 || bComplex2);
 
         if (pOut->isComplex())
         {
@@ -2470,14 +2426,14 @@ template<> InternalType* sub_M_M<Double, Sparse, Double>(Double* _pL, Sparse* _p
     {
         //D - SP
         pOut = (Double*)_pL->clone();
-        pOut->setComplex(bComplex1 | bComplex2);
+        pOut->setComplex(bComplex1 || bComplex2);
 
         int nonZeros = static_cast<int>(_pR->nonZeros());
         int* pRows = new int[nonZeros * 2];
         _pR->outputRowCol(pRows);
         int* pCols = pRows + nonZeros;
 
-        if (bComplex1)
+        if (bComplex1 || bComplex2)
         {
             for (int i = 0 ; i < nonZeros ; i++)
             {
@@ -2515,12 +2471,13 @@ template<> InternalType* sub_M_M<Sparse, Double, Double>(Sparse* _pL, Double* _p
     int iOne = 1; //fortran
     bool bComplex1 = _pL->isComplex();
     bool bComplex2 = _pR->isComplex();
+    bool bComplexOut = bComplex1 || bComplex2;
 
     if (_pL->isScalar() && _pR->isScalar())
     {
         //sp - d
         pOut = (Double*)_pR->clone();
-        pOut->setComplex(bComplex1 | bComplex2);
+        pOut->setComplex(bComplexOut);
         if (bComplex1)
         {
             std::complex<double> dbl = _pL->getImg(0, 0);
@@ -2538,7 +2495,7 @@ template<> InternalType* sub_M_M<Sparse, Double, Double>(Sparse* _pL, Double* _p
     if (_pR->isScalar())
     {
         //SP - d
-        pOut = new Double(_pL->getRows(), _pL->getCols(), bComplex1 | bComplex2);
+        pOut = new Double(_pL->getRows(), _pL->getCols(), bComplexOut);
         int iSize = _pL->getSize();
         double dblVal = -_pR->get(0);
         double dblValI = 0;
@@ -2591,7 +2548,7 @@ template<> InternalType* sub_M_M<Sparse, Double, Double>(Sparse* _pL, Double* _p
     {
         //sp - D
         pOut = (Double*)_pR->clone();
-        pOut->setComplex(bComplex1 | bComplex2);
+        pOut->setComplex(bComplexOut);
 
         if (bComplex1)
         {
@@ -2619,46 +2576,45 @@ template<> InternalType* sub_M_M<Sparse, Double, Double>(Sparse* _pL, Double* _p
     }
 
 
-    if (_pL->getRows() == _pR->getRows() && _pL->getCols() == _pR->getCols())
+    if (_pL->getRows() != _pR->getRows() || _pL->getCols() != _pR->getCols())
     {
-        //SP - D
-        pOut = (Double*)_pR->clone();
-        pOut->setComplex(bComplex1 | bComplex2);
+        throw ast::ScilabError(_W("Inconsistent row/column dimensions.\n"));
+    }
 
-        int nonZeros = static_cast<int>(_pL->nonZeros());
-        int* pRows = new int[nonZeros * 2];
-        _pL->outputRowCol(pRows);
-        int* pCols = pRows + nonZeros;
+    //SP - D
+    pOut = new types::Double(_pL->getRows(), _pL->getCols(), _pL->isComplex());
+    _pL->fill(*pOut);
+    int iSize = pOut->getSize();
+    pOut->setComplex(bComplexOut);
+    double* pdblOutR = pOut->get();
+    double* pdblOutI = pOut->getImg(); //can be null for non complex output
+    double* pdblRR = _pR->get();
+    double* pdblRI = _pR->getImg(); //can be null for non complex output
 
-        if (bComplex1)
+    if (bComplex1)
+    {
+        if (bComplex2)
         {
-            for (int i = 0 ; i < nonZeros ; i++)
-            {
-                int iRow = static_cast<int>(pRows[i]) - 1;
-                int iCol = static_cast<int>(pCols[i]) - 1;
-                std::complex<double> dbl = _pL->getImg(iRow, iCol);
-                pOut->set(iRow, iCol, dbl.real() - pOut->get(iRow, iCol));
-                pOut->setImg(iRow, iCol, dbl.imag() - pOut->getImg(iRow, iCol));
-            }
+            sub(pdblOutR, pdblOutI, iSize, pdblRR, pdblRI, pdblOutR, pdblOutI);
         }
         else
         {
-            for (int i = 0 ; i < nonZeros ; i++)
-            {
-                int iRow = static_cast<int>(pRows[i]) - 1;
-                int iCol = static_cast<int>(pCols[i]) - 1;
-                pOut->set(iRow, iCol, _pL->get(iRow, iCol) - pOut->get(iRow, iCol));
-            }
+            sub(pdblOutR, pdblOutI, iSize, pdblRR, pdblOutR, pdblOutI);
         }
-
-        //clear
-        delete[] pRows;
-        return pOut;
     }
     else
     {
-        throw ast::ScilabError(_W("Inconsistent row/column dimensions.\n"));
+        if (bComplex2)
+        {
+            sub(pdblOutR, iSize, pdblRR, pdblRI, pdblOutR, pdblOutI);
+        }
+        else
+        {
+            sub(pdblOutR, iSize, pdblRR, pdblOutR);
+        }
     }
+
+    return pOut;
 }
 
 //[] - sp
index a4d7cce..d303a1f 100644 (file)
@@ -318,8 +318,513 @@ cc=c+rand(6,6)*%i;
 assert_checkequal(full(ac.*c), full(ac).*c);
 assert_checkequal(full(cc.*a), cc.*full(a));
 // sparse sparse
-assert_checkequal(full(ac.*zer), full(zer));
-assert_checkequal : L'objet calculé est de type complexe, cependant il aurait dû être réel.
-at line    86 of function assert_checkequal called by :
-assert_checkequal(full((ac .* zer)), full(zer))
-at line   355 of exec file called by :
+assert_checkequal(full(ac.*zer), full(zer)*%i);
+assert_checkequal(full(zer.*ac), full(zer)*%i);
+assert_checkequal(full(ac.*a), full(ac).*full(a));
+assert_checkequal(full(bc.*b), full(bc).*full(b));
+assert_checkequal(full(a.*bc), full(a).*full(bc));
+assert_checkequal(full(b.*ac), full(b).*full(ac));
+// // complex x complex
+assert_checkequal(full(ac.*cc), full(ac).*cc);
+assert_checkequal(full(cc.*ac), cc.*full(ac));
+// sparse sparse
+assert_checkequal(full(ac.*ac), full(ac).*full(ac));
+assert_checkequal(full(bc.*bc), full(bc).*full(bc));
+assert_checkequal(full(bc.*ac), full(bc).*full(ac));
+// ----------------------------------------------------------
+// test de la transposition
+//-----------------------------------------------------------
+assert_checkequal(full(a'), full(a)');
+assert_checkequal(full(ac'), full(ac)');
+assert_checkequal(full(zer'), full(zer)' );
+v=sparse([2 1;3 1;4 1;6 1],[10;11;12;13],[6,1]);
+assert_checkequal(full(v'), full(v)');
+assert_checkequal(full((v')'), full(v));
+vc=sparse([2 1;3 1;4 1;6 1],[10-3*%i;11;12+5*%i;13+0.5*%i],[6,1]);
+assert_checkequal(full(vc'), full(vc)');
+assert_checkequal(full((vc')'), full(vc));
+// ----------------------------------------------------------
+// test des concatenation
+//-----------------------------------------------------------
+assert_checkequal(full([a]), full(a));
+assert_checkequal(full([a b]), [full(a) full(b)]);
+assert_checkequal(full([a;b]), [full(a);full(b)]);
+assert_checkequal(full([a []]), full(a));
+assert_checkequal(full([a;[]]), full(a));
+assert_checkequal(full([a zer]), [full(a) full(zer)]);
+assert_checkequal(full([zer;b]), [full(zer);full(b)]);
+assert_checkequal(full([ac]), full(ac));
+assert_checkequal(full([ac b]), [full(ac) full(b)]);
+assert_checkequal(full([ac;b]), [full(ac);full(b)]);
+assert_checkequal(full([ac []]), full(ac));
+assert_checkequal(full([ac;[]]), full(ac));
+assert_checkequal(full([a bc]), [full(a) full(bc)]);
+assert_checkequal(full([a;bc]), [full(a);full(bc)]);
+assert_checkequal(full([ac bc]), [full(ac) full(bc)]);
+assert_checkequal(full([ac;bc]), [full(ac);full(bc)]);
+// ----------------------------------------------------------
+// test des extractions
+//-----------------------------------------------------------
+af=full(a);
+assert_checkequal(full(a(1,3)), af(1,3));
+assert_checkequal(full(a(1,4)), af(1,4));
+assert_checkequal(full(a(1,:)), af(1,:));
+v=sparse([2 1;3 1;4 1;6 1],[10;11;12;13],[6,1]);vf=full(v);
+assert_checkequal(full(v(:)), vf(:));
+assert_checkequal(full(v(3:4)), vf(3:4));
+assert_checkequal(full(v([1 5])), vf([1 5]));
+assert_checkequal(full(v([4 3])), vf([4 3]));
+assert_checkequal(full(v([4 4])), vf([4 4]));
+assert_checkequal(full(v([1 1])), vf([1 1]));
+v=v';vf=vf';
+assert_checkequal(full(v(:)), vf(:));
+assert_checkequal(full(v(3:4)), vf(3:4));
+assert_checkequal(full(v([1 5])), vf([1 5]));
+assert_checkequal(full(v([4 3])), vf([4 3]));
+assert_checkequal(full(v([4 4])), vf([4 4]));
+assert_checkequal(full(v([1 1])), vf([1 1]));
+acff=full(ac);
+assert_checkequal(full(ac(1,3)), acff(1,3));
+assert_checkequal(full(ac(1,4)), acff(1,4));
+assert_checkequal(full(ac(1,:)), acff(1,:));
+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);
+assert_checkequal(full(vc(:)), vcf(:));
+assert_checkequal(full(vc(3:4)), vcf(3:4));
+assert_checkequal(full(vc([1 5])), vcf([1 5]));
+assert_checkequal(full(vc([4 3])), vcf([4 3]));
+assert_checkequal(full(vc([4 4])), vcf([4 4]));
+assert_checkequal(full(vc([1 1])), vcf([1 1]));
+vc=vc';vcf=vcf';
+assert_checkequal(full(vc(:)), vcf(:));
+assert_checkequal(full(vc(3:4)), vcf(3:4));
+assert_checkequal(full(vc([1 5])), vcf([1 5]));
+assert_checkequal(full(vc([4 3])), vcf([4 3]));
+assert_checkequal(full(vc([4 4])), vcf([4 4]));
+assert_checkequal(full(vc([1 1])), vcf([1 1]));
+// ----------------------------------------------------------
+// test des insertions
+//-----------------------------------------------------------
+a=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],1:9,[6 6]);
+vt=sparse([1 2;1 3;1 4;1 6],[10;11;12;13],[1,6]);
+// full line insertion
+//----------------------
+a1=a;a1(1,:)=vt;A=full(a);Vt=full(vt);A(1,:)=Vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(3,:)=vt;A=full(a);Vt=full(vt);A(3,:)=Vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(1,:)=vt;A=full(a);Vt=full(vt);A(1,:)=Vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(3,:)=vt;A=full(a);Vt=full(vt);A(3,:)=Vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(7,:)=vt;A=full(a);Vt=full(vt);A(7,:)=Vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(8,:)=vt;A=full(a);Vt=full(vt);A(8,:)=Vt;
+assert_checkequal(full(a1), A);
+a1=a;a1([1 3],:)=[vt;2*vt];A=full(a);Vt=full(vt);A([1 3],:)=[Vt;2*Vt];
+assert_checkequal(full(a1), A);
+a1=a;a1([3 1],:)=[vt;2*vt];A=full(a);Vt=full(vt);A([3 1],:)=[Vt;2*Vt];
+assert_checkequal(full(a1), A);
+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];
+assert_checkequal(full(a1), A);
+//  insert zero vector
+vt=sparse([],[],[1,6]);
+a1=a;a1(1,:)=vt;A=full(a);Vt=full(vt);A(1,:)=Vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(3,:)=vt;A=full(a);Vt=full(vt);A(3,:)=Vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(1,:)=vt;A=full(a);Vt=full(vt);A(1,:)=Vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(3,:)=vt;A=full(a);Vt=full(vt);A(3,:)=Vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(7,:)=vt;A=full(a);Vt=full(vt);A(7,:)=Vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(8,:)=vt;A=full(a);Vt=full(vt);A(8,:)=Vt;
+assert_checkequal(full(a1), A);
+a1=a;a1([1 3],:)=[vt;2*vt];A=full(a);Vt=full(vt);A([1 3],:)=[Vt;2*Vt];
+assert_checkequal(full(a1), A);
+a1=a;a1([3 1],:)=[vt;2*vt];A=full(a);Vt=full(vt);A([3 1],:)=[Vt;2*Vt];
+assert_checkequal(full(a1), A);
+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];
+assert_checkequal(full(a1), A);
+a=sparse([],[],[6,6]);
+a1=a;a1(1,:)=vt;A=full(a);Vt=full(vt);A(1,:)=Vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(3,:)=vt;A=full(a);Vt=full(vt);A(3,:)=Vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(1,:)=vt;A=full(a);Vt=full(vt);A(1,:)=Vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(3,:)=vt;A=full(a);Vt=full(vt);A(3,:)=Vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(7,:)=vt;A=full(a);Vt=full(vt);A(7,:)=Vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(8,:)=vt;A=full(a);Vt=full(vt);A(8,:)=Vt;
+assert_checkequal(full(a1), A);
+b=sparse([1 1;1 3;1 6;2 1;2 2;2 4],10:15,[2,6]);
+a1=a;a1([1 3],:)=b;A=full(a);B=full(b);A([1 3],:)=B;
+assert_checkequal(full(a1), A);
+a1=a;a1([3 1],:)=b;A=full(a);B=full(b);A([3 1],:)=B;
+assert_checkequal(full(a1), A);
+b=sparse([1 1;1 3;1 6;2 1;2 2;2 4;3 3;3 5],10:17,[3,6]);
+a1=a;a1([1 3 1],:)=b;A=full(a);B=full(b);A([1 3 1],:)=B;
+assert_checkequal(full(a1), A);
+//  insert zero vector
+vt=sparse([],[],[1,6]);
+a1=a;a1(1,:)=vt;A=full(a);Vt=full(vt);A(1,:)=Vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(3,:)=vt;A=full(a);Vt=full(vt);A(3,:)=Vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(1,:)=vt;A=full(a);Vt=full(vt);A(1,:)=Vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(3,:)=vt;A=full(a);Vt=full(vt);A(3,:)=Vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(7,:)=vt;A=full(a);Vt=full(vt);A(7,:)=Vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(8,:)=vt;A=full(a);Vt=full(vt);A(8,:)=Vt;
+assert_checkequal(full(a1), A);
+b=sparse([1 1;1 3;1 6;2 1;2 2;2 4],10:15,[2,6]);
+a1=a;a1([1 3],:)=b;A=full(a);B=full(b);A([1 3],:)=B;
+assert_checkequal(full(a1), A);
+a1=a;a1([3 1],:)=b;A=full(a);B=full(b);A([3 1],:)=B;
+assert_checkequal(full(a1), A);
+b=sparse([1 1;1 3;1 6;2 1;2 2;2 4;3 3;3 5],10:17,[3,6]);
+a1=a;a1([1 3 1],:)=b;A=full(a);B=full(b);A([1 3 1],:)=B;
+assert_checkequal(full(a1), A);
+// full column insertion
+//----------------------
+a=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],1:9,[6 6]);
+v=sparse([2 1;3 1;4 1;6 1],[10;11;12;13],[6,1]);
+a1=a;a1(:,1)=v;A=full(a);V=full(v);A(:,1)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,2)=v;A=full(a);V=full(v);A(:,2)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,1)=v;A=full(a);V=full(v);A(:,1)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,2)=v;A=full(a);V=full(v);A(:,2)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,3)=v;A=full(a);V=full(v);A(:,3)=V;
+assert_checkequal(full(a1), A);
+//
+a1=a;a1(:,7)=v;A=full(a);V=full(v);A(:,7)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,8)=v;A=full(a);V=full(v);A(:,8)=V;
+assert_checkequal(full(a1), A);
+b=sparse([1 2;2 1;3 1;3 2;4 1;6 2],10:15,[6,2]);
+a1=a;a1(:,[1 3])=b;A=full(a);B=full(b);A(:,[1 3])=B;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,[3 1])=b;A=full(a);B=full(b);A(:,[3 1])=B;
+assert_checkequal(full(a1), A);
+b=sparse([1 2;2 1;2 3;3 1;3 2;4 1;5 3;6 2],10:17,[6,3]);
+a1=a;a1(:,[1 3 1])=b;A=full(a);B=full(b);A(:,[1 3 1])=B;
+assert_checkequal(full(a1), A);
+v=sparse([],[],[6,1]);
+a1=a;a1(:,1)=v;A=full(a);V=full(v);A(:,1)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,2)=v;A=full(a);V=full(v);A(:,2)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,1)=v;A=full(a);V=full(v);A(:,1)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,2)=v;A=full(a);V=full(v);A(:,2)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,3)=v;A=full(a);V=full(v);A(:,3)=V;
+assert_checkequal(full(a1), A);
+//
+a1=a;a1(:,7)=v;A=full(a);V=full(v);A(:,7)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,8)=v;A=full(a);V=full(v);A(:,8)=V;
+assert_checkequal(full(a1), A);
+b=sparse([],[],[6,2]);
+a1=a;a1(:,[1 3])=b;A=full(a);B=full(b);A(:,[1 3])=B;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,[3 1])=b;A=full(a);B=full(b);A(:,[3 1])=B;
+assert_checkequal(full(a1), A);
+b=sparse([],[],[6,3]);
+a1=a;a1(:,[1 3 1])=b;A=full(a);B=full(b);A(:,[1 3 1])=B;
+assert_checkequal(full(a1), A);
+a=sparse([],[],[6,6]);
+a1=a;a1(:,1)=v;A=full(a);V=full(v);A(:,1)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,2)=v;A=full(a);V=full(v);A(:,2)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,1)=v;A=full(a);V=full(v);A(:,1)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,2)=v;A=full(a);V=full(v);A(:,2)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,3)=v;A=full(a);V=full(v);A(:,3)=V;
+assert_checkequal(full(a1), A);
+//
+a1=a;a1(:,7)=v;A=full(a);V=full(v);A(:,7)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,8)=v;A=full(a);V=full(v);A(:,8)=V;
+assert_checkequal(full(a1), A);
+b=sparse([1 2;2 1;3 1;3 2;4 1;6 2],10:15,[6,2]);
+a1=a;a1(:,[1 3])=b;A=full(a);B=full(b);A(:,[1 3])=B;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,[3 1])=b;A=full(a);B=full(b);A(:,[3 1])=B;
+assert_checkequal(full(a1), A);
+b=sparse([1 2;2 1;2 3;3 1;3 2;4 1;5 3;6 2],10:17,[6,3]);
+a1=a;a1(:,[1 3 1])=b;A=full(a);B=full(b);A(:,[1 3 1])=B;
+assert_checkequal(full(a1), A);
+v=sparse([],[],[6,1]);
+a1=a;a1(:,1)=v;A=full(a);V=full(v);A(:,1)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,2)=v;A=full(a);V=full(v);A(:,2)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,1)=v;A=full(a);V=full(v);A(:,1)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,2)=v;A=full(a);V=full(v);A(:,2)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,3)=v;A=full(a);V=full(v);A(:,3)=V;
+assert_checkequal(full(a1), A);
+//
+a1=a;a1(:,7)=v;A=full(a);V=full(v);A(:,7)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,8)=v;A=full(a);V=full(v);A(:,8)=V;
+assert_checkequal(full(a1), A);
+b=sparse([1 2;2 1;3 1;3 2;4 1;6 2],10:15,[6,2]);
+a1=a;a1(:,[1 3])=b;A=full(a);B=full(b);A(:,[1 3])=B;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,[3 1])=b;A=full(a);B=full(b);A(:,[3 1])=B;
+assert_checkequal(full(a1), A);
+b=sparse([1 2;2 1;2 3;3 1;3 2;4 1;5 3;6 2],10:17,[6,3]);
+a1=a;a1(:,[1 3 1])=b;A=full(a);B=full(b);A(:,[1 3 1])=B;
+assert_checkequal(full(a1), A);
+v=sparse([],[],[6,1]);
+a1=a;a1(:,1)=v;A=full(a);V=full(v);A(:,1)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,2)=v;A=full(a);V=full(v);A(:,2)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,1)=v;A=full(a);V=full(v);A(:,1)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,2)=v;A=full(a);V=full(v);A(:,2)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,3)=v;A=full(a);V=full(v);A(:,3)=V;
+assert_checkequal(full(a1), A);
+//
+a1=a;a1(:,7)=v;A=full(a);V=full(v);A(:,7)=V;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,8)=v;A=full(a);V=full(v);A(:,8)=V;
+assert_checkequal(full(a1), A);
+b=sparse([],[],[6,2]);
+a1=a;a1(:,[1 3])=b;A=full(a);B=full(b);A(:,[1 3])=B;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,[3 1])=b;A=full(a);B=full(b);A(:,[3 1])=B;
+assert_checkequal(full(a1), A);
+b=sparse([],[],[6,3]);
+a1=a;a1(:,[1 3 1])=b;A=full(a);B=full(b);A(:,[1 3 1])=B;
+assert_checkequal(full(a1), A);
+// row column insertion
+a=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],1:9,[6 6]);
+b=sparse([1 2;1 3;3 3],-(1:3),[3,3]);
+a1=a;a1(1,1)=sparse(30);A=full(a);A(1,1)=30;
+assert_checkequal(full(a1), A);
+a1=a;a1(1,6)=sparse(30);A=full(a);A(1,6)=30;
+assert_checkequal(full(a1), A);
+a1=a;a1(1,8)=sparse(30);A=full(a);A(1,8)=30;
+assert_checkequal(full(a1), A);
+a1=a;a1(1:3,1:3)=b;A=full(a);A(1:3,1:3)=full(b);
+assert_checkequal(full(a1), A);
+a1=a;a1(1:3,6:8)=b;A=full(a);A(1:3,6:8)=full(b);
+assert_checkequal(full(a1), A);
+a1=a;a1(6:8,1:3)=b;A=full(a);A(6:8,1:3)=full(b);
+assert_checkequal(full(a1), A);
+a1=a;a1([3 2 1],1:3)=b;A=full(a);A([3 2 1],1:3)=full(b);
+assert_checkequal(full(a1), A);
+a1=a;a1([1 2 1],1:3)=b;A=full(a);A([1 2 1],1:3)=full(b);
+assert_checkequal(full(a1), A);
+a1=a;a1([3 2 1],[3 2 1])=b;A=full(a);A([3 2 1],[3 2 1])=full(b);
+assert_checkequal(full(a1), A);
+a1=a;a1([1 2 1],[3 2 1])=b;A=full(a);A([1 2 1],[3 2 1])=full(b);
+assert_checkequal(full(a1), A);
+a1=a;a1([1 2 1],[1 2 1])=b;A=full(a);A([1 2 1],[1 2 1])=full(b);
+assert_checkequal(full(a1), A);
+//sparse full
+a=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],1:9,[6 6]);
+vt=11:16;
+// full line insertion
+//----------------------
+a1=a;a1(1,:)=vt;A=full(a);A(1,:)=vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(3,:)=vt;A=full(a);A(3,:)=vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(1,:)=vt;A=full(a);A(1,:)=vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(3,:)=vt;A=full(a);A(3,:)=vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(7,:)=vt;A=full(a);A(7,:)=vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(8,:)=vt;A=full(a);A(8,:)=vt;
+assert_checkequal(full(a1), A);
+a1=a;a1([1 3],:)=[vt;2*vt];A=full(a);A([1 3],:)=[vt;2*vt];
+assert_checkequal(full(a1), A);
+a1=a;a1([3 1],:)=[vt;2*vt];A=full(a);A([3 1],:)=[vt;2*vt];
+assert_checkequal(full(a1), A);
+a1=a;a1([1 3 1],:)=[vt;2*vt;3*vt];A=full(a);A([1 3 1],:)=[vt;2*vt;3*vt];
+assert_checkequal(full(a1), A);
+a=sparse([],[],[6,6]);
+a1=a;a1(1,:)=vt;A=full(a);A(1,:)=vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(3,:)=vt;A=full(a);A(3,:)=vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(1,:)=vt;A=full(a);A(1,:)=vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(3,:)=vt;A=full(a);A(3,:)=vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(7,:)=vt;A=full(a);A(7,:)=vt;
+assert_checkequal(full(a1), A);
+a1=a;a1(8,:)=vt;A=full(a);A(8,:)=vt;
+assert_checkequal(full(a1), A);
+b=[1:6;11:16];
+a1=a;a1([1 3],:)=b;A=full(a);A([1 3],:)=b;
+assert_checkequal(full(a1), A);
+a1=a;a1([3 1],:)=b;A=full(a);A([3 1],:)=b;
+assert_checkequal(full(a1), A);
+b=[1:6;11:16;21:26];
+a1=a;a1([1 3 1],:)=b;A=full(a);A([1 3 1],:)=b;
+assert_checkequal(full(a1), A);
+// full column insertion
+//----------------------
+a=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],1:9,[6 6]);
+v=(1:6)';
+a1=a;a1(:,1)=v;A=full(a);A(:,1)=v;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,2)=v;A=full(a);A(:,2)=v;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,1)=v;A=full(a);A(:,1)=v;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,2)=v;A=full(a);A(:,2)=v;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,3)=v;A=full(a);A(:,3)=v;
+assert_checkequal(full(a1), A);
+//
+a1=a;a1(:,7)=v;A=full(a);A(:,7)=v;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,8)=v;A=full(a);A(:,8)=v;
+assert_checkequal(full(a1), A);
+b=[(1:6)' (11:16)'];
+a1=a;a1(:,[1 3])=b;A=full(a);A(:,[1 3])=b;
+assert_checkequal(full(a1), A);
+a1=a;a1(:,[3 1])=b;A=full(a);A(:,[3 1])=b;
+assert_checkequal(full(a1), A);
+b=[(1:6)' (11:16)' (21:26)'];
+a1=a;a1(:,[1 3 1])=b;A=full(a);A(:,[1 3 1])=b;
+assert_checkequal(full(a1), A);
+//********
+// row column insertion
+a=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],1:9,[6 6]);
+b=-[1 2 3;4 5 6;7 8 9];
+a1=a;a1(1,1)=30;A=full(a);A(1,1)=30;
+assert_checkequal(full(a1), A);
+a1=a;a1(1,6)=30;A=full(a);A(1,6)=30;
+assert_checkequal(full(a1), A);
+a1=a;a1(1,8)=30;A=full(a);A(1,8)=30;
+assert_checkequal(full(a1), A);
+a1=a;a1(1:3,1:3)=b;A=full(a);A(1:3,1:3)=b;
+assert_checkequal(full(a1), A);
+a1=a;a1(1:3,6:8)=b;A=full(a);A(1:3,6:8)=b;
+assert_checkequal(full(a1), A);
+a1=a;a1(6:8,1:3)=b;A=full(a);A(6:8,1:3)=b;
+assert_checkequal(full(a1), A);
+a1=a;a1([3 2 1],1:3)=b;A=full(a);A([3 2 1],1:3)=b;
+assert_checkequal(full(a1), A);
+a1=a;a1([1 2 1],1:3)=b;A=full(a);A([1 2 1],1:3)=b;
+assert_checkequal(full(a1), A);
+a1=a;a1([3 2 1],[3 2 1])=b;A=full(a);A([3 2 1],[3 2 1])=b;
+assert_checkequal(full(a1), A);
+a1=a;a1([1 2 1],[3 2 1])=b;A=full(a);A([1 2 1],[3 2 1])=b;
+assert_checkequal(full(a1), A);
+a1=a;a1([1 2 1],[1 2 1])=b;A=full(a);A([1 2 1],[1 2 1])=b;
+assert_checkequal(full(a1), A);
+// vector insertion
+v=sparse([1 1;3 1;6 1],[10 11 12],[6 1]);
+v1=v;v1(1)=33;V=full(v);V(1)=33;
+assert_checkequal(full(v1), V);
+v1=v;v1(2)=33;V=full(v);V(2)=33;
+assert_checkequal(full(v1), V);
+v1=v;v1(8)=33;V=full(v);V(8)=33;
+assert_checkequal(full(v1), V);
+v1=v;v1([1 2 8])=[5;10;33];V=full(v);V([1 2 8])=[5;10;33];
+assert_checkequal(full(v1), V);
+v1=v;v1(:)=[];
+assert_checkequal(full(v1), []);
+v1=v;v1(1)=sparse(33);V=full(v);V(1)=33;
+assert_checkequal(full(v1), V);
+v1=v;v1(2)=sparse(33);V=full(v);V(2)=33;
+assert_checkequal(full(v1), V);
+v1=v;v1(8)=sparse(33);V=full(v);V(8)=33;
+assert_checkequal(full(v1), V);
+v1=v;v1([1 2 8])=sparse([5;10;33]);V=full(v);V([1 2 8])=[5;10;33];
+assert_checkequal(full(v1), V);
+v1=v;v1([1 2 1])=sparse([5;10;33]);V=full(v);V([1 2 1])=[5;10;33];
+assert_checkequal(full(v1), V);
+v1=v;v1(:)=[];
+assert_checkequal(full(v1), []);
+v1=v;v1(:)=sparse([2 1],44,[6 1]);V=full(v);V(:)=[0;44;0;0;0;0];
+assert_checkequal(full(v1), V);
+v=v';
+v1=v;v1(1)=33;V=full(v);V(1)=33;
+assert_checkequal(full(v1), V);
+v1=v;v1(2)=33;V=full(v);V(2)=33;
+assert_checkequal(full(v1), V);
+v1=v;v1(8)=33;V=full(v);V(8)=33;
+assert_checkequal(full(v1), V);
+v1=v;v1([1 2 8])=[5 10 33];V=full(v);V([1 2 8])=[5 10 33];
+assert_checkequal(full(v1), V);
+v1=v;v1(1)=sparse(33);V=full(v);V(1)=33;
+assert_checkequal(full(v1), V);
+v1=v;v1(2)=sparse(33);V=full(v);V(2)=33;
+assert_checkequal(full(v1), V);
+v1=v;v1(8)=sparse(33);V=full(v);V(8)=33;
+assert_checkequal(full(v1), V);
+v1=v;v1([1 2 8])=sparse([5 10 33]);V=full(v);V([1 2 8])=[5 10 33];
+assert_checkequal(full(v1), V);
+v1=v;v1([1 2 1])=sparse([5 10 33]);V=full(v);V([1 2 1])=[5 10 33];
+assert_checkequal(full(v1), V);
+v1=v;v1(:)=sparse([1 2],44,[1,6]);V=full(v);V(:)=[0 44 0 0 0 0];
+assert_checkequal(full(v1), V);
+v1=v;v1(1)=[];V=full(v);V(1)=[];
+assert_checkequal(full(v1), V);
+//test des comparaisons
+a=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],1:9,[6 6]);
+b=sparse([1 6;1 2;6 5],[10;-1;-1],[6 6]);
+assert_checkequal(full(a==a), full(a)==full(a));
+assert_checkequal(full(a<>a), (full(a)<>full(a)));
+assert_checkequal(full(a>sparse(5)), (full(a)>5));
+assert_checkequal(full(sparse(5)>a), (5>full(a)));
+assert_checkequal(full(b>a), (full(b)>full(a)));
+assert_checkequal(full(a==full(a)), full(a)==full(a));
+assert_checkequal(full(a<>full(a)), (full(a)<>full(a)));
+assert_checkequal(full(a>5), (full(a)>5));
+assert_checkequal(full(5>a), (5>full(a)));
+assert_checkequal(full(b>full(a)), (full(b)>full(a)));
+assert_checkequal(full(full(a)==a), full(a)==full(a));
+assert_checkequal(full(full(a)<>a), (full(a)<>full(a)));
+assert_checkequal(full(full(a)>sparse(5)), (full(a)>5));
+assert_checkequal(full(full(b)>a), (full(b)>full(a)));
+a=sparse([1 1;3 1;6 1],[10 11 12],[6 1]);
+assert_checkequal(full(a==a), full(a)==full(a));
+assert_checkequal(full(a<>a), (full(a)<>full(a)));
+assert_checkequal(full(a>sparse(5)), (full(a)>5));
+assert_checkequal(full(sparse(5)>a), (5>full(a)));
+assert_checkequal(full(a==full(a)), full(a)==full(a));
+assert_checkequal(full(a<>full(a)), (full(a)<>full(a)));
+assert_checkequal(full(a>5), (full(a)>5));
+assert_checkequal(full(5>a), (5>full(a)));
+assert_checkequal(full(full(a)==a), full(a)==full(a));
+assert_checkequal(full(full(a)<>a), (full(a)<>full(a)));
+assert_checkequal(full(full(a)>sparse(5)), (full(a)>5));
+a=a';
+assert_checkequal(full(a==a), full(a)==full(a));
+assert_checkequal(full(a<>a), (full(a)<>full(a)));
+assert_checkequal(full(a>sparse(5)), (full(a)>5));
+assert_checkequal(full(sparse(5)>a), (5>full(a)));
+assert_checkequal(full(a==full(a)), full(a)==full(a));
+assert_checkequal(full(a<>full(a)), (full(a)<>full(a)));
+assert_checkequal(full(a>5), (full(a)>5));
+assert_checkequal(full(5>a), (5>full(a)));
+assert_checkequal(full(full(a)==a), full(a)==full(a));
+assert_checkequal(full(full(a)<>a), (full(a)<>full(a)));
+assert_checkequal(full(full(a)>sparse(5)), (full(a)>5));
+a=sparse([1 6;1 5;1 3;2 4;2 1;4 4;4 3;5 1;6 6],1:9,[6 6]);
+b=sparse([1 6;1 2;5 5],[10;-1;-1],[5 6]);
+assert_checkfalse(a==b);
+assert_checktrue(a<>b);
index 3655a27..53189af 100644 (file)
@@ -339,8 +339,8 @@ cc=c+rand(6,6)*%i;
 assert_checkequal(full(ac.*c), full(ac).*c);
 assert_checkequal(full(cc.*a), cc.*full(a));
 // sparse sparse
-assert_checkequal(full(ac.*zer), full(zer));
-assert_checkequal(full(zer.*ac), full(zer));
+assert_checkequal(full(ac.*zer), full(zer)*%i);
+assert_checkequal(full(zer.*ac), full(zer)*%i);
 assert_checkequal(full(ac.*a), full(ac).*full(a));
 assert_checkequal(full(bc.*b), full(bc).*full(b));
 assert_checkequal(full(a.*bc), full(a).*full(bc));