summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel GOUGEON <sgougeon@free.fr>2020-03-14 23:37:05 +0100
committerClément DAVID <clement.david@esi-group.com>2020-04-01 15:20:04 +0200
commit8937019ec7463bc7e92352d783b18861f6bc2723 (patch)
tree8c326125f9bdb6934540d998658a4490fb9d59cb
parent6ab071d525918b0c5b5b7a16e0b1415783bbc2cc (diff)
downloadscilab-8937019ec7463bc7e92352d783b18861f6bc2723.zip
scilab-8937019ec7463bc7e92352d783b18861f6bc2723.tar.gz
* Bug 16365 fixed: median(m,'r'|'c') was wrong after 5dc990
http://bugzilla.scilab.org/16365 Change-Id: I4c269f9f06ed89ba2ad99899b36068142e1468eb
-rw-r--r--scilab/CHANGES.md4
-rw-r--r--scilab/modules/statistics/macros/median.sci2
-rw-r--r--scilab/modules/statistics/tests/nonreg_tests/bug_16365.tst54
3 files changed, 57 insertions, 3 deletions
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
264Bug Fixes 264Bug Fixes
265--------- 265---------
266 266
267### Bugs fixed in 6.1.0: 267### Bugs fixed in 6.1.1:
268* [#3188](https://bugzilla.scilab.org/3188): `part()` was slower than in Scilab 4.1.2. 268* [#3188](https://bugzilla.scilab.org/3188): `part()` was slower than in Scilab 4.1.2.
269* [#16342](https://bugzilla.scilab.org/16342): `strcat()` was much slower in Scilab 6.0.2. 269* [#16342](https://bugzilla.scilab.org/16342): `strcat()` was much slower in Scilab 6.0.2.
270 270* [#16365](https://bugzilla.scilab.org/16365): `median(m,"r")` and `median(m,"c")` yielded wrong results (6.1.0 regression)
271 271
272### Bugs fixed in 6.1.0: 272### Bugs fixed in 6.1.0:
273* [#2694](https://bugzilla.scilab.org/2694): `bitget` did not accept positive integers of types int8, int16 or int32. 273* [#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)
99 n = xsize(orient) 99 n = xsize(orient)
100 for k = 1:N 100 for k = 1:N
101 for i = 1:M 101 for i = 1:M
102 ytemp = gsort(x(i+(0:n-1)*M+(k-1)*P),"r","i") 102 ytemp = gsort(x(i+(0:n-1)'*M+(k-1)*P),"r","i")
103 if 2*int(n/2)==n then 103 if 2*int(n/2)==n then
104 // avoid overflow: http://bugzilla.scilab.org/14640 104 // avoid overflow: http://bugzilla.scilab.org/14640
105 a = ytemp(n/2) 105 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 @@
1// ===================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2020 - Samuel GOUGEON
4//
5// This file is distributed under the same license as the Scilab package.
6// ===================================================================
7
8// <-- CLI SHELL MODE -->
9// <-- NO CHECK REF -->
10// <-- Non-regression test for bug 16365 -->
11//
12// <-- Bugzilla URL -->
13// http://bugzilla.scilab.org/16365
14//
15// <-- Short Description -->
16// median(m,"r") and median(m,"c") were wrong
17// ===================================================================
18
19m = [
20 2. 8. 9. 6. 9. 4.
21 2. 3. 4. 6. 8. 6.
22 4. 5. 7. 6. 6. 5.
23 5. 5. 6. 3. 5. 0.
24 4. 0. 9. 0. 3. 7.
25 1. 6. 9. 1. 3. 6.
26 9. 9. 3. 2. 7. 5.
27 5. 0. 9. 9. 8. 4.
28 ];
29
30//--> gsort(m,"r","i")
31// ans =
32// 1. 0. 3. 0. 3. 0.
33// 2. 0. 4. 1. 3. 4.
34// 2. 3. 6. 2. 5. 4.
35// 4. 5. 7. 3. 6. 5.
36// 4. 5. 9. 6. 7. 5.
37// 5. 6. 9. 6. 8. 6.
38// 5. 8. 9. 6. 8. 6.
39// 9. 9. 9. 9. 9. 7.
40ref=[4 5 8 4.5 6.5 5 ];
41assert_checkequal(median(m,"r"), ref);
42
43//--> gsort(m,"c","i")
44// ans =
45// 2. 4. 6. 8. 9. 9.
46// 2. 3. 4. 6. 6. 8.
47// 4. 5. 5. 6. 6. 7.
48// 0. 3. 5. 5. 5. 6.
49// 0. 0. 3. 4. 7. 9.
50// 1. 1. 3. 6. 6. 9.
51// 2. 3. 5. 7. 9. 9.
52// 0. 4. 5. 8. 9. 9.
53ref = [7 5 5.5 5 3.5 4.5 6 6.5]';
54assert_checkequal(median(m,"c"), ref);