Mercurial > hg > octave-jordi
changeset 4501:693ad5220d1e
[project @ 2003-09-05 20:55:40 by jwe]
author | jwe |
---|---|
date | Fri, 05 Sep 2003 20:55:40 +0000 |
parents | aa3b7d89864e |
children | 955cb1e87de2 |
files | src/ChangeLog src/pt-cell.cc src/pt-mat.cc |
diffstat | 3 files changed, 86 insertions(+), 45 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,14 @@ 2003-09-05 John W. Eaton <jwe@bevo.che.wisc.edu> + * pt-cell.cc (tree_cell::rvalue): Don't assume that the number of + elements in a tree_argument_list is the same as the number of + objects it contains (cs-list objects expand to more than one). + + * pt-mat.cc (tm_row_const::tm_row_const_rep::do_init_element): + New function, extracted from tm_row_const::tm_row_const_rep::init. + (tm_row_const::tm_row_const_rep::init): Use it. + Also handle cs-list objects. + * ov-cs-list.cc (octave_cs_list::print_raw): New function. * ov-cs-list.h (octave_cs_list::print_raw): Provide decl. * ov-list.h (octave_list::lst): Now protected instead of private.
--- a/src/pt-cell.cc +++ b/src/pt-cell.cc @@ -53,20 +53,7 @@ int nr = length (); int nc = -1; - for (iterator p = begin (); p != end (); p++) - { - tree_argument_list *elt = *p; - - if (nc < 0) - nc = elt->length (); - else if (nc != static_cast<int> (elt->length ())) - { - ::error ("number of columns must match"); - return retval; - } - } - - Cell val (nr, nc); + Cell val; int i = 0; @@ -76,6 +63,23 @@ octave_value_list row = elt->convert_to_const_vector (); + if (nc < 0) + { + nc = row.length (); + + val = Cell (nr, nc); + } + else + { + int this_nc = row.length (); + + if (nc != this_nc) + { + ::error ("number of columns must match"); + return retval; + } + } + for (int j = 0; j < nc; j++) val(i,j) = row(j);
--- a/src/pt-mat.cc +++ b/src/pt-mat.cc @@ -89,6 +89,8 @@ bool ok; + bool do_init_element (tree_expression *, const octave_value&, bool&); + void init (const tree_argument_list&); private: @@ -164,6 +166,51 @@ tm_row_const_rep *rep; }; +bool +tm_row_const::tm_row_const_rep::do_init_element (tree_expression *elt, + const octave_value& val, + bool& first_elem) +{ + int this_elt_nr = val.rows (); + int this_elt_nc = val.columns (); + + if (this_elt_nr > 0 || this_elt_nc > 0) + { + all_mt = false; + + if (first_elem) + { + first_elem = false; + + nr = this_elt_nr; + } + else if (this_elt_nr != nr) + { + eval_error ("number of rows must match", + elt->line (), elt->column (), this_elt_nr, nr); + return false; + } + + nc += this_elt_nc; + + append (val); + } + else if (Vwarn_empty_list_elements) + eval_warning ("empty matrix found in matrix list", + elt->line (), elt->column ()); + + if (all_str && ! val.is_string ()) + all_str = false; + + if (! some_str && val.is_string ()) + some_str = true; + + if (! is_cmplx && val.is_complex_type ()) + is_cmplx = true; + + return true; +} + void tm_row_const::tm_row_const_rep::init (const tree_argument_list& row) { @@ -183,45 +230,26 @@ break; else { - int this_elt_nr = tmp.rows (); - int this_elt_nc = tmp.columns (); - - if (this_elt_nr > 0 || this_elt_nc > 0) + if (tmp.is_cs_list ()) { - all_mt = false; + octave_value_list lst = tmp.list_value (); - if (first_elem) - { - first_elem = false; - - nr = this_elt_nr; - } - else if (this_elt_nr != nr) + for (int i = 0; i < lst.length (); i++) { - eval_error ("number of rows must match", - elt->line (), elt->column (), this_elt_nr, nr); - break; + if (! do_init_element (elt, lst(i), first_elem)) + goto done; } - - nc += this_elt_nc; - - append (tmp); } - else if (Vwarn_empty_list_elements) - eval_warning ("empty matrix found in matrix list", - elt->line (), elt->column ()); - - if (all_str && ! tmp.is_string ()) - all_str = false; - - if (! some_str && tmp.is_string ()) - some_str = true; - - if (! is_cmplx && tmp.is_complex_type ()) - is_cmplx = true; + else + { + if (! do_init_element (elt, tmp, first_elem)) + goto done; + } } } + done: + ok = ! error_state; }