Mercurial > hg > octave-nkf
diff scripts/set/union.m @ 20623:2edd668e7784
union.m: Matlab compatible output orientation for empty input ([]).
* union.m: Check inputs a,b with isempty which qualifies as a row vector.
Add BIST tests to verify new behavior.
author | Juan Pablo Carbajal <ajuanpi+dev@gmail.com> |
---|---|
date | Fri, 31 Jul 2015 14:01:39 +0200 |
parents | 72ccbd36e23c |
children | 6dc15d4cc17e |
line wrap: on
line diff
--- a/scripts/set/union.m +++ b/scripts/set/union.m @@ -51,7 +51,7 @@ [a, b] = validsetargs ("union", a, b, varargin{:}); by_rows = nargin == 3; - isrowvec = isvector (a) && isvector (b) && isrow (a) && isrow (b); + isrowvec = (isrow (a) || isempty (a)) && (isrow (b) || isempty (b)); if (by_rows) y = [a; b]; @@ -94,6 +94,12 @@ %! assert (y, [1; 2; 3; 4; 5]); %! assert (y, sort ([a(ia)'; b(ib)'])); +## Test format when input is empty +%!assert (union ([],[1,2]), [1,2]) +%!assert (union ([1,2],[]), [1,2]) +%!assert (union ([],[1;2]), [1;2]) +%!assert (union ([1;2],[]), [1;2]) + ## Test common input validation for set routines contained in validsetargs %!error <cell array of strings cannot be combined> union ({"a"}, 1) %!error <A and B must be arrays or cell arrays> union (@sin, 1) @@ -102,4 +108,3 @@ %!error <A and B must be arrays or cell arrays> union (@sin, 1, "rows") %!error <A and B must be 2-dimensional matrices> union (rand(2,2,2), 1, "rows") %!error <number of columns in A and B must match> union ([1 2], 1, "rows") -