// 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
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
--- /dev/null
+// =============================================================================
+// 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);
--- /dev/null
+// =============================================================================
+// 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