Fix test of min & max function 11/8711/8
Adeline CARNIS [Thu, 16 Aug 2012 07:24:37 +0000 (09:24 +0200)]
test_run("overloading","bug_10479")

Change-Id: I9ee8209166203b588b8e26f142831c4edb13a23a

scilab/modules/elementary_functions/sci_gateway/fortran/sci_f_maxi.f
scilab/modules/overloading/macros/%hm_max.sci [moved from scilab/modules/overloading/macros/%hm_maxi.sci with 80% similarity]
scilab/modules/overloading/macros/%hm_min.sci [moved from scilab/modules/overloading/macros/%hm_mini.sci with 79% similarity]

index cb2880f..5b1cacf 100644 (file)
@@ -55,9 +55,9 @@ c     ------call macro
          if(istk(il).lt.0) il=iadr(istk(il+1))
 
          if ((fin.eq.17).or.(fin.eq.54)) then
-            call funnam(ids(1,pt+1),'mini',il)
+            call funnam(ids(1,pt+1),'min',il)
          else
-            call funnam(ids(1,pt+1),'maxi',il)
+            call funnam(ids(1,pt+1),'max',il)
          endif
          fun=-1
          return
-// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab\r
-// Copyright (C) INRIA\r
-// Copyright (C) 2012 - Scilab Enterprises - Adeline CARNIS\r
-// \r
-// This file must be used under the terms of the CeCILL.\r
-// This source file is licensed as described in the file COPYING, which\r
-// you should have received as part of this distribution.  The terms\r
-// are also available at    \r
-// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt\r
-\r
-function [x,k] = %hm_maxi(varargin)\r
-    n=size(varargin)\r
-    if n==1 then\r
-        m = varargin(1).dims\r
-        [x,k] = max(varargin(1).entries)\r
-        if (argn(1) > 1 & (m(length(m)) <> size(varargin(1), "*"))) then\r
-            k = ind2sub(m, k(1))\r
-        end\r
-    else\r
-        if n==2 then\r
-            d=varargin(2)\r
-            if type(d)==10 then\r
-                [x,k]=%hm_oriented_max(varargin(1),d)\r
-                return\r
-            end\r
-        end\r
-        x=varargin(1)(:)\r
-        dims=size(varargin(1))\r
-        for kk=2:n\r
-            sz=size(varargin(kk))\r
-            if or(dims<>sz) then \r
-                if prod(dims)<>1&prod(sz)<>1 then\r
-                    error(42)\r
-                end\r
-                if prod(dims)==1 then dims=sz,end\r
-            end\r
-            [x,k]=max(x,varargin(kk)(:))\r
-        end\r
-        x=hypermat(dims,x)\r
-        k=hypermat(dims,k)\r
-    end\r
-endfunction\r
-\r
-function [x,k]=%hm_oriented_max(m,d)\r
-    if d=='m' then\r
-        d=find(m.dims>1,1)\r
-        if d==[] then \r
-            [x,k1]=max(m.entries)\r
-            k=ind2sub(m.dims,k1(1))\r
-            return,\r
-        end\r
-    elseif d=='r' then \r
-        d=1\r
-    elseif d=='c' then\r
-        d=2\r
-    end\r
-    dims=m.dims;\r
-    if type(dims==8) then flag=1; dims=double(dims); else flag=0;end\r
-    N=size(dims,'*');\r
-    p1=prod(dims(1:d-1));// step for one max\r
-    p2=p1*dims(d);//step for beginning of vector to max \r
-    ind=(0:p1:p2-1)';// selection for vector to max\r
-    deb=(1:p1);\r
-    I=ind*ones(deb)+ones(ind)*deb \r
-\r
-    ind=(0:p2:prod(dims)-1);\r
-    I=ones(ind).*.I+ind.*.ones(I)\r
-\r
-    [x,k]=max(matrix(m.entries(I),dims(d),-1),'r')\r
-\r
-    dims(d)=1\r
-    if d==N then\r
-        dims=dims(1:$)\r
-    else\r
-        dims(d)=1\r
-    end\r
-    if size(dims,'*')==2 then \r
-        if flag==1 then dims=int32(dims);end\r
-        x=matrix(x,dims(1),dims(2))\r
-        k=matrix(k,dims(1),dims(2))\r
-    else\r
-        if flag==1 then dims=int32(dims);end\r
-        x=hypermat(dims,matrix(x,-1,1))\r
-        k=hypermat(dims,matrix(k,-1,1))\r
-    end\r
-endfunction\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r\r
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) INRIA
+// Copyright (C) 2012 - Scilab Enterprises - Adeline CARNIS
+// 
+// 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-en.txt
+
+function [x,k] = %hm_max(varargin)
+    n = size(varargin)
+    // One input argument
+    if n == 1 then
+        // Retrieve the dimensions
+        m = varargin(1).dims
+        // Compute the max of column vector
+        // varargin(1).entries gives column vector
+        [x,k] = max(varargin(1).entries)
+        // check if lhs = 2 and if varargin(1) is vector
+        if (argn(1) > 1 & (m(length(m)) <> size(varargin(1), "*"))) then
+            k = ind2sub(m, k(1))
+        end
+    else
+        if n==2 then
+            d=varargin(2)
+            // Check if d is a string
+            if type(d)==10 then
+                [x,k]=%hm_oriented_max(varargin(1),d)
+                return
+            end
+        end
+        // if the second input argument is a matrix or hypermatrix
+        // Obtain column vector
+        x=varargin(1)(:)
+        dims=size(varargin(1))
+        for kk=2:n
+            sz=size(varargin(kk))
+            // check if the dim are different
+            if or(dims<>sz) then 
+                if prod(dims)<>1&prod(sz)<>1 then
+                    error(42)
+                end
+                // the first argument is a scalar
+                if prod(dims)==1 then dims=sz,end
+            end
+            // max between hypermatrix and hypermatrix
+            [x,k]=max(x,varargin(kk)(:))
+        end
+        x=hypermat(dims,x)
+        k=hypermat(dims,k)
+    end
+endfunction
+
+function [x,k]=%hm_oriented_max(m,d)
+    if d=='m' then
+        d=find(m.dims>1,1)
+        if d==[] then 
+            [x,k1]=max(m.entries)
+            k=ind2sub(m.dims,k1(1))
+            return,
+        end
+    elseif d=='r' then 
+        d=1
+    elseif d=='c' then
+        d=2
+    end
+    dims=m.dims;
+    if type(dims==8) then flag=1; dims=double(dims); else flag=0;end
+    N=size(dims,'*');
+    p1=prod(dims(1:d-1));// step for one max
+    p2=p1*dims(d);//step for beginning of vector to max 
+    ind=(0:p1:p2-1)';// selection for vector to max
+    deb=(1:p1);
+    I=ind*ones(deb)+ones(ind)*deb 
+
+    ind=(0:p2:prod(dims)-1);
+    I=ones(ind).*.I+ind.*.ones(I)
+
+    [x,k]=max(matrix(m.entries(I),dims(d),-1),'r')
+
+    dims(d)=1
+    if d==N then
+        dims=dims(1:$)
+    else
+        dims(d)=1
+    end
+    if size(dims,'*')==2 then 
+        if flag==1 then dims=int32(dims);end
+        x=matrix(x,dims(1),dims(2))
+        k=matrix(k,dims(1),dims(2))
+    else
+        if flag==1 then dims=int32(dims);end
+        x=hypermat(dims,matrix(x,-1,1))
+        k=hypermat(dims,matrix(k,-1,1))
+    end
+endfunction
+
+
+
+
+
+
+
+
+
+
@@ -1,85 +1,98 @@
-// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab\r
-// Copyright (C) INRIA\r
-// Copyright (C) 2012 - Scilab Enterprises - Adeline CARNIS\r
-// \r
-// This file must be used under the terms of the CeCILL.\r
-// This source file is licensed as described in the file COPYING, which\r
-// you should have received as part of this distribution.  The terms\r
-// are also available at    \r
-// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt\r
-function [x,k] = %hm_mini(varargin)\r
-    n=size(varargin)\r
-    if n==1 then\r
-        m = varargin(1).dims\r
-        [x,k] = min(varargin(1).entries)\r
-        if (argn(1) > 1 & (m(length(m)) <> size(varargin(1), "*"))) then\r
-            k = ind2sub(m, k(1))\r
-        end\r
-    else\r
-        if n==2 then\r
-            d=varargin(2)\r
-            if type(d)==10 then\r
-                [x,k]=%hm_oriented_min(varargin(1),d)\r
-                return\r
-            end\r
-        end\r
-        x=varargin(1)(:)\r
-        dims=size(varargin(1))\r
-        for kk=2:n\r
-            if or(dims<>sz) then \r
-                if prod(dims)<>1&prod(sz)<>1 then\r
-                    error(42)\r
-                end\r
-                if prod(dims)==1 then dims=sz,end\r
-            end\r
-            [x,k]=min(x,varargin(kk)(:))\r
-        end\r
-        x=hypermat(dims,x)\r
-        k=hypermat(dims,k)\r
-    end\r
-endfunction\r
-\r
-function [x,k]=%hm_oriented_min(m,d)\r
-    if d=='m' then\r
-        d=find(dims>1,1)\r
-        if d==[] then \r
-            [x,k1]=max(m.entries)\r
-            k=ind2sub(m.dims,k1(1))\r
-            return,\r
-        end\r
-    elseif d=='r' then \r
-        d=1\r
-    elseif d=='c' then\r
-        d=2\r
-    end\r
-    dims=m.dims;\r
-    if type(dims==8) then flag=1; dims=double(dims); else flag=0;end\r
-    N=size(dims,'*');\r
-    p1=prod(dims(1:d-1));// step for one min\r
-    p2=p1*dims(d);//step for beginning of vector to min \r
-    ind=(0:p1:p2-1)';// selection for vector to min\r
-    deb=(1:p1);\r
-    I=ind*ones(deb)+ones(ind)*deb \r
-\r
-    ind=(0:p2:prod(dims)-1);\r
-    I=ones(ind).*.I+ind.*.ones(I)\r
-\r
-    [x,k]=min(matrix(m.entries(I),dims(d),-1),'r')\r
-\r
-    dims(d)=1\r
-    if d==N then\r
-        dims=dims(1:$)\r
-    else\r
-        dims(d)=1\r
-    end\r
-    if size(dims,'*')==2 then\r
-        if flag==1 then dims=int32(dims);end\r
-        x=matrix(x,dims(1),dims(2))\r
-        k=matrix(k,dims(1),dims(2))\r
-    else\r
-        if flag==1 then dims=int32(dims);end\r
-        x=hypermat(dims,x)\r
-        k=hypermat(dims,matrix(k,-1,1))\r
-    end\r
-endfunction\r
-\r\r
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) INRIA
+// Copyright (C) 2012 - Scilab Enterprises - Adeline CARNIS
+// 
+// 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-en.txt
+function [x,k] = %hm_min(varargin)
+    n = size(varargin)
+    // One input argument
+    if n ==1 then
+        // Retrieve the dimensions
+        m = varargin(1).dims
+        // Compute the min of column vector
+        // varargin(1).entries gives column vector
+        [x,k] = min(varargin(1).entries)
+        // check if lhs = 2 and if varargin(1) is vector
+        if (argn(1) > 1 & (m(length(m)) <> size(varargin(1), "*"))) then
+            k = ind2sub(m, k(1))
+        end
+    else
+        if n==2 then
+            d=varargin(2)
+            // Check if d is a string
+            if type(d)==10 then
+                [x,k]=%hm_oriented_min(varargin(1),d)
+                return
+            end
+        end
+        // if the second input argument is a matrix or hypermatrix
+        // Obtain column vector
+        x=varargin(1)(:)
+        dims=size(varargin(1))
+        for kk=2:n
+            sz=size(varargin(kk))
+            // check if the dim are different
+            if or(dims<>sz) then 
+                if prod(dims)<>1&prod(sz)<>1 then
+                    error(42)
+                end
+                // the first argument is a scalar
+                if prod(dims)==1 then dims=sz,end
+            end
+            // min between hypermatrix and hypermatrix
+            [x,k]=min(x,varargin(kk)(:))
+        end
+        x=hypermat(dims,x)
+        k=hypermat(dims,k)
+    end
+endfunction
+
+function [x,k]=%hm_oriented_min(m,d)
+    if d=='m' then
+        d=find(dims>1,1)
+        if d==[] then 
+            [x,k1]=max(m.entries)
+            k=ind2sub(m.dims,k1(1))
+            return,
+        end
+    elseif d=='r' then 
+        d=1
+    elseif d=='c' then
+        d=2
+    end
+    dims=m.dims;
+    if type(dims==8) then flag=1; dims=double(dims); else flag=0;end
+    N=size(dims,'*');
+    p1=prod(dims(1:d-1));// step for one min
+    p2=p1*dims(d);//step for beginning of vector to min 
+    ind=(0:p1:p2-1)';// selection for vector to min
+    deb=(1:p1);
+    I=ind*ones(deb)+ones(ind)*deb 
+
+    ind=(0:p2:prod(dims)-1);
+    I=ones(ind).*.I+ind.*.ones(I)
+
+    [x,k]=min(matrix(m.entries(I),dims(d),-1),'r')
+
+    dims(d)=1
+    if d==N then
+        dims=dims(1:$)
+    else
+        dims(d)=1
+    end
+    if size(dims,'*')==2 then
+        if flag==1 then dims=int32(dims);end
+        x=matrix(x,dims(1),dims(2))
+        k=matrix(k,dims(1),dims(2))
+    else
+        if flag==1 then dims=int32(dims);end
+        x=hypermat(dims,x)
+        k=hypermat(dims,matrix(k,-1,1))
+    end
+endfunction
+
+