Mercurial > hg > octave-nkf
changeset 14440:3d4bea9accd7 stable
Fix segfault on multidimensional median call (bug #35679).
* Array.c (Array::nth_elemnt): Readjust dim after chopping singletons.
* median.m: Add tests.
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Wed, 07 Mar 2012 00:02:41 -0500 |
parents | ec660526ae50 |
children | d27e638b1c3a |
files | liboctave/Array.cc scripts/statistics/base/median.m |
diffstat | 2 files changed, 11 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -2253,6 +2253,7 @@ dv(dim) = std::min (nn, ns); dv.chop_trailing_singletons (); + dim = std::min (dv.length (), dim); Array<T> m (dv);
--- a/scripts/statistics/base/median.m +++ b/scripts/statistics/base/median.m @@ -99,6 +99,16 @@ %! assert(median ([x2, 2*x2]) == [3.5, 7]); %! assert(median ([y2, 3*y2]) == [4, 12]); +%% Test multidimensional arrays (bug #35679) +%!shared a, b, x, y +%! rand ("seed", 2); +%! a = rand (2,3,4,5); +%! b = rand (3,4,6,5); +%! x = sort (a, 4); +%! y = sort (b, 3); +%!assert (median (a, 4), x(:, :, :, 3)); +%!assert (median (b, 3), (y(:, :, 3, :) + y(:, :, 4, :))/2); + %!assert(median (single([1,2,3])), single(2)); %!assert(median ([1,2,NaN;4,5,6;NaN,8,9]), [NaN, 5, NaN]);