[sum] fix about m argument 88/19488/3
Cedric Delamarre [Wed, 18 Oct 2017 10:35:33 +0000 (12:35 +0200)]
  test_run elementary_functions sum
  test_run elementary_functions sum mode_nwni_profiling

Change-Id: I11582ed22093a30f8904673b0e86a807ef65c031

scilab/modules/elementary_functions/sci_gateway/cpp/sci_sum.cpp
scilab/modules/elementary_functions/tests/unit_tests/sum.tst

index 945bf3f..49d6edc 100644 (file)
@@ -118,24 +118,9 @@ types::Function::ReturnValue sci_sum(types::typed_list &in, int _iRetCount, type
             }
             else if (wcscmp(wcsString, L"m") == 0)
             {
-                int iDims = 0;
-                int* piDimsArray = NULL;
-
-                if (pDblIn)
-                {
-                    iDims = pDblIn->getDims();
-                    piDimsArray = pDblIn->getDimsArray();
-                }
-                else if (pIntIn)
-                {
-                    iDims = pIntIn->getDims();
-                    piDimsArray = pIntIn->getDimsArray();
-                }
-                else
-                {
-                    iDims = pPolyIn->getDims();
-                    piDimsArray = pPolyIn->getDimsArray();
-                }
+                types::GenericType* pGT = in[0]->getAs<types::GenericType>();
+                int iDims = pGT->getDims();
+                int* piDimsArray = pGT->getDimsArray();
 
                 // old function was "mtlsel"
                 for (int i = 0; i < iDims; i++)
index 977d802..dc13f0f 100644 (file)
@@ -334,5 +334,13 @@ 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
+//=======================================================================
+//"m" option"
+
+d=[1 10;254 9];
+assert_checkequal(sum(d, "m"), sum(d, "r"));
+d=[1 10 254 9];
+assert_checkequal(sum(d, "m"), sum(d, "c"));
+d=d';
+assert_checkequal(sum(d, "m"), sum(d, "r"));