* Bug #13839 fixed - sign() could not be used with sparse matrices 87/17887/5
Nicolas [Thu, 10 Mar 2016 13:29:09 +0000 (14:29 +0100)]
Change-Id: I0d55e54270e46a91438cf4285234c61555b5c000

scilab/CHANGES
scilab/modules/elementary_functions/help/en_US/sign.xml
scilab/modules/elementary_functions/help/fr_FR/sign.xml
scilab/modules/elementary_functions/help/ja_JP/sign.xml
scilab/modules/elementary_functions/help/pt_BR/sign.xml
scilab/modules/elementary_functions/help/ru_RU/sign.xml
scilab/modules/elementary_functions/tests/nonreg_tests/bug_13839.dia.ref [new file with mode: 0644]
scilab/modules/elementary_functions/tests/nonreg_tests/bug_13839.tst [new file with mode: 0644]
scilab/modules/overloading/macros/%sp_sign.sci [new file with mode: 0644]

index b25b6c9..a29d086 100644 (file)
@@ -109,6 +109,7 @@ Other feature additions
 
 * typeof(.., "overload") allows now to get the overloading type-code of an object
 
+* sign() can now handle a sparse matrix.
 
 Installation
 ============
@@ -317,6 +318,8 @@ In 6.0.0:
 
 * Bug #13810 fixed - householder(v, k*v) returned column of %nan. Input parameters were not checked. The Householder matrix could not be returned. Help pages were inaccurate and without examples. There was no householder() demo.
 
+* Bug #13839 fixed - sign() could not be used with sparse matrices
+
 * Bug #13869 fixed - bench_run with option nb_run=10 did not override the NB RUN tags
 
 * Bug #13965 fixed - The rendering of histograms with histplot() was poor
index c62476e..764207e 100644 (file)
     </refnamediv>
     <refsynopsisdiv>
         <title>Syntax</title>
-        <synopsis>X=sign(A)</synopsis>
+        <synopsis>X = sign(A)</synopsis>
     </refsynopsisdiv>
-    <refsection>
+    <refsection role="parameters">
         <title>Arguments</title>
         <variablelist>
             <varlistentry>
                 <term>А</term>
                 <listitem>
-                    <para>real or complex matrix</para>
+                    <para>real or complex matrix. <varname>A</varname> may be sparse.</para>
                 </listitem>
             </varlistentry>
             <varlistentry>
             </varlistentry>
         </variablelist>
     </refsection>
-    <refsection>
+    <refsection role="description">
         <title>Description</title>
         <para>
-            <literal>X=sign(A)</literal> returns the matrix made of the signs of
+            <literal>X = sign(A)</literal> returns the matrix made of the signs of
             <literal>A(i,j)</literal>. For complex <literal>A</literal>,
             <literal>sign(A) = A./abs(A)</literal>.
         </para>
     </refsection>
-    <refsection>
+    <refsection role="examples">
         <title>Examples</title>
-        <programlisting role="example"><![CDATA[ 
+        <programlisting role="example"><![CDATA[
 sign(rand(2,3))
 sign(1+%i)
+sign(sprand(8,3,0.3,"normal"))
  ]]></programlisting>
     </refsection>
     <refsection role="see also">
@@ -68,4 +69,14 @@ sign(1+%i)
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>Extension to sparse matrices
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index d0bc9ef..5ea3c50 100644 (file)
@@ -1,22 +1,58 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2008 - INRIA
+ * Copyright (C) 2015 - 2016 - Samuel GOUGEON
+ * 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.
+ *
+ -->
 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="sign" xml:lang="fr">
     <refnamediv>
         <refname>sign</refname>
         <refpurpose>fonction signe</refpurpose>
     </refnamediv>
-    <refsection>
+    <refsynopsisdiv>
+        <title>Syntaxe</title>
+        <synopsis>X = sign(A)</synopsis>
+    </refsynopsisdiv>
+    <refsection role="parameters">
+        <title>Paramètres</title>
+        <variablelist>
+            <varlistentry>
+                <term>А</term>
+                <listitem>
+                    <para>matrice de nombres réels ou complexes, d'encodage dense ou creux.</para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>X</term>
+                <listitem>
+                    <para>matrice de nombres réels ou complexes.</para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    <refsection role="description">
         <title>Description</title>
         <para>
-            <literal>X=sign(A)</literal> renvoie la matrice contenant les signes
-            de termes <literal>A(i,j)</literal>. Pour les matrices complexes,
-            <literal>sign(A) = A./abs(A)</literal>.
+            <literal>X = sign(A)</literal> renvoie la matrice contenant les signes
+            de termes <literal>A(i,j)</literal>. Pour les matrices de nombres
+            complexes, <literal>sign(A) = A./abs(A)</literal>.
         </para>
     </refsection>
-    <refsection>
+    <refsection role="examples">
         <title>Exemples</title>
-        <programlisting role="example"><![CDATA[ 
+        <programlisting role="example"><![CDATA[
 sign(rand(2,3))
 sign(1+%i)
+sign(sprand(8,3,0.3,"normal"))
  ]]></programlisting>
     </refsection>
     <refsection role="see also">
@@ -27,4 +63,14 @@ sign(1+%i)
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>Historique</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>Extension aux matrices creuses
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index d512ac9..1318081 100644 (file)
@@ -3,7 +3,7 @@
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2008 - INRIA
- * 
+ * Copyright (C) 2015 - 2016 - Samuel GOUGEON
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
  *
  * This file is hereby licensed under the terms of the GNU GPL v2.0,
  * along with this program.
  *
  -->
-
 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="sign" xml:lang="ja">
-    
     <refnamediv>
-        
         <refname>sign</refname>
-        
         <refpurpose>符号関数</refpurpose>
-        
     </refnamediv>
-    
     <refsynopsisdiv>
-        
         <title>呼び出し手順</title>
-        
-        <synopsis>X=sign(A)</synopsis>
-        
+        <synopsis>X = sign(A)</synopsis>
     </refsynopsisdiv>
-    
-    <refsection>
-        
+    <refsection role="parameters">
         <title>引数</title>
-        
         <variablelist>
-            
             <varlistentry>
-                
                 <term>A</term>
-                
                 <listitem>
-                    
-                    <para>実数または複素数の行列</para>
-                    
+                    <para>実数または複素数の行列. <varname>A</varname> may be sparse.</para>
                 </listitem>
-                
             </varlistentry>
-            
             <varlistentry>
-                
                 <term>X</term>
-                
                 <listitem>
-                    
                     <para>実数または複素数の行列</para>
-                    
                 </listitem>
-                
             </varlistentry>
-            
         </variablelist>
-        
     </refsection>
-    
-    <refsection>
-        
+    <refsection role="description">
         <title>説明</title>
-        
         <para>
-            
-            <literal>X=sign(A)</literal> は
-            
+            <literal>X = sign(A)</literal> は
             <literal>A(i,j)</literal>の符号からなる行列を返します.
-            
-            <literal>A</literal>が複素数の場合, 
-            
+            <literal>A</literal>が複素数の場合,
             <literal>sign(A) = A./abs(A)</literal> 関数となります.
-            
         </para>
-        
     </refsection>
-    
-    <refsection>
-        
+    <refsection role="examples">
         <title>例</title>
-        
-        <programlisting role="example"><![CDATA[ 
+        <programlisting role="example"><![CDATA[
 sign(rand(2,3))
 sign(1+%i)
+sign(sprand(8,3,0.3,"normal"))
  ]]></programlisting>
-        
     </refsection>
-    
     <refsection role="see also">
-        
         <title>参照</title>
-        
         <simplelist type="inline">
-            
             <member>
-                
                 <link linkend="abs">abs</link>
-                
             </member>
-            
             <member>
-                
                 <link linkend="csgn">csgn</link>
-                
             </member>
-            
             <member>
-                
                 <link linkend="signm">signm</link>
-                
             </member>
-            
         </simplelist>
-        
     </refsection>
-    
+    <refsection role="history">
+        <title>履歴</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>Extension to sparse matrices
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
-
index 2ac746d..82095a6 100644 (file)
@@ -1,8 +1,7 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
+<?xml version="1.0" encoding="UTF-8"?>
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2008 - INRIA
- * 
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
  *
  * This file is hereby licensed under the terms of the GNU GPL v2.0,
  * along with this program.
  *
  -->
-<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="sign" xml:lang="en">
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="sign" xml:lang="pt">
     <refnamediv>
         <refname>sign</refname>
-        <refpurpose>função de sinal</refpurpose>
+        <refpurpose>função de sinal</refpurpose>
     </refnamediv>
-    <refsection>
-        <title>Descrição</title>
+    <refsynopsisdiv>
+        <title>Seqüência de Chamamento</title>
+        <synopsis>X = sign(A)</synopsis>
+    </refsynopsisdiv>
+    <refsection role="parameters">
+        <title>Parâmetros</title>
+        <variablelist>
+            <varlistentry>
+                <term>?</term>
+                <listitem>
+                    <para>real or complex matrix. <varname>A</varname> may be sparse.</para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>X</term>
+                <listitem>
+                    <para>real or complex matrix</para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    <refsection role="description">
+        <title>Descrição</title>
         <para>
-            <literal>X=sign(A)</literal> retorna a matriz feita dos sinais de
+            <literal>X = sign(A)</literal> retorna a matriz feita dos sinais de
             <literal>A(i,j)</literal>. Para <literal>A</literal>, feita de complexos
             <literal>sign(A) = A./abs(A)</literal>.
         </para>
     </refsection>
-    <refsection>
+    <refsection role="examples">
         <title>Exemplos</title>
-        <programlisting role="example"><![CDATA[ 
+        <programlisting role="example"><![CDATA[
 sign(rand(2,3))
 sign(1+%i)
+sign(sprand(8,3,0.3,"normal"))
  ]]></programlisting>
     </refsection>
     <refsection role="see also">
-        <title>Ver Também</title>
+        <title>Ver Também</title>
         <simplelist type="inline">
             <member>
                 <link linkend="abs">abs</link>
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>Histórico</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>Extension to sparse matrices
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index 90bc95f..ea02cc1 100644 (file)
@@ -2,7 +2,7 @@
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2008 - INRIA
- * 
+ *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
  *
  * This file is hereby licensed under the terms of the GNU GPL v2.0,
     </refnamediv>
     <refsynopsisdiv>
         <title>Последовательность вызова</title>
-        <synopsis>X=sign(A)</synopsis>
+        <synopsis>X = sign(A)</synopsis>
     </refsynopsisdiv>
-    <refsection>
+    <refsection role="parameters">
         <title>Аргументы</title>
         <variablelist>
             <varlistentry>
                 <term>А</term>
                 <listitem>
-                    <para>вещественная или комплексная матрица</para>
+                    <para>вещественная или комплексная матрица. <varname>A</varname> may be sparse.</para>
                 </listitem>
             </varlistentry>
             <varlistentry>
             </varlistentry>
         </variablelist>
     </refsection>
-    <refsection>
+    <refsection role="description">
         <title>Описание</title>
         <para>
-            <literal>X=sign(A)</literal> возвращает матрицу, созданную из знаков 
+            <literal>X = sign(A)</literal> возвращает матрицу, созданную из знаков
             <literal>A(i,j)</literal>. Для комплексной  <literal>A</literal>
             <literal>sign(A) = A./abs(A)</literal>.
         </para>
     </refsection>
-    <refsection>
+    <refsection role="examples">
         <title>Примеры</title>
-        <programlisting role="example"><![CDATA[ 
+        <programlisting role="example"><![CDATA[
 sign(rand(2,3))
 sign(1+%i)
+sign(sprand(8,3,0.3,"normal"))
  ]]></programlisting>
     </refsection>
     <refsection role="see also">
@@ -68,4 +69,14 @@ sign(1+%i)
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>История</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>Extension to sparse matrices
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
diff --git a/scilab/modules/elementary_functions/tests/nonreg_tests/bug_13839.dia.ref b/scilab/modules/elementary_functions/tests/nonreg_tests/bug_13839.dia.ref
new file mode 100644 (file)
index 0000000..78aeb1a
--- /dev/null
@@ -0,0 +1,28 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2016 - Samuel GOUGEON
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- CLI SHELL MODE -->
+//
+// <-- Non-regression test for bug 13839 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=13839
+//
+// <-- Short Description -->
+//    sign() did not accept sparse matrices
+m = sprand(100,10,0.007);
+i = find(m~=0 & m<0.5);
+m(i) = m(i)-0.5;
+try
+    sign(m);
+catch
+    pause
+end
+try
+    sign(m+%i*m);
+catch
+    pause
+end
diff --git a/scilab/modules/elementary_functions/tests/nonreg_tests/bug_13839.tst b/scilab/modules/elementary_functions/tests/nonreg_tests/bug_13839.tst
new file mode 100644 (file)
index 0000000..78aeb1a
--- /dev/null
@@ -0,0 +1,28 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2016 - Samuel GOUGEON
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- CLI SHELL MODE -->
+//
+// <-- Non-regression test for bug 13839 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=13839
+//
+// <-- Short Description -->
+//    sign() did not accept sparse matrices
+m = sprand(100,10,0.007);
+i = find(m~=0 & m<0.5);
+m(i) = m(i)-0.5;
+try
+    sign(m);
+catch
+    pause
+end
+try
+    sign(m+%i*m);
+catch
+    pause
+end
diff --git a/scilab/modules/overloading/macros/%sp_sign.sci b/scilab/modules/overloading/macros/%sp_sign.sci
new file mode 100644 (file)
index 0000000..83aca2d
--- /dev/null
@@ -0,0 +1,25 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - 2016 - Samuel GOUGEON
+// 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.
+
+// Beware about the bug http://bugzilla.scilab.org/14460
+
+function r = %sp_sign(m)
+    r = m
+    c = find(imag(m)~=0)
+    if c~=[] then
+        r(c) = m(c) ./ abs(m(c))
+    end
+
+    re = real(m)
+    im = imag(m)
+    r(find(im==0 & re>0)) = 1
+    r(find(im==0 & re<0)) = -1
+endfunction