changeset 29804:977e4ad8966d

maxNumCompThreads.m: Tweaks to documentation and input validation. * maxNumCompThreads.m: Style documentation to look more like other Octave functions. Remove check for too many input variables which is automatically performed by interpreter now. Add else clause with call to error() if first input is invalid. Add BIST tests for new input validation.
author Rik <rik@octave.org>
date Tue, 22 Jun 2021 14:50:58 -0700
parents 540f25090412
children f4ccc941a941
files scripts/legacy/maxNumCompThreads.m
diffstat 1 files changed, 15 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/legacy/maxNumCompThreads.m	Tue Jun 22 13:53:49 2021 -0700
+++ b/scripts/legacy/maxNumCompThreads.m	Tue Jun 22 14:50:58 2021 -0700
@@ -24,13 +24,16 @@
 ########################################################################
 
 ## -*- texinfo -*-
-## @deftypefn {} {@var{n} = } maxNumCompThreads ()
-## @deftypefnx {} {@var{old} =} maxNumCompThreads (@var{n})
-## @deftypefnx {} {@var{old} =} maxNumCompThreads ("automatic")
-## This function is provided for Matlab compatibility only.  It uses the
-## @code{nproc} function to return the number of available processors.
-## It may also be called with an argument to set the number of
-## computational threads but that setting has no effect.
+## @deftypefn  {} {@var{n} =} maxNumCompThreads ()
+## @deftypefnx {} {@var{n_old} =} maxNumCompThreads (@var{n})
+## @deftypefnx {} {@var{n_old} =} maxNumCompThreads ("automatic")
+## This function is provided for @sc{matlab} compatibility only.
+##
+## The output @var{n} is the number of available processors as determined by
+## the @code{nproc} function.
+##
+## Programming Note: The function may be called with an argument to set the
+## number of computational threads, but that setting has @strong{no effect}.
 ## @seealso{nproc}
 ## @end deftypefn
 
@@ -38,10 +41,6 @@
 
   persistent nthreads = nproc ();
 
-  if (nargin > 1)
-    print_usage ();
-  endif
-
   retval = nthreads;
 
   if (nargin == 1)
@@ -53,11 +52,14 @@
                "maxNumCompThreads: setting number of threads has no effect");
     elseif (ischar (arg) && strcmpi (arg, "automatic"))
       nthreads = nproc ();
+    else
+      error ("maxNumCompThreads: invalid input argument");
     endif
   endif
 
 endfunction
 
+
 %!test
 %! maxNumCompThreads ("automatic");
 %! assert (maxNumCompThreads (), nproc ());
@@ -67,4 +69,5 @@
 %! maxNumCompThreads (4);
 %! assert (maxNumCompThreads ("automatic"), 4);
 
-%!error <called with too many inputs> maxNumCompThreads (1, 2);
+%!error <invalid input argument> maxNumCompThreads ([1, 2])
+%!error <invalid input argument> maxNumCompThreads ("foobar")