From: Samuel GOUGEON Date: Sat, 14 Mar 2020 22:37:05 +0000 (+0100) Subject: * Bug 16365 fixed: median(m,'r'|'c') was wrong after 5dc990 X-Git-Url: http://gitweb.scilab.org/?p=scilab.git;a=commitdiff_plain;h=0f15dd6817fa6b6665bdb5090b4bc7322d5d51e5 * Bug 16365 fixed: median(m,'r'|'c') was wrong after 5dc990 http://bugzilla.scilab.org/16365 Change-Id: I4c269f9f06ed89ba2ad99899b36068142e1468eb --- diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md index f8ac952..49f0d86 100644 --- a/scilab/CHANGES.md +++ b/scilab/CHANGES.md @@ -264,10 +264,10 @@ Known issues Bug Fixes --------- -### Bugs fixed in 6.1.0: +### Bugs fixed in 6.1.1: * [#3188](https://bugzilla.scilab.org/3188): `part()` was slower than in Scilab 4.1.2. * [#16342](https://bugzilla.scilab.org/16342): `strcat()` was much slower in Scilab 6.0.2. - +* [#16365](https://bugzilla.scilab.org/16365): `median(m,"r")` and `median(m,"c")` yielded wrong results (6.1.0 regression) ### Bugs fixed in 6.1.0: * [#2694](https://bugzilla.scilab.org/2694): `bitget` did not accept positive integers of types int8, int16 or int32. diff --git a/scilab/modules/statistics/macros/median.sci b/scilab/modules/statistics/macros/median.sci index d003790..6bd1e64 100644 --- a/scilab/modules/statistics/macros/median.sci +++ b/scilab/modules/statistics/macros/median.sci @@ -99,7 +99,7 @@ function y = median(x,orient) n = xsize(orient) for k = 1:N for i = 1:M - ytemp = gsort(x(i+(0:n-1)*M+(k-1)*P),"r","i") + ytemp = gsort(x(i+(0:n-1)'*M+(k-1)*P),"r","i") if 2*int(n/2)==n then // avoid overflow: http://bugzilla.scilab.org/14640 a = ytemp(n/2) diff --git a/scilab/modules/statistics/tests/nonreg_tests/bug_16365.tst b/scilab/modules/statistics/tests/nonreg_tests/bug_16365.tst new file mode 100644 index 0000000..de3ab78 --- /dev/null +++ b/scilab/modules/statistics/tests/nonreg_tests/bug_16365.tst @@ -0,0 +1,54 @@ +// =================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2020 - Samuel GOUGEON +// +// This file is distributed under the same license as the Scilab package. +// =================================================================== + +// <-- CLI SHELL MODE --> +// <-- NO CHECK REF --> +// <-- Non-regression test for bug 16365 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/16365 +// +// <-- Short Description --> +// median(m,"r") and median(m,"c") were wrong +// =================================================================== + +m = [ + 2. 8. 9. 6. 9. 4. + 2. 3. 4. 6. 8. 6. + 4. 5. 7. 6. 6. 5. + 5. 5. 6. 3. 5. 0. + 4. 0. 9. 0. 3. 7. + 1. 6. 9. 1. 3. 6. + 9. 9. 3. 2. 7. 5. + 5. 0. 9. 9. 8. 4. + ]; + +//--> gsort(m,"r","i") +// ans = +// 1. 0. 3. 0. 3. 0. +// 2. 0. 4. 1. 3. 4. +// 2. 3. 6. 2. 5. 4. +// 4. 5. 7. 3. 6. 5. +// 4. 5. 9. 6. 7. 5. +// 5. 6. 9. 6. 8. 6. +// 5. 8. 9. 6. 8. 6. +// 9. 9. 9. 9. 9. 7. +ref=[4 5 8 4.5 6.5 5 ]; +assert_checkequal(median(m,"r"), ref); + +//--> gsort(m,"c","i") +// ans = +// 2. 4. 6. 8. 9. 9. +// 2. 3. 4. 6. 6. 8. +// 4. 5. 5. 6. 6. 7. +// 0. 3. 5. 5. 5. 6. +// 0. 0. 3. 4. 7. 9. +// 1. 1. 3. 6. 6. 9. +// 2. 3. 5. 7. 9. 9. +// 0. 4. 5. 8. 9. 9. +ref = [7 5 5.5 5 3.5 4.5 6 6.5]'; +assert_checkequal(median(m,"c"), ref);