Mercurial > hg > octave-nkf
changeset 8587:35656d6ad061
properly reshape cs-lists assigned to struct & cells
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sat, 24 Jan 2009 21:27:07 +0100 |
parents | 31ab3b83bc8a |
children | 79845b1793cf |
files | src/ChangeLog src/ov-cell.cc src/ov-struct.cc |
diffstat | 3 files changed, 35 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2009-01-24 Jaroslav Hajek <highegg@gmail.com> + + * ov-struct.cc (octave_struct::subsasgn): Reshape cs-list on rhs + according to the index expression. + * ov-cell.cc (octave_cell::subsasgn): Dtto. + 2008-12-25 Ben Abbott <bpabbott@mac.com> * load-path.cc: New function commandlinepath.
--- a/src/ov-cell.cc +++ b/src/ov-cell.cc @@ -291,24 +291,27 @@ case '{': { - octave_value_list i = idx.front (); + octave_value_list idxf = idx.front (); if (t_rhs.is_cs_list ()) { Cell tmp_cell = Cell (t_rhs.list_value ()); - // The shape of the RHS is irrelevant, we just want - // the number of elements to agree and to preserve the - // shape of the left hand side of the assignment. + // Inquire the proper shape of the RHS. + + dim_vector didx = dims ().redim (idxf.length ()); + for (octave_idx_type k = 0; k < idxf.length (); k++) + if (! idxf(k).is_magic_colon ()) didx(k) = idxf(k).numel (); - if (numel () == tmp_cell.numel ()) - tmp_cell = tmp_cell.reshape (dims ()); + if (didx.numel () == tmp_cell.numel ()) + tmp_cell = tmp_cell.reshape (didx); + - octave_base_matrix<Cell>::assign (i, tmp_cell); + octave_base_matrix<Cell>::assign (idxf, tmp_cell); } - else if (i.all_scalars () || do_index_op (i, true).numel () == 1) + else if (idxf.all_scalars () || do_index_op (idxf, true).numel () == 1) // Regularize a null matrix if stored into a cell. - octave_base_matrix<Cell>::assign (i, Cell (t_rhs.storable_value ())); + octave_base_matrix<Cell>::assign (idxf, Cell (t_rhs.storable_value ())); else if (! error_state) error ("invalid assignment to cs-list outside multiple assignment.");
--- a/src/ov-struct.cc +++ b/src/ov-struct.cc @@ -388,7 +388,7 @@ { std::list<octave_value_list>::const_iterator p = idx.begin (); octave_value_list key_idx = *++p; - octave_value_list idx_front = idx.front (); + octave_value_list idxf = idx.front (); assert (key_idx.length () == 1); @@ -398,7 +398,19 @@ { if (t_rhs.is_cs_list ()) { - map.assign (idx.front (), key, Cell (t_rhs.list_value ())); + Cell tmp_cell = Cell (t_rhs.list_value ()); + + // Inquire the proper shape of the RHS. + + dim_vector didx = dims ().redim (idxf.length ()); + for (octave_idx_type k = 0; k < idxf.length (); k++) + if (! idxf(k).is_magic_colon ()) didx(k) = idxf(k).numel (); + + if (didx.numel () == tmp_cell.numel ()) + tmp_cell = tmp_cell.reshape (didx); + + + map.assign (idxf, key, tmp_cell); if (! error_state) { @@ -411,10 +423,10 @@ else { // cast map to const reference to avoid forced key insertion. - if (idx_front.all_scalars () - || cmap.contents (key).index (idx_front, true).numel () == 1) + if (idxf.all_scalars () + || cmap.contents (key).index (idxf, true).numel () == 1) { - map.assign (idx_front, key, t_rhs.storable_value ()); + map.assign (idxf, key, t_rhs.storable_value ()); if (! error_state) { count++;