Change the order of error messages in cumsum, cumprod, sum and prod functions. 21/11921/14
Adeline CARNIS [Wed, 3 Jul 2013 16:31:08 +0000 (18:31 +0200)]
Change-Id: I5f0b71bf04b1396185492dc003b70e091030e4a8

41 files changed:
scilab/modules/compatibility_functions/macros/%b_cumprod.sci
scilab/modules/compatibility_functions/macros/%b_cumsum.sci
scilab/modules/compatibility_functions/macros/%b_prod.sci
scilab/modules/compatibility_functions/macros/%b_sum.sci
scilab/modules/elementary_functions/help/fr_FR/matrixoperations/cumprod.xml
scilab/modules/elementary_functions/help/fr_FR/matrixoperations/cumsum.xml
scilab/modules/elementary_functions/help/fr_FR/matrixoperations/prod.xml
scilab/modules/elementary_functions/help/fr_FR/matrixoperations/sum.xml
scilab/modules/elementary_functions/sci_gateway/fortran/sci_f_cumprod.f
scilab/modules/elementary_functions/sci_gateway/fortran/sci_f_cumsum.f
scilab/modules/elementary_functions/sci_gateway/fortran/sci_f_prod.f
scilab/modules/elementary_functions/sci_gateway/fortran/sci_f_sum.f
scilab/modules/elementary_functions/src/fortran/getorient.f
scilab/modules/elementary_functions/tests/unit_tests/cumprod.dia.ref
scilab/modules/elementary_functions/tests/unit_tests/cumprod.tst
scilab/modules/elementary_functions/tests/unit_tests/cumsum.dia.ref
scilab/modules/elementary_functions/tests/unit_tests/cumsum.tst
scilab/modules/elementary_functions/tests/unit_tests/prod.dia.ref
scilab/modules/elementary_functions/tests/unit_tests/prod.tst
scilab/modules/elementary_functions/tests/unit_tests/sum.dia.ref
scilab/modules/elementary_functions/tests/unit_tests/sum.tst
scilab/modules/overloading/macros/%hm_cumprod.sci
scilab/modules/overloading/macros/%hm_cumsum.sci
scilab/modules/overloading/macros/%hm_prod.sci
scilab/modules/overloading/macros/%hm_sum.sci
scilab/modules/overloading/macros/%p_cumprod.sci
scilab/modules/overloading/macros/%p_cumsum.sci
scilab/modules/overloading/macros/%p_prod.sci
scilab/modules/overloading/macros/%p_sum.sci
scilab/modules/overloading/macros/%r_cumprod.sci
scilab/modules/overloading/macros/%r_cumsum.sci
scilab/modules/overloading/macros/%r_prod.sci
scilab/modules/overloading/macros/%r_sum.sci
scilab/modules/overloading/macros/%sp_cumprod.sci
scilab/modules/overloading/macros/%sp_cumsum.sci
scilab/modules/overloading/macros/%sp_prod.sci
scilab/modules/overloading/macros/%sp_sum.sci
scilab/modules/overloading/macros/%spb_cumprod.sci
scilab/modules/overloading/macros/%spb_cumsum.sci
scilab/modules/overloading/macros/%spb_prod.sci
scilab/modules/overloading/macros/%spb_sum.sci

index 63025d1..9922d37 100644 (file)
@@ -8,55 +8,84 @@
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
 function a=%b_cumprod(varargin)
-    if varargin($)=="native" then
-        if size(varargin)==2 then
-            d="*"
-        elseif size(varargin)==3 then
-            d=varargin(2)
+    a = varargin(1)
+    dims = size(a);
+
+    nargs = size(varargin);
+    select nargs
+    case 1
+        d = "*";
+        typ = "double";
+    case 2
+        if or(varargin(2) == ["native", "double"]) then
+            d = "*";
+            typ = varargin(2);
+        else
+            d = varargin(2);
+            typ = "double";
         end
-        if size(d,"*")<>1 then
-            if type(d)==10 then
-                error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",2))
-            else
-                error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumprod",2))
-            end
+    case 3
+        d = varargin(2);
+        typ = varargin(3);
+    else
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"),"cumprod", 1, 3));
+    end
+
+    // Check second argument : d
+    select type(d)
+    case 1
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumprod", 2))
         end
-        a=varargin(1)
-        if type(d)==10 then
-            d=find(d==["m","*","r","c"])
-            if d==[] then
-                error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-                "cumprod",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
-            end
-            d=d-2
+        if int(d) <> d | d < 0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"cumprod", 2, 1))
         end
-        dims=size(a);
-
-        if d==-1 then //'m'
-            d=find(dims>1,1)
-            if d==[] then d=0,end
+    case 10 
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",2))
         end
-        if d<0 then
+        if and(d<>["r","c","*","m"]) then
             error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-            "cumprod",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+            "cumprod",2,"""*"",""r"",""c"",""m"""))
+        end
+    else
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"cumprod",2))
+    end
+
+    // Check third argument
+    if type(typ)<>10 then
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"cumprod",3))
+    end
+
+    if size(typ,"*")<>1 then
+        error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",3))
+    end
+    
+    if and(typ <> ["native" "double"]) then
+        error(msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"cumprod", 3, "native", "double"));
+    end
+
+    if typ == "native" then
+        if type(d) == 10 then
+            pos = [1,2,0,find(dims>1,1)];
+            d=pos(find(d==["r","c","*","m"]))
         end
         select d
-        case 0 then
+        case 0
             k=find(~a,1)
-            if k<>[] then a(k:$)=%f,end
-        case 1 then
+            if k<>[] then a(k:$) = %f,end
+        case 1
             for k=1:dims(2)
                 a(:,k)=cumprod(a(:,k),"native")
             end
-        case 2 then
+        case 2
             for k=1:dims(1)
                 a(k,:)=cumprod(a(k,:),"native")
             end
         else
-            a=a
+            a = a
         end
     else
-        varargin(1)=bool2s(varargin(1))
-        a=cumprod(varargin(:))
+        a = cumprod(double(a), d)
     end
 endfunction
index 15aded1..51c2e38 100644 (file)
@@ -8,55 +8,84 @@
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
 function a=%b_cumsum(varargin)
-    if varargin($)=="native" then
-        if size(varargin)==2 then
-            d="*"
-        elseif size(varargin)==3 then
-            d=varargin(2)
+    a = varargin(1)
+    dims = size(a);
+
+    nargs = size(varargin);
+    select nargs
+    case 1
+        d = "*";
+        typ = "double";
+    case 2
+        if or(varargin(2) == ["native", "double"]) then
+            d = "*";
+            typ = varargin(2);
+        else
+            d = varargin(2);
+            typ = "double";
         end
-        if size(d,"*")<>1 then
-            if type(d)==10 then
-                error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",2))
-            else
-                error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumsum",2))
-            end
+    case 3
+        d = varargin(2);
+        typ = varargin(3);
+    else
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"),"cumsum", 1, 3));
+    end
+    
+    // Check second argument : d
+    select type(d)
+    case 1
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumsum", 2))
         end
-        a=varargin(1)
-        if type(d)==10 then
-            d=find(d==["m","*","r","c"])
-            if d==[] then
-                error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-                "cumsum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
-            end
-            d=d-2
+        if int(d) <> d | d < 0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"cumsum", 2, 1))
         end
-        dims=size(a);
-
-        if d==-1 then //'m'
-            d=find(dims>1,1)
-            if d==[] then d=0,end
+    case 10 
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",2))
         end
-        if d<0 then
+        if and(d<>["r","c","*","m"]) then
             error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-            "cumsum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+            "cumsum",2,"""*"",""r"",""c"",""m"""))
+        end
+    else
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"cumsum",2))
+    end
+
+    // Check third argument
+    if type(typ)<>10 then
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"cumsum",3))
+    end
+
+    if size(typ,"*")<>1 then
+        error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",3))
+    end
+    
+    if and(typ <> ["native" "double"]) then
+        error(msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"cumsum", 3, "native", "double"));
+    end
+
+    if typ == "native" then
+        if type(d) == 10 then
+            pos = [1,2,0,find(dims>1,1)];
+            d=pos(find(d==["r","c","*","m"]))
         end
         select d
-        case 0 then
+        case 0
             k=find(a,1)
-            if k<>[] then a(k:$)=%t,end
-        case 1 then
+            if k<>[] then a(k:$) = %t,end
+        case 1
             for k=1:dims(2)
                 a(:,k)=cumsum(a(:,k),"native")
             end
-        case 2 then
+        case 2
             for k=1:dims(1)
                 a(k,:)=cumsum(a(k,:),"native")
             end
         else
-            a=a
+            a = a
         end
     else
-        varargin(1)=bool2s(varargin(1))
-        a=cumsum(varargin(:))
+        a = cumsum(double(a), d)
     end
 endfunction
index 5c2061a..bbfb763 100644 (file)
@@ -7,15 +7,76 @@
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function r=%b_prod(varargin)
-    if varargin($)=="native" then
-        if size(varargin)==3&type(varargin(2))==1&varargin(2)>2 then
-            r=varargin(1)
+function a = %b_prod(varargin)
+    a = varargin(1)
+    dims = size(a);
+
+    nargs = size(varargin);
+    select nargs
+    case 1
+        d = "*";
+        typ = "double";
+    case 2
+        if or(varargin(2) == ["native", "double"]) then
+            d = "*";
+            typ = varargin(2);
+        else
+            d = varargin(2);
+            typ = "double";
+        end
+    case 3
+        d = varargin(2);
+        typ = varargin(3);
+    else
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"),"prod", 1, 3));
+    end
+
+    // Check second argument : d
+    select type(d)
+    case 1
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"prod", 2))
+        end
+        if int(d) <> d | d < 0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"prod", 2, 1))
+        end
+    case 10 
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",2))
+        end
+        if and(d<>["r","c","*","m"]) then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "prod",2,"""*"",""r"",""c"",""m"""))
+        end
+    else
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"prod",2))
+    end
+
+    // Check third argument
+    if type(typ)<>10 then
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"prod",3))
+    end
+
+    if size(typ,"*")<>1 then
+        error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",3))
+    end
+
+    if and(typ <> ["native" "double"]) then
+        error(msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"prod", 3, "native", "double"));
+    end
+
+    if typ == "native" then
+        if d <> "*" & type(d) == 10 then
+            pos = [1,2,find(dims>1,1)];
+            d=pos(find(d==["r","c","m"]))
+        end
+        // Case "m"
+        if type(d) == 1 & d > 2 then
+            a = a;
         else
-            r=and(varargin(1:$-1))
+            a = and(a, d)
         end
     else
-        varargin(1)=bool2s(varargin(1))
-        r=prod(varargin(:))
+        a = prod(double(a), d)
     end
 endfunction
index e2634ea..8fb93bf 100644 (file)
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function r=%b_sum(varargin)
-    if varargin($)=="native" then
-        if size(varargin)==3&type(varargin(2))==1&varargin(2)>2 then
-            r=varargin(1)
+function a=%b_sum(varargin)
+    a = varargin(1)
+    dims = size(a);
+
+    nargs = size(varargin);
+    select nargs
+    case 1
+        d = "*";
+        typ = "double";
+    case 2
+        if or(varargin(2) == ["native", "double"]) then
+            d = "*";
+            typ = varargin(2);
+        else
+            d = varargin(2);
+            typ = "double";
+        end
+    case 3
+        d = varargin(2);
+        typ = varargin(3);
+    else
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"),"sum", 1, 3));
+    end
+
+    // Check second argument : d
+    select type(d)
+    case 1
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"sum", 2))
+        end
+        if int(d) <> d | d < 0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"sum", 2, 1))
+        end
+    case 10 
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",2))
+        end
+        if and(d<>["r","c","*","m"]) then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "sum",2,"""*"",""r"",""c"",""m"""))
+        end
+    else
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"sum",2))
+    end
+
+    // Check third argument
+    if type(typ)<>10 then
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"sum",3))
+    end
+
+    if size(typ,"*")<>1 then
+        error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",3))
+    end
+
+    if and(typ <> ["native" "double"]) then
+        error(msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"sum", 3, "native", "double"));
+    end
+
+    if typ == "native" then
+        if d <> "*" & type(d) == 10 then
+            pos = [1,2,find(dims>1,1)];
+            d=pos(find(d==["r","c","m"]))
+        end
+        // Case "m"
+        if type(d) == 1 & d > 2 then
+            a = a;
         else
-            r=or(varargin(1:$-1))
+            a = or(a, d)
         end
     else
-        varargin(1)=bool2s(varargin(1))
-        r=sum(varargin(:))
+        a = sum(double(a), d)
     end
+    
+//    if varargin($)=="native" then
+//        if size(varargin)==3 & type(varargin(2))==1 & varargin(2)>2 then
+//            r=varargin(1)
+//        else
+//            // call sum(a, d) with d = "native"
+//            // or call(a, d, typ) with typ = "native"
+//            if size(varargin) == 3 then
+//                d = varargin(2);
+//                // d must be a string or scalar -> check type
+//                if and(type(d)<> [1, 10]) then
+//                    error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"sum",2))
+//                end
+//
+//                if size(d,"*")<>1 then
+//                    if type(d)==10 then
+//                        error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",2))
+//                    else
+//                        error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"sum",2))
+//                    end
+//                end
+//
+//                // If d is a string, d = "m", "c", "r" or "*"
+//                // Else d is an integer > 0
+//                if type(d)==10 then
+//                    d=find(d==["m","*","r","c"])
+//                    if d==[] then
+//                        error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+//                        "sum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(varargin(1)))))
+//                    end
+//                    d=d-2
+//                else
+//                    if d<0 then
+//                        error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+//                        "cumprod",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(varargin(1)))))
+//                    end
+//                end
+//
+//                dims=size(varargin(1));
+//
+//                if d==-1 then //'m'
+//                    d=find(dims>1,1)
+//                    if d==[] then d=0,end
+//                end
+//                
+//                // If d = 0, error in or function
+//                if d == 0 then
+//                    d = "*"
+//                end
+//                
+//                varargin(2) = d;
+//            end
+//            r=or(varargin(1:$-1))
+//        end
+//    else
+//        // converts boolean to double
+//        varargin(1)=bool2s(varargin(1))
+//
+//        // call sum(a, d, typ)
+//        if argn(2) == 3 then
+//            // d must be a string or a scalar -> check type and size
+//            d = varargin(2);
+//            if and(type(d)<> [1, 10]) then
+//                error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"sum",2))
+//            end
+//
+//            if size(d,"*")<>1 then
+//                if type(d)==10 then
+//                    error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",2))
+//                else
+//                    error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"sum",2))
+//                end
+//            end
+//
+//            // If d is a string, d = "m", "*", "r", "c"
+//            // Else  d is an integer > 0
+//            if type(d)==10 then
+//                if and(d <> ["m","*","r","c"]) then
+//                    error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+//                    "sum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(varargin(1)))))
+//                end
+//            else
+//                if d < 0 then
+//                    error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+//                    "sum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(varargin(1)))))
+//                end
+//            end
+//
+//            // typ must be a string and typ="double"
+//            typ = varargin($)
+//            if type(typ)<>10 then
+//                error(msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"sum",3))
+//            end
+//
+//            if size(typ,"*")<>1 then
+//                error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",3))
+//            end
+//
+//            if typ <> "double" then
+//                error(msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"sum", 3, "native", "double"));
+//            end
+//            varargin($) = null()
+//        end
+//        r = sum(varargin(:))
+//    end
 endfunction
index da9ce67..66c3ce5 100644 (file)
@@ -82,7 +82,7 @@
             <literal>y=cumprod(x,orientation)</literal> retourne dans
             <literal>y</literal> le produit cumulatif des éléments de
             <literal>x</literal> le long de la dimension donnée par le
-            paramêtre <literal>orientation</literal>:
+            paramètre <literal>orientation</literal>:
         </para>
         <itemizedlist>
             <listitem>
                 </para>
             </listitem>
         </itemizedlist>
+        <para>
+            L'argument <literal>outtype</literal> gère la façon dont le produit est réalisé :
+        </para>
+        <itemizedlist>
+            <listitem>
+                <para>Pour les matrices de doubles, de polynômes, de fractions rationnelles, 
+                    l'évaluation est toujours effetuée sur des nombres à virgule flottante.
+                    Les options <literal>"double"</literal> ou <literal>"native"</literal> sont équivalentes 
+                    (par défaut, <literal>outtype = "double"</literal>).
+                </para>
+            </listitem>
+            <listitem>
+                <para>Pour les tableaux d'entiers,</para>
+                <para>
+                    si <literal>outtype="native"</literal>, le calcul est effectué sur des nombres entiers
+                    (modulo 2^b, où b est le nombre de bits utilisés).
+                </para>
+                <para>
+                    si <literal>outtype="double"</literal>, le calcul est effectué sur 
+                    des nombres à virgule flottante.
+                </para>
+                <para>
+                    La valeur par défaut est <literal>outtype="native"</literal>
+                </para>
+            </listitem>
+            <listitem>
+                <para>Pour les tableaux de booléens,</para>
+                <para>
+                    si <literal>outtype="native"</literal>, le calcul est effectué sur des booléens 
+                    (* est remplacée par &amp;),
+                </para>
+                <para>
+                    si <literal>outtype="double"</literal>, le calcul est effectué sur des nombres 
+                    à virgule flottante (%t est remplacé par 1 et %f par 0).
+                </para>
+                <para>
+                    La valeur par défaut est <literal>outtype="double"</literal>
+                </para>
+            </listitem>
+        </itemizedlist>
     </refsection>
     <refsection>
         <title>Remarque</title>
index c9bdaf9..07c725d 100644 (file)
                 </para>
             </listitem>
         </itemizedlist>
+        <para>
+            L'argument <literal>outtype</literal> gère la façon dont le produit est réalisé :
+        </para>
+        <itemizedlist>
+            <listitem>
+                <para>Pour les matrices de doubles, de polynômes, de fractions rationnelles, 
+                    l'évaluation est toujours effetuée sur des nombres à virgule flottante.
+                    Les options <literal>"double"</literal> ou <literal>"native"</literal> sont équivalentes 
+                    (par défaut, <literal>outtype = "double"</literal>).
+                </para>
+            </listitem>
+            <listitem>
+                <para>Pour les tableaux d'entiers,</para>
+                <para>
+                    si <literal>outtype="native"</literal>, le calcul est effectué sur des nombres entiers
+                    (modulo 2^b, où b est le nombre de bits utilisés).
+                </para>
+                <para>
+                    si <literal>outtype="double"</literal>, le calcul est effectué sur 
+                    des nombres à virgule flottante.
+                </para>
+                <para>
+                    La valeur par défaut est <literal>outtype="native"</literal>
+                </para>
+            </listitem>
+            <listitem>
+                <para>Pour les tableaux de booléens,</para>
+                <para>
+                    si <literal>outtype="native"</literal>, le calcul est effectué sur des booléens 
+                    (* est remplacée par &amp;),
+                </para>
+                <para>
+                    si <literal>outtype="double"</literal>, le calcul est effectué sur des nombres 
+                    à virgule flottante (%t est remplacé par 1 et %f par 0).
+                </para>
+                <para>
+                    La valeur par défaut est <literal>outtype="double"</literal>
+                </para>
+            </listitem>
+        </itemizedlist>
     </refsection>
     <refsection>
         <title>Remarque</title>
index 081f73e..73ee3e5 100644 (file)
                 </para>
             </listitem>
         </itemizedlist>
+        <para>
+            L'argument <literal>outtype</literal> gère la façon dont le produit est réalisé :
+        </para>
+        <itemizedlist>
+            <listitem>
+                <para>Pour les matrices de doubles, de polynômes, de fractions rationnelles, 
+                    l'évaluation est toujours effetuée sur des nombres à virgule flottante.
+                    Les options <literal>"double"</literal> ou <literal>"native"</literal> sont équivalentes 
+                    (par défaut, <literal>outtype = "double"</literal>).
+                </para>
+            </listitem>
+            <listitem>
+                <para>Pour les tableaux d'entiers,</para>
+                <para>
+                    si <literal>outtype="native"</literal>, le calcul est effectué sur des nombres entiers
+                    (modulo 2^b, où b est le nombre de bits utilisés).
+                </para>
+                <para>
+                    si <literal>outtype="double"</literal>, le calcul est effectué sur 
+                    des nombres à virgule flottante.
+                </para>
+                <para>
+                    La valeur par défaut est <literal>outtype="native"</literal>
+                </para>
+            </listitem>
+            <listitem>
+                <para>Pour les tableaux de booléens,</para>
+                <para>
+                    si <literal>outtype="native"</literal>, le calcul est effectué sur des booléens 
+                    (* est remplacée par &amp;),
+                </para>
+                <para>
+                    si <literal>outtype="double"</literal>, le calcul est effectué sur des nombres 
+                    à virgule flottante (%t est remplacé par 1 et %f par 0).
+                </para>
+                <para>
+                    La valeur par défaut est <literal>outtype="double"</literal>
+                </para>
+            </listitem>
+        </itemizedlist>
     </refsection>
     <refsection>
         <title>Remarque</title>
index c87f089..12e6372 100644 (file)
                 </para>
             </listitem>
         </itemizedlist>
+        <para>
+            L'argument <literal>outtype</literal> gère la façon dont le produit est réalisé :
+        </para>
+        <itemizedlist>
+            <listitem>
+                <para>Pour les matrices de doubles, de polynômes, de fractions rationnelles, 
+                    l'évaluation est toujours effetuée sur des nombres à virgule flottante.
+                    Les options <literal>"double"</literal> ou <literal>"native"</literal> sont équivalentes 
+                    (par défaut, <literal>outtype = "double"</literal>).
+                </para>
+            </listitem>
+            <listitem>
+                <para>Pour les tableaux d'entiers,</para>
+                <para>
+                    si <literal>outtype="native"</literal>, le calcul est effectué sur des nombres entiers
+                    (modulo 2^b, où b est le nombre de bits utilisés).
+                </para>
+                <para>
+                    si <literal>outtype="double"</literal>, le calcul est effectué sur 
+                    des nombres à virgule flottante.
+                </para>
+                <para>
+                    La valeur par défaut est <literal>outtype="native"</literal>
+                </para>
+            </listitem>
+            <listitem>
+                <para>Pour les tableaux de booléens,</para>
+                <para>
+                    si <literal>outtype="native"</literal>, le calcul est effectué sur des booléens 
+                    (* est remplacée par &amp;),
+                </para>
+                <para>
+                    si <literal>outtype="double"</literal>, le calcul est effectué sur des nombres 
+                    à virgule flottante (%t est remplacé par 1 et %f par 0).
+                </para>
+                <para>
+                    La valeur par défaut est <literal>outtype="double"</literal>
+                </para>
+            </listitem>
+        </itemizedlist>
     </refsection>
     <refsection>
         <title>Remarque</title>
index 1743cdf..e5683c3 100644 (file)
@@ -41,6 +41,11 @@ c
          fun=-1
          return
       endif
+
+      if(rhs.eq.3) then
+        top=tops-1
+        rhs=rhs-1
+      endif
 c     
 c     standard matrix case
       call  orientandtype(sel,type)
index 32af107..a9b12ab 100644 (file)
@@ -43,6 +43,11 @@ c
          return
       endif
 
+      if(rhs.eq.3) then
+        top=tops-1
+        rhs=rhs-1
+      endif
+
 c     standard matrix case
       call  orientandtype(sel,type)
       if (err.gt.0.or.err1.gt.0) return
index 5349630..01c96f1 100644 (file)
@@ -36,9 +36,15 @@ c
       ilr=il0
       if(istk(il0).lt.0) il0=iadr(istk(il0+1))
       ref=ilr.ne.il0
+
 c
       if(istk(il0).eq.1) then
 c     standard matrix case
+c     the third argument is optional
+         if(rhs.eq.3) then
+            top=tops-1
+            rhs=rhs-1
+         endif
          call  orientandtype(sel,type)
          if (err.gt.0.or.err1.gt.0) return
          if (sel.gt.2) return
@@ -116,6 +122,10 @@ c     standard matrix case
          lstk(top+1)=l1+mr*nr*(it+1)
       elseif(istk(il0).eq.5) then
 c     sparse matrix case
+c     the third argument is optional
+         if(rhs.eq.3) then
+            goto 100
+         endif
          call  orientandtype(sel,type)
          if (err.gt.0.or.err1.gt.0) return
          if (sel.ne.0) goto 100
index f81f844..ecc1668 100644 (file)
@@ -39,9 +39,13 @@ c
       if(istk(il0).lt.0) il0=iadr(istk(il0+1))
       ref=ilr.ne.il0
 
-
       if(istk(il0).eq.1) then
 c     standard matrix case
+c     the third argument is optional. It's not used here
+         if(rhs.eq.3) then
+            top=tops-1
+            rhs=rhs-1
+         endif
          call  orientandtype(sel,type)
          if (err.gt.0.or.err1.gt.0) return
          if (sel.gt.2) return
@@ -126,6 +130,10 @@ c     .  *call* polelm
          return
       elseif(istk(il0).eq.5) then
 c     .  sparse matrix case
+c     the third argument is optional. It is not used here
+         if(rhs.eq.3) then
+            goto 100
+         endif
          call  orientandtype(sel,type)
          if (err.gt.0.or.err1.gt.0) return
          if(sel.ne.0) goto 100
index c4beb8e..594cbd9 100644 (file)
@@ -1,25 +1,30 @@
 c Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 c Copyright (C) INRIA
-c 
+c
 c This file must be used under the terms of the CeCILL.
 c This source file is licensed as described in the file COPYING, which
 c you should have received as part of this distribution.  The terms
-c are also available at    
+c are also available at
 c http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 c
       subroutine orientandtype(orient,type)
       INCLUDE 'stack.h'
       integer orient,type,native
       parameter (native=0)
+
       if(rhs.eq.3) then
 c     .  last argument must be "native" or "double" and previous must be
 c     .  an orientation flag
          call getresulttype(top,type)
          if (type.lt.0) then
+            top=top-1
+            call  getorient(top,orient)
+            if (err.gt.0.or.err1.gt.0) return
             err=3
             if (type.eq.-2) then
                call error(55)
+            elseif (type.eq.-3) then
+               call error(89)
             else
                call error(116)
             endif
@@ -30,7 +35,7 @@ c     .  an orientation flag
          if(err.gt.0) return
          top=top-1
       elseif(rhs.eq.2) then
-c     .  last argument must be an orientation flag or "native" or "double" 
+c     .  last argument must be an orientation flag or "native" or "double"
          call getresulttype(top,type)
          if (type.lt.0) then
 c     .     orientation flag
@@ -55,7 +60,7 @@ c
       integer iadr,sadr
 c
       data row/27/,col/12/,star/47/,mtlb/22/
-c     
+c
       iadr(l)=l+l-1
       sadr(l)=(l/2)+1
 
@@ -107,13 +112,15 @@ c     -------------------------------
       integer type
       character*7 temp
       integer iadr
-c     
+c
       iadr(l)=l+l-1
 
       il=iadr(lstk(k))
       if (istk(il).lt.0) il=iadr(istk(il+1))
-      if (istk(il).ne.10.or.istk(il+1).ne.1.or.istk(il+2).ne.1) then
+      if (istk(il).ne.10) then
          type=-2
+      elseif (istk(il+1).ne.1.or.istk(il+2).ne.1) then
+         type=-3
       else
          n=min(7,istk(il+5)-1)
          id=il+4
index ea4ad8b..95c84d0 100644 (file)
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2010 - INRIA - Serge Steer
 // Copyright (C) 2012 - Scilab Enterprises - Cedric Delamarre
+// Copyright (C) 2013 - Scilab Enterprises - Adeline CARNIS
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
 // <-- CLI SHELL MODE -->
+// Check error
+//==============================================================================
+//float matrices
+d=[1 10;254 9];
+assert_checkfalse(execstr("cumprod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("cumprod(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("cumprod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 2);
+assert_checkerror("cumprod(d, [""r"", ""c""])", refMsg);
+//==============================================================================
+// matrices of integer
+i = uint8(d);
+assert_checkfalse(execstr("cumprod(i, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("cumprod(i, ""orient"")", refMsg);
+assert_checkfalse(execstr("cumprod(i, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 2);
+assert_checkerror("cumprod(i, [""r"", ""c""])", refMsg);
+assert_checkfalse(execstr("cumprod(i,""r"", ""nat"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong value for argument #%d.\n"), 3);
+assert_checkerror("cumprod(i,""r"", ""nat"")", refMsg);
+assert_checkfalse(execstr("cumprod(i,""r"", [""nat"" ""dble""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 3);
+assert_checkerror("cumprod(i,""r"", [""nat"" ""dble""])", refMsg);
+assert_checkfalse(execstr("cumprod(i,""orient"", ""t"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("cumprod(i,""orient"", ""t"")", refMsg);
+assert_checkfalse(execstr("cumprod(i,1,1)"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong type for argument #%d: String expected.\n"), 3);
+assert_checkerror("cumprod(i,1,1)", refMsg);
+//==============================================================================
+// sparse matrices
+d = sparse(d);
+assert_checkfalse(execstr("cumprod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumprod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumprod(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("cumprod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",2);
+assert_checkerror("cumprod(d, [""r"", ""c""])", refMsg);
+//==============================================================================
+// boolean matrices
+d = [%f %t;%t %f];
+assert_checkfalse(execstr("cumprod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),"cumprod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumprod(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("cumprod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",2);
+assert_checkerror("cumprod(d, [""r"", ""c""])", refMsg);
+assert_checkfalse(execstr("cumprod(d,""r"", ""nat"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"cumprod", 3, "native", "double");
+assert_checkerror("cumprod(d,""r"", ""nat"")", refMsg);
+assert_checkfalse(execstr("cumprod(d,""r"", [""nat"" ""dble""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",3);
+assert_checkerror("cumprod(d,""r"", [""nat"" ""dble""])", refMsg);
+assert_checkfalse(execstr("cumprod(d,""orient"", ""t"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumprod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumprod(d,""orient"", ""t"")", refMsg);
+assert_checkfalse(execstr("cumprod(d,1,1)"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"cumprod",3);
+assert_checkerror("cumprod(d,1,1)", refMsg);
+//==============================================================================
+// sparse boolean matrices
+d = sparse(d);
+assert_checkfalse(execstr("cumprod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumprod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumprod(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("cumprod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",2);
+assert_checkerror("cumprod(d, [""r"", ""c""])", refMsg);
+assert_checkfalse(execstr("cumprod(d,""r"", ""nat"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"cumprod", 3, "native", "double");
+assert_checkerror("cumprod(d,""r"", ""nat"")", refMsg);
+assert_checkfalse(execstr("cumprod(d,""r"", [""nat"" ""dble""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",3);
+assert_checkerror("cumprod(d,""r"", [""nat"" ""dble""])", refMsg);
+assert_checkfalse(execstr("cumprod(d,""orient"", ""t"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumprod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumprod(d,""orient"", ""t"")", refMsg);
+assert_checkfalse(execstr("cumprod(d,1,1)"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"cumprod",3);
+assert_checkerror("cumprod(d,1,1)", refMsg);
+//==============================================================================
+// hypermatrices
+d = rand(2,2,2);
+assert_checkfalse(execstr("cumprod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumprod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumprod(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("cumprod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",2);
+assert_checkerror("cumprod(d, [""r"", ""c""])", refMsg);
+//==============================================================================
+// polynome
+s = poly(0, "s");
+d = [s s^2;s*%i 1];
+assert_checkfalse(execstr("cumprod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumprod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumprod(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("cumprod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",2);
+assert_checkerror("cumprod(d, [""r"", ""c""])", refMsg);
+//==============================================================================
+// rational matrices
+s = poly(0, "s");
+d = [1/s 1/s^2; 1/s 1];
+assert_checkfalse(execstr("cumprod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumprod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumprod(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("cumprod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",2);
+assert_checkerror("cumprod(d, [""r"", ""c""])", refMsg);
 //cumprod
 //Empty matrices
 T=list(list(),list('native'),list('double'));
index 5feb303..7a022bd 100644 (file)
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2010 - INRIA - Serge Steer
 // Copyright (C) 2012 - Scilab Enterprises - Cedric Delamarre
+// Copyright (C) 2013 - Scilab Enterprises - Adeline CARNIS
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
 
 // <-- CLI SHELL MODE -->
+// Check error
+//==============================================================================
+//float matrices
+d=[1 10;254 9];
+
+assert_checkfalse(execstr("cumprod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("cumprod(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("cumprod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 2);
+assert_checkerror("cumprod(d, [""r"", ""c""])", refMsg);
+
+//==============================================================================
+// matrices of integer
+i = uint8(d);
+
+assert_checkfalse(execstr("cumprod(i, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("cumprod(i, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("cumprod(i, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 2);
+assert_checkerror("cumprod(i, [""r"", ""c""])", refMsg);
+
+assert_checkfalse(execstr("cumprod(i,""r"", ""nat"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong value for argument #%d.\n"), 3);
+assert_checkerror("cumprod(i,""r"", ""nat"")", refMsg);
+
+assert_checkfalse(execstr("cumprod(i,""r"", [""nat"" ""dble""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 3);
+assert_checkerror("cumprod(i,""r"", [""nat"" ""dble""])", refMsg);
+
+assert_checkfalse(execstr("cumprod(i,""orient"", ""t"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("cumprod(i,""orient"", ""t"")", refMsg);
+
+assert_checkfalse(execstr("cumprod(i,1,1)"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong type for argument #%d: String expected.\n"), 3);
+assert_checkerror("cumprod(i,1,1)", refMsg);
+
+//==============================================================================
+// sparse matrices
+d = sparse(d);
+assert_checkfalse(execstr("cumprod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumprod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumprod(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("cumprod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",2);
+assert_checkerror("cumprod(d, [""r"", ""c""])", refMsg);
+
+//==============================================================================
+// boolean matrices
+d = [%f %t;%t %f];
+assert_checkfalse(execstr("cumprod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),"cumprod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumprod(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("cumprod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",2);
+assert_checkerror("cumprod(d, [""r"", ""c""])", refMsg);
+
+assert_checkfalse(execstr("cumprod(d,""r"", ""nat"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"cumprod", 3, "native", "double");
+assert_checkerror("cumprod(d,""r"", ""nat"")", refMsg);
+
+assert_checkfalse(execstr("cumprod(d,""r"", [""nat"" ""dble""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",3);
+assert_checkerror("cumprod(d,""r"", [""nat"" ""dble""])", refMsg);
+
+assert_checkfalse(execstr("cumprod(d,""orient"", ""t"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumprod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumprod(d,""orient"", ""t"")", refMsg);
+
+assert_checkfalse(execstr("cumprod(d,1,1)"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"cumprod",3);
+assert_checkerror("cumprod(d,1,1)", refMsg);
+
+//==============================================================================
+// sparse boolean matrices
+d = sparse(d);
+assert_checkfalse(execstr("cumprod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumprod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumprod(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("cumprod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",2);
+assert_checkerror("cumprod(d, [""r"", ""c""])", refMsg);
+
+assert_checkfalse(execstr("cumprod(d,""r"", ""nat"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"cumprod", 3, "native", "double");
+assert_checkerror("cumprod(d,""r"", ""nat"")", refMsg);
+
+assert_checkfalse(execstr("cumprod(d,""r"", [""nat"" ""dble""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",3);
+assert_checkerror("cumprod(d,""r"", [""nat"" ""dble""])", refMsg);
+
+assert_checkfalse(execstr("cumprod(d,""orient"", ""t"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumprod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumprod(d,""orient"", ""t"")", refMsg);
+
+assert_checkfalse(execstr("cumprod(d,1,1)"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"cumprod",3);
+assert_checkerror("cumprod(d,1,1)", refMsg);
+
+//==============================================================================
+// hypermatrices
+d = rand(2,2,2);
+assert_checkfalse(execstr("cumprod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumprod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumprod(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("cumprod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",2);
+assert_checkerror("cumprod(d, [""r"", ""c""])", refMsg);
+
+//==============================================================================
+// polynome
+s = poly(0, "s");
+d = [s s^2;s*%i 1];
+assert_checkfalse(execstr("cumprod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumprod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumprod(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("cumprod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",2);
+assert_checkerror("cumprod(d, [""r"", ""c""])", refMsg);
+
+//==============================================================================
+// rational matrices
+s = poly(0, "s");
+d = [1/s 1/s^2; 1/s 1];
+assert_checkfalse(execstr("cumprod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumprod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumprod(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("cumprod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",2);
+assert_checkerror("cumprod(d, [""r"", ""c""])", refMsg);
 
 //cumprod
 //Empty matrices
@@ -176,6 +324,7 @@ assert_checkequal(cumprod(bs,'native'), sparse([1,1;1,2;2,1;2,2],[%t;%t;%t;%t],[
 assert_checkequal(cumprod(bs,'*','native'), sparse([1,1;1,2;2,1;2,2],[%t;%t;%t;%t],[2,3]));
 
 assert_checkequal(cumprod(bs,1,'native'), sparse([1,1;1,2;2,1;2,2],[%t;%t;%t;%t],[2,3]));
+
 assert_checkequal(cumprod(bs,2,'native'), sparse([1,1;1,2;2,1;2,2;2,3],[%t;%t;%t;%t;%t],[2,3]));
 assert_checkequal(cumprod(bs,3,'native'), bs);
 
index 4aa9826..2ab31fb 100644 (file)
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2010 - INRIA - Serge Steer
 // Copyright (C) 2012 - Scilab Enterprises - Cedric Delamarre
+// Copyright (C) 2013 - Scilab Enterprises - Adeline CARNIS
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
 // <-- CLI SHELL MODE -->
+warning("off")
+// Check error
+//==============================================================================
+//float matrices
+d=[1 10;254 9];
+assert_checkfalse(execstr("cumsum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("cumsum(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("cumsum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 2);
+assert_checkerror("cumsum(d, [""r"", ""c""])", refMsg);
+//==============================================================================
+// matrices of integer
+i = uint8(d);
+assert_checkfalse(execstr("cumsum(i, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("cumsum(i, ""orient"")", refMsg);
+assert_checkfalse(execstr("cumsum(i, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 2);
+assert_checkerror("cumsum(i, [""r"", ""c""])", refMsg);
+assert_checkfalse(execstr("cumsum(i,""r"", ""nat"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong value for argument #%d.\n"), 3);
+assert_checkerror("cumsum(i,""r"", ""nat"")", refMsg);
+assert_checkfalse(execstr("cumsum(i,""r"", [""nat"" ""dble""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 3);
+assert_checkerror("cumsum(i,""r"", [""nat"" ""dble""])", refMsg);
+assert_checkfalse(execstr("cumsum(i,""orient"", ""t"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("cumsum(i,""orient"", ""t"")", refMsg);
+assert_checkfalse(execstr("cumsum(i,1,1)"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong type for argument #%d: String expected.\n"), 3);
+assert_checkerror("cumsum(i,1,1)", refMsg);
+//==============================================================================
+// sparse matrices
+d = sparse(d);
+assert_checkfalse(execstr("cumsum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumsum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumsum(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("cumsum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",2);
+assert_checkerror("cumsum(d, [""r"", ""c""])", refMsg);
+//==============================================================================
+// boolean matrices
+d = [%f %t;%t %f];
+assert_checkfalse(execstr("cumsum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),"cumsum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumsum(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("cumsum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",2);
+assert_checkerror("cumsum(d, [""r"", ""c""])", refMsg);
+assert_checkfalse(execstr("cumsum(d,""r"", ""nat"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"cumsum", 3, "native", "double");
+assert_checkerror("cumsum(d,""r"", ""nat"")", refMsg);
+assert_checkfalse(execstr("cumsum(d,""r"", [""nat"" ""dble""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",3);
+assert_checkerror("cumsum(d,""r"", [""nat"" ""dble""])", refMsg);
+assert_checkfalse(execstr("cumsum(d,""orient"", ""t"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumsum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumsum(d,""orient"", ""t"")", refMsg);
+assert_checkfalse(execstr("cumsum(d,1,1)"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"cumsum",3);
+assert_checkerror("cumsum(d,1,1)", refMsg);
+//==============================================================================
+// sparse boolean matrices
+d = sparse(d);
+assert_checkfalse(execstr("cumsum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumsum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumsum(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("cumsum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",2);
+assert_checkerror("cumsum(d, [""r"", ""c""])", refMsg);
+assert_checkfalse(execstr("cumsum(d,""r"", ""nat"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"cumsum", 3, "native", "double");
+assert_checkerror("cumsum(d,""r"", ""nat"")", refMsg);
+assert_checkfalse(execstr("cumsum(d,""r"", [""nat"" ""dble""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",3);
+assert_checkerror("cumsum(d,""r"", [""nat"" ""dble""])", refMsg);
+assert_checkfalse(execstr("cumsum(d,""orient"", ""t"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumsum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumsum(d,""orient"", ""t"")", refMsg);
+assert_checkfalse(execstr("cumsum(d,1,1)"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"cumsum",3);
+assert_checkerror("cumsum(d,1,1)", refMsg);
+//==============================================================================
+// hypermatrices
+d = [1 2;3 4];
+d(:,:,2) = [1 0;1 0];
+assert_checkfalse(execstr("cumsum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumsum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumsum(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("cumsum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",2);
+assert_checkerror("cumsum(d, [""r"", ""c""])", refMsg);
+//==============================================================================
+// polynome
+s = poly(0, "s");
+d = [s s^2;s*%i 1];
+assert_checkfalse(execstr("cumsum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumsum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumsum(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("cumsum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",2);
+assert_checkerror("cumsum(d, [""r"", ""c""])", refMsg);
+//==============================================================================
+// rational matrices
+s = poly(0, "s");
+d = [1/s 1/s^2; 1/s 1];
+assert_checkfalse(execstr("cumsum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumsum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumsum(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("cumsum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",2);
+assert_checkerror("cumsum(d, [""r"", ""c""])", refMsg);
 //empty matrices
 T=list(list(),list('native'),list('double'));
 for typ=T
@@ -159,3 +280,4 @@ assert_checkequal(cumsum(bs,1,'native'), sparse([1,2;2,2;2,3],[%t;%t;%t],[2,3]))
 assert_checkequal(cumsum(bs,2,'native'), sparse([1,2;1,3;2,2;2,3],[%t;%t;%t;%t],[2,3]));
 assert_checkequal(cumsum(bs,3,'native'), bs);
 // TODO : test the "m" option
+warning("on")
index f4fe2a8..9a4230f 100644 (file)
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2010 - INRIA - Serge Steer
 // Copyright (C) 2012 - Scilab Enterprises - Cedric Delamarre
+// Copyright (C) 2013 - Scilab Enterprises - Adeline CARNIS
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
 
 // <-- CLI SHELL MODE -->
+warning("off")
+// Check error
+//==============================================================================
+//float matrices
+d=[1 10;254 9];
+
+assert_checkfalse(execstr("cumsum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("cumsum(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("cumsum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 2);
+assert_checkerror("cumsum(d, [""r"", ""c""])", refMsg);
+
+//==============================================================================
+// matrices of integer
+i = uint8(d);
+
+assert_checkfalse(execstr("cumsum(i, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("cumsum(i, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("cumsum(i, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 2);
+assert_checkerror("cumsum(i, [""r"", ""c""])", refMsg);
+
+assert_checkfalse(execstr("cumsum(i,""r"", ""nat"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong value for argument #%d.\n"), 3);
+assert_checkerror("cumsum(i,""r"", ""nat"")", refMsg);
+
+assert_checkfalse(execstr("cumsum(i,""r"", [""nat"" ""dble""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 3);
+assert_checkerror("cumsum(i,""r"", [""nat"" ""dble""])", refMsg);
+
+assert_checkfalse(execstr("cumsum(i,""orient"", ""t"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("cumsum(i,""orient"", ""t"")", refMsg);
+
+assert_checkfalse(execstr("cumsum(i,1,1)"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong type for argument #%d: String expected.\n"), 3);
+assert_checkerror("cumsum(i,1,1)", refMsg);
+
+//==============================================================================
+// sparse matrices
+d = sparse(d);
+assert_checkfalse(execstr("cumsum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumsum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumsum(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("cumsum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",2);
+assert_checkerror("cumsum(d, [""r"", ""c""])", refMsg);
+
+
+//==============================================================================
+// boolean matrices
+d = [%f %t;%t %f];
+assert_checkfalse(execstr("cumsum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),"cumsum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumsum(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("cumsum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",2);
+assert_checkerror("cumsum(d, [""r"", ""c""])", refMsg);
+
+assert_checkfalse(execstr("cumsum(d,""r"", ""nat"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"cumsum", 3, "native", "double");
+assert_checkerror("cumsum(d,""r"", ""nat"")", refMsg);
+
+assert_checkfalse(execstr("cumsum(d,""r"", [""nat"" ""dble""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",3);
+assert_checkerror("cumsum(d,""r"", [""nat"" ""dble""])", refMsg);
+
+assert_checkfalse(execstr("cumsum(d,""orient"", ""t"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumsum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumsum(d,""orient"", ""t"")", refMsg);
+
+assert_checkfalse(execstr("cumsum(d,1,1)"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"cumsum",3);
+assert_checkerror("cumsum(d,1,1)", refMsg);
+
+//==============================================================================
+// sparse boolean matrices
+d = sparse(d);
+assert_checkfalse(execstr("cumsum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumsum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumsum(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("cumsum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",2);
+assert_checkerror("cumsum(d, [""r"", ""c""])", refMsg);
+
+assert_checkfalse(execstr("cumsum(d,""r"", ""nat"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"cumsum", 3, "native", "double");
+assert_checkerror("cumsum(d,""r"", ""nat"")", refMsg);
+
+assert_checkfalse(execstr("cumsum(d,""r"", [""nat"" ""dble""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",3);
+assert_checkerror("cumsum(d,""r"", [""nat"" ""dble""])", refMsg);
+
+assert_checkfalse(execstr("cumsum(d,""orient"", ""t"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumsum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumsum(d,""orient"", ""t"")", refMsg);
+
+assert_checkfalse(execstr("cumsum(d,1,1)"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"cumsum",3);
+assert_checkerror("cumsum(d,1,1)", refMsg);
+
+//==============================================================================
+// hypermatrices
+d = [1 2;3 4];
+d(:,:,2) = [1 0;1 0];
+assert_checkfalse(execstr("cumsum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumsum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumsum(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("cumsum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",2);
+assert_checkerror("cumsum(d, [""r"", ""c""])", refMsg);
+
+//==============================================================================
+// polynome
+s = poly(0, "s");
+d = [s s^2;s*%i 1];
+assert_checkfalse(execstr("cumsum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumsum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumsum(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("cumsum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",2);
+assert_checkerror("cumsum(d, [""r"", ""c""])", refMsg);
+
+//==============================================================================
+// rational matrices
+s = poly(0, "s");
+d = [1/s 1/s^2; 1/s 1];
+assert_checkfalse(execstr("cumsum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "cumsum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("cumsum(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("cumsum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",2);
+assert_checkerror("cumsum(d, [""r"", ""c""])", refMsg);
 
 //empty matrices
 T=list(list(),list('native'),list('double'));
@@ -21,6 +172,8 @@ end
 //=======================================================================
 //float matrices
 d=[1 10;254 9];
+
+
 T=list(list(),list('native'),list('double'));
 for typ=T
     assert_checkequal(cumsum(d,typ(:)), [1,265;255,274]);
@@ -179,3 +332,4 @@ assert_checkequal(cumsum(bs,2,'native'), sparse([1,2;1,3;2,2;2,3],[%t;%t;%t;%t],
 assert_checkequal(cumsum(bs,3,'native'), bs);
 
 // TODO : test the "m" option
+warning("on")
index 36bf611..d1fa54f 100644 (file)
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2010 - INRIA - Serge Steer
+// Copyright (C) 2013 - Scilab Enterprises - Adeline CARNIS
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
 // <-- CLI SHELL MODE -->
 // prod 
+// Check error
+d=[1 10;254 9];
+assert_checkfalse(execstr("prod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("prod(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("prod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 2);
+assert_checkerror("prod(d, [""r"", ""c""])", refMsg);
+//==============================================================================
+// matrices of integer
+i = uint8(d);
+assert_checkfalse(execstr("prod(i, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("prod(i, ""orient"")", refMsg);
+assert_checkfalse(execstr("prod(i, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 2);
+assert_checkerror("prod(i, [""r"", ""c""])", refMsg);
+assert_checkfalse(execstr("prod(i,""r"", ""nat"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong value for argument #%d.\n"), 3);
+assert_checkerror("prod(i,""r"", ""nat"")", refMsg);
+assert_checkfalse(execstr("prod(i,""r"", [""nat"" ""dble""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 3);
+assert_checkerror("prod(i,""r"", [""nat"" ""dble""])", refMsg);
+assert_checkfalse(execstr("prod(i,""orient"", ""t"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("prod(i,""orient"", ""t"")", refMsg);
+assert_checkfalse(execstr("prod(i,1,1)"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong type for argument #%d: String expected.\n"), 3);
+assert_checkerror("prod(i,1,1)", refMsg);
+//==============================================================================
+// sparse matrices
+d = sparse(d);
+assert_checkfalse(execstr("prod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("prod(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("prod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 2);
+assert_checkerror("prod(d, [""r"", ""c""])", refMsg);
+//==============================================================================
+// boolean matrices
+d = [%f %t;%t %f];
+assert_checkfalse(execstr("prod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),"prod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("prod(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("prod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",2);
+assert_checkerror("prod(d, [""r"", ""c""])", refMsg);
+assert_checkfalse(execstr("prod(d,""r"", ""nat"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"prod", 3, "native", "double");
+assert_checkerror("prod(d,""r"", ""nat"")", refMsg);
+assert_checkfalse(execstr("prod(d,""r"", [""nat"" ""dble""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",3);
+assert_checkerror("prod(d,""r"", [""nat"" ""dble""])", refMsg);
+assert_checkfalse(execstr("prod(d,""orient"", ""t"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "prod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("prod(d,""orient"", ""t"")", refMsg);
+assert_checkfalse(execstr("prod(d,1,1)"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"prod",3);
+assert_checkerror("prod(d,1,1)", refMsg);
+//==============================================================================
+// sparse boolean matrices
+d = sparse(d);
+assert_checkfalse(execstr("prod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+"prod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("prod(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("prod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",2);
+assert_checkerror("prod(d, [""r"", ""c""])", refMsg);
+assert_checkfalse(execstr("prod(d,""r"", ""nat"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"prod", 3, "native", "double");
+assert_checkerror("prod(d,""r"", ""nat"")", refMsg);
+assert_checkfalse(execstr("prod(d,""r"", [""nat"" ""dble""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",3);
+assert_checkerror("prod(d,""r"", [""nat"" ""dble""])", refMsg);
+assert_checkfalse(execstr("prod(d,""orient"", ""t"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+"prod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("prod(d,""orient"", ""t"")", refMsg);
+assert_checkfalse(execstr("prod(d,1,1)"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"prod",3);
+assert_checkerror("prod(d,1,1)", refMsg);
+//==============================================================================
+// hypermatrices
+d = rand(2,2,2);
+assert_checkfalse(execstr("prod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+"prod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("prod(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("prod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",2);
+assert_checkerror("prod(d, [""r"", ""c""])", refMsg);
+//==============================================================================
+// polynome
+s = poly(0, "s");
+d = [s s^2;s*%i 1];
+assert_checkfalse(execstr("prod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+"prod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("prod(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("prod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",2);
+assert_checkerror("prod(d, [""r"", ""c""])", refMsg);
+//==============================================================================
+// rational matrices
+s = poly(0, "s");
+d = [1/s 1/s^2; 1/s 1];
+assert_checkfalse(execstr("prod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+"prod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("prod(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("prod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",2);
+assert_checkerror("prod(d, [""r"", ""c""])", refMsg);
 //empty matrices
 T=list(list(),list('native'),list('double'));
 for typ=T
@@ -20,142 +136,146 @@ end
 d=[1 10;254 9];
 T=list(list(),list('native'),list('double'));
 for typ=T
-  if prod(d,typ(:))<>22860 then bugmes();quit;end
-  if prod(d,'*',typ(:))<>22860 then bugmes();quit;end
-  if or(prod(d,1,typ(:))<>[254 90]) then bugmes();quit;end
-  if or(prod(d,2,typ(:))<>[10;2286]) then bugmes();quit;end
-  if or(prod(d,3,typ(:))<>d) then bugmes();quit;end
+    assert_checkequal(prod(d, typ(:)), 22860);
+    assert_checkequal(prod(d, "*", typ(:)), 22860);
+    assert_checkequal(prod(d, 1, typ(:)), [254 90]);
+    assert_checkequal(prod(d, 2, typ(:)), [10;2286]);
+    assert_checkequal(prod(d, 3, typ(:)), d);
 end
 //hypermatrices of floats
 d=[1 10;254 9];d(:,:,2)=1;
 T=list(list(),list('native'),list('double'));
 for typ=T
-  if prod(d,typ(:))<>22860 then bugmes();quit;end
-  if prod(d,'*',typ(:))<>22860 then bugmes();quit;end
-  if or(prod(d,1,typ(:))<>hypermat([1,2,2],[254;90;1;1])) then bugmes();quit;end
-  if or(prod(d,2,typ(:))<>hypermat([2,1,2],[10;2286;1;1])) then bugmes();quit;end
-  if or(prod(d,3,typ(:))<>[1,10;254,9]) then bugmes();quit;end
-  if or(prod(d,5,typ(:))<>d) then bugmes();quit;end
+    assert_checkequal(prod(d, typ(:)), 22860);
+    assert_checkequal(prod(d, "*", typ(:)), 22860);
+    assert_checkequal(prod(d, 1, typ(:)), hypermat([1,2,2],[254;90;1;1]));
+    assert_checkequal(prod(d, 2, typ(:)), hypermat([2,1,2],[10;2286;1;1]));
+    assert_checkequal(prod(d, 3, typ(:)), [1,10;254,9]);
+    assert_checkequal(prod(d, 5, typ(:)), d);
 end
 //=======================================================================
 //matrices of short integers
 i=uint8([1 10;254 9]);
 T=list(list(),list('native'));
 for typ=T
-  if prod(i,typ(:))<>uint8(76) then bugmes();quit;end
-  if prod(i,'*',typ(:))<>uint8(76) then bugmes();quit;end
-  if or(prod(i,1,typ(:))<>uint8([254 90])) then bugmes();quit;end
-  if or(prod(i,2,typ(:))<>uint8([10;238])) then bugmes();quit;end
-  if or(prod(i,3,typ(:))<>i) then bugmes();quit;end
+    assert_checkequal(prod(i, typ(:)), uint8(76));
+    assert_checkequal(prod(i, "*", typ(:)), uint8(76));
+    assert_checkequal(prod(i, 1, typ(:)), uint8([254 90]));
+    assert_checkequal(prod(i, 2, typ(:)), uint8([10;238]));
+    assert_checkequal(prod(i, 3, typ(:)), double(i));
 end
-if prod(i,'double')<>22860 then bugmes();quit;end
-if prod(i,'*','double')<>22860 then bugmes();quit;end
-if or(prod(i,1,'double')<>[254 90]) then bugmes();quit;end
-if or(prod(i,2,'double')<>[10;2286]) then bugmes();quit;end
-if or(prod(i,3,'double')<>double(i)) then bugmes();quit;end
+assert_checkequal(prod(i, "double"), 22860);
+assert_checkequal(prod(i, "*", "double"), 22860);
+assert_checkequal(prod(i, 1, "double"), [254 90]);
+assert_checkequal(prod(i, 2, "double"), [10;2286]);
+assert_checkequal(prod(i, 3, "double"), double(i));
 //with hypermatrices
 i=uint8([1 10;254 9]);i(:,:,2)=uint8(1);
-for typ=list(list(),list('native'));
-  if prod(i,typ(:))<>uint8(76) then bugmes();quit;end
-  if prod(i,'*',typ(:))<>uint8(76) then bugmes();quit;end
-  if or(prod(i,1,typ(:))<>hypermat([1,2,2],uint8([254;90;1;1]))) then bugmes();quit;end
-  if or(prod(i,2,typ(:))<>hypermat([2,1,2],uint8([10;238;1;1]))) then bugmes();quit;end
-  if or(prod(i,3,typ(:))<>([1,10;254,9])) then bugmes();quit;end
-  if or(prod(i,5,typ(:))<>i) then bugmes();quit;end
+T = list(list(),list('native'));
+for typ=T
+    assert_checkequal(prod(i, typ(:)), uint8(76));
+    assert_checkequal(prod(i, "*", typ(:)), uint8(76));
+    assert_checkequal(prod(i, 1, typ(:)), hypermat([1,2,2],uint8([254;90;1;1])));
+    assert_checkequal(prod(i, 2, typ(:)), hypermat([2,1,2],uint8([10;238;1;1])));
+    assert_checkequal(prod(i, 3, typ(:)), uint8([1,10;254,9]));
+    assert_checkequal(prod(i, 5, typ(:)), double(i));
 end
-if prod(i,'double')<>22860 then bugmes();quit;end
-if prod(i,'*','double')<>22860 then bugmes();quit;end
-if or(prod(i,1,'double')<>hypermat([1,2,2],[254;90;1;1])) then bugmes();quit;end
-if or(prod(i,2,'double')<>hypermat([2,1,2],[10;2286;1;1])) then bugmes();quit;end
-if or(prod(i,3,'double')<>[1,10;254,9]) then bugmes();quit;end
-if or(prod(i,5,'double')<>double(i)) then bugmes();quit;end
+assert_checkequal(prod(i, "double"), 22860);
+assert_checkequal(prod(i, "*", "double"), 22860);
+assert_checkequal(prod(i, 1, "double"), hypermat([1,2,2],[254;90;1;1]));
+assert_checkequal(prod(i, 2, "double"), hypermat([2,1,2],[10;2286;1;1]));
+assert_checkequal(prod(i, 3, "double"), [1,10;254,9]);
+assert_checkequal(prod(i, 5, "double"), double(i));
 //Polynomials
 s=%s;p=[s s+1;s^2 1];
 T=list(list(),list('native'),list('double'));
 for typ=T
-  if prod(p,typ(:))<>s^3+s^4 then bugmes();quit;end
-  if prod(p,'*',typ(:))<>s^3+s^4 then bugmes();quit;end
-  if or(prod(p,1,typ(:))<>[s^3,1+s]) then bugmes();quit;end
-  if or(prod(p,2,typ(:))<>[s+s^2;s^2]) then bugmes();quit;end
-  if or(prod(p,3,typ(:))<>p) then bugmes();quit;end
+    assert_checkequal(prod(p, typ(:)), s^3+s^4);
+    assert_checkequal(prod(p, "*", typ(:)), s^3+s^4);
+    assert_checkequal(prod(p, 1, typ(:)), [s^3,1+s]);
+    assert_checkequal(prod(p, 2, typ(:)), [s+s^2;s^2]);
+    assert_checkequal(prod(p, 3, typ(:)), p);
 end
 //with hypermatrices
 s=%s;p=[s s+1;s^2 1];p(:,:,2)=[1 s;s+1 2];
 T=list(list(),list('native'),list('double'));
 for typ=T
-  if prod(p,typ(:))<>2*s^4+4*s^5+2*s^6 then bugmes();quit;end
-  if prod(p,'*',typ(:))<>2*s^4+4*s^5+2*s^6 then bugmes();quit;end
-  if or(prod(p,1,typ(:))<>hypermat([1,2,2],[s^3;1+s;1+s;2*s])) then bugmes();quit;end
-  if or(prod(p,2,typ(:))<>hypermat([2,1,2],[s+s^2;s^2;s;2+2*s])) then bugmes();quit;end
-  if or(prod(p,3,typ(:))<>[s,s+s^2;s^2+s^3,2]) then bugmes();quit;end
-  if or(prod(p,5,typ(:))<>p) then bugmes();quit;end
+    assert_checkequal(prod(p, typ(:)), 2*s^4+4*s^5+2*s^6);
+    assert_checkequal(prod(p, "*", typ(:)), 2*s^4+4*s^5+2*s^6);
+    assert_checkequal(prod(p, 1, typ(:)), hypermat([1,2,2],[s^3;1+s;1+s;2*s]));
+    assert_checkequal(prod(p, 2, typ(:)), hypermat([2,1,2],[s+s^2;s^2;s;2+2*s]));
+    assert_checkequal(prod(p, 3, typ(:)), [s,s+s^2;s^2+s^3,2]);
+    assert_checkequal(prod(p, 5, typ(:)), p);
 end
 //=======================================================================
 //Matrices of rationals
 s=%s;r=1.0 ./[s s+1;s^2 1];
 T=list(list(),list('native'),list('double'));
 for typ=T
-  if prod(r,typ(:))<>1.0/(s^3+s^4) then bugmes();quit;end
-  if prod(r,'*',typ(:))<>1.0/(s^3+s^4) then bugmes();quit;end
-  if or(prod(r,1,typ(:))<>[1,1]./[s^3,1+s]) then bugmes();quit;end
-  if or(prod(r,2,typ(:))<>[1;1]./[s+s^2;s^2]) then bugmes();quit;end
-  if or(prod(r,3,typ(:))<>r) then bugmes();quit;end
+    assert_checkequal(prod(r, typ(:)), 1.0/(s^3+s^4));
+    assert_checkequal(prod(r, "*", typ(:)), 1.0/(s^3+s^4));
+    assert_checkequal(prod(r, 1, typ(:)), [1,1]./[s^3,1+s]);
+    assert_checkequal(prod(r, 2, typ(:)), [1;1]./[s+s^2;s^2]);
+    assert_checkequal(prod(r, 3, typ(:)), r);
 end
 //=======================================================================
 //Matrices of booleans
 b=[%t %t; %f %t];
-for typ=list(list(),list('double'));
-  if prod(b,typ(:))<>0 then bugmes();quit;end
-  if prod(b,'*',typ(:))<>0 then bugmes();quit;end
-  if or(prod(b,1,typ(:))<>[0 1]) then bugmes();quit;end
-  if or(prod(b,2,typ(:))<>[1;0]) then bugmes();quit;end
-  if or(prod(b,3,typ(:))<>double(b)) then bugmes();quit;end
+T = list(list(),list('double'));
+for typ=T
+    assert_checkequal(prod(b, typ(:)), 0);
+    assert_checkequal(prod(b, "*", typ(:)), 0);
+    assert_checkequal(prod(b, 1, typ(:)), [0 1]);
+    assert_checkequal(prod(b, 2, typ(:)), [1;0]);
+    assert_checkequal(prod(b, 3, typ(:)), double(b));
 end
-if prod(b,'native')<>%f then bugmes();quit;end
-if prod(b,'*','native')<>%f then bugmes();quit;end
-if or(prod(b,1,'native')<>[%f %t]) then bugmes();quit;end
-if or(prod(b,2,'native')<>[%t;%f]) then bugmes();quit;end
-if or(prod(b,3,'native')<>b) then bugmes();quit;end
-//with hypermatrices 
+assert_checkequal(prod(b, "native"), %f);
+assert_checkequal(prod(b, "*", "native"), %f);
+assert_checkequal(prod(b, 1, "native"), [%f %t]);
+assert_checkequal(prod(b, 2, "native"), [%t;%f]);
+assert_checkequal(prod(b, 3, "native"), b);
+//with hypermatrices   
 b=[%t %t;%f %t];b(1,1,2)=%t;
-for typ=list(list(),list('double'));
-  if prod(b,typ(:))<>0 then bugmes();quit;end
-  if prod(b,'*',typ(:))<>0 then bugmes();quit;end
-  if or(prod(b,1,typ(:))<>hypermat([1,2,2],[0;1;0;0])) then bugmes();quit;end
-  if or(prod(b,2,typ(:))<>hypermat([2,1,2],[1;0;0;0])) then bugmes();quit;end
-  if or(prod(b,3,typ(:))<>[1,0;0,0]) then bugmes();quit;end
-  if or(prod(b,5,typ(:))<>double(b)) then bugmes();quit;end
+T = list(list(),list('double'));
+for typ=T
+    assert_checkequal(prod(b, typ(:)), 0);
+    assert_checkequal(prod(b, "*", typ(:)), 0);
+    assert_checkequal(prod(b, 1, typ(:)), hypermat([1,2,2],[0;1;0;0]));
+    assert_checkequal(prod(b, 2, typ(:)), hypermat([2,1,2],[1;0;0;0]));
+    assert_checkequal(prod(b, 3, typ(:)), [1,0;0,0]);
+    assert_checkequal(prod(b, 5, typ(:)), double(b));
 end
-if prod(b,'native')<>%f then bugmes();quit;end
-if prod(b,'*','native')<>%f then bugmes();quit;end
-if or(prod(b,1,'native')<>hypermat([1,2,2],[%f;%t;%f;%f])) then bugmes();quit;end
-if or(prod(b,2,'native')<>hypermat([2,1,2],[%t;%f;%f;%f])) then bugmes();quit;end
-if or(prod(b,3,'native')<>[%t,%f;%f,%f]) then bugmes();quit;end
-if or(prod(b,5,'native')<>b) then bugmes();quit;end
+assert_checkequal(prod(b, "native"), %f);
+assert_checkequal(prod(b, "*", "native"), %f);
+assert_checkequal(prod(b, 1, "native"), hypermat([1,2,2],[%f;%t;%f;%f]));
+assert_checkequal(prod(b, 2, "native"), hypermat([2,1,2],[%t;%f;%f;%f]));
+assert_checkequal(prod(b, 3, "native"), [%t,%f;%f,%f]);
+assert_checkequal(prod(b, 5, "native"), b);
 //=======================================================================
 //sparse matrices of floats
 s=sparse([1 10 2;-1 254 9]);
 T=list(list(),list('native'),list('double'));
 for typ=T
-  if prod(s,typ(:))<>-45720 then bugmes();quit;end
-  if prod(s,'*',typ(:))<>-45720 then bugmes();quit;end
-  if or(prod(s,1,typ(:))<>sparse([-1 2540 18])) then bugmes();quit;end
-  if or(prod(s,2,typ(:))<>sparse([20;-2286])) then bugmes();quit;end
-  if or(prod(s,3,typ(:))<>s) then bugmes();quit;end
+    assert_checkequal(prod(s, typ(:)), -45720);
+    assert_checkequal(prod(s, "*", typ(:)), -45720);
+    assert_checkequal(prod(s, 1, typ(:)), sparse([-1 2540 18]));
+    assert_checkequal(prod(s, 2, typ(:)), sparse([20;-2286]));
+    assert_checkequal(prod(s, 3, typ(:)), s);
 end
 //=======================================================================
 //sparse  matrices of boolean
 bs=sparse([%t %t %f;%t %t %t]);
-for typ=list(list(),list('double'));
-  if prod(bs,typ(:))<>0 then bugmes();quit;end
-  if prod(bs,'*',typ(:))<>0 then bugmes();quit;end
-  if or(prod(bs,1,typ(:))<>sparse([1,1,0])) then bugmes();quit;end
-  if or(prod(bs,2,typ(:))<>sparse([0;1])) then bugmes();quit;end
-  if or(prod(bs,3,typ(:))<>bool2s(bs)) then bugmes();quit;end
+T = list(list(),list('double'));
+for typ=T
+    assert_checkequal(prod(bs, typ(:)), 0);
+    assert_checkequal(prod(bs, "*", typ(:)), 0);
+    assert_checkequal(prod(bs, 1, typ(:)), sparse([1,1,0]));
+    assert_checkequal(prod(bs, 2, typ(:)), sparse([0;1]));
+    assert_checkequal(prod(bs, 3, typ(:)), bool2s(bs));
 end
-if prod(bs,'native')<>%f then bugmes();quit;end
-if prod(bs,'*','native')<>%f then bugmes();quit;end
-if or(prod(bs,1,'native')<>sparse([%t,%t,%f])) then bugmes();quit;end
-if or(prod(bs,2,'native')<>sparse([%f;%t])) then bugmes();quit;end
-if or(prod(bs,3,'native')<>bs) then bugmes();quit;end
+assert_checkequal(prod(bs, "native"), %f);
+assert_checkequal(prod(bs, "*", "native"), %f);
+assert_checkequal(prod(bs, 1, "native"), sparse([%t,%t,%f]));
+assert_checkequal(prod(bs, 2, "native"), sparse([%f;%t]));
+assert_checkequal(prod(bs, 3, "native"), bs);
 // TODO : test the "m" option
index b3cc828..439630b 100644 (file)
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2010 - INRIA - Serge Steer
+// Copyright (C) 2013 - Scilab Enterprises - Adeline CARNIS
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
 
 // <-- CLI SHELL MODE -->
 // prod 
+// Check error
+d=[1 10;254 9];
+assert_checkfalse(execstr("prod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("prod(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("prod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 2);
+assert_checkerror("prod(d, [""r"", ""c""])", refMsg);
+
+//==============================================================================
+// matrices of integer
+i = uint8(d);
+assert_checkfalse(execstr("prod(i, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("prod(i, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("prod(i, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 2);
+assert_checkerror("prod(i, [""r"", ""c""])", refMsg);
+
+assert_checkfalse(execstr("prod(i,""r"", ""nat"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong value for argument #%d.\n"), 3);
+assert_checkerror("prod(i,""r"", ""nat"")", refMsg);
+
+assert_checkfalse(execstr("prod(i,""r"", [""nat"" ""dble""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 3);
+assert_checkerror("prod(i,""r"", [""nat"" ""dble""])", refMsg);
+
+assert_checkfalse(execstr("prod(i,""orient"", ""t"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("prod(i,""orient"", ""t"")", refMsg);
+
+assert_checkfalse(execstr("prod(i,1,1)"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong type for argument #%d: String expected.\n"), 3);
+assert_checkerror("prod(i,1,1)", refMsg);
+
+//==============================================================================
+// sparse matrices
+d = sparse(d);
+assert_checkfalse(execstr("prod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("prod(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("prod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 2);
+assert_checkerror("prod(d, [""r"", ""c""])", refMsg);
+
+//==============================================================================
+// boolean matrices
+d = [%f %t;%t %f];
+assert_checkfalse(execstr("prod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),"prod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("prod(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("prod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",2);
+assert_checkerror("prod(d, [""r"", ""c""])", refMsg);
+
+assert_checkfalse(execstr("prod(d,""r"", ""nat"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"prod", 3, "native", "double");
+assert_checkerror("prod(d,""r"", ""nat"")", refMsg);
+
+assert_checkfalse(execstr("prod(d,""r"", [""nat"" ""dble""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",3);
+assert_checkerror("prod(d,""r"", [""nat"" ""dble""])", refMsg);
+
+assert_checkfalse(execstr("prod(d,""orient"", ""t"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+            "prod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("prod(d,""orient"", ""t"")", refMsg);
+
+assert_checkfalse(execstr("prod(d,1,1)"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"prod",3);
+assert_checkerror("prod(d,1,1)", refMsg);
+
+//==============================================================================
+// sparse boolean matrices
+d = sparse(d);
+assert_checkfalse(execstr("prod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+"prod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("prod(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("prod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",2);
+assert_checkerror("prod(d, [""r"", ""c""])", refMsg);
+
+assert_checkfalse(execstr("prod(d,""r"", ""nat"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"prod", 3, "native", "double");
+assert_checkerror("prod(d,""r"", ""nat"")", refMsg);
+
+assert_checkfalse(execstr("prod(d,""r"", [""nat"" ""dble""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",3);
+assert_checkerror("prod(d,""r"", [""nat"" ""dble""])", refMsg);
+
+assert_checkfalse(execstr("prod(d,""orient"", ""t"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+"prod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("prod(d,""orient"", ""t"")", refMsg);
+
+assert_checkfalse(execstr("prod(d,1,1)"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"prod",3);
+assert_checkerror("prod(d,1,1)", refMsg);
+
+//==============================================================================
+// hypermatrices
+d = rand(2,2,2);
+assert_checkfalse(execstr("prod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+"prod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("prod(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("prod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",2);
+assert_checkerror("prod(d, [""r"", ""c""])", refMsg);
+
+//==============================================================================
+// polynome
+s = poly(0, "s");
+d = [s s^2;s*%i 1];
+assert_checkfalse(execstr("prod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+"prod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("prod(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("prod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",2);
+assert_checkerror("prod(d, [""r"", ""c""])", refMsg);
+
+//==============================================================================
+// rational matrices
+s = poly(0, "s");
+d = [1/s 1/s^2; 1/s 1];
+assert_checkfalse(execstr("prod(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+"prod",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("prod(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("prod(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",2);
+assert_checkerror("prod(d, [""r"", ""c""])", refMsg);
+
 //empty matrices
 T=list(list(),list('native'),list('double'));
 for typ=T
@@ -22,11 +166,11 @@ end
 d=[1 10;254 9];
 T=list(list(),list('native'),list('double'));
 for typ=T
-  if prod(d,typ(:))<>22860 then pause,end
-  if prod(d,'*',typ(:))<>22860 then pause,end
-  if or(prod(d,1,typ(:))<>[254 90]) then pause,end
-  if or(prod(d,2,typ(:))<>[10;2286]) then pause,end
-  if or(prod(d,3,typ(:))<>d) then pause,end
+    assert_checkequal(prod(d, typ(:)), 22860);
+    assert_checkequal(prod(d, "*", typ(:)), 22860);
+    assert_checkequal(prod(d, 1, typ(:)), [254 90]);
+    assert_checkequal(prod(d, 2, typ(:)), [10;2286]);
+    assert_checkequal(prod(d, 3, typ(:)), d);
 end
 
 
@@ -34,12 +178,12 @@ end
 d=[1 10;254 9];d(:,:,2)=1;
 T=list(list(),list('native'),list('double'));
 for typ=T
-  if prod(d,typ(:))<>22860 then pause,end
-  if prod(d,'*',typ(:))<>22860 then pause,end
-  if or(prod(d,1,typ(:))<>hypermat([1,2,2],[254;90;1;1])) then pause,end
-  if or(prod(d,2,typ(:))<>hypermat([2,1,2],[10;2286;1;1])) then pause,end
-  if or(prod(d,3,typ(:))<>[1,10;254,9]) then pause,end
-  if or(prod(d,5,typ(:))<>d) then pause,end
+    assert_checkequal(prod(d, typ(:)), 22860);
+    assert_checkequal(prod(d, "*", typ(:)), 22860);
+    assert_checkequal(prod(d, 1, typ(:)), hypermat([1,2,2],[254;90;1;1]));
+    assert_checkequal(prod(d, 2, typ(:)), hypermat([2,1,2],[10;2286;1;1]));
+    assert_checkequal(prod(d, 3, typ(:)), [1,10;254,9]);
+    assert_checkequal(prod(d, 5, typ(:)), d);
 end
 
 //=======================================================================
@@ -47,58 +191,58 @@ end
 i=uint8([1 10;254 9]);
 T=list(list(),list('native'));
 for typ=T
-  if prod(i,typ(:))<>uint8(76) then pause,end
-  if prod(i,'*',typ(:))<>uint8(76) then pause,end
-  if or(prod(i,1,typ(:))<>uint8([254 90])) then pause,end
-  if or(prod(i,2,typ(:))<>uint8([10;238])) then pause,end
-  if or(prod(i,3,typ(:))<>i) then pause,end
+    assert_checkequal(prod(i, typ(:)), uint8(76));
+    assert_checkequal(prod(i, "*", typ(:)), uint8(76));
+    assert_checkequal(prod(i, 1, typ(:)), uint8([254 90]));
+    assert_checkequal(prod(i, 2, typ(:)), uint8([10;238]));
+    assert_checkequal(prod(i, 3, typ(:)), double(i));
 end
 
-if prod(i,'double')<>22860 then pause,end
-if prod(i,'*','double')<>22860 then pause,end
-if or(prod(i,1,'double')<>[254 90]) then pause,end
-if or(prod(i,2,'double')<>[10;2286]) then pause,end
-if or(prod(i,3,'double')<>double(i)) then pause,end
+assert_checkequal(prod(i, "double"), 22860);
+assert_checkequal(prod(i, "*", "double"), 22860);
+assert_checkequal(prod(i, 1, "double"), [254 90]);
+assert_checkequal(prod(i, 2, "double"), [10;2286]);
+assert_checkequal(prod(i, 3, "double"), double(i));
 
 //with hypermatrices
 i=uint8([1 10;254 9]);i(:,:,2)=uint8(1);
-for typ=list(list(),list('native'));
-  if prod(i,typ(:))<>uint8(76) then pause,end
-  if prod(i,'*',typ(:))<>uint8(76) then pause,end
-  if or(prod(i,1,typ(:))<>hypermat([1,2,2],uint8([254;90;1;1]))) then pause,end
-  if or(prod(i,2,typ(:))<>hypermat([2,1,2],uint8([10;238;1;1]))) then pause,end
-  if or(prod(i,3,typ(:))<>([1,10;254,9])) then pause,end
-  if or(prod(i,5,typ(:))<>i) then pause,end
+T = list(list(),list('native'));
+for typ=T
+    assert_checkequal(prod(i, typ(:)), uint8(76));
+    assert_checkequal(prod(i, "*", typ(:)), uint8(76));
+    assert_checkequal(prod(i, 1, typ(:)), hypermat([1,2,2],uint8([254;90;1;1])));
+    assert_checkequal(prod(i, 2, typ(:)), hypermat([2,1,2],uint8([10;238;1;1])));
+    assert_checkequal(prod(i, 3, typ(:)), uint8([1,10;254,9]));
+    assert_checkequal(prod(i, 5, typ(:)), double(i));
 end
 
-if prod(i,'double')<>22860 then pause,end
-if prod(i,'*','double')<>22860 then pause,end
-if or(prod(i,1,'double')<>hypermat([1,2,2],[254;90;1;1])) then pause,end
-if or(prod(i,2,'double')<>hypermat([2,1,2],[10;2286;1;1])) then pause,end
-if or(prod(i,3,'double')<>[1,10;254,9]) then pause,end
-if or(prod(i,5,'double')<>double(i)) then pause,end
-
+assert_checkequal(prod(i, "double"), 22860);
+assert_checkequal(prod(i, "*", "double"), 22860);
+assert_checkequal(prod(i, 1, "double"), hypermat([1,2,2],[254;90;1;1]));
+assert_checkequal(prod(i, 2, "double"), hypermat([2,1,2],[10;2286;1;1]));
+assert_checkequal(prod(i, 3, "double"), [1,10;254,9]);
+assert_checkequal(prod(i, 5, "double"), double(i));
 
 //Polynomials
 s=%s;p=[s s+1;s^2 1];
 T=list(list(),list('native'),list('double'));
 for typ=T
-  if prod(p,typ(:))<>s^3+s^4 then pause,end
-  if prod(p,'*',typ(:))<>s^3+s^4 then pause,end
-  if or(prod(p,1,typ(:))<>[s^3,1+s]) then pause,end
-  if or(prod(p,2,typ(:))<>[s+s^2;s^2]) then pause,end
-  if or(prod(p,3,typ(:))<>p) then pause,end
+    assert_checkequal(prod(p, typ(:)), s^3+s^4);
+    assert_checkequal(prod(p, "*", typ(:)), s^3+s^4);
+    assert_checkequal(prod(p, 1, typ(:)), [s^3,1+s]);
+    assert_checkequal(prod(p, 2, typ(:)), [s+s^2;s^2]);
+    assert_checkequal(prod(p, 3, typ(:)), p);
 end
 //with hypermatrices
 s=%s;p=[s s+1;s^2 1];p(:,:,2)=[1 s;s+1 2];
 T=list(list(),list('native'),list('double'));
 for typ=T
-  if prod(p,typ(:))<>2*s^4+4*s^5+2*s^6 then pause,end
-  if prod(p,'*',typ(:))<>2*s^4+4*s^5+2*s^6 then pause,end
-  if or(prod(p,1,typ(:))<>hypermat([1,2,2],[s^3;1+s;1+s;2*s])) then pause,end
-  if or(prod(p,2,typ(:))<>hypermat([2,1,2],[s+s^2;s^2;s;2+2*s])) then pause,end
-  if or(prod(p,3,typ(:))<>[s,s+s^2;s^2+s^3,2]) then pause,end
-  if or(prod(p,5,typ(:))<>p) then pause,end
+    assert_checkequal(prod(p, typ(:)), 2*s^4+4*s^5+2*s^6);
+    assert_checkequal(prod(p, "*", typ(:)), 2*s^4+4*s^5+2*s^6);
+    assert_checkequal(prod(p, 1, typ(:)), hypermat([1,2,2],[s^3;1+s;1+s;2*s]));
+    assert_checkequal(prod(p, 2, typ(:)), hypermat([2,1,2],[s+s^2;s^2;s;2+2*s]));
+    assert_checkequal(prod(p, 3, typ(:)), [s,s+s^2;s^2+s^3,2]);
+    assert_checkequal(prod(p, 5, typ(:)), p);
 end
 
 //=======================================================================
@@ -106,74 +250,78 @@ end
 s=%s;r=1.0 ./[s s+1;s^2 1];
 T=list(list(),list('native'),list('double'));
 for typ=T
-  if prod(r,typ(:))<>1.0/(s^3+s^4) then pause,end
-  if prod(r,'*',typ(:))<>1.0/(s^3+s^4) then pause,end
-  if or(prod(r,1,typ(:))<>[1,1]./[s^3,1+s]) then pause,end
-  if or(prod(r,2,typ(:))<>[1;1]./[s+s^2;s^2]) then pause,end
-  if or(prod(r,3,typ(:))<>r) then pause,end
+    assert_checkequal(prod(r, typ(:)), 1.0/(s^3+s^4));
+    assert_checkequal(prod(r, "*", typ(:)), 1.0/(s^3+s^4));
+    assert_checkequal(prod(r, 1, typ(:)), [1,1]./[s^3,1+s]);
+    assert_checkequal(prod(r, 2, typ(:)), [1;1]./[s+s^2;s^2]);
+    assert_checkequal(prod(r, 3, typ(:)), r);
 end
 
 //=======================================================================
 //Matrices of booleans
 b=[%t %t; %f %t];
-for typ=list(list(),list('double'));
-  if prod(b,typ(:))<>0 then pause,end
-  if prod(b,'*',typ(:))<>0 then pause,end
-  if or(prod(b,1,typ(:))<>[0 1]) then pause,end
-  if or(prod(b,2,typ(:))<>[1;0]) then pause,end
-  if or(prod(b,3,typ(:))<>double(b)) then pause,end
+T = list(list(),list('double'));
+for typ=T
+    assert_checkequal(prod(b, typ(:)), 0);
+    assert_checkequal(prod(b, "*", typ(:)), 0);
+    assert_checkequal(prod(b, 1, typ(:)), [0 1]);
+    assert_checkequal(prod(b, 2, typ(:)), [1;0]);
+    assert_checkequal(prod(b, 3, typ(:)), double(b));
 end
 
-if prod(b,'native')<>%f then pause,end
-if prod(b,'*','native')<>%f then pause,end
-if or(prod(b,1,'native')<>[%f %t]) then pause,end
-if or(prod(b,2,'native')<>[%t;%f]) then pause,end
-if or(prod(b,3,'native')<>b) then pause,end
-//with hypermatrices 
-  
+assert_checkequal(prod(b, "native"), %f);
+assert_checkequal(prod(b, "*", "native"), %f);
+assert_checkequal(prod(b, 1, "native"), [%f %t]);
+assert_checkequal(prod(b, 2, "native"), [%t;%f]);
+assert_checkequal(prod(b, 3, "native"), b);
+
+//with hypermatrices   
 b=[%t %t;%f %t];b(1,1,2)=%t;
-for typ=list(list(),list('double'));
-  if prod(b,typ(:))<>0 then pause,end
-  if prod(b,'*',typ(:))<>0 then pause,end
-  if or(prod(b,1,typ(:))<>hypermat([1,2,2],[0;1;0;0])) then pause,end
-  if or(prod(b,2,typ(:))<>hypermat([2,1,2],[1;0;0;0])) then pause,end
-  if or(prod(b,3,typ(:))<>[1,0;0,0]) then pause,end
-  if or(prod(b,5,typ(:))<>double(b)) then pause,end
+T = list(list(),list('double'));
+for typ=T
+    assert_checkequal(prod(b, typ(:)), 0);
+    assert_checkequal(prod(b, "*", typ(:)), 0);
+    assert_checkequal(prod(b, 1, typ(:)), hypermat([1,2,2],[0;1;0;0]));
+    assert_checkequal(prod(b, 2, typ(:)), hypermat([2,1,2],[1;0;0;0]));
+    assert_checkequal(prod(b, 3, typ(:)), [1,0;0,0]);
+    assert_checkequal(prod(b, 5, typ(:)), double(b));
 end
 
-if prod(b,'native')<>%f then pause,end
-if prod(b,'*','native')<>%f then pause,end
-if or(prod(b,1,'native')<>hypermat([1,2,2],[%f;%t;%f;%f])) then pause,end
-if or(prod(b,2,'native')<>hypermat([2,1,2],[%t;%f;%f;%f])) then pause,end
-if or(prod(b,3,'native')<>[%t,%f;%f,%f]) then pause,end
-if or(prod(b,5,'native')<>b) then pause,end
+assert_checkequal(prod(b, "native"), %f);
+assert_checkequal(prod(b, "*", "native"), %f);
+assert_checkequal(prod(b, 1, "native"), hypermat([1,2,2],[%f;%t;%f;%f]));
+assert_checkequal(prod(b, 2, "native"), hypermat([2,1,2],[%t;%f;%f;%f]));
+assert_checkequal(prod(b, 3, "native"), [%t,%f;%f,%f]);
+assert_checkequal(prod(b, 5, "native"), b);
+
 //=======================================================================
 //sparse matrices of floats
 s=sparse([1 10 2;-1 254 9]);
 T=list(list(),list('native'),list('double'));
 for typ=T
-  if prod(s,typ(:))<>-45720 then pause,end
-  if prod(s,'*',typ(:))<>-45720 then pause,end
-  if or(prod(s,1,typ(:))<>sparse([-1 2540 18])) then pause,end
-  if or(prod(s,2,typ(:))<>sparse([20;-2286])) then pause,end
-  if or(prod(s,3,typ(:))<>s) then pause,end
+    assert_checkequal(prod(s, typ(:)), -45720);
+    assert_checkequal(prod(s, "*", typ(:)), -45720);
+    assert_checkequal(prod(s, 1, typ(:)), sparse([-1 2540 18]));
+    assert_checkequal(prod(s, 2, typ(:)), sparse([20;-2286]));
+    assert_checkequal(prod(s, 3, typ(:)), s);
 end
 
 //=======================================================================
 //sparse  matrices of boolean
 bs=sparse([%t %t %f;%t %t %t]);
-for typ=list(list(),list('double'));
-  if prod(bs,typ(:))<>0 then pause,end
-  if prod(bs,'*',typ(:))<>0 then pause,end
-  if or(prod(bs,1,typ(:))<>sparse([1,1,0])) then pause,end
-  if or(prod(bs,2,typ(:))<>sparse([0;1])) then pause,end
-  if or(prod(bs,3,typ(:))<>bool2s(bs)) then pause,end
+T = list(list(),list('double'));
+for typ=T
+    assert_checkequal(prod(bs, typ(:)), 0);
+    assert_checkequal(prod(bs, "*", typ(:)), 0);
+    assert_checkequal(prod(bs, 1, typ(:)), sparse([1,1,0]));
+    assert_checkequal(prod(bs, 2, typ(:)), sparse([0;1]));
+    assert_checkequal(prod(bs, 3, typ(:)), bool2s(bs));
 end
 
-if prod(bs,'native')<>%f then pause,end
-if prod(bs,'*','native')<>%f then pause,end
-if or(prod(bs,1,'native')<>sparse([%t,%t,%f])) then pause,end
-if or(prod(bs,2,'native')<>sparse([%f;%t])) then pause,end
-if or(prod(bs,3,'native')<>bs) then pause,end
+assert_checkequal(prod(bs, "native"), %f);
+assert_checkequal(prod(bs, "*", "native"), %f);
+assert_checkequal(prod(bs, 1, "native"), sparse([%t,%t,%f]));
+assert_checkequal(prod(bs, 2, "native"), sparse([%f;%t]));
+assert_checkequal(prod(bs, 3, "native"), bs);
 
 // TODO : test the "m" option
index 3fde4c0..95f2b76 100644 (file)
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2010 - INRIA - Serge Steer
+// Copyright (C) 2013 - Scilab Enterprises - Adeline CARNIS
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
 // <-- CLI SHELL MODE -->
+// Check error
+d=[1 10;254 9];
+assert_checkfalse(execstr("sum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("sum(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("sum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 2);
+assert_checkerror("sum(d, [""r"", ""c""])", refMsg);
+assert_checkfalse(execstr("sum(d, ""e"", ""double"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("sum(d, ""e"", ""double"")", refMsg);
+assert_checkfalse(execstr("sum(d, -1.5, ""double"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("sum(d, -1.5, ""double"")", refMsg);
+//==============================================================================
+// matrices of integer
+i = uint8(d);
+assert_checkfalse(execstr("sum(i, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("sum(i, ""orient"")", refMsg);
+assert_checkfalse(execstr("sum(i, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 2);
+assert_checkerror("sum(i, [""r"", ""c""])", refMsg);
+assert_checkfalse(execstr("sum(i,""r"", ""nat"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong value for argument #%d.\n"), 3);
+assert_checkerror("sum(i,""r"", ""nat"")", refMsg);
+assert_checkfalse(execstr("sum(i,""r"", [""nat"" ""dble""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 3);
+assert_checkerror("sum(i,""r"", [""nat"" ""dble""])", refMsg);
+assert_checkfalse(execstr("sum(i,""orient"", ""t"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("sum(i,""orient"", ""t"")", refMsg);
+assert_checkfalse(execstr("sum(i,1,1)"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong type for argument #%d: String expected.\n"), 3);
+assert_checkerror("sum(i,1,1)", refMsg);
+//==============================================================================
+// sparse matrices
+d = sparse(d);
+assert_checkfalse(execstr("sum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("sum(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("sum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 2);
+assert_checkerror("sum(d, [""r"", ""c""])", refMsg);
+//==============================================================================
+// boolean matrices
+d = [%f %t;%t %f];
+assert_checkfalse(execstr("sum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),"sum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("sum(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("sum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",2);
+assert_checkerror("sum(d, [""r"", ""c""])", refMsg);
+assert_checkfalse(execstr("sum(d,""r"", ""nat"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"sum", 3, "native", "double");
+assert_checkerror("sum(d,""r"", ""nat"")", refMsg);
+assert_checkfalse(execstr("sum(d,""r"", [""nat"" ""dble""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",3);
+assert_checkerror("sum(d,""r"", [""nat"" ""dble""])", refMsg);
+assert_checkfalse(execstr("sum(d,""orient"", ""t"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+"sum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("sum(d,""orient"", ""t"")", refMsg);
+assert_checkfalse(execstr("sum(d,1,1)"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"), "sum", 3);
+assert_checkerror("sum(d,1,1)", refMsg);
+//==============================================================================
+// sparse boolean matrices
+d = sparse(d);
+assert_checkfalse(execstr("sum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+"sum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("sum(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("sum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",2);
+assert_checkerror("sum(d, [""r"", ""c""])", refMsg);
+assert_checkfalse(execstr("sum(d,""r"", ""nat"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"sum", 3, "native", "double");
+assert_checkerror("sum(d,""r"", ""nat"")", refMsg);
+assert_checkfalse(execstr("sum(d,""r"", [""nat"" ""dble""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",3);
+assert_checkerror("sum(d,""r"", [""nat"" ""dble""])", refMsg);
+assert_checkfalse(execstr("sum(d,""orient"", ""t"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+"sum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("sum(d,""orient"", ""t"")", refMsg);
+assert_checkfalse(execstr("sum(d,1,1)"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"sum",3);
+assert_checkerror("sum(d,1,1)", refMsg);
+//==============================================================================
+// hypermatrices
+d = rand(2,2,2);
+assert_checkfalse(execstr("sum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+"sum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("sum(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("sum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",2);
+assert_checkerror("sum(d, [""r"", ""c""])", refMsg);
+//==============================================================================
+// polynome
+s = poly(0, "s");
+d = [s s^2;s*%i 1];
+assert_checkfalse(execstr("sum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+"sum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("sum(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("sum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",2);
+assert_checkerror("sum(d, [""r"", ""c""])", refMsg);
+//==============================================================================
+// rational matrices
+s = poly(0, "s");
+d = [1/s 1/s^2; 1/s 1];
+assert_checkfalse(execstr("sum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+"sum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("sum(d, ""orient"")", refMsg);
+assert_checkfalse(execstr("sum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",2);
+assert_checkerror("sum(d, [""r"", ""c""])", refMsg);
 //empty matrices
 T=list(list(),list('native'),list('double'));
 for typ=T
-  if sum([],typ(:))<>0 then bugmes();quit;end
-  if sum([],'*',typ(:))<>0 then bugmes();quit;end
-  if sum([],1,typ(:))<>[] then bugmes();quit;end
-  if sum([],2,typ(:))<>[] then bugmes();quit;end
-  if sum([],3,typ(:))<>[] then bugmes();quit;end
+    assert_checkequal(sum([], typ(:)), 0);
+    assert_checkequal(sum([], "*", typ(:)), 0);
+    assert_checkequal(sum([], 1, typ(:)), []);
+    assert_checkequal(sum([], 2, typ(:)), []);
+    assert_checkequal(sum([], 3, typ(:)), []);
 end
 //=======================================================================
 //float matrices
 d=[1 10;254 9];
 T=list(list(),list('native'),list('double'));
 for typ=T
-  if sum(d,typ(:))<>274 then bugmes();quit;end
-  if sum(d,'*',typ(:))<>274 then bugmes();quit;end
-  if or(sum(d,1,typ(:))<>[255 19]) then bugmes();quit;end
-  if or(sum(d,2,typ(:))<>[11;263]) then bugmes();quit;end
-  if or(sum(d,3,typ(:))<>d) then bugmes();quit;end
+    assert_checkequal(sum(d, typ(:)), 274);
+    assert_checkequal(sum(d, "*", typ(:)), 274);
+    assert_checkequal(sum(d, 1, typ(:)), [255 19]);
+    assert_checkequal(sum(d, 2, typ(:)), [11; 263]);
+    assert_checkequal(sum(d, 3, typ(:)), d);
 end
 //hypermatrices of floats
 d(1,1,2)=1;
 for typ=T
-  if sum(d,typ(:))<>275 then bugmes();quit;end
-  if sum(d,'*',typ(:))<>275 then bugmes();quit;end
-  if or(sum(d,1,typ(:))<>hypermat([1,2,2],[255;19;1;0])) then bugmes();quit;end
-  if or(sum(d,2,typ(:))<>hypermat([2,1,2],[11;263;1;0])) then bugmes();quit;end
-  if or(sum(d,3,typ(:))<>[2,10;254,9]) then bugmes();quit;end
-  if or(sum(d,5,typ(:))<>d) then bugmes();quit;end
+    assert_checkequal(sum(d, typ(:)), 275);
+    assert_checkequal(sum(d, "*", typ(:)), 275);
+    assert_checkequal(sum(d, 1, typ(:)), hypermat([1,2,2],[255;19;1;0]));
+    assert_checkequal(sum(d, 2, typ(:)), hypermat([2,1,2],[11;263;1;0]));
+    assert_checkequal(sum(d, 3, typ(:)), [2,10;254,9]);
+    assert_checkequal(sum(d, 5, typ(:)), d);
 end
 //=======================================================================
 //matrices of short integers
 // Caution : uint8([11;263]) is equal to uint8([11;7])
 i=uint8([1 10;254 9]);
-for typ=list(list(),list('native'));
-  if sum(i,typ(:))<>uint8(274) then bugmes();quit;end
-  if sum(i,'*',typ(:))<>uint8(274) then bugmes();quit;end
-  if or(sum(i,1,typ(:))<>uint8([255 19])) then bugmes();quit;end
-  if or(sum(i,2,typ(:))<>uint8([11;263])) then bugmes();quit;end
-  if or(sum(i,3,typ(:))<>i) then bugmes();quit;end
+T = list(list(),list('native'));
+for typ=T
+    assert_checkequal(sum(i, typ(:)), uint8(274));
+    assert_checkequal(sum(i, "*", typ(:)), uint8(274));
+    assert_checkequal(sum(i, 1, typ(:)), uint8([255 19]));
+    assert_checkequal(sum(i, 2, typ(:)), uint8([11;263]));
+    assert_checkequal(sum(i, 3, typ(:)), double(i));
 end
-if sum(i,'double')<>274 then bugmes();quit;end
-if sum(i,'*','double')<>274 then bugmes();quit;end
-if or(sum(i,1,'double')<>[255 19]) then bugmes();quit;end
-if or(sum(i,2,'double')<>[11;263]) then bugmes();quit;end
-if or(sum(i,3,'double')<>double(i)) then bugmes();quit;end
+assert_checkequal(sum(i, "double"), 274);
+assert_checkequal(sum(i, "*", "double"), 274);
+assert_checkequal(sum(i, 1, "double"), [255 19]);
+assert_checkequal(sum(i, 2, "double"), [11; 263]);
+assert_checkequal(sum(i, 3, "double"), double(i));
 //with hypermatrices
 i(1,1,2)=uint8(1);
-for typ=list(list(),list('native'));
-  if sum(i,typ(:))<>uint8(275) then bugmes();quit;end
-  if sum(i,'*',typ(:))<>uint8(275) then bugmes();quit;end
-  if or(sum(i,1,typ(:))<>hypermat([1,2,2],uint8([255;19;1;0]))) then bugmes();quit;end
-  if or(sum(i,2,typ(:))<> hypermat([2,1,2],uint8([11;263;1;0]))) then bugmes();quit;end
-  if or(sum(i,3,typ(:))<> uint8([2,10;254,9])) then bugmes();quit;end
-  if or(sum(i,5,typ(:))<> i) then bugmes();quit;end
+T = list(list(),list('native'));
+for typ=T
+    assert_checkequal(sum(i, typ(:)), uint8(275));
+    assert_checkequal(sum(i, "*", typ(:)), uint8(275));
+    assert_checkequal(sum(i, 1, typ(:)), hypermat([1,2,2],uint8([255;19;1;0])));
+    assert_checkequal(sum(i, 2, typ(:)), hypermat([2,1,2],uint8([11;263;1;0])));
+    assert_checkequal(sum(i, 3, typ(:)), uint8([2,10;254,9]));
+    assert_checkequal(sum(i, 5, typ(:)), i);
 end
-if sum(i,'double')<>275 then bugmes();quit;end
-if sum(i,'*','double')<>275 then bugmes();quit;end
-if or(sum(i,1,'double')<>hypermat([1,2,2],[255;19;1;0])) then bugmes();quit;end
-if or(sum(i,2,'double')<> hypermat([2,1,2],[11;263;1;0])) then bugmes();quit;end
-if or(sum(i,3,'double')<>[2,10;254,9]) then bugmes();quit;end
+assert_checkequal(sum(i, "double"), 275);
+assert_checkequal(sum(i, "*", "double"), 275);
+assert_checkequal(sum(i, 1, "double"), hypermat([1,2,2],[255;19;1;0]));
+assert_checkequal(sum(i, 2, "double"), hypermat([2,1,2],[11;263;1;0]));
+assert_checkequal(sum(i, 3, "double"), [2,10;254,9]);
 //=======================================================================
 //Matrices of polynomials
 s=%s;
 p=[s s+1;s^2 0];
 T=list(list(),list('native'),list('double'));
 for typ=T
-  if sum(p,typ(:))<>1+2*s+s^2 then bugmes();quit;end
-  if sum(p,'*',typ(:))<>1+2*s+s^2 then bugmes();quit;end
-  if or(sum(p,1,typ(:))<>[s+s^2,1+s]) then bugmes();quit;end
-  if or(sum(p,2,typ(:))<>[1+2*s;s^2]) then bugmes();quit;end
-  if or(sum(p,3,typ(:))<>p) then bugmes();quit;end
+    assert_checkequal(sum(p, typ(:)), 1+2*s+s^2);
+    assert_checkequal(sum(p, "*", typ(:)), 1+2*s+s^2);
+    assert_checkequal(sum(p, 1, typ(:)), [s + s^2, 1 + s]);
+    assert_checkequal(sum(p, 2, typ(:)), [1+2*s;s^2]);
+    assert_checkequal(sum(p, 3, typ(:)), p);
 end
 //with hypermatrices
 p(1,1,2)=-1;
 for typ=T
-  if sum(p,typ(:))<>2*s+s^2 then bugmes();quit;end
-  if sum(p,'*',typ(:))<>2*s+s^2 then bugmes();quit;end
-  if or(sum(p,1,typ(:))<>hypermat([1,2,2],[s+s^2;1+s;-1;0*s])) then bugmes();quit;end
-  if or(sum(p,2,typ(:))<>hypermat([2,1,2],[1+2*s;s^2;-1;0*s])) then bugmes();quit;end
-  if or(sum(p,3,typ(:))<>[-1+s,1+s;s^2,0]) then bugmes();quit;end
-  if or(sum(p,5,typ(:))<>p) then bugmes();quit;end
+    assert_checkequal(sum(p, typ(:)), 2*s+s^2);
+    assert_checkequal(sum(p, "*", typ(:)), 2*s+s^2);
+    assert_checkequal(sum(p, 1, typ(:)), hypermat([1,2,2],[s+s^2;1+s;-1;0*s]));
+    assert_checkequal(sum(p, 2, typ(:)), hypermat([2,1,2],[1+2*s;s^2;-1;0*s]));
+    assert_checkequal(sum(p, 3, typ(:)), [-1+s,1+s;s^2,0]);
+    assert_checkequal(sum(p, 5, typ(:)), p);
 end
 //=======================================================================
 //Matrices of rationals
@@ -94,67 +218,70 @@ s=%s;
 r=1.0 ./[s s+1;s^2 1];
 T=list(list(),list('native'),list('double'));
 for typ=T
-  if sum(r,typ(:))<>(1+2*s+3*s^2+s^3)./(s^2+s^3) then bugmes();quit;end
-  if sum(r,'*',typ(:))<>(1+2*s+3*s^2+s^3)./(s^2+s^3) then bugmes();quit;end
-  if or(sum(r,1,typ(:))<>[1+s,2+s]./[s^2,1+s]) then bugmes();quit;end
-  if or(sum(r,2,typ(:))<>[1+2*s;1+s^2]./[s+s^2;s^2]) then bugmes();quit;end
-  if or(sum(r,3,typ(:))<>r) then bugmes();quit;end
+    assert_checkequal(sum(r, typ(:)), (1+2*s+3*s^2+s^3)./(s^2+s^3));
+    assert_checkequal(sum(r, "*", typ(:)), (1+2*s+3*s^2+s^3)./(s^2+s^3));
+    assert_checkequal(sum(r, 1, typ(:)), [1+s,2+s]./[s^2,1+s]);
+    assert_checkequal(sum(r, 2, typ(:)), [1+2*s;1+s^2]./[s+s^2;s^2]);
+    assert_checkequal(sum(r, 3, typ(:)), r);
 end
 //=======================================================================
 ///Matrices of boolean
 b=[%t %t %f %t];
-for typ=list(list(),list('double'));
-  if sum(b,typ(:))<>3 then bugmes();quit;end
-  if sum(b,'*',typ(:))<>3 then bugmes();quit;end
-  if or(sum(b,1,typ(:))<>[1 1 0 1]) then bugmes();quit;end
-  if or(sum(b,2,typ(:))<>3) then bugmes();quit;end
-  if or(sum(b,3,typ(:))<>double(b)) then bugmes();quit;end
+T = list(list(),list('double'));
+for typ=T
+    assert_checkequal(sum(b, typ(:)), 3);
+    assert_checkequal(sum(b, "*", typ(:)), 3);
+    assert_checkequal(sum(b, 1, typ(:)), [1 1 0 1]);
+    assert_checkequal(sum(b, 2, typ(:)), 3);
+    assert_checkequal(sum(b, 3, typ(:)), double(b));
 end
-if sum(b,'native')<>%t then bugmes();quit;end
-if sum(b,'*','native')<>%t then bugmes();quit;end
-if or(sum(b,1,'native')<>b) then bugmes();quit;end
-if or(sum(b,2,'native')<>%t) then bugmes();quit;end
-if or(sum(b,3,'native')<>b) then bugmes();quit;end
+assert_checkequal(sum(b, "native"), %t);
+assert_checkequal(sum(b, "*", "native"), %t);
+assert_checkequal(sum(b, 1, "native"), b);
+assert_checkequal(sum(b, 2, "native"), %t);
+assert_checkequal(sum(b, 3, "native"), b);
 //with hypermatrices 
 b=[%t %t %f %t];b(1,1,2)=%f;
-for typ=list(list(),list('double'));
-  if sum(b,typ(:))<>3 then bugmes();quit;end
-  if sum(b,'*',typ(:))<>3 then bugmes();quit;end
-  if or(sum(b,1,typ(:))<>hypermat([1,4,2],[1;1;0;1;0;0;0;0])) then bugmes();quit;end
-  if or(sum(b,2,typ(:))<>hypermat([1,1,2],[3;0])) then bugmes();quit;end
-  if or(sum(b,3,typ(:))<>[1 1 0 1]) then bugmes();quit;end
-  if or(sum(b,5,typ(:))<>double(b)) then bugmes();quit;end
+T = list(list(),list('double'));
+for typ=T
+    assert_checkequal(sum(b, typ(:)), 3);
+    assert_checkequal(sum(b, "*", typ(:)), 3);
+    assert_checkequal(sum(b, 1, typ(:)), hypermat([1,4,2],[1;1;0;1;0;0;0;0]));
+    assert_checkequal(sum(b, 2, typ(:)), hypermat([1,1,2],[3;0]));
+    assert_checkequal(sum(b, 3, typ(:)), [1 1 0 1]);
+    assert_checkequal(sum(b, 5, typ(:)), double(b));
 end
-if sum(b,'native')<>%t then bugmes();quit;end
-if sum(b,'*','native')<>%t then bugmes();quit;end
-if or(sum(b,1,'native')<>hypermat([1,4,2],[%t;%t;%f;%t;%f;%f;%f;%f])) then bugmes();quit;end
-if or(sum(b,2,'native')<>hypermat([1,1,2],[%t;%f])) then bugmes();quit;end
-if or(sum(b,3,'native')<>[%t %t %f %t]) then bugmes();quit;end
-if or(sum(b,5,'native')<>b) then bugmes();quit;end
+assert_checkequal(sum(b, "native"), %t);
+assert_checkequal(sum(b, "*", "native"), %t);
+assert_checkequal(sum(b, 1, "native"), hypermat([1,4,2],[%t;%t;%f;%t;%f;%f;%f;%f]));
+assert_checkequal(sum(b, 2, "native"), hypermat([1,1,2],[%t;%f]));
+assert_checkequal(sum(b, 3, "native"), [%t %t %f %t]);
+assert_checkequal(sum(b, 5, "native"), b);
 //=======================================================================
 //sparse matrices of floats
 s=sparse([1 10 0;0 254 9]);
 T=list(list(),list('native'),list('double'));
 for typ=T
-  if sum(s,typ(:))<>274 then bugmes();quit;end
-  if sum(s,'*',typ(:))<>274 then bugmes();quit;end
-  if or(sum(s,1,typ(:))<>sparse([1,264,9])) then bugmes();quit;end
-  if or(sum(s,2,typ(:))<>sparse([11;263])) then bugmes();quit;end
-  if or(sum(s,3,typ(:))<>s) then bugmes();quit;end
+    assert_checkequal(sum(s, typ(:)), 274);
+    assert_checkequal(sum(s, "*", typ(:)), 274);
+    assert_checkequal(sum(s, 1, typ(:)), sparse([1,264,9]));
+    assert_checkequal(sum(s, 2, typ(:)), sparse([11;263]));
+    assert_checkequal(sum(s, 3, typ(:)), s);
 end
 //=======================================================================
 //sparse  matrices of boolean
 bs=sparse([1 10 0;0 254 9])<>0;
-for typ=list(list(),list('double'));
-  if sum(bs,typ(:))<>4 then bugmes();quit;end
-  if sum(bs,'*',typ(:))<>4 then bugmes();quit;end
-  if or(sum(bs,1,typ(:))<>sparse([1,2,1])) then bugmes();quit;end
-  if or(sum(bs,2,typ(:))<>sparse([2;2])) then bugmes();quit;end
-  if or(sum(bs,3,typ(:))<>bool2s(bs)) then bugmes();quit;end
+T = list(list(),list('double'));
+for typ=T
+    assert_checkequal(sum(bs, typ(:)), 4);
+    assert_checkequal(sum(bs, "*", typ(:)), 4);
+    assert_checkequal(sum(bs, 1, typ(:)), sparse([1,2,1]));
+    assert_checkequal(sum(bs, 2, typ(:)), sparse([2;2]));
+    assert_checkequal(sum(bs, 3, typ(:)), bool2s(bs));
 end
-if sum(bs,'native')<>%t then bugmes();quit;end
-if sum(bs,'*','native')<>%t then bugmes();quit;end
-if or(sum(bs,1,'native')<>sparse([%t,%t,%t])) then bugmes();quit;end
-if or(sum(bs,2,'native')<>sparse([%t;%t])) then bugmes();quit;end
-if or(sum(bs,3,'native')<>bs) then bugmes();quit;end
+assert_checkequal(sum(bs, "native"), %t);
+assert_checkequal(sum(bs, "*", "native"), %t);
+assert_checkequal(sum(bs, 1, "native"), sparse([%t,%t,%t]));
+assert_checkequal(sum(bs, 2, "native"), sparse([%t;%t]));
+assert_checkequal(sum(bs, 3, "native"),bs);
 // TODO : test the "m" option
index a567b22..42bac2c 100644 (file)
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2010 - INRIA - Serge Steer
+// Copyright (C) 2013 - Scilab Enterprises - Adeline CARNIS
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
 
 // <-- CLI SHELL MODE -->
+// Check error
+d=[1 10;254 9];
+assert_checkfalse(execstr("sum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("sum(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("sum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 2);
+assert_checkerror("sum(d, [""r"", ""c""])", refMsg);
+
+assert_checkfalse(execstr("sum(d, ""e"", ""double"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("sum(d, ""e"", ""double"")", refMsg);
+
+assert_checkfalse(execstr("sum(d, -1.5, ""double"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("sum(d, -1.5, ""double"")", refMsg);
+
+//==============================================================================
+// matrices of integer
+i = uint8(d);
+assert_checkfalse(execstr("sum(i, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("sum(i, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("sum(i, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 2);
+assert_checkerror("sum(i, [""r"", ""c""])", refMsg);
+
+assert_checkfalse(execstr("sum(i,""r"", ""nat"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong value for argument #%d.\n"), 3);
+assert_checkerror("sum(i,""r"", ""nat"")", refMsg);
+
+assert_checkfalse(execstr("sum(i,""r"", [""nat"" ""dble""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 3);
+assert_checkerror("sum(i,""r"", [""nat"" ""dble""])", refMsg);
+
+assert_checkfalse(execstr("sum(i,""orient"", ""t"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("sum(i,""orient"", ""t"")", refMsg);
+
+assert_checkfalse(execstr("sum(i,1,1)"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong type for argument #%d: String expected.\n"), 3);
+assert_checkerror("sum(i,1,1)", refMsg);
+
+//==============================================================================
+// sparse matrices
+d = sparse(d);
+assert_checkfalse(execstr("sum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong argument #%d.\n"), 2);
+assert_checkerror("sum(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("sum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("Wrong size for argument #%d.\n"), 2);
+assert_checkerror("sum(d, [""r"", ""c""])", refMsg);
+
+//==============================================================================
+// boolean matrices
+d = [%f %t;%t %f];
+assert_checkfalse(execstr("sum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),"sum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("sum(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("sum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",2);
+assert_checkerror("sum(d, [""r"", ""c""])", refMsg);
+
+assert_checkfalse(execstr("sum(d,""r"", ""nat"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"sum", 3, "native", "double");
+assert_checkerror("sum(d,""r"", ""nat"")", refMsg);
+
+assert_checkfalse(execstr("sum(d,""r"", [""nat"" ""dble""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",3);
+assert_checkerror("sum(d,""r"", [""nat"" ""dble""])", refMsg);
+
+assert_checkfalse(execstr("sum(d,""orient"", ""t"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+"sum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("sum(d,""orient"", ""t"")", refMsg);
+
+assert_checkfalse(execstr("sum(d,1,1)"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"), "sum", 3);
+assert_checkerror("sum(d,1,1)", refMsg);
+
+//==============================================================================
+// sparse boolean matrices
+d = sparse(d);
+assert_checkfalse(execstr("sum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+"sum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("sum(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("sum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",2);
+assert_checkerror("sum(d, [""r"", ""c""])", refMsg);
+
+assert_checkfalse(execstr("sum(d,""r"", ""nat"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"sum", 3, "native", "double");
+assert_checkerror("sum(d,""r"", ""nat"")", refMsg);
+
+assert_checkfalse(execstr("sum(d,""r"", [""nat"" ""dble""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",3);
+assert_checkerror("sum(d,""r"", [""nat"" ""dble""])", refMsg);
+
+assert_checkfalse(execstr("sum(d,""orient"", ""t"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+"sum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("sum(d,""orient"", ""t"")", refMsg);
+
+assert_checkfalse(execstr("sum(d,1,1)"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"sum",3);
+assert_checkerror("sum(d,1,1)", refMsg);
+
+//==============================================================================
+// hypermatrices
+d = rand(2,2,2);
+assert_checkfalse(execstr("sum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+"sum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("sum(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("sum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",2);
+assert_checkerror("sum(d, [""r"", ""c""])", refMsg);
+
+//==============================================================================
+// polynome
+s = poly(0, "s");
+d = [s s^2;s*%i 1];
+assert_checkfalse(execstr("sum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+"sum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("sum(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("sum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",2);
+assert_checkerror("sum(d, [""r"", ""c""])", refMsg);
+
+//==============================================================================
+// rational matrices
+s = poly(0, "s");
+d = [1/s 1/s^2; 1/s 1];
+assert_checkfalse(execstr("sum(d, ""orient"")"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+"sum",2,"""*"",""r"",""c"",""m""");
+assert_checkerror("sum(d, ""orient"")", refMsg);
+
+assert_checkfalse(execstr("sum(d, [""r"", ""c""])"   ,"errcatch") == 0);
+refMsg = msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",2);
+assert_checkerror("sum(d, [""r"", ""c""])", refMsg);
+
 //empty matrices
 T=list(list(),list('native'),list('double'));
 for typ=T
-  if sum([],typ(:))<>0 then pause,end
-  if sum([],'*',typ(:))<>0 then pause,end
-  if sum([],1,typ(:))<>[] then pause,end
-  if sum([],2,typ(:))<>[] then pause,end
-  if sum([],3,typ(:))<>[] then pause,end
+    assert_checkequal(sum([], typ(:)), 0);
+    assert_checkequal(sum([], "*", typ(:)), 0);
+
+    assert_checkequal(sum([], 1, typ(:)), []);
+    assert_checkequal(sum([], 2, typ(:)), []);
+    assert_checkequal(sum([], 3, typ(:)), []);
 end
 //=======================================================================
 //float matrices
 d=[1 10;254 9];
 T=list(list(),list('native'),list('double'));
 for typ=T
-  if sum(d,typ(:))<>274 then pause,end
-  if sum(d,'*',typ(:))<>274 then pause,end
-  if or(sum(d,1,typ(:))<>[255 19]) then pause,end
-  if or(sum(d,2,typ(:))<>[11;263]) then pause,end
-  if or(sum(d,3,typ(:))<>d) then pause,end
+    assert_checkequal(sum(d, typ(:)), 274);
+    assert_checkequal(sum(d, "*", typ(:)), 274);
+    assert_checkequal(sum(d, 1, typ(:)), [255 19]);
+    assert_checkequal(sum(d, 2, typ(:)), [11; 263]);
+    assert_checkequal(sum(d, 3, typ(:)), d);
 end
 
 //hypermatrices of floats
 d(1,1,2)=1;
 for typ=T
-  if sum(d,typ(:))<>275 then pause,end
-  if sum(d,'*',typ(:))<>275 then pause,end
-  if or(sum(d,1,typ(:))<>hypermat([1,2,2],[255;19;1;0])) then pause,end
-  if or(sum(d,2,typ(:))<>hypermat([2,1,2],[11;263;1;0])) then pause,end
-  if or(sum(d,3,typ(:))<>[2,10;254,9]) then pause,end
-  if or(sum(d,5,typ(:))<>d) then pause,end
+    assert_checkequal(sum(d, typ(:)), 275);
+    assert_checkequal(sum(d, "*", typ(:)), 275);
+    assert_checkequal(sum(d, 1, typ(:)), hypermat([1,2,2],[255;19;1;0]));
+    assert_checkequal(sum(d, 2, typ(:)), hypermat([2,1,2],[11;263;1;0]));
+    assert_checkequal(sum(d, 3, typ(:)), [2,10;254,9]);
+    assert_checkequal(sum(d, 5, typ(:)), d);
 end
 
 //=======================================================================
 //matrices of short integers
 // Caution : uint8([11;263]) is equal to uint8([11;7])
 i=uint8([1 10;254 9]);
-for typ=list(list(),list('native'));
-  if sum(i,typ(:))<>uint8(274) then pause,end
-  if sum(i,'*',typ(:))<>uint8(274) then pause,end
-  if or(sum(i,1,typ(:))<>uint8([255 19])) then pause,end
-  if or(sum(i,2,typ(:))<>uint8([11;263])) then pause,end
-  if or(sum(i,3,typ(:))<>i) then pause,end
+T = list(list(),list('native'));
+for typ=T
+    assert_checkequal(sum(i, typ(:)), uint8(274));
+    assert_checkequal(sum(i, "*", typ(:)), uint8(274));
+    assert_checkequal(sum(i, 1, typ(:)), uint8([255 19]));
+    assert_checkequal(sum(i, 2, typ(:)), uint8([11;263]));
+    assert_checkequal(sum(i, 3, typ(:)), double(i));
 end
 
-if sum(i,'double')<>274 then pause,end
-if sum(i,'*','double')<>274 then pause,end
-if or(sum(i,1,'double')<>[255 19]) then pause,end
-if or(sum(i,2,'double')<>[11;263]) then pause,end
-if or(sum(i,3,'double')<>double(i)) then pause,end
+assert_checkequal(sum(i, "double"), 274);
+assert_checkequal(sum(i, "*", "double"), 274);
+assert_checkequal(sum(i, 1, "double"), [255 19]);
+assert_checkequal(sum(i, 2, "double"), [11; 263]);
+assert_checkequal(sum(i, 3, "double"), double(i));
 
 //with hypermatrices
 i(1,1,2)=uint8(1);
-for typ=list(list(),list('native'));
-  if sum(i,typ(:))<>uint8(275) then pause,end
-  if sum(i,'*',typ(:))<>uint8(275) then pause,end
-  if or(sum(i,1,typ(:))<>hypermat([1,2,2],uint8([255;19;1;0]))) then pause,end
-  if or(sum(i,2,typ(:))<> hypermat([2,1,2],uint8([11;263;1;0]))) then pause,end
-  if or(sum(i,3,typ(:))<> uint8([2,10;254,9])) then pause,end
-  if or(sum(i,5,typ(:))<> i) then pause,end
+T = list(list(),list('native'));
+for typ=T
+    assert_checkequal(sum(i, typ(:)), uint8(275));
+    assert_checkequal(sum(i, "*", typ(:)), uint8(275));
+    assert_checkequal(sum(i, 1, typ(:)), hypermat([1,2,2],uint8([255;19;1;0])));
+    assert_checkequal(sum(i, 2, typ(:)), hypermat([2,1,2],uint8([11;263;1;0])));
+    assert_checkequal(sum(i, 3, typ(:)), uint8([2,10;254,9]));
+    assert_checkequal(sum(i, 5, typ(:)), i);
 end
 
-if sum(i,'double')<>275 then pause,end
-if sum(i,'*','double')<>275 then pause,end
-if or(sum(i,1,'double')<>hypermat([1,2,2],[255;19;1;0])) then pause,end
-if or(sum(i,2,'double')<> hypermat([2,1,2],[11;263;1;0])) then pause,end
-if or(sum(i,3,'double')<>[2,10;254,9]) then pause,end
+assert_checkequal(sum(i, "double"), 275);
+assert_checkequal(sum(i, "*", "double"), 275);
+assert_checkequal(sum(i, 1, "double"), hypermat([1,2,2],[255;19;1;0]));
+assert_checkequal(sum(i, 2, "double"), hypermat([2,1,2],[11;263;1;0]));
+assert_checkequal(sum(i, 3, "double"), [2,10;254,9]);
 
 //=======================================================================
 //Matrices of polynomials
@@ -79,22 +234,22 @@ s=%s;
 p=[s s+1;s^2 0];
 T=list(list(),list('native'),list('double'));
 for typ=T
-  if sum(p,typ(:))<>1+2*s+s^2 then pause,end
-  if sum(p,'*',typ(:))<>1+2*s+s^2 then pause,end
-  if or(sum(p,1,typ(:))<>[s+s^2,1+s]) then pause,end
-  if or(sum(p,2,typ(:))<>[1+2*s;s^2]) then pause,end
-  if or(sum(p,3,typ(:))<>p) then pause,end
+    assert_checkequal(sum(p, typ(:)), 1+2*s+s^2);
+    assert_checkequal(sum(p, "*", typ(:)), 1+2*s+s^2);
+    assert_checkequal(sum(p, 1, typ(:)), [s + s^2, 1 + s]);
+    assert_checkequal(sum(p, 2, typ(:)), [1+2*s;s^2]);
+    assert_checkequal(sum(p, 3, typ(:)), p);
 end
 
 //with hypermatrices
 p(1,1,2)=-1;
 for typ=T
-  if sum(p,typ(:))<>2*s+s^2 then pause,end
-  if sum(p,'*',typ(:))<>2*s+s^2 then pause,end
-  if or(sum(p,1,typ(:))<>hypermat([1,2,2],[s+s^2;1+s;-1;0*s])) then pause,end
-  if or(sum(p,2,typ(:))<>hypermat([2,1,2],[1+2*s;s^2;-1;0*s])) then pause,end
-  if or(sum(p,3,typ(:))<>[-1+s,1+s;s^2,0]) then pause,end
-  if or(sum(p,5,typ(:))<>p) then pause,end
+    assert_checkequal(sum(p, typ(:)), 2*s+s^2);
+    assert_checkequal(sum(p, "*", typ(:)), 2*s+s^2);
+    assert_checkequal(sum(p, 1, typ(:)), hypermat([1,2,2],[s+s^2;1+s;-1;0*s]));
+    assert_checkequal(sum(p, 2, typ(:)), hypermat([2,1,2],[1+2*s;s^2;-1;0*s]));
+    assert_checkequal(sum(p, 3, typ(:)), [-1+s,1+s;s^2,0]);
+    assert_checkequal(sum(p, 5, typ(:)), p);
 end
 
 //=======================================================================
@@ -103,77 +258,80 @@ s=%s;
 r=1.0 ./[s s+1;s^2 1];
 T=list(list(),list('native'),list('double'));
 for typ=T
-  if sum(r,typ(:))<>(1+2*s+3*s^2+s^3)./(s^2+s^3) then pause,end
-  if sum(r,'*',typ(:))<>(1+2*s+3*s^2+s^3)./(s^2+s^3) then pause,end
-  if or(sum(r,1,typ(:))<>[1+s,2+s]./[s^2,1+s]) then pause,end
-  if or(sum(r,2,typ(:))<>[1+2*s;1+s^2]./[s+s^2;s^2]) then pause,end
-  if or(sum(r,3,typ(:))<>r) then pause,end
+    assert_checkequal(sum(r, typ(:)), (1+2*s+3*s^2+s^3)./(s^2+s^3));
+    assert_checkequal(sum(r, "*", typ(:)), (1+2*s+3*s^2+s^3)./(s^2+s^3));
+    assert_checkequal(sum(r, 1, typ(:)), [1+s,2+s]./[s^2,1+s]);
+    assert_checkequal(sum(r, 2, typ(:)), [1+2*s;1+s^2]./[s+s^2;s^2]);
+    assert_checkequal(sum(r, 3, typ(:)), r);
 end
 
 //=======================================================================
 ///Matrices of boolean
 
 b=[%t %t %f %t];
-for typ=list(list(),list('double'));
-  if sum(b,typ(:))<>3 then pause,end
-  if sum(b,'*',typ(:))<>3 then pause,end
-  if or(sum(b,1,typ(:))<>[1 1 0 1]) then pause,end
-  if or(sum(b,2,typ(:))<>3) then pause,end
-  if or(sum(b,3,typ(:))<>double(b)) then pause,end
+T = list(list(),list('double'));
+for typ=T
+    assert_checkequal(sum(b, typ(:)), 3);
+    assert_checkequal(sum(b, "*", typ(:)), 3);
+    assert_checkequal(sum(b, 1, typ(:)), [1 1 0 1]);
+    assert_checkequal(sum(b, 2, typ(:)), 3);
+    assert_checkequal(sum(b, 3, typ(:)), double(b));
 end
 
-if sum(b,'native')<>%t then pause,end
-if sum(b,'*','native')<>%t then pause,end
-if or(sum(b,1,'native')<>b) then pause,end
-if or(sum(b,2,'native')<>%t) then pause,end
-if or(sum(b,3,'native')<>b) then pause,end
+assert_checkequal(sum(b, "native"), %t);
+assert_checkequal(sum(b, "*", "native"), %t);
+assert_checkequal(sum(b, 1, "native"), b);
+assert_checkequal(sum(b, 2, "native"), %t);
+assert_checkequal(sum(b, 3, "native"), b);
+
 //with hypermatrices 
 b=[%t %t %f %t];b(1,1,2)=%f;
-for typ=list(list(),list('double'));
-  if sum(b,typ(:))<>3 then pause,end
-  if sum(b,'*',typ(:))<>3 then pause,end
-  if or(sum(b,1,typ(:))<>hypermat([1,4,2],[1;1;0;1;0;0;0;0])) then pause,end
-  if or(sum(b,2,typ(:))<>hypermat([1,1,2],[3;0])) then pause,end
-  if or(sum(b,3,typ(:))<>[1 1 0 1]) then pause,end
-  if or(sum(b,5,typ(:))<>double(b)) then pause,end
+T = list(list(),list('double'));
+for typ=T
+    assert_checkequal(sum(b, typ(:)), 3);
+    assert_checkequal(sum(b, "*", typ(:)), 3);
+    assert_checkequal(sum(b, 1, typ(:)), hypermat([1,4,2],[1;1;0;1;0;0;0;0]));
+    assert_checkequal(sum(b, 2, typ(:)), hypermat([1,1,2],[3;0]));
+    assert_checkequal(sum(b, 3, typ(:)), [1 1 0 1]);
+    assert_checkequal(sum(b, 5, typ(:)), double(b));
 end
 
-if sum(b,'native')<>%t then pause,end
-if sum(b,'*','native')<>%t then pause,end
-if or(sum(b,1,'native')<>hypermat([1,4,2],[%t;%t;%f;%t;%f;%f;%f;%f])) then pause,end
-if or(sum(b,2,'native')<>hypermat([1,1,2],[%t;%f])) then pause,end
-if or(sum(b,3,'native')<>[%t %t %f %t]) then pause,end
-if or(sum(b,5,'native')<>b) then pause,end
+assert_checkequal(sum(b, "native"), %t);
+assert_checkequal(sum(b, "*", "native"), %t);
+assert_checkequal(sum(b, 1, "native"), hypermat([1,4,2],[%t;%t;%f;%t;%f;%f;%f;%f]));
+assert_checkequal(sum(b, 2, "native"), hypermat([1,1,2],[%t;%f]));
+assert_checkequal(sum(b, 3, "native"), [%t %t %f %t]);
+assert_checkequal(sum(b, 5, "native"), b);
 
 //=======================================================================
 //sparse matrices of floats
 s=sparse([1 10 0;0 254 9]);
 T=list(list(),list('native'),list('double'));
 for typ=T
-  if sum(s,typ(:))<>274 then pause,end
-  if sum(s,'*',typ(:))<>274 then pause,end
-  if or(sum(s,1,typ(:))<>sparse([1,264,9])) then pause,end
-  if or(sum(s,2,typ(:))<>sparse([11;263])) then pause,end
-  if or(sum(s,3,typ(:))<>s) then pause,end
+    assert_checkequal(sum(s, typ(:)), 274);
+    assert_checkequal(sum(s, "*", typ(:)), 274);
+    assert_checkequal(sum(s, 1, typ(:)), sparse([1,264,9]));
+    assert_checkequal(sum(s, 2, typ(:)), sparse([11;263]));
+    assert_checkequal(sum(s, 3, typ(:)), s);
 end
 
 //=======================================================================
 //sparse  matrices of boolean
 bs=sparse([1 10 0;0 254 9])<>0;
-for typ=list(list(),list('double'));
-  if sum(bs,typ(:))<>4 then pause,end
-  if sum(bs,'*',typ(:))<>4 then pause,end
-  if or(sum(bs,1,typ(:))<>sparse([1,2,1])) then pause,end
-  if or(sum(bs,2,typ(:))<>sparse([2;2])) then pause,end
-  if or(sum(bs,3,typ(:))<>bool2s(bs)) then pause,end
+T = list(list(),list('double'));
+for typ=T
+    assert_checkequal(sum(bs, typ(:)), 4);
+    assert_checkequal(sum(bs, "*", typ(:)), 4);
+    assert_checkequal(sum(bs, 1, typ(:)), sparse([1,2,1]));
+    assert_checkequal(sum(bs, 2, typ(:)), sparse([2;2]));
+    assert_checkequal(sum(bs, 3, typ(:)), bool2s(bs));
 end
 
-if sum(bs,'native')<>%t then pause,end
-if sum(bs,'*','native')<>%t then pause,end
-if or(sum(bs,1,'native')<>sparse([%t,%t,%t])) then pause,end
-if or(sum(bs,2,'native')<>sparse([%t;%t])) then pause,end
-if or(sum(bs,3,'native')<>bs) then pause,end
+assert_checkequal(sum(bs, "native"), %t);
+assert_checkequal(sum(bs, "*", "native"), %t);
+assert_checkequal(sum(bs, 1, "native"), sparse([%t,%t,%t]));
+assert_checkequal(sum(bs, 2, "native"), sparse([%t;%t]));
+assert_checkequal(sum(bs, 3, "native"),bs);
 
 // TODO : test the "m" option
 
-
index 7920e1d..a0170c9 100644 (file)
@@ -7,74 +7,91 @@
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function x=%hm_cumprod(m,d,typ)
-    if argn(2)==1 then
-        typ=list()
-        d="*"
-    elseif argn(2)==2 then
-        if argn(2)==2& or(d==["native","double"]) then
-            typ=list(d)
-            d="*"
+function a = %hm_cumprod(varargin)
+    a = varargin(1)
+    dims = size(a);
+    tm = type(a.entries)
+
+    nargs = size(varargin);
+    select nargs
+    case 1
+        d = 0;
+        if tm == 8 then
+            typ = "native";
         else
-            typ=list()
+            typ = "double";
         end
-    else
-        typ=list(typ)
-    end
-    if size(d,"*")<>1 then
-        if type(d)==10 then
-            error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",2))
+    case 2
+        if or(varargin(2) == ["native", "double"]) then
+            d = 0;
+            typ = varargin(2);
         else
-            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumprod",2))
+            d = varargin(2);
+            if tm == 8 then
+                typ = "native";
+            else
+                typ = "double";
+            end
         end
+    case 3
+        d = varargin(2);
+        typ = varargin(3);
+    else
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"),"cumprod", 1, 3));
     end
 
-    if type(d)==10 then
-        d=find(d==["m","*","r","c"])
-        if d==[] then
+    // Check second argument : d
+    select type(d)
+    case 1
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumprod", 2))
+        end
+        if int(d) <> d | d < 0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"cumprod", 2, 1))
+        end
+    case 10 
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",2))
+        end
+        if and(d<>["r","c","*","m"]) then
             error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-            "cumprod",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+            "cumprod",2,"""*"",""r"",""c"",""m"""))
         end
-        d=d-2
+        pos=[1,2,0,find(dims>1,1)];
+        d=pos(find(d==["r","c","*","m"]))
+    else
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"cumprod",2))
     end
-    dims=m.dims;
 
-    if d==-1 then //'m'
-        d=find(dims>1,1)
-        if d==[] then d=0,end
+    // Check third argument
+    if type(typ)<>10 then
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"cumprod",3))
     end
-    if d<0 then
-        error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-        "cumprod",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+
+    if size(typ,"*")<>1 then
+        error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",3))
     end
-    if d==0 then// '*'
-        x=hypermat(m.dims,cumprod(m.entries,typ(:)))
-        return
+
+    if and(typ <> ["native" "double"]) then
+        error(msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"cumprod", 3, "native", "double"));
     end
-    if d>size(dims,"*") then
+
+    if d == 0 then // '*'
+        a=matrix(cumprod(a.entries, "*", typ), dims);
+    elseif d > size(dims,"*") then
         //requested summation direction exceeds array dims, return the array, converted
         //to double if necessary.
-        tm=type(m.entries)
-        if (tm==8&typ==list("double"))|(tm==4&typ<>list("native")) then
-            m.entries=double(m.entries),
+        if typ == "double" & or(tm == [4 8]) then
+            a.entries=double(a.entries),
         end
-        x=m
-        return
+        a=a
+    else
+        //permute the array dimension to put the selected dimension first
+        p=1:size(dims,"*");
+        p([1,d])=p([d,1]);
+        a=matrix(permute(a,p),dims(d),-1)
+        a=cumprod(a,1,typ);
+        //permute back
+        a=permute(matrix(a,dims(p)),p)
     end
-
-    if type(dims==8) then flag=1; dims=double(dims); else flag=0;end
-    N=size(dims,"*");
-    p1=prod(dims(1:d-1));//summation step
-    p2=p1*dims(d);//step for next to sum
-    ind=(0:p1:p2-1);// selection for summation
-    deb=(1:p1)';
-    I=deb*ones(ind)+ones(deb)*ind
-
-
-    ind=(0:p2:prod(dims)-1)';
-    I=ones(ind).*.I+ind.*.ones(I)
-    x=cumprod(matrix(m.entries(I),-1,dims(d)),2,typ(:))
-    x(I)=matrix(x,-1,1)
-    if flag==1 then dims=int32(dims);end
-    x=hypermat(dims,x)
 endfunction
index 87cd9de..ddc411f 100644 (file)
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function x=%hm_cumsum(m,d,typ)
-    if argn(2)==1 then
-        typ=list()
-        d="*"
-    elseif argn(2)==2 then
-        if argn(2)==2& or(d==["native","double"]) then
-            typ=list(d)
-            d="*"
+function a = %hm_cumsum(varargin)
+    a = varargin(1)
+    dims = size(a);
+    tm = type(a.entries)
+
+    nargs = size(varargin);
+    select nargs
+    case 1
+        d = 0;
+        if tm == 8 then
+            typ = "native";
         else
-            typ=list()
+            typ = "double";
         end
-    else
-        typ=list(typ)
-    end
-    if size(d,"*")<>1 then
-        if type(d)==10 then
-            error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",2))
+    case 2
+        if or(varargin(2) == ["native", "double"]) then
+            d = 0;
+            typ = varargin(2);
         else
-            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumsum",2))
+            d = varargin(2);
+            if tm == 8 then
+                typ = "native";
+            else
+                typ = "double";
+            end
         end
+    case 3
+        d = varargin(2);
+        typ = varargin(3);
+    else
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"),"cumsum", 1, 3));
     end
 
-    if type(d)==10 then
-        d=find(d==["m","*","r","c"])
-        if d==[] then
+    // Check second argument : d
+    select type(d)
+    case 1
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumsum", 2))
+        end
+        if int(d) <> d | d < 0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"cumsum", 2, 1))
+        end
+    case 10 
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",2))
+        end
+        if and(d<>["r","c","*","m"]) then
             error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-            "cumsum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+            "cumsum",2,"""*"",""r"",""c"",""m"""))
         end
-        d=d-2
+        pos=[1,2,0,find(dims>1,1)];
+        d=pos(find(d==["r","c","*","m"]))
+    else
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"cumsum",2))
     end
-    dims=m.dims;
 
-    if d==-1 then //'m'
-        d=find(dims>1,1)
-        if d==[] then d=0,end
+    // Check third argument
+    if type(typ)<>10 then
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"cumsum",3))
     end
 
-    if d<0 then
-        error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-        "cumsum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+    if size(typ,"*")<>1 then
+        error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",3))
     end
 
-    if d==0 then// '*'
-        x=hypermat(m.dims,cumsum(m.entries,typ(:)))
-        return
+    if and(typ <> ["native" "double"]) then
+        error(msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"cumsum", 3, "native", "double"));
     end
 
-    if d>size(dims,"*") then
+    if d == 0 then // '*'
+        a=matrix(cumsum(a.entries, "*", typ), dims);
+    elseif d > size(dims,"*") then
         //requested summation direction exceeds array dims, return the array, converted
         //to double if necessary.
-        tm=type(m.entries)
-        if (tm==8&typ==list("double"))|(tm==4&typ<>list("native")) then
-            m.entries=double(m.entries),
+        if typ == "double" & or(tm == [4 8]) then
+            a.entries=double(a.entries),
         end
-        x=m
-        return
+        a=a
+    else
+        //permute the array dimension to put the selected dimension first
+        p=1:size(dims,"*");
+        p([1,d])=p([d,1]);
+        a=matrix(permute(a,p),dims(d),-1)
+        a=cumsum(a,1,typ);
+        //permute back
+        a=permute(matrix(a,dims(p)),p)
+//        N=size(dims,"*");
+//        p1=prod(dims(1:d-1));//summation step
+//        p2=p1*dims(d);//step for next to sum
+//        ind=(0:p1:p2-1);// selection for summation
+//        deb=(1:p1)';
+//        I=deb*ones(ind)+ones(deb)*ind
+//
+//
+//        ind=(0:p2:prod(dims)-1)';
+//        I=ones(ind).*.I+ind.*.ones(I)
+//        a=cumsum(matrix(a.entries(I),-1,dims(d)),2,typ)
+//        a(I)=matrix(a,-1,1)
+//        a=hypermat(dims,a)
     end
-
-
-    if type(dims==8) then flag=1; dims=double(dims); else flag=0;end
-    N=size(dims,"*");
-    p1=prod(dims(1:d-1));//summation step
-    p2=p1*dims(d);//step for next to sum
-    ind=(0:p1:p2-1);// selection for summation
-    deb=(1:p1)';
-    I=deb*ones(ind)+ones(deb)*ind
-
-
-    ind=(0:p2:prod(dims)-1)';
-    I=ones(ind).*.I+ind.*.ones(I)
-    x=cumsum(matrix(m.entries(I),-1,dims(d)),2,typ(:))
-    x(I)=matrix(x,-1,1)
-    if flag==1 then dims=int32(dims);end
-    x=hypermat(dims,x)
 endfunction
index 71c4518..c3d5858 100644 (file)
@@ -7,87 +7,97 @@
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function x=%hm_prod(m,d,typ)
-    if argn(2)==1 then
-        typ=list()
-        d="*"
-    elseif argn(2)==2 then
-        if argn(2)==2& or(d==["native","double"]) then
-            typ=list(d)
-            d="*"
+function a = %hm_prod(varargin)
+    a = varargin(1)
+    dims = size(a);
+    tm = type(a.entries)
+
+    nargs = size(varargin);
+    select nargs
+    case 1
+        d = 0;
+        if tm == 8 then
+            typ = "native";
+        else
+            typ = "double";
+        end
+    case 2
+        if or(varargin(2) == ["native", "double"]) then
+            d = 0;
+            typ = varargin(2);
         else
-            typ=list()
+            d = varargin(2);
+            if tm == 8 then
+                typ = "native";
+            else
+                typ = "double";
+            end
         end
+    case 3
+        d = varargin(2);
+        typ = varargin(3);
     else
-        typ=list(typ)
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"),"prod", 1, 3));
     end
-    if size(d,"*")<>1 then
-        if type(d)==10 then
+
+    // Check second argument : d
+    select type(d)
+    case 1
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"prod", 2))
+        end
+        if int(d) <> d | d < 0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"prod", 2, 1))
+        end
+    case 10 
+        if size(d,'*') <> 1 then
             error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",2))
-        else
-            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"prod",2))
         end
-    end
-    if type(d)==10 then
-        d=find(d==["m","*","r","c"])
-        if d==[] then
+        if and(d<>["r","c","*","m"]) then
             error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-            "prod",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+            "prod",2,"""*"",""r"",""c"",""m"""))
         end
-        d=d-2
+        pos=[1,2,0,find(dims>1,1)];
+        d=pos(find(d==["r","c","*","m"]))
+    else
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"prod",2))
     end
-    dims=m.dims;
 
-    if d==-1 then
-        //sum(x,'m'), determine the product direction
-        d=find(dims>1,1)
-        if d==[] then d=0,end
+    // Check third argument
+    if type(typ)<>10 then
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"prod",3))
     end
-    if d<0 then
-        error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-        "prod",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+
+    if size(typ,"*")<>1 then
+        error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",3))
     end
-    if d==0 then
-        //prod of all elements
-        x=prod(m.entries,typ(:))
-        return
+
+    if and(typ <> ["native" "double"]) then
+        error(msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"prod", 3, "native", "double"));
     end
 
-    if d>size(dims,"*") then
-        //requested  product direction exceeds array dims, return the array, converted
+    if d == 0 then // '*'
+        a=prod(a.entries, "*", typ), dims;
+    elseif d > size(dims,"*") then
+        //requested summation direction exceeds array dims, return the array, converted
         //to double if necessary.
-        tm=type(m.entries)
-        if (tm==8&typ==list("double"))|(tm==4&typ<>list("native")) then
-            m.entries=double(m.entries),
+        if typ == "double" & or(tm == [4 8]) then
+            a.entries=double(a.entries),
         end
-        x=m
-        return
-    end
-
-
-    if type(dims==8) then flag=1; dims=double(dims); else flag=0;end
-    N=size(dims,"*");
-    p1=prod(dims(1:d-1));//product step
-    p2=p1*dims(d);//step for next to prod
-    ind=(0:p1:p2-1)';// selection for product
-    deb=(1:p1);
-    I=ind*ones(deb)+ones(ind)*deb
-
-    ind=(0:p2:prod(dims)-1);
-    I=ones(ind).*.I+ind.*.ones(I)
-
-    x=prod(matrix(m.entries(I),dims(d),-1),1,typ(:))
-    dims(d)=1
-    while  dims($)==1 then dims($)=[],end
-    if d==N then
-        dims=dims(1:$)
+        a=a
     else
-        dims(d)=1
-    end
-    if size(dims,"*")==2 then
-        x=matrix(x,dims(1),dims(2))
-    elseif dims<>[] then
-        if flag==1 then dims=int32(dims);end
-        x=hypermat(dims,x)
+        //permute the array dimension to put the selected dimension first
+        p=1:size(dims,"*");
+        p([1,d])=p([d,1]);
+        a=matrix(permute(a,p),dims(d),-1)
+        a=prod(a,1,typ);
+        //permute back
+        if d==size(dims, "*") then
+            dims=dims(1:$-1)
+            p(1) = []
+        else
+            dims(d)=1
+        end
+        a=permute(matrix(a,dims(p)),p)
     end
 endfunction
index e537b00..95ccad5 100644 (file)
@@ -7,89 +7,97 @@
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function x=%hm_sum(m,d,typ)
-    if argn(2)==1 then
-        typ=list()
-        d="*"
-    elseif argn(2)==2 then
-        if argn(2)==2& or(d==["native","double"]) then
-            typ=list(d)
-            d="*"
+function a = %hm_sum(varargin)
+    a = varargin(1)
+    dims = size(a);
+    tm = type(a.entries)
+
+    nargs = size(varargin);
+    select nargs
+    case 1
+        d = 0;
+        if tm == 8 then
+            typ = "native";
         else
-            typ=list()
+            typ = "double";
         end
-    else
-        typ=list(typ)
-    end
-    if size(d,"*")<>1 then
-        if type(d)==10 then
-            error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",2))
+    case 2
+        if or(varargin(2) == ["native", "double"]) then
+            d = 0;
+            typ = varargin(2);
         else
-            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"sum",2))
+            d = varargin(2);
+            if tm == 8 then
+                typ = "native";
+            else
+                typ = "double";
+            end
         end
+    case 3
+        d = varargin(2);
+        typ = varargin(3);
+    else
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"),"sum", 1, 3));
     end
 
-    if type(d)==10 then
-        d=find(d==["m","*","r","c"])
-        if d==[] then
+    // Check second argument : d
+    select type(d)
+    case 1
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"sum", 2))
+        end
+        if int(d) <> d | d < 0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"sum", 2, 1))
+        end
+    case 10 
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",2))
+        end
+        if and(d<>["r","c","*","m"]) then
             error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-            "sum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+            "sum",2,"""*"",""r"",""c"",""m"""))
         end
-        d=d-2
+        pos=[1,2,0,find(dims>1,1)];
+        d=pos(find(d==["r","c","*","m"]))
+    else
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"sum",2))
     end
-    dims=m.dims;
 
-    if d==-1 then
-        //sum(x,'m'), determine the summation direction
-        d=find(dims>1,1)
-        if d==[] then d=0,end
+    // Check third argument
+    if type(typ)<>10 then
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"sum",3))
     end
-    if d<0 then
-        error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-        "sum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+
+    if size(typ,"*")<>1 then
+        error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",3))
     end
 
-    if d==0 then
-        //sum of all elements
-        x=sum(m.entries,typ(:))
-        return
+    if and(typ <> ["native" "double"]) then
+        error(msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"sum", 3, "native", "double"));
     end
-    if d>size(dims,"*") then
+
+    if d == 0 then // '*'
+        a=sum(a.entries, "*", typ), dims;
+    elseif d > size(dims,"*") then
         //requested summation direction exceeds array dims, return the array, converted
         //to double if necessary.
-        tm=type(m.entries)
-        if (tm==8&typ==list("double"))|(tm==4&typ<>list("native")) then
-            m.entries=double(m.entries),
+        if typ == "double" & or(tm == [4 8]) then
+            a.entries=double(a.entries),
         end
-        x=m
-        return
-    end
-
-
-    if type(dims==8) then flag=1; dims=double(dims); else flag=0;end
-    N=size(dims,"*");
-    p1=prod(dims(1:d-1));// step to build one vector on which sum is applied
-    p2=p1*dims(d);//step for beginning of next vectors
-    ind=(0:p1:p2-1)';// selection for building one vector
-    deb=(1:p1);
-    I=ind*ones(deb)+ones(ind)*deb
-
-    ind=(0:p2:prod(dims)-1);
-    I=ones(ind).*.I+ind.*.ones(I)
-    x=sum(matrix(m.entries(I),dims(d),-1),1,typ(:))
-
-    dims(d)=1
-    while  dims($)==1 then dims($)=[],end
-    if d==N then
-        dims=dims(1:$)
+        a=a
     else
-        dims(d)=1
-    end
-    if size(dims,"*")==2 then
-        x=matrix(x,dims(1),dims(2))
-    elseif dims<>[] then
-        if flag==1 then dims=int32(dims);end
-        x=hypermat(dims,x)
+        //permute the array dimension to put the selected dimension first
+        p=1:size(dims,"*");
+        p([1,d])=p([d,1]);
+        a=matrix(permute(a,p),dims(d),-1)
+        a=sum(a,1,typ);
+        //permute back
+        if d==size(dims, "*") then
+            dims=dims(1:$-1)
+            p(1) = []
+        else
+            dims(d)=1
+        end
+        a=permute(matrix(a,dims(p)),p)
     end
-
 endfunction
index 79212d3..5bb2c6f 100644 (file)
@@ -7,48 +7,51 @@
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function a=%p_cumprod(a,d,typ)
-    if argn(2)==1 then
-        typ=list()
-        d="*"
-    elseif argn(2)==2 then
-        if argn(2)==2& or(d==["native","double"]) then
-            typ=list(d)
-            d="*"
+function a = %p_cumprod(varargin)
+    // If we call cumprod with 3 arguments, the third is optional for polynomial matrices.
+    a = varargin(1)
+    dims = size(a);
+
+    nargs = size(varargin);
+    select nargs
+    case 1
+        d = "*";
+    case 2
+        if or(varargin(2) == ["native", "double"]) then
+            d = "*";
         else
-            typ=list()
+            d = varargin(2);
         end
+    case 3
+        d = varargin(2);
     else
-        typ=list(typ)
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"),"cumprod", 1, 3));
     end
-    if size(d,"*")<>1 then
-        if type(d)==10 then
+
+    // Check second argument : d
+    select type(d)
+    case 1
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumprod", 2))
+        end
+        if int(d) <> d | d < 0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"cumprod", 2, 1))
+        end
+    case 10 
+        if size(d,'*') <> 1 then
             error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",2))
-        else
-            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumprod",2))
         end
-    end
-
-    if type(d)==10 then
-        d=find(d==["m","*","r","c"])
-        if d==[] then
+        if and(d<>["r","c","*","m"]) then
             error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-            "cumprod",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+            "cumprod",2,"""*"",""r"",""c"",""m"""))
         end
-        d=d-2
-    end
-    dims=size(a);
-
-    if d==-1 then //'m'
-        d=find(dims>1,1)
-        if d==[] then d=0,end
-    end
-    if d<0 then
-        error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-        "cumprod",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+        
+        pos = [1,2,0,find(dims>1,1)];
+        d=pos(find(d==["r","c","*","m"]))
+    else
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"cumprod",2))
     end
 
-
     select d
     case 0 then
         for k=2:prod(dims)
@@ -56,11 +59,11 @@ function a=%p_cumprod(a,d,typ)
         end
     case 1 then
         for k=1:dims(2)
-            a(:,k)=cumprod(a(:,k),typ(:))
+            a(:,k)=cumprod(a(:,k))
         end
     case 2 then
         for k=1:dims(1)
-            a(k,:)=cumprod(a(k,:),typ(:))
+            a(k,:)=cumprod(a(k,:))
         end
     else
         a=a
index bb41e4a..da69703 100644 (file)
@@ -7,45 +7,49 @@
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function a=%p_cumsum(a,d,typ)
-    if argn(2)==1 then
-        typ=list()
-        d="*"
-    elseif argn(2)==2 then
-        if argn(2)==2& or(d==["native","double"]) then
-            typ=list(d)
-            d="*"
+function a = %p_cumsum(varargin)
+    a = varargin(1)
+    dims = size(a);
+
+    nargs = size(varargin);
+    select nargs
+    case 1
+        d = "*";
+    case 2
+        if or(varargin(2) == ["native", "double"]) then
+            d = "*";
         else
-            typ=list()
+            d = varargin(2);
         end
+    case 3
+        d = varargin(2);
     else
-        typ=list(typ)
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"),"cumsum", 1, 3));
     end
-    if size(d,"*")<>1 then
-        if type(d)==10 then
+
+    // Check second argument : d
+    select type(d)
+    case 1
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumsum", 2))
+        end
+        if int(d) <> d | d < 0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"cumsum", 2, 1))
+        end
+    case 10 
+        if size(d,'*') <> 1 then
             error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",2))
-        else
-            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumsum",2))
         end
-    end
-
-    if type(d)==10 then
-        d=find(d==["m","*","r","c"])
-        if d==[] then
+        if and(d<>["r","c","*","m"]) then
             error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-            "cumsum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+            "cumsum",2,"""*"",""r"",""c"",""m"""))
         end
-        d=d-2
-    end
-    dims=size(a);
-
-    if d==-1 then //'m'
-        d=find(dims>1,1)
-        if d==[] then d=0,end
-    end
-    if d<0 then
-        error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-        "cumsum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+        
+        pos = [1,2,0,find(dims>1,1)];
+        d=pos(find(d==["r","c","*","m"]))
+        
+    else
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"cumsum",2))
     end
 
     select d
@@ -55,11 +59,11 @@ function a=%p_cumsum(a,d,typ)
         end
     case 1 then
         for k=1:dims(2)
-            a(:,k)=cumsum(a(:,k),typ(:))
+            a(:,k)=cumsum(a(:,k))
         end
     case 2 then
         for k=1:dims(1)
-            a(k,:)=cumsum(a(k,:),typ(:))
+            a(k,:)=cumsum(a(k,:))
         end
     else
         a=a
index 95f93ff..bab4458 100644 (file)
@@ -7,57 +7,61 @@
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function r=%p_prod(a,d,typ)
-    if argn(2)==1 then
-        typ=list()
-        d="*"
-    elseif argn(2)==2 then
-        if argn(2)==2& or(d==["native","double"]) then
-            typ=list(d)
-            d="*"
+function r = %p_prod(varargin)
+    // If we call prod with 3 arguments, the third is optional for polynomial matrices
+    a = varargin(1)
+    dims = size(a);
+
+    nargs = size(varargin);
+    select nargs
+    case 1
+        d = "*";
+    case 2
+        if or(varargin(2) == ["native", "double"]) then
+            d = "*";
         else
-            typ=list()
+            d = varargin(2);
         end
+    case 3
+        d = varargin(2);
     else
-        typ=list(typ)
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"),"prod", 1, 3));
     end
-    if size(d,"*")<>1 then
-        if type(d)==10 then
+
+    // Check second argument : d
+    select type(d)
+    case 1
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"prod", 2))
+        end
+        if int(d) <> d | d < 0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"prod", 2, 1))
+        end
+    case 10 
+        if size(d,'*') <> 1 then
             error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",2))
-        else
-            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"prod",2))
         end
-    end
-
-    if type(d)==10 then
-        d=find(d==["m","*","r","c"])
-        if d==[] then
+        if and(d<>["r","c","*","m"]) then
             error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-            "prod",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+            "prod",2,"""*"",""r"",""c"",""m"""))
         end
-        d=d-2
-    end
-    dims=size(a);
-
-    if d==-1 then //'m'
-        d=find(dims>1,1)
-        if d==[] then d=0,end
-    end
-    if d<0 then
-        error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-        "prod",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+        
+        pos = [1,2,0,find(dims>1,1)];
+        d=pos(find(d==["r","c","*","m"]))
+    else
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"prod",2))
     end
-
+    
     select d
     case 0 then
-        r=prod(a)
+            r=prod(a)
     case 1 then
         for k=1:dims(2)
-            r(1,k)=prod(a(:,k),typ(:))
+            r(1,k) = prod(a(:,k))
         end
     case 2 then
         for k=1:dims(1)
-            r(k,1)=prod(a(k,:),typ(:))
+            r(k,1)=prod(a(k,:))
         end
     else
         r=a
index 739a4a4..a08d246 100644 (file)
@@ -7,44 +7,53 @@
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function a=%p_sum(a,d,typ)
+function a = %p_sum(varargin)
     //sum of a polynomial matrix. Sum of Polynomial hypermatrices are
     //handled by %hm_sum
-    if argn(2)==1 then
-        typ=list()
-        d="*"
-    elseif argn(2)==2 then
-        if argn(2)==2& or(d==["native","double"]) then
-            typ=list(d)
-            d="*"
+    // If we call sum with 3 arguments, the third is optional for polynomial matrices
+    a = varargin(1)
+    dims = size(a);
+
+    nargs = size(varargin);
+    select nargs
+    case 1
+        d = "*";
+    case 2
+        if or(varargin(2) == ["native", "double"]) then
+            d = "*";
         else
-            typ=list()
+            d = varargin(2);
         end
+    case 3
+        d = varargin(2);
     else
-        typ=list(typ)
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"),"sum", 1, 3));
     end
-    if size(d,"*")<>1 then
-        if type(d)==10 then
+
+    // Check second argument : d
+    select type(d)
+    case 1
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"sum", 2))
+        end
+        if int(d) <> d | d < 0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"sum", 2, 1))
+        end
+    case 10 
+        if size(d,'*') <> 1 then
             error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",2))
-        else
-            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"sum",2))
         end
-    end
-
-    if type(d)==10 then
-        d=find(d==["m","*","r","c"])
-        if d==[] then
+        if and(d<>["r","c","*","m"]) then
             error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-            "sum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+            "sum",2,"""*"",""r"",""c"",""m"""))
         end
-        d=d-2
-    end
-    dims=size(a);
-
-    if d==-1 then //'m'
-        d=find(dims>1,1)
-        if d==[] then d=0,end
+        
+        pos = [1,2,0,find(dims>1,1)];
+        d=pos(find(d==["r","c","*","m"]))
+    else
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"sum",2))
     end
+    
     select d
     case 0 then
         a=sum(a)
index 2040fea..5e08d77 100644 (file)
@@ -7,47 +7,62 @@
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function a=%r_cumprod(a,d,typ)
+function a=%r_cumprod(varargin)
     //prod of a rational matrix
-    if argn(2)==1 then
-        d="*"
-    elseif argn(2)==2 then
-        if argn(2)==2& or(d==["native","double"]) then
-            d="*"
-        end
-    end
-    if size(d,"*")<>1 then
-        if type(d)==10 then
-            error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",2))
+    // If we call cumprod with 3 arguments, the third is optional for rational matrices.
+    a = varargin(1)
+    dims = size(a);
+
+    nargs = size(varargin);
+    select nargs
+    case 1
+        d = "*";
+    case 2
+        if or(varargin(2) == ["native", "double"]) then
+            d = "*";
         else
-            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumprod",2))
+            d = varargin(2);
         end
+    case 3
+        d = varargin(2);
+    else
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"),"cumprod", 1, 3));
     end
-    dims=size(a);
 
-    if type(d)==10 then
-        d=find(d==["m","*","r","c"])
-        if d==[] then
+    // Check second argument : d
+    select type(d)
+    case 1
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumprod", 2))
+        end
+        if int(d) <> d | d < 0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"cumprod", 2, 1))
+        end
+    case 10 
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",2))
+        end
+        if and(d<>["r","c","*","m"]) then
             error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-            "cumprod",2,"""*"",""r"",""c"",""m"",1:"+string(size(dims,"*"))))
+            "cumprod",2,"""*"",""r"",""c"",""m"""))
         end
-        d=d-2
-    end
 
-    if d==-1 then //'m'
-        d=find(dims>1,1)
-        if d==[] then d=0,end
-    end
-    if d<0 then
-        error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-        "cumprod",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+        pos = [1,2,0,find(dims>1,1)];
+        d=pos(find(d==["r","c","*","m"]))
+    else
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"cumprod",2))
     end
+
     if d==0 then //'*'
         a=rlist(cumprod(a.num),cumprod(a.den),a.dt)
-        if simp_mode() then a=simp(a),end
+        if simp_mode() then 
+            a=simp(a)
+        end
     elseif or(d==[1 2]) then
         a=rlist(cumprod(a.num,d),cumprod(a.den,d),a.dt)
-        if simp_mode() then a=simp(a),end
+        if simp_mode() then 
+            a=simp(a)
+        end
     else
         a=a
     end
index da9b244..b254571 100644 (file)
@@ -7,53 +7,54 @@
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function a=%r_cumsum(a, orient, typ)
-    // cumulative sum for rational matrics
-    rhs = argn(2);
-    select rhs
+function a = %r_cumsum(varargin)
+    // cumulative sum for rational matrices
+    // If we call cumsum with 3 arguments, the third is optional for rational matrices.
+    a = varargin(1)
+    dims = size(a);
+
+    nargs = size(varargin);
+    select nargs
     case 1
-        orient = "*";
+        d = "*";
     case 2
-        if or(orient == ["native", "double"]) then
-            orient = "*";
+        if or(varargin(2) == ["native", "double"]) then
+            d = "*";
+        else
+            d = varargin(2);
         end
     case 3
-        if and(typ <> ["native", "double"]) then
-            error(msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"cumsum", 3, "native", "double"));
-        end
+        d = varargin(2);
+    else
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"),"cumsum", 1, 3));
     end
 
-    if size(orient, "*") <> 1 then
-        if type(orient) == 10 then
-            error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum", 2));
-        else
-            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumsum", 2));
+    // Check second argument : d
+    select type(d)
+    case 1
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumsum", 2))
         end
-    end
-
-    dims = size(a);
-
-    if type(orient) == 10 then
-        orient = find(orient == ["m","*","r","c"]);
-        if isempty(orient) then
+        if int(d) <> d | d < 0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"cumsum", 2, 1))
+        end
+    case 10 
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",2))
+        end
+        if and(d<>["r","c","*","m"]) then
             error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-            "cumsum",2,"""*"",""r"",""c"",""m"",1:"+string(size(dims,"*"))));
+            "cumsum",2,"""*"",""r"",""c"",""m"""))
         end
-        orient=orient-2;
+        
+        pos = [1,2,0,find(dims>1,1)];
+        d=pos(find(d==["r","c","*","m"]))
+        
+    else
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"cumsum",2))
     end
 
-    if orient == -1 then //'m'
-        orient = find(dims > 1, 1);
-        if isempty(orient) then
-            orient = 0;
-        end
-    end
-    if orient<0 then
-        error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-        "cumsum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))));
-    end
-    
-    select orient
+    select d
     case 0 then // case "*"
         a = tril(ones(size(a,"*"), size(a, "*"))) * matrix(a, -1, 1);
         if simp_mode() then
index e86f8c4..95204fd 100644 (file)
@@ -7,40 +7,50 @@
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function a=%r_prod(a,d,typ)
+function a = %r_prod(varargin)
     //prod of a rational matrix
-    if argn(2)==1 then
-        d="*"
-    elseif argn(2)==2 then
-        if argn(2)==2& or(d==["native","double"]) then
-            d="*"
-        end
-    end
-    if size(d,"*")<>1 then
-        if type(d)==10 then
-            error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",2))
+    // If we call prod with 3 argumetns, the thrid argumetn is optional for rational matrices.
+    a = varargin(1)
+    dims = size(a);
+
+    nargs = size(varargin);
+    select nargs
+    case 1
+        d = "*";
+    case 2
+        if or(varargin(2) == ["native", "double"]) then
+            d = "*";
         else
-            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"prod",2))
+            d = varargin(2);
         end
+    case 3
+        d = varargin(2);
+    else
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"),"prod", 1, 3));
     end
-    dims=size(a);
 
-    if type(d)==10 then
-        d=find(d==["m","*","r","c"])
-        if d==[] then
+    // Check second argument : d
+    select type(d)
+    case 1
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"prod", 2))
+        end
+        if int(d) <> d | d < 0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"prod", 2, 1))
+        end
+    case 10 
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",2))
+        end
+        if and(d<>["r","c","*","m"]) then
             error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-            "prod",2,"""*"",""r"",""c"",""m"",1:"+string(size(dims,"*"))))
+            "prod",2,"""*"",""r"",""c"",""m"""))
         end
-        d=d-2
-    end
-
-    if d==-1 then //'m'
-        d=find(dims>1,1)
-        if d==[] then d=0,end
-    end
-    if d<0 then
-        error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-        "prod",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+        
+        pos = [1,2,0,find(dims>1,1)];
+        d=pos(find(d==["r","c","*","m"]))
+    else
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"prod",2))
     end
 
     if d==0 then //'*'
index 9fb04c9..c8d6821 100644 (file)
@@ -7,38 +7,53 @@
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function a=%r_sum(a,d,typ)
+function a=%r_sum(varargin)
     //sum of a rational matrix. Sum of rational hypermatrices are
     //handled by %hm_sum
+    // If we call sum with 3 arguments, the third is optional with rational matrices.
+    a = varargin(1)
+    dims = size(a);
 
-    if argn(2)==1 then
-        d="*"
-    elseif argn(2)==2 then
-        if argn(2)==2& or(d==["native","double"]) then
-            d="*"
+    nargs = size(varargin);
+    select nargs
+    case 1
+        d = "*";
+    case 2
+        if or(varargin(2) == ["native", "double"]) then
+            d = "*";
+        else
+            d = varargin(2);
         end
+    case 3
+        d = varargin(2);
+    else
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"),"sum", 1, 3));
     end
-    if size(d,"*")<>1 then
-        if type(d)==10 then
+
+    // Check second argument : d
+    select type(d)
+    case 1
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"sum", 2))
+        end
+        if int(d) <> d | d < 0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"sum", 2, 1))
+        end
+    case 10 
+        if size(d,'*') <> 1 then
             error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",2))
-        else
-            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"sum",2))
         end
-    end
-    dims=size(a);
-    if type(d)==10 then
-        d=find(d==["m","*","r","c"])
-        if d==[] then
+        if and(d<>["r","c","*","m"]) then
             error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-            "sum",2,"""*"",""r"",""c"",""m"",1:"+string(size(dims,"*"))))
+            "sum",2,"""*"",""r"",""c"",""m"""))
         end
-        d=d-2
+        
+        pos = [1,2,0,find(dims>1,1)];
+        d=pos(find(d==["r","c","*","m"]))
+    else
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"sum",2))
     end
 
-    if d==-1 then //'m'
-        d=find(dims>1,1)
-        if d==[] then d=0,end
-    end
     select d
     case 0 then//'*'
         a=ones(1,size(a,"*"))*matrix(a,-1,1)
index fe2346f..162968a 100644 (file)
@@ -7,48 +7,50 @@
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function r=%sp_cumprod(a,d,typ)
-    if argn(2)==1 then
-        typ=list()
-        d="*"
-    elseif argn(2)==2 then
-        if argn(2)==2& or(d==["native","double"]) then
-            typ=list(d)
-            d="*"
+function r=%sp_cumprod(varargin)
+    a = varargin(1)
+    dims = size(a);
+
+    nargs = size(varargin);
+    select nargs
+    case 1
+        d = "*";
+    case 2
+        if or(varargin(2) == ["native", "double"]) then
+            d = "*";
         else
-            typ=list()
+            d = varargin(2);
         end
+    case 3
+        d = varargin(2);
     else
-        typ=list(typ)
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"),"cumprod", 1, 3));
     end
-    if size(d,"*")<>1 then
-        if type(d)==10 then
+
+    // Check second argument : d
+    select type(d)
+    case 1
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumprod", 2))
+        end
+        if int(d) <> d | d < 0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"cumprod", 2, 1))
+        end
+    case 10 
+        if size(d,'*') <> 1 then
             error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",2))
-        else
-            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumprod",2))
         end
-    end
-
-    if type(d)==10 then
-        d=find(d==["m","*","r","c"])
-        if d==[] then
+        if and(d<>["r","c","*","m"]) then
             error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-            "cumprod",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+            "cumprod",2,"""*"",""r"",""c"",""m"""))
         end
-        d=d-2
-    end
-    dims=size(a);
 
-    if d==-1 then //'m'
-        d=find(dims>1,1)
-        if d==[] then d=0,end
-    end
-    if d<0 then
-        error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-        "cumprod",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+        pos = [1,2,0,find(dims>1,1)];
+        d=pos(find(d==["r","c","*","m"]))
+    else
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"cumprod",2))
     end
-
-
+    
     r=sparse(dims,0,dims)
     select d
     case 0 then
index f9bdb07..d3ec2b8 100644 (file)
@@ -7,41 +7,49 @@
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function r=%sp_cumsum(a,d,typ)
-    rhs=argn(2)
-    if rhs==1 then
-        d="*"
-    elseif rhs==2 then
-        if argn(2)==2& or(d==["native","double"]) then
-            d="*"
+function r=%sp_cumsum(varargin)
+    a = varargin(1)
+    dims = size(a);
+
+    nargs = size(varargin);
+    select nargs
+    case 1
+        d = "*";
+    case 2
+        if or(varargin(2) == ["native", "double"]) then
+            d = "*";
+        else
+            d = varargin(2);
         end
+    case 3
+        d = varargin(2);
+    else
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"),"cumsum", 1, 3));
     end
-    if size(d,"*")<>1 then
-        if type(d)==10 then
+
+    // Check second argument : d
+    select type(d)
+    case 1
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumsum", 2))
+        end
+        if int(d) <> d | d < 0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"cumsum", 2, 1))
+        end
+    case 10 
+        if size(d,'*') <> 1 then
             error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",2))
-        else
-            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumsum",2))
         end
-    end
-    if type(d)==10 then
-        d=find(d==["m","*","r","c"])
-        if d==[] then
+        if and(d<>["r","c","*","m"]) then
             error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-            "cumsum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+            "cumsum",2,"""*"",""r"",""c"",""m"""))
         end
-        d=d-2
-    end
-
-    dims=size(a)
-
-    if d==-1 then
-        //sum(x,'m'), determine the summation direction
-        d=find(dims>1,1)
-        if d==[] then d=0,end
-    end
-    if d<0 then
-        error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-        "cumsum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+        
+        pos = [1,2,0,find(dims>1,1)];
+        d=pos(find(d==["r","c","*","m"]))
+        
+    else
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"cumsum",2))
     end
 
     select d
index bd665e5..66bfc15 100644 (file)
@@ -7,40 +7,48 @@
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function r=%sp_prod(a,d,typ)
-    if argn(2)==1 then
-        d="*"
-    elseif argn(2)==2 then
-        if argn(2)==2& or(d==["native","double"]) then
-            d="*"
+function r=%sp_prod(varargin)
+    a = varargin(1)
+    dims = size(a);
 
-        end
-    end
-    if size(d,"*")<>1 then
-        if type(d)==10 then
-            error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",2))
+    nargs = size(varargin);
+    select nargs
+    case 1
+        d = "*";
+    case 2
+        if or(varargin(2) == ["native", "double"]) then
+            d = "*";
         else
-            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"prod",2))
+            d = varargin(2);
         end
+    case 3
+        d = varargin(2);
+    else
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"),"prod", 1, 3));
     end
 
-    if type(d)==10 then
-        d=find(d==["m","*","r","c"])
-        if d==[] then
+    // Check second argument : d
+    select type(d)
+    case 1
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"prod", 2))
+        end
+        if int(d) <> d | d < 0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"prod", 2, 1))
+        end
+    case 10 
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",2))
+        end
+        if and(d<>["r","c","*","m"]) then
             error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-            "prod",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+            "prod",2,"""*"",""r"",""c"",""m"""))
         end
-        d=d-2
-    end
-    dims=size(a);
-
-    if d==-1 then //'m'
-        d=find(dims>1,1)
-        if d==[] then d=0,end
-    end
-    if d<0 then
-        error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-        "prod",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+        
+        pos = [1,2,0,find(dims>1,1)];
+        d=pos(find(d==["r","c","*","m"]))
+    else
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"prod",2))
     end
 
     select d
index 308b526..da35c5a 100644 (file)
@@ -7,41 +7,50 @@
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function a=%sp_sum(a,d,typ)
-    rhs=argn(2)
-    if rhs==1 then
-        d="*"
-    elseif rhs==2 then
-        if argn(2)==2& or(d==["native","double"]) then
-            d="*"
+function a=%sp_sum(varargin)
+    a = varargin(1)
+    dims = size(a);
+
+    nargs = size(varargin);
+    select nargs
+    case 1
+        d = "*";
+    case 2
+        if or(varargin(2) == ["native", "double"]) then
+            d = "*";
+        else
+            d = varargin(2);
         end
+    case 3
+        d = varargin(2);
+    else
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"),"sum", 1, 3));
     end
-    if size(d,"*")<>1 then
-        if type(d)==10 then
+
+    // Check second argument : d
+    select type(d)
+    case 1
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"sum", 2))
+        end
+        if int(d) <> d | d < 0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"sum", 2, 1))
+        end
+    case 10 
+        if size(d,'*') <> 1 then
             error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",2))
-        else
-            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"sum",2))
         end
-    end
-    dims=size(a)
-    if type(d)==10 then
-        d=find(d==["m","*","r","c"])
-        if d==[] then
+        if and(d<>["r","c","*","m"]) then
             error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-            "sum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+            "sum",2,"""*"",""r"",""c"",""m"""))
         end
-        d=d-2
+        
+        pos = [1,2,0,find(dims>1,1)];
+        d=pos(find(d==["r","c","*","m"]))
+    else
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"sum",2))
     end
 
-    if d==-1 then
-        //sum(x,'m'), determine the summation direction
-        d=find(dims>1,1)
-        if d==[] then d=0,end
-    end
-    if d<0 then
-        error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-        "sum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
-    end
     select d
     case 0 then
         //sum of all elements
index 5073204..4044038 100644 (file)
@@ -7,47 +7,65 @@
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function r=%spb_cumprod(a,d,typ)
-    if argn(2)==1 then
-        typ=list()
-        d="*"
-    elseif argn(2)==2 then
-        if argn(2)==2& or(d==["native","double"]) then
-            typ=list(d)
-            d="*"
+function r = %spb_cumprod(varargin)
+    a = varargin(1)
+    dims = size(a);
+
+    nargs = size(varargin);
+    select nargs
+    case 1
+        d = "*";
+        typ = "double";
+    case 2
+        if or(varargin(2) == ["native", "double"]) then
+            d = "*";
+            typ = varargin(2);
         else
-            typ=list()
+            d = varargin(2);
+            typ = "double";
         end
+    case 3
+        d = varargin(2);
+        typ = varargin(3);
     else
-        typ=list(typ)
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"),"cumprod", 1, 3));
     end
-    if size(d,"*")<>1 then
-        if type(d)==10 then
+
+    // Check second argument : d
+    select type(d)
+    case 1
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumprod", 2))
+        end
+        if int(d) <> d | d < 0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"cumprod", 2, 1))
+        end
+    case 10 
+        if size(d,'*') <> 1 then
             error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",2))
-        else
-            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumprod",2))
         end
-    end
-
-    if type(d)==10 then
-        d=find(d==["m","*","r","c"])
-        if d==[] then
+        if and(d<>["r","c","*","m"]) then
             error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-            "cumprod",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+            "cumprod",2,"""*"",""r"",""c"",""m"""))
         end
-        d=d-2
+        pos = [1,2,0,find(dims>1,1)];
+        d=pos(find(d==["r","c","*","m"]))
+    else
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"cumprod",2))
     end
-    dims=size(a);
 
-    if d==-1 then //'m'
-        d=find(dims>1,1)
-        if d==[] then d=0,end
+    // Check third argument
+    if type(typ)<>10 then
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"cumprod",3))
     end
-    if d<0 then
-        error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-        "cumprod",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+
+    if size(typ,"*")<>1 then
+        error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumprod",3))
     end
 
+    if and(typ <> ["native" "double"]) then
+        error(msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"cumprod", 3, "native", "double"));
+    end
 
     r=sparse(dims,0,dims)
     select d
@@ -56,19 +74,19 @@ function r=%spb_cumprod(a,d,typ)
         if dims(1)==1 then
             l=find(diff(ij(:,2))>1,1)
             if l==[] then
-                r=sparse(ij,cumprod(v,typ(:)),dims)
+                r=sparse(ij,cumprod(v,typ),dims)
             else
-                r=sparse(ij(1:l,:),cumprod(v(1:l),typ(:)),dims)
+                r=sparse(ij(1:l,:),cumprod(v(1:l),typ),dims)
             end
         elseif dims(2)==1 then
             l=find(diff(ij(:,1))>1,1)
             if l==[] then
-                r=sparse(ij,cumprod(v,typ(:)),dims)
+                r=sparse(ij,cumprod(v,typ),dims)
             else
-                r=sparse(ij(1:l,:),cumprod(v(1:l),typ(:)),dims)
+                r=sparse(ij(1:l,:),cumprod(v(1:l),typ),dims)
             end
         else
-            r=matrix(cumprod(matrix(a,1,-1),typ(:)),dims)
+            r=matrix(cumprod(matrix(a,1,-1),typ),dims)
         end
     case 1 then
         ij=[];v=[];
@@ -78,10 +96,10 @@ function r=%spb_cumprod(a,d,typ)
                 l=find(diff(ijk(:,1))>1,1);
                 if l==[] then
                     ij=[ij;[ijk(:,1) k*ones(vk)]];
-                    v=[v;cumprod(vk,typ(:))];
+                    v=[v;cumprod(vk,typ)];
                 else
                     ij=[ij;[ijk(1:l,1) k*ones(l,1)]];
-                    v=[v;cumprod(vk(1:l,:),typ(:))];
+                    v=[v;cumprod(vk(1:l,:),typ)];
                 end
             end
         end
@@ -94,16 +112,16 @@ function r=%spb_cumprod(a,d,typ)
                 l=find(diff(ijk(:,2))>1,1)
                 if l==[] then
                     ij=[ij;[k*ones(vk) ijk(:,2)]];
-                    v=[v;cumprod(vk,typ(:))]
+                    v=[v;cumprod(vk,typ)]
                 else
                     ij=[ij;[k*ones(l,1),ijk(1:l,2)]];
-                    v=[v;cumprod(vk(1:l,:),typ(:))]
+                    v=[v;cumprod(vk(1:l,:),typ)]
                 end
             end
         end
         r=sparse(ij,v,dims)
     else
-        if typ==list("native")
+        if typ=="native"
             r=a
         else
             r=bool2s(a)
index df13b62..1745ccf 100644 (file)
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function r=%spb_cumsum(a,d,typ)
-    if argn(2)==1 then
-        typ=list()
-        d="*"
-    elseif argn(2)==2 then
-        if argn(2)==2& or(d==["native","double"]) then
-            typ=list(d)
-            d="*"
+function r = %spb_cumsum(varargin)
+    a = varargin(1)
+    dims = size(a);
+    
+    nargs = size(varargin);
+    select nargs
+    case 1
+        d = "*";
+        typ = "double";
+    case 2
+        if or(varargin(2) == ["native", "double"]) then
+            d = "*";
+            typ = varargin(2);
         else
-            typ=list()
+            d = varargin(2);
+            typ = "double";
         end
+    case 3
+        d = varargin(2);
+        typ = varargin(3);
     else
-        typ=list(typ)
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"),"cumsum", 1, 3));
     end
-    if size(d,"*")<>1 then
-        if type(d)==10 then
+    
+    // Check second argument : d
+    select type(d)
+    case 1
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumsum", 2))
+        end
+        if int(d) <> d | d < 0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"cumsum", 2, 1))
+        end
+    case 10 
+        if size(d,'*') <> 1 then
             error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",2))
-        else
-            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumsum",2))
         end
-    end
-
-    if type(d)==10 then
-        d=find(d==["m","*","r","c"])
-        if d==[] then
+        if and(d<>["r","c","*","m"]) then
             error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-            "cumsum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+            "cumsum",2,"""*"",""r"",""c"",""m"""))
         end
-        d=d-2
+        pos = [1,2,0,find(dims>1,1)];
+        d=pos(find(d==["r","c","*","m"]))
+    else
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"cumsum",2))
     end
 
-    dims=size(a)
+    // Check third argument
+    if type(typ)<>10 then
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"cumsum",3))
+    end
 
-    if d==-1 then
-        //sum(x,'m'), determine the summation direction
-        d=find(dims>1,1)
-        if d==[] then d=0,end
+    if size(typ,"*")<>1 then
+        error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",3))
     end
-    if d<0 then
-        error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-        "cumsum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+    
+    if and(typ <> ["native" "double"]) then
+        error(msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"cumsum", 3, "native", "double"));
     end
+    
+//    rhs=argn(2);
+//    dims=size(a)
+//    if rhs==1 then
+//        typ=list()
+//        d=0 //"*"
+//    else
+//        // call cumsum(a, d) or cumsum(a, d, typ)
+//        // d must be a string or scalar -> check type and size
+//        if and(type(d)<> [1, 10]) then
+//            error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"cumsum",2))
+//        end
+//
+//        if size(d,"*")<>1 then
+//            if type(d)==10 then
+//                error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",2))
+//            else
+//                error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"cumsum",2))
+//            end
+//        end
+//
+//        // call cumsum(a, d) with d = "native" or "double"
+//        if rhs == 2 & or(d==["native","double"]) then
+//            typ=list(d)
+//            d=0 //"*"
+//        else
+//            // call cumsum(a, d) with d is a string or scalar
+//            // or cumsum(a, d, typ)
+//            // If d is a string, d = "m", "c", "r" or "*"
+//            // Else d is an integer > 0
+//            if type(d)==10 then
+//                d=find(d==["m","*","r","c"])
+//                if d==[] then
+//                    error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+//                    "cumsum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+//                end
+//                d=d-2
+//            else
+//                if d<0 then
+//                    error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+//                    "cumsum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+//                end
+//            end
+//            
+//            if d==-1 then
+//                //cumsum(x,'m'), determine the summation direction
+//                d=find(dims>1,1)
+//                if d==[] then d=0,end
+//            end
+//
+//            if rhs == 3  then
+//                if type(typ)<>10 then
+//                    error(msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"cumsum",3))
+//                end
+//
+//                if size(typ,"*")<>1 then
+//                    error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"cumsum",3))
+//                end
+//
+//                if and(typ <> ["native", "double"])  then
+//                    error(msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"cumsum", 3, "native", "double"));
+//                end
+//                typ=list(typ)
+//            else
+//                typ=list()
+//            end
+//        end
+//    end
 
-    if typ<>list("native") then
+    if typ<>"native" then
         r=sparse(dims,0,dims);
     else
         r=sparse(dims,%f,dims);
@@ -62,20 +147,20 @@ function r=%spb_cumsum(a,d,typ)
         if size(ij,1)==0 then return,end
         if dims(1)==1 then
             mnj=min(ij(:,2))
-            r(1,mnj:$)=sparse(cumsum(full(a(1,mnj:$)),typ(:)))
+            r(1,mnj:$)=sparse(cumsum(full(a(1,mnj:$)),typ))
         elseif dims(2)==1 then
             mni=min(ij(:,1))
-            r(mni:$,1)=sparse(cumsum(full(a(mni:$,1)),typ(:)))
+            r(mni:$,1)=sparse(cumsum(full(a(mni:$,1)),typ))
         else
             mnj=min(ij(:,2))
-            r(:,mnj:dims(2))=sparse(cumsum(full(a(:,mnj:$)),typ(:)))
+            r(:,mnj:dims(2))=sparse(cumsum(full(a(:,mnj:$)),typ))
         end
     case 1 then
         for k=1:dims(2)
             ij=spget(a(:,k))
             if size(ij,1)<>0 then
                 mni=min(ij(:,1))
-                r(mni:$,k)=sparse(cumsum(full(a(mni:$,k)),typ(:)))
+                r(mni:$,k)=sparse(cumsum(full(a(mni:$,k)),typ))
             end
         end
     case 2 then
@@ -83,11 +168,11 @@ function r=%spb_cumsum(a,d,typ)
             ij=spget(a(k,:))
             if size(ij,1)<>0 then
                 mnj=min(ij(:,2))
-                r(k,mnj:$)=sparse(cumsum(full(a(k,mnj:$)),typ(:)))
+                r(k,mnj:$)=sparse(cumsum(full(a(k,mnj:$)),typ))
             end
         end
     else
-        if typ==list("native") then
+        if typ=="native" then
             r=a
         else
             r=bool2s(a)
index 3cb06d8..cc70125 100644 (file)
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function r=%spb_prod(a,d,typ)
-    if argn(2)==1 then
-        typ=list()
-        d="*"
-    elseif argn(2)==2 then
-        if argn(2)==2& or(d==["native","double"]) then
-            typ=list(d)
-            d="*"
+function r=%spb_prod(varargin)
+    a = varargin(1)
+    dims = size(a);
+
+    nargs = size(varargin);
+    select nargs
+    case 1
+        d = "*";
+        typ = "double";
+    case 2
+        if or(varargin(2) == ["native", "double"]) then
+            d = "*";
+            typ = varargin(2);
         else
-            typ=list()
+            d = varargin(2);
+            typ = "double";
         end
+    case 3
+        d = varargin(2);
+        typ = varargin(3);
     else
-        typ=list(typ)
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"),"prod", 1, 3));
     end
-    if size(d,"*")<>1 then
-        if type(d)==10 then
+
+    // Check second argument : d
+    select type(d)
+    case 1
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"prod", 2))
+        end
+        if int(d) <> d | d < 0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"prod", 2, 1))
+        end
+    case 10 
+        if size(d,'*') <> 1 then
             error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",2))
-        else
-            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"prod",2))
         end
-    end
-
-    if type(d)==10 then
-        d=find(d==["m","*","r","c"])
-        if d==[] then
+        if and(d<>["r","c","*","m"]) then
             error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-            "prod",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+            "prod",2,"""*"",""r"",""c"",""m"""))
         end
-        d=d-2
+        pos = [1,2,0,find(dims>1,1)];
+        d=pos(find(d==["r","c","*","m"]))
+    else
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"prod",2))
     end
-    dims=size(a);
 
-    if d==-1 then //'m'
-        d=find(dims>1,1)
-        if d==[] then d=0,end
+    // Check third argument
+    if type(typ)<>10 then
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"prod",3))
     end
-    if d<0 then
-        error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-        "prod",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+
+    if size(typ,"*")<>1 then
+        error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",3))
     end
 
+    if and(typ <> ["native" "double"]) then
+        error(msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"prod", 3, "native", "double"));
+    end
+    
+//    rhs = argn(2);
+//    dims=size(a);
+//    if rhs==1 then
+//        typ="double";
+//        d=0 //"*"
+//    else
+//        // call prod(a, d) or prod(a, d, typ)
+//        // d must be a string or scalar -> check type and size
+//        if and(type(d)<> [1, 10]) then
+//            error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"prod",2))
+//        end
+//
+//        if size(d,"*")<>1 then
+//            if type(d)==10 then
+//                error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",2))
+//            else
+//                error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"prod",2))
+//            end
+//        end
+//
+//        // call prod(a, d) with d = "native" or "double"
+//        if rhs == 2 & or(d==["native","double"]) then
+//            typ=d;
+//            d=0 //"*"
+//        else
+//            // If d is a string, d = "m", "*", "r" or "c"
+//            // Else d is an integer > 0
+//            if type(d)==10 then
+//                d=find(d==["m","*","r","c"])
+//                if d==[] then
+//                    error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+//                    "prod",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+//                end
+//                d=d-2
+//            else
+//                if d<0 then
+//                    error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+//                    "prod",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+//                end
+//            end
+//
+//            if d==-1 then //'m'
+//                d=find(dims>1,1)
+//                if d==[] then d=0,end
+//            end
+//
+//            // call prod(a, d, typ)
+//            // typ must be a string, equal to "native" or "double"
+//            if rhs == 3  then
+//                if type(typ)<>10 then
+//                    error(msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"prod",3))
+//                end
+//
+//                if size(typ,"*")<>1 then
+//                    error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"prod",3))
+//                end
+//
+//                if and(typ <> ["native", "double"])  then
+//                    error(msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"prod", 3, "native", "double"));
+//                end
+//            else
+//                typ="double"
+//            end
+//        end
+//    end
+
     select d
     case 0 then
         ij=spget(a)
         r=size(ij,1)==prod(dims)
-        if typ<>list("native") then r=bool2s(r),end
+        if typ<>"native" then r=bool2s(r),end
     case 1 then
         for k=1:dims(2)
-            r(1,k)=prod(a(:,k),typ(:))
+            r(1,k)=prod(a(:,k),typ)
         end
         r=sparse(r)
     case 2 then
         for k=1:dims(1)
-            r(k,1)=prod(a(k,:),typ(:))
+            r(k,1)=prod(a(k,:),typ)
         end
         r=sparse(r)
     else
         r=a
-        if typ<>list("native") then r=bool2s(r),end
+        if typ<>"native" then r=bool2s(r),end
     end
 
 endfunction
index 24f76a2..8696555 100644 (file)
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function r=%spb_sum(a,d,typ)
-    rhs=argn(2)
-    if rhs==1 then
-        d="*"
-        typ="double"
-    elseif rhs==2 then
-        if or(d==["native","double"]) then
-            typ=d
-            d="*"
+function r=%spb_sum(varargin)
+    a = varargin(1)
+    dims = size(a);
+
+    nargs = size(varargin);
+    select nargs
+    case 1
+        d = "*";
+        typ = "double";
+    case 2
+        if or(varargin(2) == ["native", "double"]) then
+            d = "*";
+            typ = varargin(2);
         else
-            typ="double"
+            d = varargin(2);
+            typ = "double";
         end
+    case 3
+        d = varargin(2);
+        typ = varargin(3);
+    else
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"),"sum", 1, 3));
     end
 
-    if size(d,"*")<>1 then
-        if type(d)==10 then
+    // Check second argument : d
+    select type(d)
+    case 1
+        if size(d,'*') <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"sum", 2))
+        end
+        if int(d) <> d | d < 0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"sum", 2, 1))
+        end
+    case 10 
+        if size(d,'*') <> 1 then
             error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",2))
-        else
-            error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"sum",2))
         end
-    end
-    dims=size(a)
-    if type(d)==10 then
-        d=find(d==["m","*","r","c"])
-        if d==[] then
+        if and(d<>["r","c","*","m"]) then
             error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-            "sum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+            "sum",2,"""*"",""r"",""c"",""m"""))
         end
-        d=d-2
+        pos = [1,2,0,find(dims>1,1)];
+        d=pos(find(d==["r","c","*","m"]))
+    else
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"sum",2))
     end
 
-    if d==-1 then
-        //sum(x,'m'), determine the summation direction
-        d=find(dims>1,1)
-        if d==[] then d=0,end
+    // Check third argument
+    if type(typ)<>10 then
+        error(msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"sum",3))
     end
-    if d<0 then
-        error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-        "sum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+
+    if size(typ,"*")<>1 then
+        error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",3))
     end
 
+    if and(typ <> ["native" "double"]) then
+        error(msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"sum", 3, "native", "double"));
+    end
+    
+//    rhs=argn(2)
+//    if rhs==1 then
+//        d=0 //"*"
+//        typ="double"
+//    else
+//        // call sum(a, d) or sum(a, d, typ)
+//        // d must be a string or scalar -> check type and size
+//        if and(type(d)<> [1, 10]) then
+//            error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"sum",2))
+//        end
+//
+//        if size(d,"*")<>1 then
+//            if type(d)==10 then
+//                error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",2))
+//            else
+//                error(msprintf(_("%s: Wrong size for input argument #%d: A scalar expected.\n"),"sum",2))
+//            end
+//        end
+//
+//        // call sum(a, d) with d = "native" or "double"
+//        if rhs == 2 & or(d==["native","double"]) then
+//            typ=d
+//            d=0 //"*"
+//        else
+//            // If d is a string, d = "m", "r", "c" or "*"
+//            // Else d is an integer > 0
+//            if type(d)==10 then
+//                d=find(d==["m","*","r","c"])
+//                if d==[] then
+//                    error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+//                    "sum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+//                end
+//                d=d-2
+//            else
+//                if d<0 then
+//                    error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+//                    "sum",2,"""*"",""r"",""c"",""m"",1:"+string(ndims(a))))
+//                end
+//            end
+//
+//            // call sum(a, d, typ)
+//            // typ must be a string and typ must be equal to "native" or "double"
+//            // check typ or size
+//            if rhs == 3  then
+//                if type(typ)<>10 then
+//                    error(msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"sum",3))
+//                end
+//
+//                if size(typ,"*")<>1 then
+//                    error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sum",3))
+//                end
+//
+//                if and(typ <> ["native", "double"])  then
+//                    error(msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"sum", 3, "native", "double"));
+//                end
+//            else
+//                typ="double"
+//            end
+//        end
+//    end
+//
+//    dims=size(a)
+//
+//    if d==-1 then
+//        //sum(x,'m'), determine the summation direction
+//        d=find(dims>1,1)
+//        if d==[] then d=0,end
+//    end
+
     ij=spget(a);
     select d
     case 0 then