*Bug #14330 fixed - luget was really slow. 43/19043/3
Adeline CARNIS [Mon, 6 Feb 2017 15:16:29 +0000 (16:16 +0100)]
Change-Id: I193f028fe0ee78d5cdf3e80ee0d10350ced5b986

scilab/CHANGES.md
scilab/modules/core/help/en_US/1_keywords/backslash.xml
scilab/modules/core/help/fr_FR/1_keywords/backslash.xml
scilab/modules/core/help/ja_JP/1_keywords/backslash.xml
scilab/modules/core/help/pt_BR/1_keywords/backslash.xml
scilab/modules/core/help/ru_RU/1_keywords/backslash.xml
scilab/modules/sparse/sci_gateway/cpp/sci_luget.cpp
scilab/modules/sparse/tests/nonreg_tests/bug_14330.tst [new file with mode: 0644]

index d519759..acab6fe 100644 (file)
@@ -401,6 +401,7 @@ Bug Fixes
 * [#14192](http://bugzilla.scilab.org/show_bug.cgi?id=14192): `g_margin` error-ed for double integrator.
 * [#14278](http://bugzilla.scilab.org/show_bug.cgi?id=14278): `ltitr` returned an incorrect xf output value.
 * [#14306](http://bugzilla.scilab.org/show_bug.cgi?id=14306): Comparisons `>` and `>=` between integers of mismatching inttypes were not implemented.
+* [#14330](http://bugzilla.scilab.org/show_bug.cgi?id=14330): luget was really slow.
 * [#14367](http://bugzilla.scilab.org/show_bug.cgi?id=14367): `edit_curv` failed opening due to a `[]+1` operation.
 * [#14379](http://bugzilla.scilab.org/show_bug.cgi?id=14379): Problem with lists of functions having 2 arguments.
 * [#14395](http://bugzilla.scilab.org/show_bug.cgi?id=14395): `dir` displayed a []+".." warning when no subdirectory exists.
index 6c2fae5..66faade 100644 (file)
@@ -92,7 +92,7 @@ A*x-b, A*y-b
 // A benchmark of several linear solvers
 
 [A,descr,ref,mtype] = ReadHBSparse(SCI+..
-   "/modules/umfpack/examples/bcsstk24.rsa");
+   "/modules/umfpack/demos/bcsstk24.rsa");
 
 b = zeros(size(A,1),1);
 
index bc6fcd4..afa6cae 100644 (file)
@@ -40,7 +40,7 @@ A=rand(3,1)*rand(1,2); b=[1;1;1]; x=A\b; y=pinv(A)*b; A*x-b, A*y-b
 A=rand(2,1)*rand(1,3); b=[1;1]; x=A\b; y=pinv(A)*b; A*x-b, A*y-b
 // Une comparaison de différents solveurs linéaire creux
 
-[A,descr,ref,mtype] = ReadHBSparse(SCI+"/modules/umfpack/examples/bcsstk24.rsa");
+[A,descr,ref,mtype] = ReadHBSparse(SCI+"/modules/umfpack/demos/bcsstk24.rsa");
 
 b = zeros(size(A,1),1);
 
index f6bd86e..41f9b05 100644 (file)
 <?xml version="1.0" encoding="UTF-8"?>
 
 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="ja" xml:id="backslash">
-
+    
     <refnamediv>
-
+        
         <refname>backslash</refname>
-
+        
         <refpurpose>(\) 左行列除算.</refpurpose>
-
+        
     </refnamediv>
-
+    
     <refsynopsisdiv>
-
+        
         <title>呼び出し手順</title>
-
+        
         <synopsis>X=A\B</synopsis>
-
+        
     </refsynopsisdiv>
-
+    
     <refsection>
-
+        
         <title>説明</title>
-
+        
         <para>
-
+            
             バックスラッシュは左行列除算を定義します.
-
+            
             <literal>X=A\B</literal> は <literal>A*X=B</literal>の解です.
-
+            
         </para>
-
+        
         <para>
-
+            
             <literal>A</literal> が正方で非特異の場合,
-
+            
             <literal>X=A\B</literal> は <literal>X=inv(A)*B</literal>
-
+            
             と等価です.しかし,計算はより正確で浮動小数点演算の負荷は小さくなります.
-
+            
             すなわち,線形システムの方程式<code>A*X=B</code>の解を計算する際には,
-
+            
             バックスラッシュ演算子を使用するべきであり,<function>inv</function>関数の
-
+            
             使用は避けるべきです.
-
+            
         </para>
-
+        
         <para>
-
+            
             <literal>A</literal>が正方の場合, 解<literal>X</literal>は
-
+            
             LU分解または線形最小二乗ソルバのどちらかにより計算できます.
-
+            
             <literal>A</literal>の条件数が<code>1/(10*%eps)</code>よりも小さい場合
-
+            
             (つまり,<literal>A</literal>の条件が良い場合),ピボット選択付きLU分解が使用されます.
-
+            
             そうでない場合(<literal>A</literal>の条件が悪い場合),
-
+            
             <literal>X</literal> は<literal>A</literal>の完全直交分解を用いて
-
+            
             <literal>||A*X-B||</literal>を最小化する最小ノルム解となります
-
+            
             (すなわち,<literal>X</literal>は線形最小二乗問題の解です).
-
+            
         </para>
-
+        
         <para>
-
+            
             <literal>A</literal> が正方でない場合, <literal>X</literal> は最小二乗解となります.
-
+            
             すなわち, <code>norm(A*X-B)</code> は,最小値 (ユークリッドノルム)となります.
-
+            
             <literal>A</literal> が列フルランクの場合,最小二乗解, <literal>X=A\B</literal>, は
-
+            
             唯一の解 (<literal>norm(A*X-B)</literal>を最小化する唯一の
-
+            
             <literal>X</literal>が存在)となります.
-
+            
             <literal>A</literal> が列フルランクでない場合, 最小二乗解は唯一ではなくなり,
-
+            
             <literal>X=A\B</literal>は一般に最小ノルム解ではなくなります
-
+            
             (最小ノルム解は <literal>X=pinv(A)*B</literal>です).
-
+            
         </para>
-
+        
         <para>
-
+            
             <literal>A.\B</literal>  は<literal>(i,j)</literal> エントリが
-
+            
             <literal>A(i,j)\B(i,j)</literal>となる行列となります.
-
+            
             <literal>A.\B</literal> は
-
+            
             <literal>A*ones(B).\B</literal> (または <literal>A.\(B*ones(A))</literal>
-
+            
             と等価になります.
-
+            
         </para>
-
+        
         <para>
-
+            
             <literal>A\.B</literal>  は定義されていない演算子です.
-
+            
             この演算子は, <literal>*</literal> または <literal>/</literal> のように
-
+            
             新しい演算子を定義する際に使用できます
-
+            
             (<link linkend="overloading">オーバーロード</link>参照).
-
+            
         </para>
-
+        
     </refsection>
-
+    
     <refsection>
-
+        
         <title>例</title>
-
+        
         <programlisting role="example"><![CDATA[
 A=[
    9.   -36.    30.
@@ -157,7 +157,7 @@ A*x-b, A*y-b
 // 複数の線形ソルバのベンチマーク
 
 [A,descr,ref,mtype] = ReadHBSparse(SCI+..
-   "/modules/umfpack/examples/bcsstk24.rsa");
+   "/modules/umfpack/demos/bcsstk24.rsa");
 
 b = zeros(size(A,1),1);
 
@@ -173,79 +173,79 @@ tic();
 res = A\b;
 mprintf('\ntime with backslash: %.3f\n',toc());
  ]]></programlisting>
-
+        
     </refsection>
-
+    
     <refsection role="see also">
-
+        
         <title>参照</title>
-
+        
         <simplelist type="inline">
-
+            
             <member>
-
+                
                 <link linkend="slash">slash</link>
-
+                
             </member>
-
+            
             <member>
-
+                
                 <link linkend="inv">inv</link>
-
+                
             </member>
-
+            
             <member>
-
+                
                 <link linkend="pinv">pinv</link>
-
+                
             </member>
-
+            
             <member>
-
+                
                 <link linkend="percent">percent</link>
-
+                
             </member>
-
+            
             <member>
-
+                
                 <link linkend="ieee">ieee</link>
-
+                
             </member>
-
+            
             <member>
-
+                
                 <link linkend="linsolve">linsolve</link>
-
+                
             </member>
-
+            
             <member>
-
+                
                 <link linkend="umfpack">umfpack</link>
-
+                
             </member>
-
+            
         </simplelist>
-
+        
     </refsection>
-
+    
     <refsection>
-
+        
         <title>履歴</title>
-
+        
         <revhistory>
-
+            
             <revision>
-
+                
                 <revnumber>5.4.1</revnumber>
-
+                
                 <revremark>バックスラッシュの条件数の閾値が増加しました.</revremark>
-
+                
             </revision>
-
+            
         </revhistory>
-
+        
     </refsection>
-
+    
 </refentry>
 
 
index 476cb5b..3f72aca 100644 (file)
@@ -52,7 +52,7 @@ A=rand(2,1)*rand(1,3); b=[1;1]; x=A\b; y=pinv(A)*b; A*x-b, A*y-b
 
 // A benchmark of several linear solvers
 
-[A,descr,ref,mtype] = ReadHBSparse(SCI+"/modules/umfpack/examples/bcsstk24.rsa");
+[A,descr,ref,mtype] = ReadHBSparse(SCI+"/modules/umfpack/demos/bcsstk24.rsa");
 
 b = zeros(size(A,1),1);
 
index 3e9ef29..6f354cf 100644 (file)
@@ -96,7 +96,7 @@ A*x-b, A*y-b
 
 // Проверка эффективности нескольких программ решения систем линейных уравнений
 
-[A,descr,ref,mtype] = ReadHBSparse(SCI+"/modules/umfpack/examples/bcsstk24.rsa");
+[A,descr,ref,mtype] = ReadHBSparse(SCI+"/modules/umfpack/demos/bcsstk24.rsa");
 
 b = zeros(size(A,1),1);
 
index ad8106d..a60401f 100644 (file)
@@ -1,17 +1,17 @@
 /*
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2014 - Scilab Enterprises - Anais AUBERT
- *
- * Copyright (C) 2012 - 2016 - Scilab Enterprises
- *
- * This file is hereby licensed under the terms of the GNU GPL v2.0,
- * pursuant to article 5.3.4 of the CeCILL v.2.1.
- * This file was originally licensed under the terms of the CeCILL v2.1,
- * and continues to be available under such terms.
- * For more information, see the COPYING file which you should have received
- * along with this program.
- *
- */
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2014 - Scilab Enterprises - Anais AUBERT
+*
+* Copyright (C) 2012 - 2016 - Scilab Enterprises
+*
+* This file is hereby licensed under the terms of the GNU GPL v2.0,
+* pursuant to article 5.3.4 of the CeCILL v.2.1.
+* This file was originally licensed under the terms of the CeCILL v2.1,
+* and continues to be available under such terms.
+* For more information, see the COPYING file which you should have received
+* along with this program.
+*
+*/
 
 #include "sparse_gw.hxx"
 #include "function.hxx"
@@ -31,35 +31,34 @@ extern "C"
 }
 types::Function::ReturnValue sci_luget(types::typed_list &in, int _iRetCount, types::typed_list &out)
 {
-    double abstol   = 0;
-    double reltol   = 0.001;
-    int nrank       = 0;
-    int ierr        = 0;
-    int n1          = 0;
-    int nl          = 0;
-    int nu          = 0;
-    int tp          = 0;
-    int nonZerosP   = 0;
-    int nonZerosL   = 0;
-    int nonZerosU   = 0;
-    int nonZerosQ   = 0;
-
-    bool cplx           = false;
-    const void* pData   = NULL;
-
-    double* dblP    = NULL;
-    double* dblL    = NULL;
-    double* dblU    = NULL;
-    double* dblQ    = NULL;
-    int* itemsRowP  = NULL;
-    int* itemsRowL  = NULL;
-    int* itemsRowU  = NULL;
-    int* itemsRow   = NULL;
-    int* itemsRowQ  = NULL;
-    int* fmatindex  = NULL;
+    double abstol = 0;
+    double reltol = 0.001;
+    int nrank = 0;
+    int ierr = 0;
+    int n1 = 0;
+    int nl = 0;
+    int nu = 0;
+    int nonZerosP = 0;
+    int nonZerosL = 0;
+    int nonZerosU = 0;
+    int nonZerosQ = 0;
+
+    bool cplx = false;
+    const void* pData = NULL;
+
+    double* dblP = NULL;
+    double* dblL = NULL;
+    double* dblU = NULL;
+    double* dblQ = NULL;
+    int* itemsRowP = NULL;
+    int* itemsRowL = NULL;
+    int* itemsRowU = NULL;
+    int* itemsRow = NULL;
+    int* itemsRowQ = NULL;
+    int* fmatindex = NULL;
 
     //check input parameters
-    if (in.size() != 1 )
+    if (in.size() != 1)
     {
         Scierror(999, _("%s: Wrong number of input argument(s): %d  expected.\n"), "luget", 1);
         return types::Function::Error;
@@ -107,46 +106,30 @@ types::Function::ReturnValue sci_luget(types::typed_list &in, int _iRetCount, ty
 
     C2F(luget1)(fmatindex, itemsRowP, dblP, itemsRowL, dblL, itemsRowU, dblU, itemsRowQ, dblQ, &ierr);
 
-    tp = n1;
-    for (int i = 0; i < n1; i++)
-    {
-        for (int j = 0; j < itemsRowP[i]; j++)
-        {
-            p->set(i, itemsRowP[j + tp] - 1, dblP[j + tp - n1], true);
-        }
-        tp += itemsRowP[i];
-    }
+    int tpL = n1;
+    int tpU = n1;
 
-    tp = n1;
     for (int i = 0; i < n1; i++)
     {
+        p->set(i, itemsRowP[i + n1] - 1, dblP[i], false);
+        q->set(i, itemsRowQ[i + n1] - 1, dblQ[i], false);
+
         for (int j = 0; j < itemsRowL[i]; j++)
         {
-
-            l->set(i, itemsRowL[j + tp] - 1, dblL[j + tp - n1], true);
+            l->set(i, itemsRowL[j + tpL] - 1, dblL[j + tpL - n1], false);
         }
-        tp += itemsRowL[i];
-    }
-
-    tp = n1;
-    for (int i = 0; i < n1; i++)
-    {
+        tpL += itemsRowL[i];
         for (int j = 0; j < itemsRowU[i]; j++)
         {
-            u->set(i, itemsRowU[j + tp] - 1, dblU[j + tp - n1], true);
+            u->set(i, itemsRowU[j + tpU] - 1, dblU[j + tpU - n1], false);
         }
-        tp += itemsRowU[i];
+        tpU += itemsRowU[i];
     }
 
-    tp = n1;
-    for (int i = 0; i < n1; i++)
-    {
-        for (int j = 0; j < itemsRowQ[i]; j++)
-        {
-            q->set(i, itemsRowQ[j + tp] - 1, dblQ[j + tp - n1], true);
-        }
-        tp += itemsRowQ[i];
-    }
+    p->finalize();
+    q->finalize();
+    u->finalize();
+    l->finalize();
 
     out.push_back(p);
     out.push_back(l);
diff --git a/scilab/modules/sparse/tests/nonreg_tests/bug_14330.tst b/scilab/modules/sparse/tests/nonreg_tests/bug_14330.tst
new file mode 100644 (file)
index 0000000..5d4146c
--- /dev/null
@@ -0,0 +1,24 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2017 - Scilab Enterprises - Adeline CARNIS
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- CLI SHELL MODE -->
+// <-- NO CHECK REF -->
+
+
+// <-- Non-regression test for bug 14330 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=
+//
+// <-- Short Description -->
+//    luget was really slow.
+
+[A,descr,ref,mtype] = ReadHBSparse(SCI+"/modules/umfpack/demos/bcsstk24.rsa");
+[hand,rk] = lufact(A);
+[P,L,U,Q] = luget(hand);
+assert_checktrue(norm(P*L*U*Q-A)<1d-2);
+ludel(hand);