* Bug 16097 fixed: tanh() & coth() improved 88/20988/4
Samuel GOUGEON [Mon, 27 May 2019 17:54:28 +0000 (19:54 +0200)]
  http://bugzilla.scilab.org/16097

  - coth() 2.3x faster
  - tanh & coth now accept sparses

Change-Id: I7f46e055bb754416e1d00c5a00bfad24d0273803

15 files changed:
scilab/CHANGES.md
scilab/modules/elementary_functions/help/en_US/trigonometry/coth.xml
scilab/modules/elementary_functions/help/en_US/trigonometry/tanh.xml
scilab/modules/elementary_functions/help/fr_FR/trigonometry/coth.xml
scilab/modules/elementary_functions/help/fr_FR/trigonometry/tanh.xml
scilab/modules/elementary_functions/help/ja_JP/trigonometry/coth.xml
scilab/modules/elementary_functions/help/ja_JP/trigonometry/tanh.xml
scilab/modules/elementary_functions/help/pt_BR/trigonometry/coth.xml
scilab/modules/elementary_functions/help/pt_BR/trigonometry/tanh.xml
scilab/modules/elementary_functions/help/ru_RU/trigonometry/coth.xml
scilab/modules/elementary_functions/help/ru_RU/trigonometry/tanh.xml
scilab/modules/elementary_functions/macros/%sp_tanh.sci [new file with mode: 0644]
scilab/modules/elementary_functions/macros/coth.sci
scilab/modules/elementary_functions/tests/unit_tests/coth.tst [new file with mode: 0644]
scilab/modules/elementary_functions/tests/unit_tests/tanh.tst [new file with mode: 0644]

index fe0b712..fb0b0cc 100644 (file)
@@ -286,6 +286,7 @@ Bug Fixes
 * [#16085](http://bugzilla.scilab.org/show_bug.cgi?id=16085): insertion in an empty struct was broken.
 * [#16087](http://bugzilla.scilab.org/show_bug.cgi?id=16087): Insertion of struct in a non-empty struct crashed Scilab.
 * [#16089](http://bugzilla.scilab.org/show_bug.cgi?id=16089): x=1:1e10 freezed Scilab.
+* [#16097](http://bugzilla.scilab.org/show_bug.cgi?id=16097): `coth()` was more than twice slower than `1./tanh()`. `tanh` and `coth` did not accept sparse-encoded input.
 * [#16104](http://bugzilla.scilab.org/show_bug.cgi?id=16104): `assert_checkequal` did not support properly or at all Nan and void in lists, Nan in sparse, implicit lists, macros, libraries, built-in functions, graphical handles. For input arrays or lists of matching typeof and sizes, the failure message did not display neither the index nor the values of the first mismatching elements.
 * [#16111](http://bugzilla.scilab.org/show_bug.cgi?id=16111): `isglobal` was not supporting non-scalar array of strings as input.
 * [#16118](http://bugzilla.scilab.org/show_bug.cgi?id=16118): `%s <> (1+%s)` returned %F.
index bf388e1..ca8d4cb 100644 (file)
@@ -2,8 +2,8 @@
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2008 - INRIA
- *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ * Copyright (C) 2019 - Samuel GOUGEON
  *
  * 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.
  * 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="coth" 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="coth" xml:lang="en">
     <refnamediv>
         <refname>coth</refname>
         <refpurpose>hyperbolic cotangent</refpurpose>
     </refnamediv>
     <refsynopsisdiv>
         <title>Syntax</title>
-        <synopsis>[t] = coth(x)</synopsis>
+        <synopsis>t = coth(x)</synopsis>
     </refsynopsisdiv>
     <refsection>
         <title>Arguments</title>
             <varlistentry>
                 <term>x</term>
                 <listitem>
-                    <para>a real or complex vector or matrix.</para>
+                    <para>
+                      vector or matrix of real or complex numbers (full or sparse-encoded).
+                   </para>
                 </listitem>
             </varlistentry>
             <varlistentry>
                 <term>t</term>
                 <listitem>
-                    <para>a real or complex vector or matrix.</para>
+                    <para>a full-encoded vector or matrix of real or complex numbers.</para>
                 </listitem>
             </varlistentry>
         </variablelist>
             The elements of <varname>t</varname> are the hyperbolic
             cotangent of elements of <varname>x</varname>.
         </para>
+        <note>
+          <literal>coth(0)</literal> not being 0, the result for any input
+          sparse-encoded matrix is always full-encoded (as for <literal>cos()</literal>).
+        </note>
     </refsection>
     <refsection>
         <title>Examples</title>
         <programlisting role="example"><![CDATA[
-x=[1,2*%i]
-t=exp(x);
+x = [1, 2*%i]
+t = exp(x);
 (t-ones(x)./t).\(t+ones(x)./t)
 coth(x)
+coth([-0 0])
+
+// With sparses:
+s = sparse([1 1; 3 1; 2 2; 2 3; 1 3],[0.02 0.7 0.15 0.4 3],[3 3])
+coth(s)   // no longer sparse
  ]]></programlisting>
+    <screen>
+--> (t-ones(x)./t).\(t+ones(x)./t)
+ ans  =
+   1.3130353   0.4576576i
+
+--> coth(x)
+ ans  =
+   1.3130353   0.4576576i
+
+--> coth([-0 0])
+ ans  =
+  -Inf   Inf
+
+--> // With sparses:
+--> s = sparse([1 1; 3 1; 2 2; 2 3; 1 3],[0.02 0.7 0.15 0.4 3],[3 3])
+ s  =
+(  3,  3) sparse matrix
+(  1,  1)      0.02
+(  1,  3)      3.
+(  2,  2)      0.15
+(  2,  3)      0.4
+(  3,  1)      0.7
+
+--> coth(s)   // no longer sparse
+ ans  =
+   50.006666   Inf         1.0049698
+   Inf         6.7165918   2.6319324
+   1.6546216   Inf         Inf
+</screen>
     </refsection>
     <refsection role="see also">
         <title>See also</title>
@@ -63,4 +106,15 @@ coth(x)
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    Extension to sparse matrices.
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index 80f4589..069823d 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="tanh" 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="tanh" xml:lang="en">
     <refnamediv>
         <refname>tanh</refname>
         <refpurpose>hyperbolic tangent</refpurpose>
@@ -58,4 +61,15 @@ sinh(x)./cosh(x)
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    Extension to sparse matrices.
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index 0a95fad..c50ad4e 100644 (file)
@@ -1,12 +1,29 @@
 <?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: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="coth" xml:lang="fr">
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2008 - INRIA
+ * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ * Copyright (C) 2019 - Samuel GOUGEON
+ *
+ * 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="coth" xml:lang="fr">
     <refnamediv>
         <refname>coth</refname>
         <refpurpose>cotangente hyperbolique</refpurpose>
     </refnamediv>
     <refsynopsisdiv>
         <title>Séquence d'appel</title>
-        <synopsis>[t]=coth(x)</synopsis>
+        <synopsis>t = coth(x)</synopsis>
     </refsynopsisdiv>
     <refsection>
         <title>Paramètres</title>
             <varlistentry>
                 <term>x</term>
                 <listitem>
-                    <para>vecteur ou matrice réel ou complexe.</para>
+                    <para>
+                       vecteur ou matrice de nombres réels ou complexes (encodée dense ou creuse).
+                    </para>
                 </listitem>
             </varlistentry>
             <varlistentry>
                 <term>t</term>
                 <listitem>
-                    <para>vecteur ou matrice réel ou complexe.</para>
+                    <para>
+                      vecteur ou matrice de nombres réels ou complexes (toujours encodée en format dense).
+                    </para>
                 </listitem>
             </varlistentry>
         </variablelist>
             Les éléments de <literal>t</literal> sont les cotangentes
             hyperboliques des éléments de <literal>x</literal>.
         </para>
+        <note>
+          <literal>coth(0)</literal> n'étant pas nul, le résultat pour toute matrice d'entrée
+          encodée creuse est encodé en format dense (comme avec <literal>cos()</literal>).
+        </note>
     </refsection>
     <refsection>
         <title>Exemples</title>
         <programlisting role="example"><![CDATA[
-x=[1,2*%i]
-t=exp(x);
+x = [1, 2*%i]
+t = exp(x);
 (t-ones(x)./t).\(t+ones(x)./t)
 coth(x)
+coth([-0 0])
+
+// avec une matrice creuse :
+s = sparse([1 1; 3 1; 2 2; 2 3; 1 3],[0.02 0.7 0.15 0.4 3],[3 3])
+coth(s)   // => format dense
  ]]></programlisting>
+    <screen>
+--> (t-ones(x)./t).\(t+ones(x)./t)
+ ans  =
+   1.3130353   0.4576576i
+
+--> coth(x)
+ ans  =
+   1.3130353   0.4576576i
+
+--> coth([-0 0])
+ ans  =
+  -Inf   Inf
+
+--> // avec une matrice creuse :
+--> s = sparse([1 1; 3 1; 2 2; 2 3; 1 3],[0.02 0.7 0.15 0.4 3],[3 3])
+ s  =
+(  3,  3) sparse matrix
+(  1,  1)      0.02
+(  1,  3)      3.
+(  2,  2)      0.15
+(  2,  3)      0.4
+(  3,  1)      0.7
+
+--> coth(s)   // => format dense
+ ans  =
+   50.006666   Inf         1.0049698
+   Inf         6.7165918   2.6319324
+   1.6546216   Inf         Inf
+</screen>
     </refsection>
     <refsection role="see also">
         <title>Voir aussi</title>
@@ -49,4 +108,15 @@ coth(x)
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>Historique</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    Extension aux matrices creuses.
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index 4d47f41..62c1d71 100644 (file)
@@ -1,5 +1,8 @@
 <?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: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="tanh" xml:lang="fr">
+<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="tanh" xml:lang="fr">
     <refnamediv>
         <refname>tanh</refname>
         <refpurpose>tangente hyperbolique</refpurpose>
@@ -48,4 +51,15 @@ sinh(x)./cosh(x)
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>Historique</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    Extension aux matrices creuses.
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index 6db2d8b..4783d13 100644 (file)
@@ -1,10 +1,9 @@
 <?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
+ * Copyright (C) 2019 - Samuel GOUGEON
  *
  * 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.
  * 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="coth" 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="coth" xml:lang="ja">
 
     <refnamediv>
 
@@ -29,7 +30,7 @@
 
         <title>呼び出し手順</title>
 
-        <synopsis>[t] = coth(x)</synopsis>
+        <synopsis>t = coth(x)</synopsis>
 
     </refsynopsisdiv>
 
             なります.
 
         </para>
+        <note>
+          <literal>coth(0)</literal> not being 0, the result for any input
+          sparse-encoded matrix is always full-encoded (as for <literal>cos()</literal>).
+        </note>
 
     </refsection>
 
     <refsection>
-
         <title>例</title>
-
         <programlisting role="example"><![CDATA[
-x=[1,2*%i]
-t=exp(x);
+x = [1, 2*%i]
+t = exp(x);
 (t-ones(x)./t).\(t+ones(x)./t)
 coth(x)
- ]]></programlisting>
+coth([-0 0])
 
+// With sparses:
+s = sparse([1 1; 3 1; 2 2; 2 3; 1 3],[0.02 0.7 0.15 0.4 3],[3 3])
+coth(s)   // no longer sparse
+ ]]></programlisting>
+    <screen>
+--> (t-ones(x)./t).\(t+ones(x)./t)
+ ans  =
+   1.3130353   0.4576576i
+
+--> coth(x)
+ ans  =
+   1.3130353   0.4576576i
+
+--> coth([-0 0])
+ ans  =
+  -Inf   Inf
+
+--> // With sparses:
+--> s = sparse([1 1; 3 1; 2 2; 2 3; 1 3],[0.02 0.7 0.15 0.4 3],[3 3])
+ s  =
+(  3,  3) sparse matrix
+(  1,  1)      0.02
+(  1,  3)      3.
+(  2,  2)      0.15
+(  2,  3)      0.4
+(  3,  1)      0.7
+
+--> coth(s)   // no longer sparse
+ ans  =
+   50.006666   Inf         1.0049698
+   Inf         6.7165918   2.6319324
+   1.6546216   Inf         Inf
+</screen>
     </refsection>
 
     <refsection role="see also">
@@ -111,6 +147,16 @@ coth(x)
         </simplelist>
 
     </refsection>
-
+    <refsection role="history">
+        <title>履歴</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    Extension to sparse matrices.
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
 
index caefde3..e5a0983 100644 (file)
  *
  -->
 
-<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="tanh" 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="tanh" xml:lang="ja">
 
     <refnamediv>
 
@@ -100,6 +103,16 @@ sinh(x)./cosh(x)
         </simplelist>
 
     </refsection>
-
+    <refsection role="history">
+        <title>履歴</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    Extension to sparse matrices.
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
 
index ad36c77..131bd51 100644 (file)
@@ -2,8 +2,8 @@
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2008 - INRIA
- *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ * Copyright (C) 2019 - Samuel GOUGEON
  *
  * 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.
  * 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="coth" xml:lang="pt">
+<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="coth" xml:lang="pt">
     <refnamediv>
         <refname>coth</refname>
         <refpurpose>cotangente hiperbólica</refpurpose>
     </refnamediv>
     <refsynopsisdiv>
         <title>Seqüência de Chamamento</title>
-        <synopsis>[t]=coth(x)</synopsis>
+        <synopsis>t = coth(x)</synopsis>
     </refsynopsisdiv>
     <refsection>
+        <title>Parâmetros</title>
+        <variablelist>
+            <varlistentry>
+                <term>x</term>
+                <listitem>
+                    <para>
+                      vector or matrix of real or complex numbers (full or sparse-encoded).
+                   </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>t</term>
+                <listitem>
+                    <para>a full-encoded vector or matrix of real or complex numbers.</para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    <refsection>
         <title>Descrição</title>
         <para>
             Os elementos do vetor <literal>t</literal> são as cotangentes
             hiperbólicas dos elementos do vetor <literal>x</literal>.
         </para>
+        <note>
+          <literal>coth(0)</literal> not being 0, the result for any input
+          sparse-encoded matrix is always full-encoded (as for <literal>cos()</literal>).
+        </note>
     </refsection>
     <refsection>
         <title>Exemplos</title>
         <programlisting role="example"><![CDATA[
-x=[1,2*%i]
-t=exp(x);
+x = [1, 2*%i]
+t = exp(x);
 (t-ones(x)./t).\(t+ones(x)./t)
 coth(x)
+coth([-0 0])
+
+// With sparses:
+s = sparse([1 1; 3 1; 2 2; 2 3; 1 3],[0.02 0.7 0.15 0.4 3],[3 3])
+coth(s)   // no longer sparse
  ]]></programlisting>
+    <screen>
+--> (t-ones(x)./t).\(t+ones(x)./t)
+ ans  =
+   1.3130353   0.4576576i
+
+--> coth(x)
+ ans  =
+   1.3130353   0.4576576i
+
+--> coth([-0 0])
+ ans  =
+  -Inf   Inf
+
+--> // With sparses:
+--> s = sparse([1 1; 3 1; 2 2; 2 3; 1 3],[0.02 0.7 0.15 0.4 3],[3 3])
+ s  =
+(  3,  3) sparse matrix
+(  1,  1)      0.02
+(  1,  3)      3.
+(  2,  2)      0.15
+(  2,  3)      0.4
+(  3,  1)      0.7
+
+--> coth(s)   // no longer sparse
+ ans  =
+   50.006666   Inf         1.0049698
+   Inf         6.7165918   2.6319324
+   1.6546216   Inf         Inf
+</screen>
     </refsection>
     <refsection role="see also">
         <title>Ver Também</title>
@@ -46,4 +106,15 @@ coth(x)
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>Histórico</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    Extension to sparse matrices.
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index a8e9b55..a92c2d0 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:ns3="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="tanh" xml:lang="pt">
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns3="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="tanh" xml:lang="pt">
     <refnamediv>
         <refname>tanh</refname>
         <refpurpose>tangente hiperbólica</refpurpose>
@@ -51,4 +54,15 @@ sinh(x)./cosh(x)
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>Histórico</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    Extension to sparse matrices.
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index 4315657..5d08bc3 100644 (file)
@@ -2,8 +2,8 @@
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2008 - INRIA
- *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ * Copyright (C) 2019 - Samuel GOUGEON
  *
  * 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.
  * 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="coth" xml:lang="ru">
+<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="coth" xml:lang="ru">
     <refnamediv>
         <refname>coth</refname>
         <refpurpose>гиперболический котангенс</refpurpose>
     </refnamediv>
     <refsynopsisdiv>
         <title>Синтаксис</title>
-        <synopsis>[t] = coth(x)</synopsis>
+        <synopsis>t = coth(x)</synopsis>
     </refsynopsisdiv>
     <refsection>
+        <title>Аргументы</title>
+        <variablelist>
+            <varlistentry>
+                <term>x</term>
+                <listitem>
+                    <para>
+                      вектор или матрица вещественных или комплексных чисел (полная или разрежённая).
+                   </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>t</term>
+                <listitem>
+                    <para>полный вектор или матрица вещественных или комплексных чисел.</para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    <refsection>
         <title>Описание</title>
         <para>
             Элементы <varname>t</varname> являются гиперболическим котангенсом соответствующих элементов
             <varname>x</varname>.
         </para>
+        <note>
+          <literal>coth(0)</literal> не равен 0, результат для любой входной разрежённой матрицы всегда
+          будет полной матрицей (как и для <literal>cos()</literal>).
+        </note>
     </refsection>
     <refsection>
         <title>Примеры</title>
         <programlisting role="example"><![CDATA[
-x=[1,2*%i]
-t=exp(x);
+x = [1, 2*%i]
+t = exp(x);
 (t-ones(x)./t).\(t+ones(x)./t)
 coth(x)
+coth([-0 0])
+
+// С разряжённой матрицей:
+s = sparse([1 1; 3 1; 2 2; 2 3; 1 3],[0.02 0.7 0.15 0.4 3],[3 3])
+coth(s)   // более не разрежённая
  ]]></programlisting>
+    <screen>
+--> (t-ones(x)./t).\(t+ones(x)./t)
+ ans  =
+   1.3130353   0.4576576i
+
+--> coth(x)
+ ans  =
+   1.3130353   0.4576576i
+
+--> coth([-0 0])
+ ans  =
+  -Inf   Inf
+
+--> //  С разряжённой матрицей:
+--> s = sparse([1 1; 3 1; 2 2; 2 3; 1 3], [0.02 0.7 0.15 0.4 3], [3 3])
+ s  =
+(  3,  3) sparse matrix
+(  1,  1)      0.02
+(  1,  3)      3.
+(  2,  2)      0.15
+(  2,  3)      0.4
+(  3,  1)      0.7
+
+--> coth(s)   // более не разрежённая
+ ans  =
+   50.006666   Inf         1.0049698
+   Inf         6.7165918   2.6319324
+   1.6546216   Inf         Inf
+</screen>
     </refsection>
     <refsection role="see also">
         <title>Смотрите также</title>
@@ -46,4 +106,15 @@ coth(x)
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>История</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    Расширение до разрежённых матриц.
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index f77ee86..61c8e84 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="tanh" xml:lang="ru">
+<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="tanh" xml:lang="ru">
     <refnamediv>
         <refname>tanh</refname>
         <refpurpose>гиперболический тангенс</refpurpose>
@@ -57,4 +60,15 @@ sinh(x)./cosh(x)
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>История</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    Расширение до разрежённых матриц.
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
diff --git a/scilab/modules/elementary_functions/macros/%sp_tanh.sci b/scilab/modules/elementary_functions/macros/%sp_tanh.sci
new file mode 100644 (file)
index 0000000..309a0b7
--- /dev/null
@@ -0,0 +1,16 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2019 - Samuel GOUGEON
+//
+// 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.
+
+function t = %sp_tanh(x)
+    // Syntax : t = tanh(x)
+    // hyperbolic tangente for sparse inputs
+    [ij, t, mn] = spget(x)
+    t = sparse(ij, tanh(t), mn)
+endfunction
index 1e0b46b..ee72194 100644 (file)
@@ -1,7 +1,7 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) INRIA
-//
 // Copyright (C) 2012 - 2016 - Scilab Enterprises
+// Copyright (C) 2019 - Samuel GOUGEON
 //
 // 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.
 // For more information, see the COPYING file which you should have received
 // along with this program.
 
-function t=coth(x)
+function t = coth(x)
     //Syntax : t=coth(x)
     //
     // hyperbolic co-tangent of x
 
-    rhs = argn(2);
-
-    if rhs <> 1 then
+    if argn(2) <> 1 then
         error(msprintf(gettext("%s: Wrong number of input argument(s): %d expected.\n"),"coth",1));
     end
 
-    if type(x)<>1 then
+    if and(type(x) <> [1 5]) then
         error(msprintf(gettext("%s: Wrong type for input argument #%d: Real or complex matrix expected.\n"),"coth",1));
     end
-    t=exp(x);
-    t=(t-ones(x)./t).\(t+ones(x)./t);
+    // ( coth(0) => +/- Inf ) => (sparse => full)
+    t = 1 ./ tanh(full(x))
 endfunction
diff --git a/scilab/modules/elementary_functions/tests/unit_tests/coth.tst b/scilab/modules/elementary_functions/tests/unit_tests/coth.tst
new file mode 100644 (file)
index 0000000..d91cec9
--- /dev/null
@@ -0,0 +1,61 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2019 - Samuel GOUGEON
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- CLI SHELL MODE -->
+// <-- NO CHECK REF -->
+
+// Unitary tests for coth()
+
+s = sprand(5, 4, 0.3);
+assert_checkequal(coth(s), coth(full(s)));
+
+x = [0:0.01:0.1 0.1:0.1:1 1:20]';
+r = [
+   %inf
+   100.003333311111305
+   50.0066664888956609
+   33.3433327333847558
+   25.0133319113277963
+   20.0166638895500988
+   16.6866618683117913
+   14.3090400003806923
+   12.5266552958194826
+   11.1410949235981391
+   10.0333111322539885
+   10.0333111322539885
+   5.06648956343947265
+   3.43273843032174097
+   2.63193244183218855
+   2.16395341373865291
+   1.8620255213866661 
+   1.65462163580262911
+   1.50594070204370678
+   1.39606725303001178
+   1.31303528549933146
+   1.31303528549933146
+   1.03731472072754816
+   1.004969823313689
+   1.00067115040168253
+   1.00009080398201955
+   1.00001228850020984
+   1.0000016630588211
+   1.00000022507037478
+   1.00000003045995989
+   1.00000000412230716
+   1.00000000055789373
+   1.00000000007550272
+   1.00000000001021827
+   1.00000000000138289
+   1.00000000000018718
+   1.00000000000002554
+   1.00000000000000355
+   1.00000000000000044
+   1.00000000000000022
+   1.
+   ];
+assert_checkequal(coth(x), r);
+assert_checkequal(coth(-x), -r);
diff --git a/scilab/modules/elementary_functions/tests/unit_tests/tanh.tst b/scilab/modules/elementary_functions/tests/unit_tests/tanh.tst
new file mode 100644 (file)
index 0000000..0e9ef5d
--- /dev/null
@@ -0,0 +1,62 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2019 - Samuel GOUGEON
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- CLI SHELL MODE -->
+// <-- NO CHECK REF -->
+
+// Unitary tests for tanh()
+
+s = sprand(5, 4, 0.3);
+assert_checkequal(tanh(s), sparse(tanh(full(s))));
+
+x = [0:0.01:0.1 0.1:0.1:1 1:20]';
+r = [
+   0.
+   0.0099996666799994604
+   0.0199973337599309332
+   0.0299910032388201429
+   0.0399786803111635697
+   0.0499583749578799766
+   0.059928103529143503
+   0.0698858903164289724
+   0.079829769111131349 
+   0.0897577847471601048
+   0.0996679946249558191
+   0.09966799462495583
+   0.19737532022490401
+   0.29131261245159096
+   0.37994896225522484
+   0.46211715726000979
+   0.5370495669980353
+   0.60436777711716361
+   0.66403677026784891
+   0.71629787019902447
+   0.76159415595576485
+   0.76159415595576485
+   0.964027580075817
+   0.99505475368673058
+   0.99932929973906703
+   0.999909204262595
+   0.9999877116507956
+   0.99999833694394458
+   0.99999977492967596
+   0.999999969540041
+   0.99999999587769284
+   0.99999999944210638
+   0.99999999992449728
+   0.99999999998978184
+   0.99999999999861722
+   0.99999999999981282
+   0.99999999999997446
+   0.99999999999999656
+   0.99999999999999956
+   0.99999999999999978
+   1.
+   ];
+assert_checkalmostequal(tanh(x), r, %eps);
+assert_checkalmostequal(tanh(-x), -r, %eps);
+assert_checkequal(1/tanh(-0), -%inf);