Mercurial > octave
changeset 21098:99d373870017
Fix assigning to trailing singletons for structs and cell (bug #39789, bug #35841)
* Array.cc (index (Array<idx_vector> ia, bool, T)):
Only return empty array if resized dimension mismatches ia.
* ov-struct.cc (subsasgn): Remove workaround for index(_,_,_) returning an
empty array for trailing singletons introduced to solve bug #35841.
* index.tst: Add tests for bug #35841, #39789.
author | Lachlan Andrew <lachlanbis@gmail.com> |
---|---|
date | Wed, 16 Dec 2015 12:09:59 +1100 |
parents | 87b3348d8d76 |
children | 52af4092f863 |
files | libinterp/octave-value/ov-struct.cc liboctave/array/Array.cc test/index.tst |
diffstat | 3 files changed, 16 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-struct.cc Tue Dec 15 21:30:25 2015 +1100 +++ b/libinterp/octave-value/ov-struct.cc Wed Dec 16 12:09:59 2015 +1100 @@ -317,10 +317,6 @@ { map.contents (pkey).make_unique (); tmpc = map.contents (pkey).index (idx.front (), true); - // See bug #35841, assigning to struct with trailing - // singleton dimensions. - if (tmpc.is_empty ()) - tmpc = Cell (1,1); } // FIXME: better code reuse? @@ -455,8 +451,7 @@ const_cast<const octave_map &> (map); // cast to const reference, avoid forced key insertion. if (idxf.all_scalars () - || cmap.contents (key).index (idxf, true).numel () - <= 1) + || cmap.contents (key).index (idxf, true).numel () == 1) { map.assign (idxf, key, Cell (t_rhs.storable_value ()));
--- a/liboctave/array/Array.cc Tue Dec 15 21:30:25 2015 +1100 +++ b/liboctave/array/Array.cc Wed Dec 16 12:09:59 2015 +1100 @@ -1115,7 +1115,8 @@ int ial = ia.numel (); dim_vector dv = dimensions.redim (ial); dim_vector dvx = dim_vector::alloc (ial); - for (int i = 0; i < ial; i++) dvx(i) = ia(i).extent (dv(i)); + for (int i = 0; i < ial; i++) + dvx(i) = ia(i).extent (dv(i)); if (! (dvx == dv)) { bool all_scalars = true; @@ -1125,10 +1126,10 @@ return Array<T> (dim_vector (1, 1), rfv); else tmp.resize (dvx, rfv); + + if (tmp.dimensions != dvx) + return Array<T> (); } - - if (tmp.dimensions != dvx) - return Array<T> (); } return tmp.index (ia);
--- a/test/index.tst Tue Dec 15 21:30:25 2015 +1100 +++ b/test/index.tst Wed Dec 16 12:09:59 2015 +1100 @@ -576,3 +576,13 @@ %!error <abc\(1\+0.5i,_\): subscripts must be real> abc(1+0.5*i,3) %!error <abc\(_,0-2i\): subscripts must be real> abc(2,0-2*i) +## bug #35841 +%!test +%! a(1,1,1).b(1) = 2; +%! a(1,1,1).b(1) = 3; + +## bug #39789 +%!test +%! c = cell(1,1,1); +%! c{1,1,1} = zeros(5, 2); +%! c{1,1,1}(:, 1) = 1;