From ff8ffa604d2a511a93fd8e6b57054e21c50e8118 Mon Sep 17 00:00:00 2001 From: Paul Bignier Date: Mon, 25 Nov 2013 09:07:57 +0100 Subject: [PATCH] Statistics: scalar a priori mean for hypermatrices in stdev Fix for commit https://codereview.scilab.org/#/c/12833/ , wfter which hypermatrices could not handle scalar a priori means. Change-Id: I965fced5dd24d3886c92099a83f3e7b0245c8138 --- scilab/modules/overloading/macros/%hm_stdev.sci | 6 +++++- .../statistics/tests/nonreg_tests/bug_7593.dia.ref | 6 ++++++ .../statistics/tests/nonreg_tests/bug_7593.tst | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/scilab/modules/overloading/macros/%hm_stdev.sci b/scilab/modules/overloading/macros/%hm_stdev.sci index 0f90281..83545fd 100644 --- a/scilab/modules/overloading/macros/%hm_stdev.sci +++ b/scilab/modules/overloading/macros/%hm_stdev.sci @@ -43,7 +43,11 @@ function x = %hm_stdev(m, d, ms) I = ones(ind).*.I+ind.*.ones(I); if argn(2) == 3 then - x = stdev(matrix(m.entries(I),dims(d),-1), 1, ms.entries'); + if isscalar(ms) then + x = stdev(matrix(m.entries(I),dims(d),-1), 1, ms); + else + x = stdev(matrix(m.entries(I),dims(d),-1), 1, ms.entries'); + end else x = stdev(matrix(m.entries(I),dims(d),-1), 1); end diff --git a/scilab/modules/statistics/tests/nonreg_tests/bug_7593.dia.ref b/scilab/modules/statistics/tests/nonreg_tests/bug_7593.dia.ref index 6e2b070..0a85c2d 100644 --- a/scilab/modules/statistics/tests/nonreg_tests/bug_7593.dia.ref +++ b/scilab/modules/statistics/tests/nonreg_tests/bug_7593.dia.ref @@ -50,6 +50,12 @@ assert_checkalmostequal(stdev(x, 1, 1), refR); assert_checkalmostequal(stdev(x, "r", 1), refR); assert_checkalmostequal(stdev(x, 2, 1), refC); assert_checkalmostequal(stdev(x, "c", 1), refC); +// Scalar a priori mean for hypermatrix +grand("setsd", 0); +x = grand(4, 3, 2, "unf", 0, 10); +refHM = [2.09659394107671737 2.55579559873818374 1.1805640530346788]; +refHM(:, :, 2) = [3.14196221819646615 2.64930672717197169 2.1435288607041616]; +assert_checkalmostequal(stdev(x, "r", 5), refHM); // Error checks refMsg = msprintf(_("%s: Wrong size for input argument #%d.\n"),"stdev",3); assert_checkerror("stdev(x, ""*"", [1 1])", refMsg); diff --git a/scilab/modules/statistics/tests/nonreg_tests/bug_7593.tst b/scilab/modules/statistics/tests/nonreg_tests/bug_7593.tst index 0c4ae60..e8abba9 100644 --- a/scilab/modules/statistics/tests/nonreg_tests/bug_7593.tst +++ b/scilab/modules/statistics/tests/nonreg_tests/bug_7593.tst @@ -55,6 +55,12 @@ assert_checkalmostequal(stdev(x, "r", 1), refR); assert_checkalmostequal(stdev(x, 2, 1), refC); assert_checkalmostequal(stdev(x, "c", 1), refC); +// Scalar a priori mean for hypermatrix +grand("setsd", 0); +x = grand(4, 3, 2, "unf", 0, 10); +refHM = [2.09659394107671737 2.55579559873818374 1.1805640530346788]; +refHM(:, :, 2) = [3.14196221819646615 2.64930672717197169 2.1435288607041616]; +assert_checkalmostequal(stdev(x, "r", 5), refHM); // Error checks refMsg = msprintf(_("%s: Wrong size for input argument #%d.\n"),"stdev",3); -- 1.7.9.5