// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) INRIA
+// Copyright (C) Samuel GOUGEON - 2015 : http://bugzilla.scilab.org/13829
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// 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"),"prod", 2))
end
if int(d) <> d | d < 0 then
error(msprintf(_("%s: Wrong value for input argument #%d: Integer >= %d expected.\n"),"prod", 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"),"prod",2))
end
if and(d<>["r","c","*","m"]) then
end
if d == 0 then // '*'
- a=prod(a.entries, "*", typ), dims;
+ a = prod(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
+ 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=prod(a,1,typ);
- //permute back
- if d==size(dims, "*") then
- dims=dims(1:$-1)
- p(1) = []
+ p = 1:size(dims,"*")
+ p([1,d]) = p([d,1])
+ a = matrix(permute(a,p), dims(d), -1)
+ // Multiplying
+ a = prod(a,1,typ)
+ // Reshaping according to sizes of other dimensions
+ if d>1
+ dims([1,d]) = [1 dims(1)]
else
- dims(d)=1
+ dims(1) = 1
end
- a=permute(matrix(a,dims(p)),p)
+ a = matrix(a,dims)
+ // back-permuting switched dimensions
+ a = permute(a,p)
end
endfunction
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) INRIA
+// Copyright (C) Samuel GOUGEON - 2015 : http://bugzilla.scilab.org/13829
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
"sum",2,"""*"",""r"",""c"",""m"""))
end
- pos=[1,2,0,find(dims>1,1)];
- d=pos(find(d==["r","c","*","m"]))
+ pos = [1,2,0,find(dims>1,1)];
+ d = pos(find(d==["r","c","*","m"]))
else
error(msprintf(_("%s: Wrong type for input argument #%d: A string or scalar expected.\n"),"sum",2))
end
//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);
- //permute back
- if d==size(dims, "*") then
- dims = dims(1:$-1)
- p(1) = p($)
- p($) = []
+ p = 1:size(dims,"*")
+ p([1,d]) = p([d,1])
+ a = permute(a,p)
+ a = matrix(a,dims(d),-1)
+ // Summing up
+ a = sum(a,1,typ)
+ // Reshaping according to sizes of other dimensions
+ if d>1
+ dims([1,d]) = [1 dims(1)]
else
- dims(d) = 1
+ dims(1) = 1
end
- a = permute(matrix(a,dims(p)),p)
+ a = matrix(a,dims)
+ // back-permuting switched dimensions
+ a = permute(a,p)
end
endfunction