# HG changeset patch # User Nicholas R. Jankowski # Date 1712024754 14400 # Node ID 90a663c1a823a2c2a568e92c180f596104decdaf # Parent 1b41fd5bbd458ccb02790980e26b0a10787f3ef2# Parent 1db14e08bee4028e6393e96e87987215e1123ae7 maint: Merge default to bytecode-interpreter. diff -r 1b41fd5bbd45 -r 90a663c1a823 etc/NEWS.10.md --- a/etc/NEWS.10.md Mon Apr 01 12:56:38 2024 -0400 +++ b/etc/NEWS.10.md Mon Apr 01 22:25:54 2024 -0400 @@ -55,6 +55,9 @@ - `iqr` now provides compatible output for empty inputs. +- `cross` now produces row vector outputs when the inputs are a mix of row +and column vectors. (bug #61295) + ### Alphabetical list of new functions added in Octave 10 * `clim` diff -r 1b41fd5bbd45 -r 90a663c1a823 scripts/io/is_valid_file_id.m --- a/scripts/io/is_valid_file_id.m Mon Apr 01 12:56:38 2024 -0400 +++ b/scripts/io/is_valid_file_id.m Mon Apr 01 22:25:54 2024 -0400 @@ -52,3 +52,14 @@ %!assert (! is_valid_file_id ("not_a_file_id")) %!assert (! is_valid_file_id (-1)) %!assert (! is_valid_file_id (pi)) +%!test <*65543> +%! unwind_protect +%! fid = tmpfile (); +%! assert (is_valid_file_id (fid)); +%! unwind_protect_cleanup +%! fclose (fid); +%! end_unwind_protect + +## Test input validation +%!error is_valid_file_id () + diff -r 1b41fd5bbd45 -r 90a663c1a823 scripts/linear-algebra/cross.m --- a/scripts/linear-algebra/cross.m Mon Apr 01 12:56:38 2024 -0400 +++ b/scripts/linear-algebra/cross.m Mon Apr 01 22:25:54 2024 -0400 @@ -68,15 +68,17 @@ nd = ndims (x); if (nargin < 3 && nd < 3 && ndims (y) < 3) - ## COMPATIBILITY -- opposite behavior for cross(row,col) - ## Swap x and y in the assignments below to get the matlab behavior. - ## Better yet, fix the calling code so that it uses conformant vectors. + ## COMPATIBILITY -- mixed row/column vector inputs + ## Transpose x and y in the assignments below to get row output to match + ## matlab behavior (verified version: 2023b). + ## Recommend users instead ensure calling code has matched vectors to + ## remove any ambiguity in output form. if (columns (x) == 1 && rows (y) == 1) - warning ("cross: taking cross product of column by row"); - y = y.'; + warning ("cross: cross product of column by row produces row output"); + x = x.'; elseif (rows (x) == 1 && columns (y) == 1) - warning ("cross: taking cross product of row by column"); - x = x.'; + warning ("cross: cross product of row by column produces row output"); + y = y.'; endif endif @@ -138,6 +140,29 @@ %! assert (cross (x, y, 2), r, eps); %! assert (cross (x, y, 1), -r, eps); +%!test +%! x = [1, 0, 0; 0, 1, 0; 0, 0, 1]; +%! x = cat (3, x, x); +%! y = [0, 1, 0; 0, 0, 1; 1, 0, 0]; +%! y = cat (3, y, y); +%! r = [0, 0, 1; 1, 0, 0; 0, 1, 0]; +%! r = cat (3, r, r); +%! assert (cross (x, y, 2), r, eps); +%! assert (cross (x, y, 1), -r, eps); +%! fail ("cross (x, y, 3)", "X and Y must have three elements"); + +## Test mixed vector inputs +%!test <*61295> +%! x = [1, 0, 0]; +%! y = [0, 1, 0]; +%! r = [0, 0, 1]; +%! warning ("off", "all", "local"); +%! assert (cross (x, y), r, eps); +%! assert (cross (x', y'), r', eps); +%! assert (cross (x', y), r, eps); +%! assert (cross (x, y'), r, eps); + + ## Test input validation %!error cross () %!error cross (1) @@ -157,8 +182,8 @@ %!error cross ([1, 2, 3], [4, 5, 6], 1.5) %!error cross ([1, 2, 3], [4, 5, 6], 2i) %!error cross ([1, 2, 3], [3, 4]) -%!warning cross ([1, 2, 3]', [4, 5, 6]); -%!warning cross ([1, 2, 3], [4, 5, 6]'); +%!warning cross ([1, 2, 3]', [4, 5, 6]); +%!warning cross ([1, 2, 3], [4, 5, 6]'); %!test %! x = cat (3, [1, 1, 1]', [1, 1, 1]');