# HG changeset patch # User John W. Eaton # Date 1209869304 14400 # Node ID 7c020c067a60c42af06f28028d4282a54bb2afe4 # Parent 5c6c6f4803c8042b7ffb51cfe574d7f7594d5272 F__end__: correctly handle fewer indices than dimensions diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,10 @@ 2008-05-03 John W. Eaton + * pt-arg-list.cc (F__end__): If there are more dimensions than + indices, smash extra dimensions first. + (num_indices): New static variable. + (tree_argument_list::convert_to_const_vector): Save and set it. + * parse.y (parse_fcn_file): Also temporarily set parser_end_of_input and get_input_from_eval_string to false while reading script files. diff --git a/src/pt-arg-list.cc b/src/pt-arg-list.cc --- a/src/pt-arg-list.cc +++ b/src/pt-arg-list.cc @@ -94,6 +94,7 @@ static const octave_value *indexed_object = 0; static int index_position = 0; +static int num_indices = 0; DEFCONSTFUN (__end__, , , "internal function") @@ -103,34 +104,30 @@ if (indexed_object) { dim_vector dv = indexed_object->dims (); + int ndims = dv.length (); - switch (index_position) + if (num_indices < ndims) { - case -1: - { - octave_idx_type numel = dv.numel (); + for (int i = num_indices; i < ndims; i++) + dv(num_indices-1) *= dv(i); - if (numel < 0) - { - std::string dv_str = dv.str (); - ::error ("invalid use of end: (index 1, dims %s)", - dv_str.c_str ()); - } - else - retval = numel; - } - break; + if (num_indices == 1) + { + ndims = 2; + dv.resize (ndims); + dv(1) = 1; + } + else + { + ndims = num_indices; + dv.resize (ndims); + } + } - default: - { - - if (index_position < dv.length ()) - retval = dv(index_position); - else - retval = 1; - } - break; - } + if (index_position < ndims) + retval = dv(index_position); + else + retval = 1; } else ::error ("invalid use of end"); @@ -171,8 +168,10 @@ if (stash_object) { unwind_protect_int (index_position); + unwind_protect_int (num_indices); - index_position = (len == 1) ? -1 : k; + index_position = k; + num_indices = len; } tree_expression *elt = *p++;