Mercurial > octave
changeset 21345:12280fef2741
automatic broadcasting: correctly handle dimensions of length zero (bug #47085)
* liboctave/numeric/bsxfun.h: fix identification of correct dimensions for
valid broadcasting. Dimensions of length zero should be considered so
use "=! 1" instead of "> 1".
* libinterp/corefcn/bsxfun.cc: add tests.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Thu, 25 Feb 2016 13:48:41 +0000 |
parents | 980abb267014 |
children | afc3108f13fe |
files | libinterp/corefcn/bsxfun.cc liboctave/numeric/bsxfun.h |
diffstat | 2 files changed, 13 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/bsxfun.cc Wed Feb 24 21:47:10 2016 -0800 +++ b/libinterp/corefcn/bsxfun.cc Thu Feb 25 13:48:41 2016 +0000 @@ -805,5 +805,15 @@ %! endfor %! endfor %! endfor -%! + +## Automatic broadcasting with zero length dimensions (bug #47085) +%!assert ([1 2 3] .+ zeros (0, 3), zeros (0, 3)) +%!assert (rand (3, 3, 1) .+ rand (3, 3, 0), zeros (3, 3, 0)) + +## In-place broadcasting with zero length dimensions (bug #47085) +%!test +%! a = zeros (0, 3); +%! a .+= [1 2 3]; +%! assert (a, zeros (0, 3)) + */
--- a/liboctave/numeric/bsxfun.h Wed Feb 24 21:47:10 2016 -0800 +++ b/liboctave/numeric/bsxfun.h Thu Feb 25 13:48:41 2016 +0000 @@ -43,7 +43,7 @@ octave_idx_type xk = dx(i); octave_idx_type yk = dy(i); // Check the three conditions for valid bsxfun dims - if (! ((xk == yk) || (xk == 1 && yk > 1) || (xk > 1 && yk == 1))) + if (! ((xk == yk) || (xk == 1 && yk != 1) || (xk != 1 && yk == 1))) return false; } @@ -73,7 +73,7 @@ octave_idx_type xk = dx(i); // Only two valid canditions to check; can't stretch rk - if (! ((rk == xk) || (rk > 1 && xk == 1))) + if (! ((rk == xk) || (rk != 1 && xk == 1))) return false; }