summaryrefslogtreecommitdiffstats
path: root/scilab
diff options
context:
space:
mode:
authorSamuel GOUGEON <sgougeon@free.fr>2020-06-14 15:09:29 +0200
committerCedric Delamarre <cdl@esi-group.com>2020-10-15 17:00:14 +0200
commite50643345711b45e84722acd5e20db0be3da36d2 (patch)
tree47eb30f9de99b2ec509432caed293343c384275e /scilab
parent2357ccb649d9d916dc9c0e8c95d9027d4e05b5ee (diff)
downloadscilab-e50643345711b45e84722acd5e20db0be3da36d2.zip
scilab-e50643345711b45e84722acd5e20db0be3da36d2.tar.gz
gsort_multilevel: special degenerate case fixed
test_run elementary_functions gsort* Change-Id: I317be9d294fa6f2e62e5406760e0eadcf7e04419
Diffstat (limited to 'scilab')
-rw-r--r--scilab/modules/elementary_functions/macros/%gsort_multilevel.sci7
-rw-r--r--scilab/modules/elementary_functions/sci_gateway/cpp/sci_gsort.cpp9
-rw-r--r--scilab/modules/elementary_functions/tests/unit_tests/gsort_multilevel_complex.tst7
3 files changed, 13 insertions, 10 deletions
diff --git a/scilab/modules/elementary_functions/macros/%gsort_multilevel.sci b/scilab/modules/elementary_functions/macros/%gsort_multilevel.sci
index adb78ed..af744bb 100644
--- a/scilab/modules/elementary_functions/macros/%gsort_multilevel.sci
+++ b/scilab/modules/elementary_functions/macros/%gsort_multilevel.sci
@@ -178,15 +178,18 @@ function v = %gsort_eval(a, fun)
178 params = fun 178 params = fun
179 params(1) = null() 179 params(1) = null()
180 fun = fun(1) 180 fun = fun(1)
181 if typeof(fun)=="fptr" & fun==atan & type(a)==1 & ~isreal(a) 181 if typeof(fun)=="fptr" & fun==atan & type(a)==1
182 v = fun(imag(a), real(a)) + params(1) 182 v = fun(imag(a), real(a)) + params(1)
183 else 183 else
184 v = fun(a, params(:)) 184 v = fun(a, params(:))
185 end 185 end
186 elseif typeof(fun)=="fptr" & fun==atan & type(a)==1 & ~isreal(a) 186
187 elseif typeof(fun)=="fptr" & fun==atan & type(a)==1
187 v = atan(imag(a), real(a)) 188 v = atan(imag(a), real(a))
189
188 elseif typeof(fun)=="implicitlist" & (1:1:$)==fun 190 elseif typeof(fun)=="implicitlist" & (1:1:$)==fun
189 v = a 191 v = a
192
190 else 193 else
191 v = fun(a) 194 v = fun(a)
192 end 195 end
diff --git a/scilab/modules/elementary_functions/sci_gateway/cpp/sci_gsort.cpp b/scilab/modules/elementary_functions/sci_gateway/cpp/sci_gsort.cpp
index 20c4b31..86b9996 100644
--- a/scilab/modules/elementary_functions/sci_gateway/cpp/sci_gsort.cpp
+++ b/scilab/modules/elementary_functions/sci_gateway/cpp/sci_gsort.cpp
@@ -63,7 +63,8 @@ types::Function::ReturnValue sci_gsort(types::typed_list &in, int _iRetCount, ty
63 63
64 // Get the sorting method, always as argin#2 for all generic types 64 // Get the sorting method, always as argin#2 for all generic types
65 // ---------------------- 65 // ----------------------
66 char* msg = _("%s: Argument #%d: 'g','r','c','lc','lr' or integer in [1, %d] expected.\n"); 66 char* msg = _("%s: Argument #%d: Must be in the set {%s} or integer in range [%d, %d].\n");
67 std::string argSetError = "'g','r','c','lc','lr'";
67 std::wstring wstrProcess = L"g"; 68 std::wstring wstrProcess = L"g";
68 int iOrientation = 0; 69 int iOrientation = 0;
69 int ndims = static_cast<int>(pGTIn->getDims()); 70 int ndims = static_cast<int>(pGTIn->getDims());
@@ -84,7 +85,7 @@ types::Function::ReturnValue sci_gsort(types::typed_list &in, int _iRetCount, ty
84 85
85 if (iOrientation <= 0 || iOrientation > ndims) 86 if (iOrientation <= 0 || iOrientation > ndims)
86 { 87 {
87 Scierror(999, msg, "gsort", 2, ndims); 88 Scierror(999, msg, "gsort", 2, argSetError.data(), 1, ndims);
88 return types::Function::Error; 89 return types::Function::Error;
89 } 90 }
90 if ( iOrientation == 1 ) 91 if ( iOrientation == 1 )
@@ -99,7 +100,7 @@ types::Function::ReturnValue sci_gsort(types::typed_list &in, int _iRetCount, ty
99 } 100 }
100 else if (in[1]->isString() == false) 101 else if (in[1]->isString() == false)
101 { 102 {
102 Scierror(999, msg, "gsort", 2, ndims); 103 Scierror(999, msg, "gsort", 2, argSetError.data(), 1, ndims);
103 return types::Function::Error; 104 return types::Function::Error;
104 } 105 }
105 else 106 else
@@ -112,7 +113,7 @@ types::Function::ReturnValue sci_gsort(types::typed_list &in, int _iRetCount, ty
112 wstrProcess != L"lc" && 113 wstrProcess != L"lc" &&
113 wstrProcess != L"lr") 114 wstrProcess != L"lr")
114 { 115 {
115 Scierror(999, msg, "gsort", 2, ndims); 116 Scierror(999, msg, "gsort", 2, argSetError.data(), 1, ndims);
116 return types::Function::Error; 117 return types::Function::Error;
117 } 118 }
118 } 119 }
diff --git a/scilab/modules/elementary_functions/tests/unit_tests/gsort_multilevel_complex.tst b/scilab/modules/elementary_functions/tests/unit_tests/gsort_multilevel_complex.tst
index 1e395bc..18daee2 100644
--- a/scilab/modules/elementary_functions/tests/unit_tests/gsort_multilevel_complex.tst
+++ b/scilab/modules/elementary_functions/tests/unit_tests/gsort_multilevel_complex.tst
@@ -53,7 +53,7 @@ y = complex(A,B);
53assert_checkequal(b, [3 2 1 4 5]); 53assert_checkequal(b, [3 2 1 4 5]);
54assert_checkequal(y(b), a); 54assert_checkequal(y(b), a);
55 55
56refMsg = msprintf(_("%s: Argument #%d: Must be in the set {%s}.\n"), "gsort", 2, "''g'',''r'',''c'',''lc'',''lr''"); 56refMsg = msprintf(_("%s: Argument #%d: Must be in the set {%s} or integer in range [%d, %d].\n"), "gsort", 2, "''g'',''r'',''c'',''lc'',''lr''", 1, 2);
57assert_checkerror("[a,b] = gsort(y,''l'')", refMsg); 57assert_checkerror("[a,b] = gsort(y,''l'')", refMsg);
58 58
59ierr = execstr("[a,b] = gsort(y,''g'');","errcatch"); 59ierr = execstr("[a,b] = gsort(y,''g'');","errcatch");
@@ -74,7 +74,7 @@ assert_checkequal(ierr, 0);
74// ------------------------------------------------------------------- 74// -------------------------------------------------------------------
75// Error messages 75// Error messages
76// ------------------------------------------------------------------- 76// -------------------------------------------------------------------
77msg = msprintf(_("%s: Argument #%d: Must be in the set {%s}.\n"), "gsort", 2, "''g'',''r'',''c'',''lc'',''lr''"); 77msg = msprintf(_("%s: Argument #%d: Must be in the set {%s} or integer in range [%d, %d].\n"), "gsort", 2, "''g'',''r'',''c'',''lc'',''lr''", 1, 2);
78assert_checkerror("gsort(%i,''q'')", msg); 78assert_checkerror("gsort(%i,''q'')", msg);
79msg = msprintf(_("%s: Argument #%d: Text(s) expected.\n"), "gsort", 3); 79msg = msprintf(_("%s: Argument #%d: Text(s) expected.\n"), "gsort", 3);
80assert_checkerror("gsort(%i,''g'',1)", msg); 80assert_checkerror("gsort(%i,''g'',1)", msg);
@@ -258,8 +258,7 @@ end
258m = complex([7 6 9 2 8 1 0 4 3 2], 0); 258m = complex([7 6 9 2 8 1 0 4 3 2], 0);
259assert_checkequal(gsort(m, "g", "i", list(atan)), m); 259assert_checkequal(gsort(m, "g", "i", list(atan)), m);
260assert_checkequal(gsort(m, "g", "i", list(imag)), m); 260assert_checkequal(gsort(m, "g", "i", list(imag)), m);
261//assert_checkequal(gsort(m, "g", ["i" "i"], list(imag, atan)), m); 261assert_checkequal(gsort(m, "g", ["i" "i"], list(imag, atan)), m);
262// zeros(n,2) is actually sorted, while it should be preserved. TO BE INVESTIGATED
263assert_checkequal(gsort(m+%i, "g", "d", list(imag)), m+%i); 262assert_checkequal(gsort(m+%i, "g", "d", list(imag)), m+%i);
264 263
265// ------------------------------------------------------------------- 264// -------------------------------------------------------------------