* Bug #11996 fixed - Extend eye() to hypermatrix. 64/13264/4
Vincent COUVERT [Thu, 28 Nov 2013 14:44:02 +0000 (15:44 +0100)]
This reverts commit 3872184733e13cd859805a04edc0eef7352e37ad.

Change-Id: I881315428e57a5d323dfabb03bf221c1dc7ba728

scilab/CHANGES_5.5.X
scilab/modules/elementary_functions/help/en_US/elementarymatrices/eye.xml
scilab/modules/elementary_functions/help/fr_FR/elementarymatrices/eye.xml
scilab/modules/overloading/macros/%hm_eye.sci [new file with mode: 0644]
scilab/modules/overloading/tests/nonreg_tests/bug_11996.dia.ref [new file with mode: 0644]
scilab/modules/overloading/tests/nonreg_tests/bug_11996.tst [new file with mode: 0644]

index 327a5ea..0203d80 100644 (file)
@@ -146,6 +146,8 @@ Scilab Bug Fixes
 
 * Bug #11680 fixed - GUI functions in Scilab 5.4.X were much slower than in Scilab 5.3.3.
 
+* Bug #11996 fixed - eye extended to hypermatrix.
+
 * Bug #12121 fixed - inv function did not work for complex sparse matrices.
 
 * Bug #12334 fixed - Mark color in legend was invalid.
index 8345982..2500fe1 100644 (file)
@@ -29,7 +29,7 @@
                 <term>A,X</term>
                 <listitem>
                     <para>
-                        matrices or <literal>syslin</literal> lists
+                        matrices, hypermatrices, or <literal>syslin</literal> lists
                     </para>
                 </listitem>
             </varlistentry>
@@ -46,7 +46,9 @@
         <para>according to its arguments defines an
             <literal>m</literal>x<literal>n</literal> matrix with 1 along the main
             diagonal or an identity matrix of the same dimension as
-            <literal>A</literal> .
+            <literal>A</literal> . In case <varname>A</varname> is an hypermatrix, 
+            <varname>X</varname> will be defined as:
+            <literal>X(i,i,...,i)=1</literal> (with <literal>i=min(size(A)</literal>).
         </para>
         <para>
             Caution: <literal>eye(10)</literal> is interpreted as
@@ -74,6 +76,7 @@ s=poly(0,'s');A=[s,1;s,s+1];eye(A)
 A=[1/s,1;s,2];eye(A);
 A=ssrand(2,2,3);eye(A)
 [1 2;3 4]+2*eye()
+eye(zeros(4,4,4,4))
  ]]></programlisting>
     </refsection>
     <refsection role="see also">
index 055f2e5..64cf429 100644 (file)
@@ -18,7 +18,7 @@
                 <term>A,X</term>
                 <listitem>
                     <para>
-                        matrices ou listes de type <literal>syslin</literal>.
+                        matrices, hypermatrices ou listes de type <literal>syslin</literal>.
                     </para>
                 </listitem>
             </varlistentry>
@@ -35,7 +35,9 @@
         <para>Renvoie, suivant les arguments, une matrice
             <literal>m</literal>x<literal>n</literal> avec des 1 sur la diagonale
             principale ou une matrice identité de même taille que <literal>A</literal>
-            .
+            . Dans le cas où <varname>A</varname> est une hypermatrice, 
+            alors <varname>X</varname> sera de la forme:
+            <literal>X(i,i,...,i)=1</literal> (avec <literal>i=min(size(A)</literal>).
         </para>
         <para>
             Attention : <literal>eye(10)</literal> est équivalent à
@@ -63,6 +65,7 @@ s=poly(0,'s');A=[s,1;s,s+1];eye(A)
 A=[1/s,1;s,2];eye(A);
 A=ssrand(2,2,3);eye(A)
 [1 2;3 4]+2*eye()
+eye(zeros(4,4,4,4))
  ]]></programlisting>
     </refsection>
     <refsection role="see also">
diff --git a/scilab/modules/overloading/macros/%hm_eye.sci b/scilab/modules/overloading/macros/%hm_eye.sci
new file mode 100644 (file)
index 0000000..21cec64
--- /dev/null
@@ -0,0 +1,22 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Charlotte HECQUET
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution.  The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+
+function M=%hm_eye(varargin)
+
+    if size(varargin) <> 1 then
+        error(msprintf(_("%s: Wrong number of input argument: %d to %d expected.\n"), "eye", 1, 2));
+    end
+    if typeof(varargin(1)) <> "hypermat" then
+        error(msprintf(_("%s: Wrong type for input argument #%d: Hypermatrix expected.\n"), "eye", 1));
+    end
+
+    M = zeros(varargin(1));
+    M(sub2ind(size(varargin(1)), (1:min(size(varargin(1))))' .*. ones(1,ndims(varargin(1))))) = 1;
+
+endfunction
diff --git a/scilab/modules/overloading/tests/nonreg_tests/bug_11996.dia.ref b/scilab/modules/overloading/tests/nonreg_tests/bug_11996.dia.ref
new file mode 100644 (file)
index 0000000..6cc7447
--- /dev/null
@@ -0,0 +1,45 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Charlotte HECQUET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- Non-regression test for bug 11996 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=11996
+//
+// <-- Short Description -->
+// Extend eye() to hypermatrix
+ref222(:,:,1) = [1,0;0,0];
+ref222(:,:,2) = [0,0;0,1];
+assert_checkequal(eye(rand(2,2,2)), ref222);
+ref4445(:,:,1,1) = [1,0,0,0;0,0,0,0;0,0,0,0;0,0,0,0];
+ref4445(:,:,2,1) = zeros(4,4);
+ref4445(:,:,3,1) = zeros(4,4);
+ref4445(:,:,4,1) = zeros(4,4);
+ref4445(:,:,1,2) = zeros(4,4);
+ref4445(:,:,2,2) = [0,0,0,0;0,1,0,0;0,0,0,0;0,0,0,0];
+ref4445(:,:,3,2) = zeros(4,4);
+ref4445(:,:,4,2) = zeros(4,4);
+ref4445(:,:,1,3) = zeros(4,4);
+ref4445(:,:,2,3) = zeros(4,4);
+ref4445(:,:,3,3) = [0,0,0,0;0,0,0,0;0,0,1,0;0,0,0,0];
+ref4445(:,:,4,3) = zeros(4,4);
+ref4445(:,:,1,4) = zeros(4,4);
+ref4445(:,:,2,4) = zeros(4,4);
+ref4445(:,:,3,4) = zeros(4,4);
+ref4445(:,:,4,4) = [0,0,0,0;0,0,0,0;0,0,0,0;0,0,0,1];
+ref4445(:,:,1,5) = zeros(4,4);
+ref4445(:,:,2,5) = zeros(4,4);
+ref4445(:,:,3,5) = zeros(4,4);
+ref4445(:,:,4,5) = zeros(4,4);
+assert_checkequal(eye(zeros(4,4,4,5)), ref4445);
+M = hypermat([2 3 2 2],1:24);
+ref2322(:,:,1,1) = [1,0,0;0,0,0];
+ref2322(:,:,2,1) = zeros(2,3);
+ref2322(:,:,1,2) = zeros(2,3);
+ref2322(:,:,2,2) = [0,0,0;0,1,0];
+assert_checkequal(eye(M), ref2322);
+// Error messages
+assert_checkerror("eye(4,4,4)", [], 42);
diff --git a/scilab/modules/overloading/tests/nonreg_tests/bug_11996.tst b/scilab/modules/overloading/tests/nonreg_tests/bug_11996.tst
new file mode 100644 (file)
index 0000000..cb2e6ee
--- /dev/null
@@ -0,0 +1,49 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Charlotte HECQUET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- Non-regression test for bug 11996 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=11996
+//
+// <-- Short Description -->
+// Extend eye() to hypermatrix
+
+ref222(:,:,1) = [1,0;0,0];
+ref222(:,:,2) = [0,0;0,1];
+assert_checkequal(eye(rand(2,2,2)), ref222);
+
+ref4445(:,:,1,1) = [1,0,0,0;0,0,0,0;0,0,0,0;0,0,0,0];
+ref4445(:,:,2,1) = zeros(4,4);
+ref4445(:,:,3,1) = zeros(4,4);
+ref4445(:,:,4,1) = zeros(4,4);
+ref4445(:,:,1,2) = zeros(4,4);
+ref4445(:,:,2,2) = [0,0,0,0;0,1,0,0;0,0,0,0;0,0,0,0];
+ref4445(:,:,3,2) = zeros(4,4);
+ref4445(:,:,4,2) = zeros(4,4);
+ref4445(:,:,1,3) = zeros(4,4);
+ref4445(:,:,2,3) = zeros(4,4);
+ref4445(:,:,3,3) = [0,0,0,0;0,0,0,0;0,0,1,0;0,0,0,0];
+ref4445(:,:,4,3) = zeros(4,4);
+ref4445(:,:,1,4) = zeros(4,4);
+ref4445(:,:,2,4) = zeros(4,4);
+ref4445(:,:,3,4) = zeros(4,4);
+ref4445(:,:,4,4) = [0,0,0,0;0,0,0,0;0,0,0,0;0,0,0,1];
+ref4445(:,:,1,5) = zeros(4,4);
+ref4445(:,:,2,5) = zeros(4,4);
+ref4445(:,:,3,5) = zeros(4,4);
+ref4445(:,:,4,5) = zeros(4,4);
+assert_checkequal(eye(zeros(4,4,4,5)), ref4445);
+
+M = hypermat([2 3 2 2],1:24);
+ref2322(:,:,1,1) = [1,0,0;0,0,0];
+ref2322(:,:,2,1) = zeros(2,3);
+ref2322(:,:,1,2) = zeros(2,3);
+ref2322(:,:,2,2) = [0,0,0;0,1,0];
+assert_checkequal(eye(M), ref2322);
+// Error messages
+assert_checkerror("eye(4,4,4)", [], 42);