# HG changeset patch # User Nicholas R. Jankowski # Date 1711990598 14400 # Node ID 1b41fd5bbd458ccb02790980e26b0a10787f3ef2 # Parent 92f34eda5c6e1171c11ba848365cb185d5787f14# Parent f9e4e87a0f4a29517ff8af47466ef8856cd113f9 maint: Merge default to bytecode-interpreter. diff -r 92f34eda5c6e -r 1b41fd5bbd45 scripts/linear-algebra/cross.m --- a/scripts/linear-algebra/cross.m Mon Apr 01 10:14:54 2024 -0400 +++ b/scripts/linear-algebra/cross.m Mon Apr 01 12:56:38 2024 -0400 @@ -67,14 +67,14 @@ nd = ndims (x); - if (nd < 3 && ndims (y) < 3 && nargin < 3) + 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. - if (iscolumn (x) && isrow (y)) + if (columns (x) == 1 && rows (y) == 1) warning ("cross: taking cross product of column by row"); y = y.'; - elseif (isrow (x) && iscolumn (y)) + elseif (rows (x) == 1 && columns (y) == 1) warning ("cross: taking cross product of row by column"); x = x.'; endif @@ -93,8 +93,9 @@ error ("cross: DIM must be a positive scalar whole number"); endif - if (dim > nd || sz(dim) != 3) - error ("cross: must have three elements in dimension DIM"); + if (dim > nd || sz(dim) != 3 || ... + dim > ndims (y) || size (y, dim) != 3) + error ("cross: X and Y must have three elements in dimension DIM"); endif endif @@ -137,22 +138,16 @@ %! assert (cross (x, y, 2), r, eps); %! assert (cross (x, y, 1), -r, eps); -%!test <*65527> -%! x = cat (3, [1, 1, 1]', [1, 1, 1]'); -%! y = cat (3, [1, 0, 0], [1, 0, 0]); -%! fail ("cross (x, y)", "X and Y must have the same dimensions"); -%! fail ("cross (y, x)", "X and Y must have the same dimensions"); - ## Test input validation %!error cross () %!error cross (1) %!error cross (0, 0) %!error cross ([1, 2], [3, 4]) %!error cross ([1, 2], [3, 4, 5]) -%!error cross (0, 0, 1) -%!error cross ([1, 2, 3], [1, 2, 3], 1) -%!error cross ([1, 2, 3], [1, 2, 3], 9) -%!error cross (magic (3), magic (3), 4) +%!error cross (0, 0, 1) +%!error cross ([1, 2, 3], [1, 2, 3], 1) +%!error cross ([1, 2, 3], [1, 2, 3], 9) +%!error cross (magic (3), magic (3), 4) %!error cross ([1, 2, 3], [4, 5, 6], {1}) %!error cross ([1, 2, 3], [4, 5, 6], "a") %!error cross ([1, 2, 3], [4, 5, 6], true) @@ -164,3 +159,9 @@ %!error cross ([1, 2, 3], [3, 4]) %!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]'); +%! y = cat (3, [1, 0, 0], [1, 0, 0]); +%! fail ("cross (x, y)", "X and Y must have the same dimensions"); +%! fail ("cross (y, x)", "X and Y must have the same dimensions");