From 2bf7a3cd98da290fb569b3debefa962d30900720 Mon Sep 17 00:00:00 2001 From: Samuel GOUGEON Date: Thu, 30 Apr 2015 11:31:03 +0200 Subject: [PATCH] * Bug #13829 fixed - mean and sum functions returned wrong results for hypermatrices. Change-Id: I1af531e81306fc2a61b290fb6e3a2c614ac456dd --- scilab/CHANGES_5.5.X | 5 ++++ scilab/modules/overloading/macros/%hm_sum.sci | 27 ++++++++++---------- .../tests/nonreg_tests/bug_13829.dia.ref | 21 +++++++++++++++ .../overloading/tests/nonreg_tests/bug_13829.tst | 24 +++++++++++++++++ 4 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 scilab/modules/overloading/tests/nonreg_tests/bug_13829.dia.ref create mode 100644 scilab/modules/overloading/tests/nonreg_tests/bug_13829.tst diff --git a/scilab/CHANGES_5.5.X b/scilab/CHANGES_5.5.X index 4196723..a3e15bc 100644 --- a/scilab/CHANGES_5.5.X +++ b/scilab/CHANGES_5.5.X @@ -1,6 +1,11 @@ Changes between version 5.5.2 and 5.5.3 ======================================= +Scilab Bug Fixes +================ + +* Bug #13829 fixed - mean and sum functions returned wrong results for hypermatrices. + Changes between version 5.5.1 and 5.5.2 diff --git a/scilab/modules/overloading/macros/%hm_sum.sci b/scilab/modules/overloading/macros/%hm_sum.sci index 95ccad5..78efba6 100644 --- a/scilab/modules/overloading/macros/%hm_sum.sci +++ b/scilab/modules/overloading/macros/%hm_sum.sci @@ -43,14 +43,14 @@ function a = %hm_sum(varargin) // Check second argument : d select type(d) case 1 - if size(d,'*') <> 1 then + 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 + 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 @@ -77,27 +77,28 @@ function a = %hm_sum(varargin) end if d == 0 then // '*' - a=sum(a.entries, "*", typ), dims; + 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. if typ == "double" & or(tm == [4 8]) then - a.entries=double(a.entries), + a.entries = double(a.entries), end 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=sum(a,1,typ); + 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) = [] + dims = dims(1:$-1) + p(1) = p($) + p($) = [] else - dims(d)=1 + dims(d) = 1 end - a=permute(matrix(a,dims(p)),p) + a = permute(matrix(a,dims(p)),p) end endfunction diff --git a/scilab/modules/overloading/tests/nonreg_tests/bug_13829.dia.ref b/scilab/modules/overloading/tests/nonreg_tests/bug_13829.dia.ref new file mode 100644 index 0000000..4d53383 --- /dev/null +++ b/scilab/modules/overloading/tests/nonreg_tests/bug_13829.dia.ref @@ -0,0 +1,21 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2015 - Scilab Enterprises - Vincent COUVERT +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// <-- Non-regression test for bug 13829 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/show_bug.cgi?id=13829 +// +// <-- Short Description --> +// mean and sum functions returned wrong results for hypermatrices. +a = matrix(1:24, 1:4); +s = sum(a,4); +ref = matrix([40 44 48 52 56 60], 1:3); +assert_checkequal(s, ref); +a = ones(1,2,3,4); +m = mean(a,4); +ref = ones(1,2,3,1); +assert_checkequal(m, ref); diff --git a/scilab/modules/overloading/tests/nonreg_tests/bug_13829.tst b/scilab/modules/overloading/tests/nonreg_tests/bug_13829.tst new file mode 100644 index 0000000..ce244bd --- /dev/null +++ b/scilab/modules/overloading/tests/nonreg_tests/bug_13829.tst @@ -0,0 +1,24 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2015 - Scilab Enterprises - Vincent COUVERT +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= + +// <-- Non-regression test for bug 13829 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/show_bug.cgi?id=13829 +// +// <-- Short Description --> +// mean and sum functions returned wrong results for hypermatrices. + +a = matrix(1:24, 1:4); +s = sum(a,4); +ref = matrix([40 44 48 52 56 60], 1:3); +assert_checkequal(s, ref); + +a = ones(1,2,3,4); +m = mean(a,4); +ref = ones(1,2,3,1); +assert_checkequal(m, ref); \ No newline at end of file -- 1.7.9.5