From bug-request at octave dot org Mon Dec 20 13:25:08 2004 Subject: Problem with end of vector From: "John W. Eaton" To: Joe Koski Cc: Date: Mon, 20 Dec 2004 14:26:17 -0500 On 20-Dec-2004, Joe Koski wrote: | Here is a short script that demonstrates the problem with end that I | mentioned in my e-mail message: | | curindminps = [1:20]; | curindmaxps = [1:30]; | LARGTRANSPS = 5; | k = 3; i = 4; | | endcurmin=length(curindminps); | endcurmax=length(curindmaxps); | | % the next line works | stopps(k,i) = min(curindminps(max([1,endcurmin - | LARGTRANSPS+1])),curindmaxps(max([1,endcurmax - LARGTRANSPS+1]))) | | % the next line doesn't work | stopps(k,i) = min(curindminps(max([1,end - | LARGTRANSPS+1])),curindmaxps(max([1,end - LARGTRANSPS+1]))); | | You may need to remove line breaks in the long lines to get this script to | work. | | Problem #2: | The same routine works with a test case provided by the originators and with | one of my data sets, but fails with another data set: Please try the following patch. Thanks, jwe src/ChangeLog: 2004-12-20 John W. Eaton * pt-idx.cc (tree_index_expression::has_magic_end): Return true if any argument list element has a magic end token. Index: pt-idx.cc =================================================================== RCS file: /usr/local/cvsroot/octave/src/pt-idx.cc,v retrieving revision 1.25 diff -u -r1.25 pt-idx.cc --- pt-idx.cc 16 Dec 2003 05:11:26 -0000 1.25 +++ pt-idx.cc 20 Dec 2004 19:22:09 -0000 at @ -110,6 +110,22 @@ } } +bool +tree_index_expression::has_magic_end (void) const +{ + for (std::list::const_iterator p = args.begin (); + p != args.end (); + p++) + { + tree_argument_list *elt = *p; + + if (elt && elt->has_magic_end ()) + return true; + } + + return false; +} + // This is useful for printing the name of the variable in an indexed // assignment. Index: pt-idx.h =================================================================== RCS file: /usr/local/cvsroot/octave/src/pt-idx.h,v retrieving revision 1.16 diff -u -r1.16 pt-idx.h --- pt-idx.h 3 Jan 2003 15:27:06 -0000 1.16 +++ pt-idx.h 20 Dec 2004 19:22:09 -0000 at @ -60,7 +60,7 @@ ~tree_index_expression (void); - bool has_magic_end (void) const { return false; } + bool has_magic_end (void) const; void append (tree_argument_list *lst = 0, char t = '('); ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------