changeset 25806:23483673ba43

Use is_function_handle instead of isa (x, "function_handle"). * ov-fcn-handle.cc (Fis_function_handle): Add BIST test for an inline function. * gradient.m, isequal.m, isequaln.m, __makeinfo__.m, nthargout.m, decic.m, ode15i.m, ode15s.m, ode23.m, ode45.m, check_default_input.m, fplot.m, __ezplot__.m, __alltohandles__.m, qmr.m, spfun.m, args.tst: Use is_function_handle instead of isa (x, "function_handle").
author Rik <rik@octave.org>
date Wed, 15 Aug 2018 15:29:11 -0700
parents b785394f10d0
children 440d7766b5c6
files libinterp/octave-value/ov-fcn-handle.cc scripts/general/gradient.m scripts/general/isequal.m scripts/general/isequaln.m scripts/help/__makeinfo__.m scripts/miscellaneous/nthargout.m scripts/ode/decic.m scripts/ode/ode15i.m scripts/ode/ode15s.m scripts/ode/ode23.m scripts/ode/ode45.m scripts/ode/private/check_default_input.m scripts/plot/draw/fplot.m scripts/plot/draw/private/__ezplot__.m scripts/sparse/private/__alltohandles__.m scripts/sparse/qmr.m scripts/sparse/spfun.m test/args.tst
diffstat 18 files changed, 40 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-fcn-handle.cc	Wed Aug 15 14:13:28 2018 -0700
+++ b/libinterp/octave-value/ov-fcn-handle.cc	Wed Aug 15 15:29:11 2018 -0700
@@ -1918,10 +1918,12 @@
 }
 
 /*
-%!shared fh
+%!shared fh, finline
 %! fh = @(x) x;
+%! finline = inline ("x");
 
 %!assert (is_function_handle (fh))
+%!assert (is_function_handle (finline))
 %!assert (! is_function_handle ({fh}))
 %!assert (! is_function_handle (1))
 
--- a/scripts/general/gradient.m	Wed Aug 15 14:13:28 2018 -0700
+++ b/scripts/general/gradient.m	Wed Aug 15 15:29:11 2018 -0700
@@ -72,7 +72,7 @@
   nargout_with_ans = max (1,nargout);
   if (isnumeric (m))
     [varargout{1:nargout_with_ans}] = matrix_gradient (m, varargin{:});
-  elseif (isa (m, "function_handle"))
+  elseif (is_function_handle (m))
     [varargout{1:nargout_with_ans}] = handle_gradient (m, varargin{:});
   elseif (ischar (m))
     [varargout{1:nargout_with_ans}] = handle_gradient (str2func (m), ...
--- a/scripts/general/isequal.m	Wed Aug 15 14:13:28 2018 -0700
+++ b/scripts/general/isequal.m	Wed Aug 15 15:29:11 2018 -0700
@@ -162,7 +162,7 @@
           idx += 1;
         endwhile
 
-      elseif (isa (x, "function_handle"))
+      elseif (is_function_handle (x))
         ## function type.  Use '==' operator which is overloaded.
         t = (x == y);
 
@@ -291,7 +291,7 @@
           idx += 1;
         endwhile
 
-      elseif (isa (x, "function_handle"))
+      elseif (is_function_handle (x))
         ## function type.  Use '==' operator which is overloaded.
         t = all (cellfun ("eq", {x}, varargin));
 
--- a/scripts/general/isequaln.m	Wed Aug 15 14:13:28 2018 -0700
+++ b/scripts/general/isequaln.m	Wed Aug 15 15:29:11 2018 -0700
@@ -160,7 +160,7 @@
           idx += 1;
         endwhile
 
-      elseif (isa (x, "function_handle"))
+      elseif (is_function_handle (x))
         ## function type.  Use '==' operator which is overloaded.
         t = (x == y);
 
@@ -275,7 +275,7 @@
           idx += 1;
         endwhile
 
-      elseif (isa (x, "function_handle"))
+      elseif (is_function_handle (x))
         ## function type.  Use '==' operator which is overloaded.
         t = all (cellfun ("eq", {x}, varargin));
 
--- a/scripts/help/__makeinfo__.m	Wed Aug 15 14:13:28 2018 -0700
+++ b/scripts/help/__makeinfo__.m	Wed Aug 15 15:29:11 2018 -0700
@@ -83,7 +83,7 @@
     endif
   endif
 
-  if (! isa (fsee_also, "function_handle"))
+  if (! is_function_handle (fsee_also))
     error ("__makeinfo__: third input argument must be a function handle");
   endif
 
--- a/scripts/miscellaneous/nthargout.m	Wed Aug 15 14:13:28 2018 -0700
+++ b/scripts/miscellaneous/nthargout.m	Wed Aug 15 15:29:11 2018 -0700
@@ -72,12 +72,12 @@
     print_usage ();
   endif
 
-  if (isa (varargin{1}, "function_handle") || ischar (varargin{1}))
+  if (is_function_handle (varargin{1}) || ischar (varargin{1}))
     ntot = max (n(:));
     func = varargin{1};
     args = varargin(2:end);
   elseif (isnumeric (varargin{1})
-          && (isa (varargin{2}, "function_handle") || ischar (varargin{2})))
+          && (is_function_handle (varargin{2}) || ischar (varargin{2})))
     ntot = varargin{1};
     func = varargin{2};
     args = varargin(3:end);
--- a/scripts/ode/decic.m	Wed Aug 15 14:13:28 2018 -0700
+++ b/scripts/ode/decic.m	Wed Aug 15 15:29:11 2018 -0700
@@ -95,7 +95,7 @@
   endif
 
   ## Validate inputs
-  if (! isa (fun, "function_handle"))
+  if (! is_function_handle (fun))
     error ("Octave:invalid-input-arg",
            "decic: FUN must be a valid function handle");
   endif
--- a/scripts/ode/ode15i.m	Wed Aug 15 14:13:28 2018 -0700
+++ b/scripts/ode/ode15i.m	Wed Aug 15 15:29:11 2018 -0700
@@ -115,7 +115,7 @@
       catch
         warning (lasterr);
       end_try_catch
-      if (! isa (options.Jacobian, "function_handle"))
+      if (! is_function_handle (options.Jacobian))
         error ("Octave:invalid-input-arg",
                [solver ": invalid value assigned to field 'Jacobian'"]);
       endif
@@ -129,7 +129,7 @@
       catch
         warning (lasterr);
       end_try_catch
-      if (! isa (options.OutputFcn, "function_handle"))
+      if (! is_function_handle (options.OutputFcn))
         error ("Octave:invalid-input-arg",
                [solver ": invalid value assigned to field 'OutputFcn'"]);
       endif
@@ -143,7 +143,7 @@
       catch
         warning (lasterr);
       end_try_catch
-      if (! isa (options.Events, "function_handle")
+      if (! is_function_handle (options.Events)
           && ! ismatrix (options.Events))
         error ("Octave:invalid-input-arg",
                [solver ": invalid value assigned to field 'Events'"]);
@@ -194,7 +194,7 @@
                [solver ": invalid value assigned to field 'Jacobian'"]);
       endif
 
-    elseif (isa (options.Jacobian, "function_handle"))
+    elseif (is_function_handle (options.Jacobian))
       options.havejacfun = true;
       if (nargin (options.Jacobian) == 3)
         [A, B] = options.Jacobian (trange(1), y0, yp0);
--- a/scripts/ode/ode15s.m	Wed Aug 15 14:13:28 2018 -0700
+++ b/scripts/ode/ode15s.m	Wed Aug 15 15:29:11 2018 -0700
@@ -109,7 +109,7 @@
       catch
         warning (lasterr);
       end_try_catch
-      if (! isa (options.Mass, "function_handle"))
+      if (! is_function_handle (options.Mass))
         error ("Octave:invalid-input-arg",
                [solver ": invalid value assigned to field 'Mass'"]);
       endif
@@ -123,7 +123,7 @@
       catch
         warning (lasterr);
       end_try_catch
-      if (! isa (options.Jacobian, "function_handle"))
+      if (! is_function_handle (options.Jacobian))
         error ("Octave:invalid-input-arg",
                [solver ": invalid value assigned to field 'Jacobian'"]);
       endif
@@ -137,7 +137,7 @@
       catch
         warning (lasterr);
       end_try_catch
-      if (! isa (options.OutputFcn, "function_handle"))
+      if (! is_function_handle (options.OutputFcn))
         error ("Octave:invalid-input-arg",
                [solver ": invalid value assigned to field '%s'"], "OutputFcn");
       endif
@@ -151,7 +151,7 @@
       catch
         warning (lasterr);
       end_try_catch
-      if (! isa (options.Events, "function_handle"))
+      if (! is_function_handle (options.Events))
         error ("Octave:invalid-input-arg",
                [solver ": invalid value assigned to field 'Events'"]);
       endif
@@ -173,7 +173,7 @@
   options.havemasssparse = false;
 
   if (! isempty (options.Mass))
-    if (isa (options.Mass, "function_handle"))
+    if (is_function_handle (options.Mass))
       options.havemassfun = true;
       if (nargin (options.Mass) == 2)
         options.havestatedep = true;
@@ -215,7 +215,7 @@
 
   if (! isempty (options.Jacobian))
     options.havejac = true;
-    if (isa (options.Jacobian, "function_handle"))
+    if (is_function_handle (options.Jacobian))
       options.havejacfun = true;
       if (nargin (options.Jacobian) == 2)
         [A] = options.Jacobian (trange(1), y0);
--- a/scripts/ode/ode23.m	Wed Aug 15 14:13:28 2018 -0700
+++ b/scripts/ode/ode23.m	Wed Aug 15 15:29:11 2018 -0700
@@ -145,7 +145,7 @@
       warning (lasterr);
     end_try_catch
   endif
-  if (! isa (fun, "function_handle"))
+  if (! is_function_handle (fun))
     error ("Octave:invalid-input-arg",
            "ode23: FUN must be a valid function handle");
   endif
@@ -199,7 +199,7 @@
   if (! isempty (odeopts.Mass) && isnumeric (odeopts.Mass))
     havemasshandle = false;
     mass = odeopts.Mass;    # constant mass
-  elseif (isa (odeopts.Mass, "function_handle"))
+  elseif (is_function_handle (odeopts.Mass))
     havemasshandle = true;  # mass defined by a function handle
   else  # no mass matrix - creating a diag-matrix of ones for mass
     havemasshandle = false; # mass = diag (ones (length (init), 1), 0);
--- a/scripts/ode/ode45.m	Wed Aug 15 14:13:28 2018 -0700
+++ b/scripts/ode/ode45.m	Wed Aug 15 15:29:11 2018 -0700
@@ -142,7 +142,7 @@
       warning (lasterr);
     end_try_catch
   endif
-  if (! isa (fun, "function_handle"))
+  if (! is_function_handle (fun))
     error ("Octave:invalid-input-arg",
            "ode45: FUN must be a valid function handle");
   endif
@@ -199,7 +199,7 @@
   if (! isempty (odeopts.Mass) && isnumeric (odeopts.Mass))
     havemasshandle = false;
     mass = odeopts.Mass;  # constant mass
-  elseif (isa (odeopts.Mass, "function_handle"))
+  elseif (is_function_handle (odeopts.Mass))
     havemasshandle = true;    # mass defined by a function handle
   else  # no mass matrix - creating a diag-matrix of ones for mass
     havemasshandle = false;   # mass = diag (ones (length (init), 1), 0);
--- a/scripts/ode/private/check_default_input.m	Wed Aug 15 14:13:28 2018 -0700
+++ b/scripts/ode/private/check_default_input.m	Wed Aug 15 15:29:11 2018 -0700
@@ -33,7 +33,7 @@
       warning (lasterr);
     end_try_catch
   endif
-  if (! isa (fun, "function_handle"))
+  if (! is_function_handle (fun))
     error ("Octave:invalid-input-arg",
                [solver ": invalid value assigned to field '%s'"], "fun");
   endif
--- a/scripts/plot/draw/fplot.m	Wed Aug 15 14:13:28 2018 -0700
+++ b/scripts/plot/draw/fplot.m	Wed Aug 15 15:29:11 2018 -0700
@@ -92,7 +92,7 @@
   if (strcmp (typeinfo (fn), "inline function"))
     fn = vectorize (fn);
     nam = formula (fn);
-  elseif (isa (fn, "function_handle"))
+  elseif (is_function_handle (fn))
     nam = func2str (fn);
   elseif (all (isalnum (fn)))
     nam = fn;
--- a/scripts/plot/draw/private/__ezplot__.m	Wed Aug 15 14:13:28 2018 -0700
+++ b/scripts/plot/draw/private/__ezplot__.m	Wed Aug 15 15:29:11 2018 -0700
@@ -103,7 +103,7 @@
       xarg = argids{1};
       yarg = argids{2};
     endif
-  elseif (isa (fun, "function_handle"))
+  elseif (is_function_handle (fun))
     fstr = func2str (fun);
     idx = index (fstr, ')');
     if (idx != 0)
@@ -165,7 +165,7 @@
       endif
       funy = vectorize (funy);
       fstry = formula (funy);
-    elseif (isa (funy, "function_handle"))
+    elseif (is_function_handle (funy))
       parametric = true;
       fstry = func2str (funy);
       idx = index (fstry, ')');
@@ -209,7 +209,7 @@
         endif
         funz = vectorize (funz);
         fstrz = formula (funz);
-      elseif (isa (funz, "function_handle"))
+      elseif (is_function_handle (funz))
         fstrz = func2str (funz);
         idx = index (fstrz, ')');
         if (idx != 0)
--- a/scripts/sparse/private/__alltohandles__.m	Wed Aug 15 14:13:28 2018 -0700
+++ b/scripts/sparse/private/__alltohandles__.m	Wed Aug 15 15:29:11 2018 -0700
@@ -53,7 +53,7 @@
   M2_is_numeric = false;
 
   ## Check A and set its type
-  if (isa (A, "function_handle"))
+  if (is_function_handle (A))
      Afun = A;
   elseif (ischar (A))
     Afun = str2func (A);
@@ -70,7 +70,7 @@
   if (isempty (M1)) # M1 empty, set to identity function
       M1fun = @(x) x;
   else # M1 not empty
-    if (isa (M1, "function_handle"))
+    if (is_function_handle (M1))
       M1fun = M1;
     elseif (ischar (M1))
       M1fun = str2func (M1);
@@ -84,7 +84,7 @@
   if (isempty (M2)) # M2 empty, then I set is to the identity function
     M2fun = @(x) x;
   else # M2 not empty
-    if (isa (M2, "function_handle"))
+    if (is_function_handle (M2))
       M2fun = M2;
     elseif (ischar (M2))
       M2fun = str2func (M2);
--- a/scripts/sparse/qmr.m	Wed Aug 15 14:13:28 2018 -0700
+++ b/scripts/sparse/qmr.m	Wed Aug 15 15:29:11 2018 -0700
@@ -95,7 +95,7 @@
       fun = str2func (A);
       Ax  = @(x) feval (fun, x, "notransp");
       Atx = @(x) feval (fun, x, "transp");
-    elseif (isa (A, "function_handle"))
+    elseif (is_function_handle (A))
       Ax  = @(x) feval (A, x, "notransp");
       Atx = @(x) feval (A, x, "transp");
     elseif (isnumeric (A) && issquare (A))
@@ -122,7 +122,7 @@
       fun = str2func (M1);
       M1m1x  = @(x) feval (fun, x, "notransp");
       M1tm1x = @(x) feval (fun, x, "transp");
-    elseif (isa (M1, "function_handle"))
+    elseif (is_function_handle (M1))
       M1m1x  = @(x) feval (M1, x, "notransp");
       M1tm1x = @(x) feval (M1, x, "transp");
     elseif (isnumeric (M1) && ismatrix (M1))
@@ -139,7 +139,7 @@
       fun = str2func (M2);
       M2m1x  = @(x) feval (fun, x, "notransp");
       M2tm1x = @(x) feval (fun, x, "transp");
-    elseif (isa (M2, "function_handle"))
+    elseif (is_function_handle (M2))
       M2m1x  = @(x) feval (M2, x, "notransp");
       M2tm1x = @(x) feval (M2, x, "transp");
     elseif (isnumeric (M2) && ismatrix (M2))
--- a/scripts/sparse/spfun.m	Wed Aug 15 14:13:28 2018 -0700
+++ b/scripts/sparse/spfun.m	Wed Aug 15 15:29:11 2018 -0700
@@ -35,7 +35,7 @@
   [i, j, v] = find (S);
   [m, n] = size (S);
 
-  if (isa (f, "function_handle") || isa (f, "inline function"))
+  if (is_function_handle (f))
     y = sparse (i, j, f(v), m, n);
   else
     y = sparse (i, j, feval (f, v), m, n);
--- a/test/args.tst	Wed Aug 15 14:13:28 2018 -0700
+++ b/test/args.tst	Wed Aug 15 15:29:11 2018 -0700
@@ -220,7 +220,7 @@
 %!function f (x = @sin)
 %!  finfo = functions (x);
 %!  fname = finfo.function;
-%!  assert (isa (x, "function_handle") && strcmp (fname, "sin"));
+%!  assert (is_function_handle (x) && strcmp (fname, "sin"));
 %!endfunction
 %!test
 %! f()
@@ -229,7 +229,7 @@
 %!function f (x = @(x) x.^2)
 %!  finfo = functions (x);
 %!  ftype = finfo.type;
-%!  assert (isa (x, "function_handle") && strcmp (ftype, "anonymous"));
+%!  assert (is_function_handle (x) && strcmp (ftype, "anonymous"));
 %!endfunction
 %!test
 %! f()