From: Michael C. <mc...@us...> - 2004-09-14 12:17:10
|
Update of /cvsroot/octave/octave-forge/main/optim In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11387/main/optim Modified Files: bfgsmin.cc bisectionstep.cc newtonstep.cc Log Message: final round arg checking for these functions (famous last words!) Index: newtonstep.cc =================================================================== RCS file: /cvsroot/octave/octave-forge/main/optim/newtonstep.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- newtonstep.cc 7 Sep 2004 10:30:02 -0000 1.5 +++ newtonstep.cc 14 Sep 2004 12:16:57 -0000 1.6 @@ -28,36 +28,50 @@ #include <octave/lo-ieee.h> #include <float.h> -// static bool -// any_bad_argument(const octave_value_list& args) -// { -// if (!args(0).is_string()) -// { -// error("newtonstep: first argument must be string holding objective function name"); -// return true; -// } -// if (!args(1).is_cell()) -// { -// error("newtonstep: second argument must cell array of function arguments"); -// return true; -// } -// if (!args(2).is_real_type()) -// { -// error("newtonstep: third argument must be column vector of directions"); -// return true; -// } -// -// if (args.length() == 4) -// { -// if (!args(3).is_real_scalar()) -// { -// error("newtonstep: 4th argument, if supplied, must be a scalar specifying which is the minimand"); -// return true; -// } -// } -// -// return false; -// } +static bool +any_bad_argument(const octave_value_list& args) +{ + if (!args(0).is_string()) + { + error("newtonstep: first argument must be string holding objective function name"); + return true; + } + if (!args(1).is_cell()) + { + error("newtonstep: second argument must cell array of function arguments"); + return true; + } + + if (!(args(2).is_real_matrix() || args(2).is_real_scalar())) + { + error("newtonstep: third argument must be column vector of directions"); + return true; + } + if ((args(2).is_real_matrix()) && (args(2).columns() != 1)) + { + error("newtonstep: third argument must be column vector of directions"); + return true; + } + + if (args.length() == 4) + { + int tmp = args(3).int_value(); + if (error_state) + { + error("newtonstep: 4th argument, if supplied, must be an integer scalar"); + return true; + } + if ((tmp > args(1).length()|| tmp < 1)) + { + error("newtonstep: 4th argument must be a positive integer that indicates \n\ +which of the elements of the second argument is the one minimization is over"); + return true; + } + + } + + return false; +} @@ -65,15 +79,15 @@ { -// int nargin = args.length (); -// if ((nargin < 3) || (nargin > 4)) -// { -// error("newtonstep: you must supply 3 or 4 arguments"); -// return octave_value_list(); -// } -// -// // check the arguments -// if (any_bad_argument(args)) return octave_value_list(); + int nargin = args.length (); + if ((nargin < 3) || (nargin > 4)) + { + error("newtonstep: you must supply 3 or 4 arguments"); + return octave_value_list(); + } + + // check the arguments + if (any_bad_argument(args)) return octave_value_list(); Index: bfgsmin.cc =================================================================== RCS file: /cvsroot/octave/octave-forge/main/optim/bfgsmin.cc,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- bfgsmin.cc 9 Sep 2004 12:16:37 -0000 1.9 +++ bfgsmin.cc 14 Sep 2004 12:16:57 -0000 1.10 @@ -85,7 +85,16 @@ { error("bfgsmin: 3rd argument must be a cell array of 4 or 5 integers"); return true; - } + } + if (i = 3) // minarg must point to one of args(1) + { + if ((tmp > args(1).length())||(tmp < 1)) + { + error("bfgsmin: 4th argument must be a positive integer that indicates \n\ +which of the elements of the second argument is the one minimization is over"); + return true; + } + } } } @@ -124,7 +133,6 @@ } } } - return false; } Index: bisectionstep.cc =================================================================== RCS file: /cvsroot/octave/octave-forge/main/optim/bisectionstep.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- bisectionstep.cc 6 Sep 2004 13:50:25 -0000 1.4 +++ bisectionstep.cc 14 Sep 2004 12:16:57 -0000 1.5 @@ -46,20 +46,34 @@ error("bisectionstep: second argument must cell array of function arguments"); return true; } - if (!args(2).is_real_type()) - { - error("bisectionstep: third argument must be column vector of directions"); - return true; - } + + if (!(args(2).is_real_matrix() || args(2).is_real_scalar())) + { + error("bisectionstep: third argument must be column vector of directions"); + return true; + } + if ((args(2).is_real_matrix()) && (args(2).columns() != 1)) + { + error("bisectionstep: third argument must be column vector of directions"); + return true; + } if (args.length() == 4) - { - if (!args(3).is_real_scalar()) - { - error("bisectionstep: 4th argument, if supplied, must be a scalar specifying which is the minimand"); - return true; - } - } + { + int tmp = args(3).int_value(); + if (error_state) + { + error("bisectionstep: 4th argument, if supplied, must be an integer scalar"); + return true; + } + if ((tmp > args(1).length()|| tmp < 1)) + { + error("bisectionstep: 4th argument must be a positive integer that indicates \n\ +which of the elements of the second argument is the one minimization is over"); + return true; + } + + } return false; } |