Mercurial > jwe > octave
changeset 23832:3544f88a2bb5
Fix reshape of octave_map with trailing singletons (bug #51634, bug #45385, bug #43650).
* oct-map.cc: Chop trailing singletons on the main dimension of retval
(retval.dimensions). Add BIST test for the issue.
author | Piotr Held <pjheld@gmail.com> |
---|---|
date | Mon, 31 Jul 2017 16:20:18 -0700 |
parents | a62e03d7d53a |
children | ca4cca5710dc |
files | libinterp/corefcn/oct-map.cc |
diffstat | 1 files changed, 17 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/oct-map.cc Wed Aug 02 23:14:19 2017 -0500 +++ b/libinterp/corefcn/oct-map.cc Mon Jul 31 16:20:18 2017 -0700 @@ -529,6 +529,10 @@ octave_map retval (xkeys); retval.dimensions = dv; + // When reshaping xvals the Array constructor chops trailing singletons, + // hence we need to do the same for the whole map. + retval.dimensions.chop_trailing_singletons (); + octave_idx_type nf = nfields (); if (nf > 0) { @@ -554,6 +558,19 @@ %!test %! x(1,1).d = 10; x(4,6).a = "b"; x(2,4).f = 27; %! assert (fieldnames (reshape (x, 3, 8)), {"d"; "a"; "f"}); + +## test chopping of trailing singletons +%!test <51634> +%! x(1,1).d = 10; x(4,6).a = "b"; x(2,4).f = 27; +%! reshape (x, 3, 8, 1, 1); + +%!test <46385> +%! M = repmat (struct ('a', ones(100), 'b', true), 1, 2); +%! M = repmat(M, 1, 2); +%! assert (size (M), [1, 4]); + +libinterp/corefcn/oct-map.cc + */ void