stdev(hypermat,idim) may return zeros(hypermat), even if idim<=ndims(hypermat). Patch attached
@sgougeon)
Reported by Samuel GOUGEON (%hm_stdev.sci (2.48 KB, text/x-csrc)
%hm_stdev.sci fixed
BUG DESCRIPTION:
----------------
This bug is due to a bad test in %hm_stdev():
if d > size(m, d) then
x = zeros(m)
return
end
must be replaced with
if d > length(size(m)) then
x = zeros(m)
return
end
or better:
if d > length(size(m)) then
msg = _("%s: Wrong value for input argument #%d: integer <= ndims(argument #%d) expected \n")
error(msprintf(msg,"stdev",2,1));
end
ERROR LOG:
----------
Wrong answer:
-->d = grand(2,2,2,"uin",1,10)
d =
(:,:,1)
3. 6.
9. 4.
(:,:,2)
8. 5.
3. 5.
-->stdev(d,3)
ans =
(:,:,1)
0. 0.
0. 0.
(:,:,2)
0. 0.
0. 0.
// Right answer:
-->stdev(d,3)
ans =
3.5355339 0.7071068
4.2426407 0.7071068
HOW TO REPRODUCE THE BUG:
-------------------------
d = grand(2,2,2,"uin",1,10)
stdev(d,3)
OTHER INFORMATION:
------------------
Patch attached:
* Zeros are no longer returned.
* An error is now yielded when the order of the dimension along which stdev should be computed is larger than the number of available dimensions.
* code simplified (trivial simplifications)