Mercurial > octave
changeset 25470:7a6e35d987bb
bitset.m: Expand third argument to match input size if necessary (bug #54110).
* bitset.m: If third argument val is a scalar, but input A is not, expand val
to size of A. Add BIST tests for correct behavior.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 13 Jun 2018 14:04:53 -0700 |
parents | 9ef52c25d543 |
children | 6a9ba6644272 |
files | scripts/general/bitset.m |
diffstat | 1 files changed, 13 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/general/bitset.m Wed Jun 13 10:29:40 2018 -0700 +++ b/scripts/general/bitset.m Wed Jun 13 14:04:53 2018 -0700 @@ -49,6 +49,13 @@ if (nargin == 2) val = true (sz); + elseif (isscalar (val) && ! isscalar (A)) + ## Expand last argument to match size of input + if (val) + val = true (sz); + else + val = false (sz); + endif endif cl = class (A); @@ -102,7 +109,12 @@ %! endfor %!assert <*36458> (bitset (uint8 ([1, 2;3 4]), 1, [0 1; 0 1]), -%! uint8 ([0, 3; 2 5])) +%! uint8 ([0, 3; 2 5])) + +%!assert (bitset (1:5, 1), [1, 3, 3, 5, 5]) +%!assert (bitset (1:5, 1, [1, 1, 1, 1, 1]), [1, 3, 3, 5, 5]) +%!assert <*54110> (bitset (1:5, 1, 1), [1, 3, 3, 5, 5]) +%!assert (bitset (1:5, 1, [1, 1, 1, 1, 0]), [1, 3, 3, 5, 4]) %!error bitset (1) %!error bitset (1, 2, 3, 4)