# HG changeset patch # User Lachlan Andrew # Date 1444443260 25200 # Node ID 45759620a9a541c5e512d64d39d33ff851b8bb96 # Parent db32862013471fe41719af13d63c158534f820e5 quantile.m: Fix operation along a singleton dimension (bug #45455). * quantile.m: Add isempty() to input validation. * quantile.m (__quantile__): Sort x explicitly along dimension 1. diff -r db3286201347 -r 45759620a9a5 scripts/statistics/base/quantile.m --- a/scripts/statistics/base/quantile.m Wed Oct 07 14:52:01 2015 -0700 +++ b/scripts/statistics/base/quantile.m Fri Oct 09 19:14:20 2015 -0700 @@ -113,8 +113,8 @@ print_usage (); endif - if (! (isnumeric (x) || islogical (x))) - error ("quantile: X must be a numeric vector or matrix"); + if (! (isnumeric (x) || islogical (x)) || isempty (x)) + error ("quantile: X must be a non-empty numeric vector or matrix"); endif if (isempty (p)) @@ -321,6 +321,9 @@ %! yexp = median (x, dim); %! assert (yobs, yexp); +## Bug #45455 +%!assert (quantile ([1 3 2], 0.5, 1), [1 3 2]) + ## Test input validation %!error quantile () %!error quantile (1, 2, 3, 4, 5) @@ -358,8 +361,7 @@ p = p(:); ## Save length and set shape of samples. - ## FIXME: does sort guarantee that NaN's come at the end? - x = sort (x); + x = sort (x, 1); m = sum (! isnan (x)); [xr, xc] = size (x); @@ -431,7 +433,7 @@ endswitch ## Duplicate single values. - imm1 = (mm == 1); + imm1 = (mm(1,:) == 1); x(2,imm1) = x(1,imm1); ## Interval indices.