* Bug 15753 fixed: issparse(sparseBooleans) returned 0 84/20484/3
Samuel GOUGEON [Sat, 1 Sep 2018 23:44:49 +0000 (01:44 +0200)]
  http://bugzilla.scilab.org/15753

Change-Id: I9c2374001fdb26fd5b913a556a0f0cb8d8a05f1a

scilab/CHANGES.md
scilab/modules/sparse/help/en_US/matrixmanip/issparse.xml
scilab/modules/sparse/help/ja_JP/matrixmanip/issparse.xml
scilab/modules/sparse/macros/issparse.sci
scilab/modules/sparse/tests/nonreg_tests/bug_15753.tst [new file with mode: 0644]

index d4649ea..ffeec98 100644 (file)
@@ -571,6 +571,7 @@ Known issues
 * [#15735](http://bugzilla.scilab.org/show_bug.cgi?id=15735): `interp1` yielded some []+n warnings.
 * [#15736](http://bugzilla.scilab.org/show_bug.cgi?id=15736): `unique` failed with complex numbers.
 * [#15747](http://bugzilla.scilab.org/show_bug.cgi?id=15747): no output in overloaded operator crashed Scilab 
+* [#15753](http://bugzilla.scilab.org/show_bug.cgi?id=15753): `issparse()` returned 0 instead of 1 for sparse booleans.
 * [#15758](http://bugzilla.scilab.org/show_bug.cgi?id=15758): sparse([0 0],1) crashes scilab (regression)
 * [#15762](http://bugzilla.scilab.org/show_bug.cgi?id=15762): `error()` refused multiline error messages.
 
index 5dade76..3683996 100644 (file)
  * 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="issparse" 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="issparse" xml:lang="en">
     <refnamediv>
         <refname>issparse</refname>
-        <refpurpose>determine whether input is sparse</refpurpose>
+        <refpurpose>tests whether the input is sparse encoded (numeric or boolean)</refpurpose>
     </refnamediv>
     <refsynopsisdiv>
         <title>Syntax</title>
@@ -34,7 +37,7 @@
             <varlistentry>
                 <term>res</term>
                 <listitem>
-                    <para>1 is the matrix is a sparse and 0 otherwise/</para>
+                    <para>1 if the matrix is a sparse, and 0 otherwise/</para>
                 </listitem>
             </varlistentry>
         </variablelist>
         <title>Description</title>
         <para>
             <literal>res = issparse(S)</literal> returns 1 if S is a sparse
-            matrix and 0 otherwise.
+            boolean or numerical matrix, and 0 otherwise.
         </para>
     </refsection>
     <refsection>
         <title>Examples</title>
-        <programlisting role="example">sp = sparse([1,2;4,5;3,10],[1,2,3]);
-            if issparse(sp) == 1 then
-            disp("It is a sparse");
-            end
+        <programlisting role="example"><![CDATA[
+sp = sprand(10, 20, 0.1);
+if issparse(sp) == 1 then
+   mprintf("Number of non-zero components: %d", nnz(sp));
+end
 
-            A = 1;
-            if issparse(A) == 0 then
-            disp("It is not a sparse");
-            end
-        </programlisting>
+A = %T;
+if issparse(A) == 0 then
+    disp("A is not a sparse matrix");
+end
+
+spb = sp~=0 & sp&lt;0.5;
+issparse(spb)
+nnz(spb)
+    ]]></programlisting>
     </refsection>
     <refsection role="see also">
         <title>See also</title>
         <simplelist type="inline">
             <member>
+                <link linkend="isreal">isreal</link>
+            </member>
+            <member>
+                <link linkend="sparse">sparse</link>
+            </member>
+            <member>
                 <link linkend="type">type</link>
             </member>
             <member>
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0.2</revnumber>
+                <revdescription>
+                    issparse() now returns 1 instead of 0 for sparse booleans.
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index 49c4b07..e05fe89 100644 (file)
  * 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="issparse" xml:lang="ja">
+<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="issparse" xml:lang="ja">
     <refnamediv>
         <refname>issparse</refname>
-        <refpurpose>入力値が疎行列かどうかを調べる</refpurpose>
+        <refpurpose>入力値が疎行列かどうかを調べる (numeric or boolean)</refpurpose>
     </refnamediv>
     <refsynopsisdiv>
         <title>呼び出し手順</title>
     </refsection>
     <refsection>
         <title>例</title>
-        <programlisting role="example">sp = sparse([1,2;4,5;3,10],[1,2,3]);
-            if issparse(sp) == 1 then
-            disp("It is a sparse");
-            end
-            A = 1;
-            if issparse(A) == 0 then
-            disp("It is not a sparse");
-            end
-        </programlisting>
+        <programlisting role="example"><![CDATA[
+sp = sprand(10, 20, 0.1);
+if issparse(sp) == 1 then
+   mprintf("Number of non-zero components: %d", nnz(sp));
+end
+
+A = %T;
+if issparse(A) == 0 then
+    disp("A is not a sparse matrix");
+end
+
+spb = sp~=0 & sp&lt;0.5;
+issparse(spb)
+nnz(spb)
+    ]]></programlisting>
     </refsection>
     <refsection role="see also">
         <title>参照</title>
         <simplelist type="inline">
             <member>
+                <link linkend="isreal">isreal</link>
+            </member>
+            <member>
+                <link linkend="sparse">sparse</link>
+            </member>
+            <member>
                 <link linkend="type">type</link>
             </member>
             <member>
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>履歴</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0.2</revnumber>
+                <revdescription>
+                    issparse() now returns 1 instead of 0 for sparse booleans.
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index 1286a5a..fb07f1c 100644 (file)
@@ -11,9 +11,9 @@
 // along with this program.
 
 
-function r=issparse(x)
-    r=0;
-    if or(type(x)==[5,7]) then
-        r=1
+function r = issparse(x)
+    r = 0;
+    if or(type(x)==[5 6 7]) then
+        r = 1
     end
 endfunction
diff --git a/scilab/modules/sparse/tests/nonreg_tests/bug_15753.tst b/scilab/modules/sparse/tests/nonreg_tests/bug_15753.tst
new file mode 100644 (file)
index 0000000..eb1aec9
--- /dev/null
@@ -0,0 +1,18 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2018 - Samuel GOUGEON
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- CLI SHELL MODE -->
+// <-- NO CHECK REF -->
+//
+// <-- Non-regression test for bug 15753 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/15753
+//
+// <-- Short Description -->
+// issparse(sparseBoolean) returned 0 instead of 1
+
+assert_checkequal(issparse(sparse([1 2 3])<2), 1);