Mercurial > octave
changeset 29192:547fc7f033da
maint: merge stable to default.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 17 Dec 2020 14:24:15 -0800 |
parents | ed1a8af4242f (current diff) ae5d758c10e1 (diff) |
children | 01e5c00a8609 |
files | scripts/set/union.m |
diffstat | 5 files changed, 91 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/set/intersect.m Tue Dec 15 17:08:43 2020 +0100 +++ b/scripts/set/intersect.m Thu Dec 17 14:24:15 2020 -0800 @@ -134,11 +134,11 @@ ## FIXME: Is there a way to avoid a call to sort? c = c(sort (ic(match))); endif - endif - ## Adjust output orientation for Matlab compatibility - if (isrowvec) - c = c.'; + ## Adjust output orientation for Matlab compatibility + if (isrowvec) + c = c.'; + endif endif if (nargout > 1) @@ -150,7 +150,7 @@ [~, idx] = min (ib); ib = [ib(idx:end); ib(1:idx-1)]; endif - if (optlegacy && isrowvec) + if (optlegacy && isrowvec && ! by_rows) ia = ia.'; ib = ib.'; endif @@ -252,6 +252,18 @@ %! assert (ia, [5, 4]); %! assert (ib, [4, 1]); +%!test # "legacy" + "rows" +%! A = [ 1 2; 3 4; 5 6; 3 4; 7 8 ]; +%! B = [ 3 4; 7 8; 9 10 ]; +%! [c, ia, ib] = intersect (A, B, "rows"); +%! assert (c, [3, 4; 7, 8]); +%! assert (ia, [2; 5]); +%! assert (ib, [1; 2]); +%! [c, ia, ib] = intersect (A, B, "rows", "legacy"); +%! assert (c, [3, 4; 7, 8]); +%! assert (ia, [4; 5]); +%! assert (ib, [1; 2]); + ## Test orientation of output %!shared a,b %! a = 1:4;
--- a/scripts/set/setdiff.m Tue Dec 15 17:08:43 2020 +0100 +++ b/scripts/set/setdiff.m Thu Dec 17 14:24:15 2020 -0800 @@ -191,6 +191,9 @@ %!test %! a = [7 9 7; 0 0 0; 7 9 7; 5 5 5; 1 4 5]; %! b = [0 0 0; 5 5 5]; +%! [c, ia] = setdiff (a, b, "rows"); +%! assert (c, [1, 4 ,5; 7, 9 7]); +%! assert (ia, [5; 1]); %! [c, ia] = setdiff (a, b, "rows", "legacy"); %! assert (c, [1, 4 ,5; 7, 9 7]); %! assert (ia, [5; 3]);
--- a/scripts/set/setxor.m Tue Dec 15 17:08:43 2020 +0100 +++ b/scripts/set/setxor.m Thu Dec 17 14:24:15 2020 -0800 @@ -140,7 +140,7 @@ if (nargout > 1) ia = ia(i(i <= na)); ib = ib(i(i > na) - na); - if (optlegacy && isrowvec) + if (optlegacy && isrowvec && ! by_rows) ia = ia(:).'; ib = ib(:).'; endif @@ -233,6 +233,10 @@ %!assert (size (setxor (x', y)), [3 1]) %!assert (size (setxor (x, y')), [3 1]) %!assert (size (setxor (x', y')), [3 1]) +%!assert (size (setxor (x, y, "legacy")), [1, 3]) +%!assert (size (setxor (x', y, "legacy")), [1, 3]) +%!assert (size (setxor (x, y', "legacy")), [1, 3]) +%!assert (size (setxor (x', y', "legacy")), [3, 1]) ## Test "legacy" input %!test @@ -246,3 +250,15 @@ %! assert (c, [2, 3, 4, 5]); %! assert (ia, [5, 1]); %! assert (ib, [4, 1]); + +%!test # "legacy" + "rows" +%! A = [1 2; 3 4; 5 6; 3 4; 7 8]; +%! B = [3 4; 7 8; 9 10]; +%! [c, ia, ib] = setxor (A, B, "rows"); +%! assert (c, [1, 2; 5, 6; 9, 10]); +%! assert (ia, [1; 3]); +%! assert (ib, [3]); +%! [c, ia, ib] = setxor (A, B, "rows", "legacy"); +%! assert (c, [1, 2; 5, 6; 9, 10]); +%! assert (ia, [1; 3]); +%! assert (ib, [3]);
--- a/scripts/set/union.m Tue Dec 15 17:08:43 2020 +0100 +++ b/scripts/set/union.m Thu Dec 17 14:24:15 2020 -0800 @@ -167,6 +167,18 @@ %! assert (ia, [1, 2]); %! assert (ib, [3, 1]); +%!test # "legacy" + "rows" +%! A = [1 2; 3 4; 5 6; 3 4; 7 8]; +%! B = [3 4; 7 8; 9 10]; +%! [c, ia, ib] = union (A, B, "rows"); +%! assert (c, [1, 2; 3, 4; 5, 6; 7, 8; 9, 10]); +%! assert (ia, [1; 2; 3; 5]); +%! assert (ib, [3]); +%! [c, ia, ib] = union (A, B, "rows", "legacy"); +%! assert (c, [1, 2; 3, 4; 5, 6; 7, 8; 9, 10]); +%! assert (ia, [1; 3]); +%! assert (ib, [1; 2; 3]); + ## Test orientation of output %!shared x,y %! x = 1:3; @@ -176,6 +188,10 @@ %!assert (size (union (x', y)), [5 1]) %!assert (size (union (x, y')), [5 1]) %!assert (size (union (x', y')), [5 1]) +%!assert (size (union (x, y, "legacy")), [1, 5]) +%!assert (size (union (x', y, "legacy")), [1, 5]) +%!assert (size (union (x, y', "legacy")), [1, 5]) +%!assert (size (union (x', y', "legacy")), [5, 1]) ## Clear shared variables %!shared
--- a/src/main.in.cc Tue Dec 15 17:08:43 2020 +0100 +++ b/src/main.in.cc Thu Dec 17 14:24:15 2020 -0800 @@ -208,9 +208,13 @@ { int retval = 0; + int idx_gui = -1; bool start_gui = false; bool gui_libs = true; + bool eval_code = false; + bool persist_octave = false; + set_octave_home (); std::string octave_bindir = get_octave_bindir (); @@ -231,7 +235,7 @@ // Declaring new_argv static avoids leak warnings when using GCC's // --address-sanitizer option. - static char **new_argv = new char * [argc + 1]; + static char **new_argv = new char * [argc + 2]; int k = 1; @@ -267,8 +271,26 @@ // If we see this option, then we fork and exec octave with // the --gui option, while continuing to handle signals in the // terminal. + // Do not copy the arg now, since we still not know if the + // gui should really be launched. Just store the index. start_gui = true; + idx_gui = i; + } + else if (! strcmp (argv[i], "--persist")) + { + // FIXME: How can we reliably detect if this option appears + // after a FILE argument. In this case octave ignores + // the option, but the GUI might still be launched if + // --gui is also given. + + persist_octave = true; + new_argv[k++] = argv[i]; + } + else if (! strcmp (argv[i], "--eval") || + (strlen (argv[i]) > 0 && argv[i][0] != '-')) + { + eval_code = true; new_argv[k++] = argv[i]; } else if (! strcmp (argv[i], "--silent") || ! strcmp (argv[i], "--quiet")) @@ -307,11 +329,16 @@ new_argv[k++] = argv[i]; } - // At this point, gui_libs and start_gui are just about options, not + if (start_gui && eval_code && ! persist_octave) + start_gui = false; + + // At this point, we definitely know whether the gui has to + // be launched or not. + // gui_libs and start_gui are just about options, not // the environment. Exit if they don't make sense. - if (start_gui) { + // GUI should be started if (! gui_libs) { std::cerr << "octave: conflicting options: --no-gui-libs and --gui" @@ -324,6 +351,14 @@ << std::endl; return 1; #endif + + // Finally, add --gui to the command line options. We can not + // just append it since options after a given file are ignored. + for (int j = k; j > 1; j--) + new_argv[j] = new_argv[j-1]; + + new_argv[1] = argv[idx_gui]; + k++; } new_argv[k] = nullptr;