changeset 27492:616b844e903a stable

ismember.m: Fix second return argument when values are complex (bug #52437). * ismember.m: Use the minimum (first index) of both the real and imag ismember results to determine the output index. Update BIST tests to check for this test case. Update BIST tests with commas for readability.
author Rik <rik@octave.org>
date Mon, 14 Oct 2019 17:21:28 -0700
parents d4ee26280bb9
children cf8784becc8a eeb2275424bc
files scripts/set/ismember.m
diffstat 1 files changed, 27 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/set/ismember.m	Thu Oct 10 09:10:49 2019 -0700
+++ b/scripts/set/ismember.m	Mon Oct 14 17:21:28 2019 -0700
@@ -90,7 +90,7 @@
     tf = real_argout{1} & imag_argout{1};
     if (isargout (2))
       s_idx = zeros (size (real_argout{2}));
-      s_idx(tf) = real_argout{2}(tf);
+      s_idx(tf) = min (real_argout{2}(tf), imag_argout{2}(tf));
     endif
     return
   endif
@@ -264,31 +264,35 @@
 %! assert (ismember (abc, {abc}), [false; false; false]);
 
 %!test <*52437>
-%! [tf, s_idx] = ismember ([5 4-3j 3+4j], [5 4-3j 3+4j]);
-%! assert (tf, logical ([1 1 1]))
-%! assert (s_idx, [1 2 3])
+%! [tf, s_idx] = ismember ([5, 4-3j, 3+4j], [5, 4-3j, 3+4j]);
+%! assert (tf, logical ([1, 1, 1]));
+%! assert (s_idx, [1, 2, 3]);
+%!
+%! [tf, s_idx] = ismember ([5, 4-3j, 3+4j], 5);
+%! assert (tf, logical ([1, 0, 0]));
+%! assert (s_idx, [1, 0, 0]);
 %!
-%! [tf, s_idx] = ismember ([5 4-3j 3+4j], 5);
-%! assert (tf, logical ([1 0 0]))
-%! assert (s_idx, [1 0 0])
+%! [tf, s_idx] = ismember ([5, 5, 5], 4-3j);
+%! assert (tf, logical ([0, 0, 0]));
+%! assert (s_idx, [0, 0, 0]);
 %!
-%! [tf, s_idx] = ismember ([5 5 5], 4-3j);
-%! assert (tf, logical ([0 0 0]))
-%! assert (s_idx, [0 0 0])
+%! [tf, s_idx] = ismember ([5, 4-3j, 3+4j; 5i, 6, 6i], [5, 6]);
+%! assert (tf, logical ([1, 0, 0; 0, 1, 0]));
+%! assert (s_idx, [1, 0, 0; 0, 2, 0]);
 %!
-%! [tf, s_idx] = ismember ([5 4-3j 3+4j; 5i 6 6i], [5 6]);
-%! assert (tf, logical ([1 0 0; 0 1 0]))
-%! assert (s_idx, [1 0 0; 0 2 0])
+%! [tf, s_idx] = ismember ([5, 4-3j, 3+4j; 5, 4-3j, 3+4j], [5, 5, 5], "rows");
+%! assert (tf, logical ([0; 0]));
+%! assert (s_idx, [0; 0]);
 %!
-%! [tf, s_idx] = ismember ([5 4-3j 3+4j; 5 4-3j 3+4j], [5 5 5], "rows");
-%! assert (tf, logical ([0; 0]))
-%! assert (s_idx, [0; 0])
+%! [tf, s_idx] = ismember ([5, 5, 5], [5, 4-3j, 3+4j; 5, 5, 5], "rows");
+%! assert (tf, true);
+%! assert (s_idx, 2);
 %!
-%! [tf, s_idx] = ismember ([5 5 5], [5 4-3j 3+4j; 5 5 5], "rows");
-%! assert (tf, true)
-%! assert (s_idx, 2)
+%! tf = ismember ([5, 4-3j, 3+4j], 5);
+%! assert (tf, logical ([1, 0, 0]))
+%! [~, s_idx] = ismember ([5, 4-3j, 3+4j], 5);
+%! assert (s_idx, [1, 0, 0]);
 %!
-%! [tf] = ismember ([5 4-3j 3+4j], 5);
-%! assert (tf, logical ([1 0 0]))
-%! [~, s_idx] = ismember ([5 4-3j 3+4j], 5);
-%! assert (s_idx, [1 0 0])
+%! [tf, s_idx] = ismember (-1-1j, [-1-1j, -1+3j, -1+1j]);
+%! assert (tf, true);
+%! assert (s_idx, 1);