comparison src/ov-cell.cc @ 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 188d38a553c7
children 1dce30ab0e72
comparison
equal deleted inserted replaced
8586:31ab3b83bc8a 8587:35656d6ad061
289 } 289 }
290 break; 290 break;
291 291
292 case '{': 292 case '{':
293 { 293 {
294 octave_value_list i = idx.front (); 294 octave_value_list idxf = idx.front ();
295 295
296 if (t_rhs.is_cs_list ()) 296 if (t_rhs.is_cs_list ())
297 { 297 {
298 Cell tmp_cell = Cell (t_rhs.list_value ()); 298 Cell tmp_cell = Cell (t_rhs.list_value ());
299 299
300 // The shape of the RHS is irrelevant, we just want 300 // Inquire the proper shape of the RHS.
301 // the number of elements to agree and to preserve the 301
302 // shape of the left hand side of the assignment. 302 dim_vector didx = dims ().redim (idxf.length ());
303 303 for (octave_idx_type k = 0; k < idxf.length (); k++)
304 if (numel () == tmp_cell.numel ()) 304 if (! idxf(k).is_magic_colon ()) didx(k) = idxf(k).numel ();
305 tmp_cell = tmp_cell.reshape (dims ()); 305
306 306 if (didx.numel () == tmp_cell.numel ())
307 octave_base_matrix<Cell>::assign (i, tmp_cell); 307 tmp_cell = tmp_cell.reshape (didx);
308
309
310 octave_base_matrix<Cell>::assign (idxf, tmp_cell);
308 } 311 }
309 else if (i.all_scalars () || do_index_op (i, true).numel () == 1) 312 else if (idxf.all_scalars () || do_index_op (idxf, true).numel () == 1)
310 // Regularize a null matrix if stored into a cell. 313 // Regularize a null matrix if stored into a cell.
311 octave_base_matrix<Cell>::assign (i, Cell (t_rhs.storable_value ())); 314 octave_base_matrix<Cell>::assign (idxf, Cell (t_rhs.storable_value ()));
312 else if (! error_state) 315 else if (! error_state)
313 error ("invalid assignment to cs-list outside multiple assignment."); 316 error ("invalid assignment to cs-list outside multiple assignment.");
314 317
315 if (! error_state) 318 if (! error_state)
316 { 319 {