# HG changeset patch # User John W. Eaton # Date 1450284071 18000 # Node ID 03e4ddd49396c8a02b6353a9662b4421c0de3a08 # Parent 0fb9de5b790310d2018534562b6c8466595a63ab omit unnecessary nargout checks * paramdemo.cc, __ichol__.cc, __ilu__.cc, balance.cc, dassl.cc, eig.cc, ellipj.cc, filter.cc, givens.cc, hess.cc, lsode.cc, lu.cc, mgorth.cc, nproc.cc, pr-output.cc, quad.cc, quadcc.cc, sylvester.cc, urlwrite.cc, variables.cc, ccolamd.cc, colamd.cc, qr.cc: Don't call print_usage based on value of nargout. If nargout doesn't alter function behavior and returning extra values is inexpensive, simply return them instead of checking nargout. diff -r 0fb9de5b7903 -r 03e4ddd49396 examples/code/paramdemo.cc --- a/examples/code/paramdemo.cc Wed Dec 16 10:25:05 2015 +0100 +++ b/examples/code/paramdemo.cc Wed Dec 16 11:41:11 2015 -0500 @@ -5,9 +5,6 @@ if (args.length () != 1) print_usage (); - if (nargout != 0) - error ("paramdemo: OUTPUT argument required"); - NDArray m = args(0).array_value (); double min_val = -10.0; diff -r 0fb9de5b7903 -r 03e4ddd49396 libinterp/corefcn/__ichol__.cc --- a/libinterp/corefcn/__ichol__.cc Wed Dec 16 10:25:05 2015 +0100 +++ b/libinterp/corefcn/__ichol__.cc Wed Dec 16 11:41:11 2015 -0500 @@ -191,7 +191,7 @@ int nargin = args.length (); std::string michol = "off"; - if (nargout > 1 || nargin < 1 || nargin > 2) + if (nargin < 1 || nargin > 2) print_usage (); if (nargin == 2) @@ -438,7 +438,7 @@ std::string michol = "off"; double droptol = 0; - if (nargout > 1 || nargin < 1 || nargin > 3) + if (nargin < 1 || nargin > 3) print_usage (); // Don't repeat input validation of arguments done in ichol.m diff -r 0fb9de5b7903 -r 03e4ddd49396 libinterp/corefcn/__ilu__.cc --- a/libinterp/corefcn/__ilu__.cc Wed Dec 16 10:25:05 2015 +0100 +++ b/libinterp/corefcn/__ilu__.cc Wed Dec 16 11:41:11 2015 -0500 @@ -136,7 +136,7 @@ { int nargin = args.length (); - if (nargout > 2 || nargin < 1 || nargin > 2) + if (nargin < 1 || nargin > 2) print_usage (); octave_value_list retval (2); @@ -473,7 +473,7 @@ { int nargin = args.length (); - if (nargout != 2 || nargin < 1 || nargin > 3) + if (nargin < 1 || nargin > 3) print_usage (); std::string milu = "off"; @@ -940,7 +940,7 @@ { int nargin = args.length (); - if (nargout < 2 || nargout > 3 || nargin < 1 || nargin > 5) + if (nargin < 1 || nargin > 5) print_usage (); octave_value_list retval; diff -r 0fb9de5b7903 -r 03e4ddd49396 libinterp/corefcn/balance.cc --- a/libinterp/corefcn/balance.cc Wed Dec 16 10:25:05 2015 +0100 +++ b/libinterp/corefcn/balance.cc Wed Dec 16 11:41:11 2015 -0500 @@ -95,7 +95,7 @@ int nargin = args.length (); - if (nargin < 1 || nargin > 3 || nargout < 0 || nargout > 4) + if (nargin < 1 || nargin > 3 || nargout < 0) print_usage (); // determine if it's AEP or GEP @@ -160,17 +160,12 @@ if (nargout == 0 || nargout == 1) retval = ovl (result.balanced_matrix ()); else if (nargout == 2) - { - retval = ovl (result.balancing_matrix (), - result.balanced_matrix ()); - } + retval = ovl (result.balancing_matrix (), + result.balanced_matrix ()); else - { - retval = ovl (result.scaling_vector (), - result.permuting_vector (), - result.balanced_matrix ()); - } - + retval = ovl (result.scaling_vector (), + result.permuting_vector (), + result.balanced_matrix ()); } else { @@ -179,16 +174,12 @@ if (nargout == 0 || nargout == 1) retval = ovl (result.balanced_matrix ()); else if (nargout == 2) - { - retval = ovl (result.balancing_matrix (), - result.balanced_matrix ()); - } + retval = ovl (result.balancing_matrix (), + result.balanced_matrix ()); else - { - retval = ovl (result.scaling_vector (), - result.permuting_vector (), - result.balanced_matrix ()); - } + retval = ovl (result.scaling_vector (), + result.permuting_vector (), + result.balanced_matrix ()); } } else @@ -200,16 +191,12 @@ if (nargout == 0 || nargout == 1) retval = ovl (result.balanced_matrix ()); else if (nargout == 2) - { - retval = ovl (result.balancing_matrix (), - result.balanced_matrix ()); - } + retval = ovl (result.balancing_matrix (), + result.balanced_matrix ()); else - { - retval = ovl (result.scaling_vector (), - result.permuting_vector (), - result.balanced_matrix ()); - } + retval = ovl (result.scaling_vector (), + result.permuting_vector (), + result.balanced_matrix ()); } else { @@ -218,16 +205,12 @@ if (nargout == 0 || nargout == 1) retval = ovl (result.balanced_matrix ()); else if (nargout == 2) - { - retval = ovl (result.balancing_matrix (), - result.balanced_matrix ()); - } + retval = ovl (result.balancing_matrix (), + result.balanced_matrix ()); else - { - retval = ovl (result.scaling_vector (), - result.permuting_vector (), - result.balanced_matrix ()); - } + retval = ovl (result.scaling_vector (), + result.permuting_vector (), + result.balanced_matrix ()); } } } diff -r 0fb9de5b7903 -r 03e4ddd49396 libinterp/corefcn/dassl.cc --- a/libinterp/corefcn/dassl.cc Wed Dec 16 10:25:05 2015 +0100 +++ b/libinterp/corefcn/dassl.cc Wed Dec 16 11:41:11 2015 -0500 @@ -293,7 +293,7 @@ int nargin = args.length (); - if (nargin < 4 || nargin > 5 || nargout > 4) + if (nargin < 4 || nargin > 5) print_usage (); std::string fcn_name, fname, jac_name, jname; diff -r 0fb9de5b7903 -r 03e4ddd49396 libinterp/corefcn/eig.cc --- a/libinterp/corefcn/eig.cc Wed Dec 16 10:25:05 2015 +0100 +++ b/libinterp/corefcn/eig.cc Wed Dec 16 11:41:11 2015 -0500 @@ -54,7 +54,7 @@ int nargin = args.length (); - if (nargin > 2 || nargin == 0 || nargout > 2) + if (nargin > 2 || nargin == 0) print_usage (); octave_value arg_a, arg_b; diff -r 0fb9de5b7903 -r 03e4ddd49396 libinterp/corefcn/ellipj.cc --- a/libinterp/corefcn/ellipj.cc Wed Dec 16 10:25:05 2015 +0100 +++ b/libinterp/corefcn/ellipj.cc Wed Dec 16 11:41:11 2015 -0500 @@ -73,8 +73,6 @@ if (nargin < 2 || nargin > 3) print_usage (); - octave_value_list retval (nargout > 3 ? 4 : 3); - octave_value u_arg = args(0); octave_value m_arg = args(1); @@ -94,10 +92,7 @@ ellipj (u, m, sn, cn, dn, err); - if (nargout <= 3) - return ovl (sn, cn, dn); - else - return ovl (sn, cn, dn, err); + return ovl (sn, cn, dn, err); } else { @@ -109,10 +104,7 @@ ellipj (u, m, sn, cn, dn, err); - if (nargout <= 3) - return ovl (sn, cn, dn); - else - return ovl (sn, cn, dn, err); + return ovl (sn, cn, dn, err); } } else @@ -135,11 +127,7 @@ for (octave_idx_type i = 0; i < nel; i++) ellipj (pu[i], m, psn[i], pcn[i], pdn[i], perr[i]); - - if (nargout <= 3) - return ovl (sn, cn, dn); - else - return ovl (sn, cn, dn, err); + return ovl (sn, cn, dn, err); } } else @@ -169,10 +157,7 @@ for (octave_idx_type i = 0; i < nel; i++) ellipj (u, pm[i], psn[i], pcn[i], pdn[i], perr[i]); - if (nargout <= 3) - return ovl (sn, cn, dn); - else - return ovl (sn, cn, dn, err); + return ovl (sn, cn, dn, err); } else { @@ -192,10 +177,7 @@ for (octave_idx_type i = 0; i < nel; i++) ellipj (u, pm[i], psn[i], pcn[i], pdn[i], perr[i]); - if (nargout <= 3) - return ovl (sn, cn, dn); - else - return ovl (sn, cn, dn, err); + return ovl (sn, cn, dn, err); } } else @@ -227,10 +209,7 @@ ellipj (pu[i], pm[j], sn(i,j), cn(i,j), dn(i,j), err(i,j)); - if (nargout <= 3) - return ovl (sn, cn, dn); - else - return ovl (sn, cn, dn, err); + return ovl (sn, cn, dn, err); } else if (sz_m == sz_u) { @@ -248,10 +227,7 @@ for (octave_idx_type i = 0; i < nel; i++) ellipj (pu[i], pm[i], psn[i], pcn[i], pdn[i], perr[i]); - if (nargout <= 3) - return ovl (sn, cn, dn); - else - return ovl (sn, cn, dn, err); + return ovl (sn, cn, dn, err); } else error ("ellipj: Invalid size combination for U and M"); @@ -282,10 +258,7 @@ ellipj (pu[i], pm[j], sn(i,j), cn(i,j), dn(i,j), err(i,j)); - if (nargout <= 3) - return ovl (sn, cn, dn); - else - return ovl (sn, cn, dn, err); + return ovl (sn, cn, dn, err); } else if (sz_m == sz_u) { @@ -303,10 +276,7 @@ for (octave_idx_type i = 0; i < nel; i++) ellipj (pu[i], pm[i], psn[i], pcn[i], pdn[i], perr[i]); - if (nargout <= 3) - return ovl (sn, cn, dn); - else - return ovl (sn, cn, dn, err); + return ovl (sn, cn, dn, err); } else error ("ellipj: Invalid size combination for U and M"); @@ -314,7 +284,7 @@ } } // m matrix - return retval; + return octave_value_list (); } /* diff -r 0fb9de5b7903 -r 03e4ddd49396 libinterp/corefcn/filter.cc --- a/libinterp/corefcn/filter.cc Wed Dec 16 10:25:05 2015 +0100 +++ b/libinterp/corefcn/filter.cc Wed Dec 16 11:41:11 2015 -0500 @@ -400,7 +400,7 @@ dim = 0; } - octave_value_list retval (nargout > 1 ? 2 : 1); + octave_value_list retval; bool isfloat = (args(0).is_single_type () || args(1).is_single_type () @@ -444,9 +444,7 @@ FloatComplexNDArray y (filter (b, a, x, si, dim)); - retval(0) = y; - if (nargout == 2) - retval(1) = si; + retval = ovl (y, si); } else { @@ -481,9 +479,7 @@ ComplexNDArray y (filter (b, a, x, si, dim)); - retval(0) = y; - if (nargout == 2) - retval(1) = si; + retval = ovl (y, si); } } else @@ -521,9 +517,7 @@ FloatNDArray y (filter (b, a, x, si, dim)); - retval(0) = y; - if (nargout == 2) - retval(1) = si; + retval = ovl (y, si); } else { @@ -558,9 +552,7 @@ NDArray y (filter (b, a, x, si, dim)); - retval(0) = y; - if (nargout == 2) - retval(1) = si; + retval = ovl (y, si); } } diff -r 0fb9de5b7903 -r 03e4ddd49396 libinterp/corefcn/givens.cc --- a/libinterp/corefcn/givens.cc Wed Dec 16 10:25:05 2015 +0100 +++ b/libinterp/corefcn/givens.cc Wed Dec 16 11:41:11 2015 -0500 @@ -76,7 +76,7 @@ { octave_value_list retval; - if (args.length () != 2 || nargout > 2) + if (args.length () != 2) print_usage (); if (args(0).is_single_type () || args(1).is_single_type ()) diff -r 0fb9de5b7903 -r 03e4ddd49396 libinterp/corefcn/hess.cc --- a/libinterp/corefcn/hess.cc Wed Dec 16 10:25:05 2015 +0100 +++ b/libinterp/corefcn/hess.cc Wed Dec 16 11:41:11 2015 -0500 @@ -66,7 +66,7 @@ { octave_value_list retval; - if (args.length () != 1 || nargout > 2) + if (args.length () != 1) print_usage (); octave_value arg = args(0); @@ -98,10 +98,8 @@ if (nargout <= 1) retval = ovl (result.hess_matrix ()); else - { - retval = ovl (result.unitary_hess_matrix (), - result.hess_matrix ()); - } + retval = ovl (result.unitary_hess_matrix (), + result.hess_matrix ()); } else if (arg.is_complex_type ()) { @@ -112,10 +110,8 @@ if (nargout <= 1) retval = ovl (result.hess_matrix ()); else - { - retval = ovl (result.unitary_hess_matrix (), - result.hess_matrix ()); - } + retval = ovl (result.unitary_hess_matrix (), + result.hess_matrix ()); } } else @@ -129,10 +125,8 @@ if (nargout <= 1) retval = ovl (result.hess_matrix ()); else - { - retval = ovl (result.unitary_hess_matrix (), - result.hess_matrix ()); - } + retval = ovl (result.unitary_hess_matrix (), + result.hess_matrix ()); } else if (arg.is_complex_type ()) { @@ -143,10 +137,8 @@ if (nargout <= 1) retval = ovl (result.hess_matrix ()); else - { - retval = ovl (result.unitary_hess_matrix (), - result.hess_matrix ()); - } + retval = ovl (result.unitary_hess_matrix (), + result.hess_matrix ()); } else { diff -r 0fb9de5b7903 -r 03e4ddd49396 libinterp/corefcn/lsode.cc --- a/libinterp/corefcn/lsode.cc Wed Dec 16 10:25:05 2015 +0100 +++ b/libinterp/corefcn/lsode.cc Wed Dec 16 11:41:11 2015 -0500 @@ -263,7 +263,7 @@ { int nargin = args.length (); - if (nargin < 3 || nargin > 4 || nargout > 3) + if (nargin < 3 || nargin > 4) print_usage (); warned_fcn_imaginary = false; diff -r 0fb9de5b7903 -r 03e4ddd49396 libinterp/corefcn/lu.cc --- a/libinterp/corefcn/lu.cc Wed Dec 16 10:25:05 2015 +0100 +++ b/libinterp/corefcn/lu.cc Wed Dec 16 11:41:11 2015 -0500 @@ -145,8 +145,7 @@ int nargin = args.length (); bool issparse = (nargin > 0 && args(0).is_sparse_type ()); - if (nargin < 1 || (issparse && (nargin > 3 || nargout > 5)) - || (! issparse && (nargin > 2 || nargout > 3))) + if (nargin < 1 || (issparse && nargin > 3) || (! issparse && nargin > 2)) print_usage (); bool vecout = false; diff -r 0fb9de5b7903 -r 03e4ddd49396 libinterp/corefcn/mgorth.cc --- a/libinterp/corefcn/mgorth.cc Wed Dec 16 10:25:05 2015 +0100 +++ b/libinterp/corefcn/mgorth.cc Wed Dec 16 11:41:11 2015 -0500 @@ -69,7 +69,7 @@ { octave_value_list retval; - if (args.length () != 2 || nargout > 2) + if (args.length () != 2) print_usage (); octave_value arg_x = args(0); diff -r 0fb9de5b7903 -r 03e4ddd49396 libinterp/corefcn/nproc.cc --- a/libinterp/corefcn/nproc.cc Wed Dec 16 10:25:05 2015 +0100 +++ b/libinterp/corefcn/nproc.cc Wed Dec 16 11:41:11 2015 -0500 @@ -53,7 +53,7 @@ int nargin = args.length (); - if ((nargin != 0 && nargin != 1) || (nargout != 0 && nargout != 1)) + if (nargin > 1) print_usage (); nproc_query query = NPROC_CURRENT; diff -r 0fb9de5b7903 -r 03e4ddd49396 libinterp/corefcn/pr-output.cc --- a/libinterp/corefcn/pr-output.cc Wed Dec 16 10:25:05 2015 +0100 +++ b/libinterp/corefcn/pr-output.cc Wed Dec 16 11:41:11 2015 -0500 @@ -3429,7 +3429,7 @@ int nargin = args.length (); - if (nargin < 1 || nargin > 2 || nargout > 1) + if (nargin < 1 || nargin > 2) print_usage (); unwind_protect frame; @@ -3508,7 +3508,7 @@ { octave_value_list retval; - if (args.length () != 1 || nargout > 1) + if (args.length () != 1) print_usage (); octave_value arg = args(0); diff -r 0fb9de5b7903 -r 03e4ddd49396 libinterp/corefcn/quad.cc --- a/libinterp/corefcn/quad.cc Wed Dec 16 10:25:05 2015 +0100 +++ b/libinterp/corefcn/quad.cc Wed Dec 16 11:41:11 2015 -0500 @@ -196,7 +196,7 @@ int nargin = args.length (); - if (nargin < 3 || nargin > 5 || nargout > 4) + if (nargin < 3 || nargin > 5) print_usage (); if (args(0).is_function_handle () || args(0).is_inline_function ()) diff -r 0fb9de5b7903 -r 03e4ddd49396 libinterp/corefcn/quadcc.cc --- a/libinterp/corefcn/quadcc.cc Wed Dec 16 10:25:05 2015 +0100 +++ b/libinterp/corefcn/quadcc.cc Wed Dec 16 11:41:11 2015 -0500 @@ -2214,16 +2214,7 @@ } #endif - /* Clean up and present the results. */ - octave_value_list retval; - - if (nargout > 2) - retval(2) = neval; - if (nargout > 1) - retval(1) = err; - retval(0) = igral; - /* All is well that ends well. */ - return retval; + return ovl (igral, err, neval); } diff -r 0fb9de5b7903 -r 03e4ddd49396 libinterp/corefcn/sylvester.cc --- a/libinterp/corefcn/sylvester.cc Wed Dec 16 10:25:05 2015 +0100 +++ b/libinterp/corefcn/sylvester.cc Wed Dec 16 11:41:11 2015 -0500 @@ -62,7 +62,7 @@ { octave_value retval; - if (args.length () != 3 || nargout > 1) + if (args.length () != 3) print_usage (); octave_value arg_a = args(0); diff -r 0fb9de5b7903 -r 03e4ddd49396 libinterp/corefcn/urlwrite.cc --- a/libinterp/corefcn/urlwrite.cc Wed Dec 16 10:25:05 2015 +0100 +++ b/libinterp/corefcn/urlwrite.cc Wed Dec 16 11:41:11 2015 -0500 @@ -388,15 +388,10 @@ if (nargout > 0) { if (curl.good ()) - { - retval = ovl (octave_env::make_absolute (filename), - true, - std::string ()); - } + retval = ovl (octave_env::make_absolute (filename), + true, std::string ()); else - { - retval = ovl (std::string (), false, curl.lasterror ()); - } + retval = ovl (std::string (), false, curl.lasterror ()); } if (nargout < 2 && ! curl.good ()) diff -r 0fb9de5b7903 -r 03e4ddd49396 libinterp/corefcn/variables.cc --- a/libinterp/corefcn/variables.cc Wed Dec 16 10:25:05 2015 +0100 +++ b/libinterp/corefcn/variables.cc Wed Dec 16 11:41:11 2015 -0500 @@ -1820,9 +1820,6 @@ @seealso{whos, isglobal, isvarname, exist, regexp}\n\ @end deftypefn") { - if (nargout > 1) - print_usage (); - int argc = args.length () + 1; string_vector argv = args.make_argv ("who"); @@ -1894,9 +1891,6 @@ @seealso{who, whos_line_format}\n\ @end deftypefn") { - if (nargout > 1) - print_usage (); - int argc = args.length () + 1; string_vector argv = args.make_argv ("whos"); diff -r 0fb9de5b7903 -r 03e4ddd49396 libinterp/dldfcn/ccolamd.cc --- a/libinterp/dldfcn/ccolamd.cc Wed Dec 16 10:25:05 2015 +0100 +++ b/libinterp/dldfcn/ccolamd.cc Wed Dec 16 11:41:11 2015 -0500 @@ -147,8 +147,8 @@ int nargin = args.length (); - if (nargout > 2 || nargin < 1 || nargin > 3) - usage ("ccolamd: incorrect number of input and/or output arguments"); + if (nargin < 1 || nargin > 3) + print_usage (); octave_value_list retval (nargout == 2 ? 2 : 1); int spumoni = 0; @@ -405,8 +405,8 @@ int nargin = args.length (); - if (nargout > 2 || nargin < 1 || nargin > 3) - usage ("ccolamd: incorrect number of input and/or output arguments"); + if (nargin < 1 || nargin > 3) + print_usage (); octave_value_list retval (nargout == 2 ? 2 : 1); int spumoni = 0; diff -r 0fb9de5b7903 -r 03e4ddd49396 libinterp/dldfcn/colamd.cc --- a/libinterp/dldfcn/colamd.cc Wed Dec 16 10:25:05 2015 +0100 +++ b/libinterp/dldfcn/colamd.cc Wed Dec 16 11:41:11 2015 -0500 @@ -281,7 +281,7 @@ #ifdef HAVE_COLAMD int nargin = args.length (); - if (nargout > 2 || nargin < 1 || nargin > 2) + if (nargin < 1 || nargin > 2) print_usage (); octave_value_list retval (nargout == 2 ? 2 : 1); @@ -516,7 +516,7 @@ int nargin = args.length (); - if (nargout > 2 || nargin < 1 || nargin > 2) + if (nargin < 1 || nargin > 2) print_usage (); octave_value_list retval (nargin == 2 ? 2 : 1); @@ -657,7 +657,7 @@ { int nargin = args.length (); - if (nargout > 2 || nargin < 1 || nargin > 2) + if (nargin < 1 || nargin > 2) print_usage (); octave_value_list retval (nargout == 2 ? 2 : 1); diff -r 0fb9de5b7903 -r 03e4ddd49396 libinterp/dldfcn/qr.cc --- a/libinterp/dldfcn/qr.cc Wed Dec 16 10:25:05 2015 +0100 +++ b/libinterp/dldfcn/qr.cc Wed Dec 16 11:41:11 2015 -0500 @@ -237,9 +237,7 @@ is_cmplx = true; } - if (have_b && nargout < 2) - error ("qr: incorrect number of output arguments"); - else if (is_cmplx) + if (is_cmplx) { SparseComplexQR q (arg.sparse_complex_matrix_value ()); @@ -251,9 +249,7 @@ warning ("qr: non minimum norm solution for under-determined problem"); } else if (nargout > 1) - { - retval = ovl (q.Q (), q.R (economy)); - } + retval = ovl (q.Q (), q.R (economy)); else retval = ovl (q.R (economy)); } @@ -268,9 +264,7 @@ warning ("qr: non minimum norm solution for under-determined problem"); } else if (nargout > 1) - { - retval = ovl (q.Q (), q.R (economy)); - } + retval = ovl (q.Q (), q.R (economy)); else retval = ovl (q.R (economy)); } @@ -703,7 +697,6 @@ %! [c,r] = qr (a, b); %! assert (r\c, full (a)\b, 10e-10) -%!error qr (sprandn (10,10,0.2), ones (10,1)) */ static diff -r 0fb9de5b7903 -r 03e4ddd49396 scripts/ode/module.mk --- a/scripts/ode/module.mk Wed Dec 16 10:25:05 2015 +0100 +++ b/scripts/ode/module.mk Wed Dec 16 11:41:11 2015 -0500 @@ -8,7 +8,7 @@ scripts/ode/private/integrate_const.m \ scripts/ode/private/integrate_n_steps.m \ scripts/ode/private/kahan.m \ - scripts/ode/private/known_option_names \ + scripts/ode/private/known_option_names.m \ scripts/ode/private/ode_event_handler.m \ scripts/ode/private/ode_struct_value_check.m \ scripts/ode/private/runge_kutta_23.m \