# HG changeset patch # User Rik # Date 1649305558 25200 # Node ID b7edac56a8109d1420537512495445dbd3356f58 # Parent 78c3dcadf13007c748ce53c1044a2809ace7200d Add functions to @inline class for Matlab compatibility (Bug #62260). * scripts/legacy/@inline/cat.m, scripts/legacy/@inline/cat.m, scripts/legacy/@inline/disp.m, scripts/legacy/@inline/exist.m, scripts/legacy/@inline/horzcat.m, scripts/legacy/@inline/nargin.m, scripts/legacy/@inline/nargout.m, scripts/legacy/@inline/symvar.m, scripts/legacy/@inline/vertcat.m: New functions * scripts/legacy/module.mk: Add new functions to build system. * scripts/legacy/@inline/argnames.m: scripts/legacy/@inline/char.m, scripts/legacy/@inline/feval.m, scripts/legacy/@inline/formula.m, scripts/legacy/@inline/subsref.m, scripts/legacy/@inline/vectorize.m: Redo documentation. Change FCN input name to FOBJ. * scripts/legacy/@inline/inline.m: Single tweak to documentation. * scripts/legacy/__vectorize__.m: Add note that this function was translated from C++. * scripts/legacy/vectorize.m: Remove incorrect note about function being translated from C++. diff -r 78c3dcadf130 -r b7edac56a810 scripts/legacy/@inline/argnames.m --- a/scripts/legacy/@inline/argnames.m Wed Apr 06 16:30:23 2022 -0700 +++ b/scripts/legacy/@inline/argnames.m Wed Apr 06 21:25:58 2022 -0700 @@ -24,14 +24,17 @@ ######################################################################## ## -*- texinfo -*- -## @deftypefn {} {@var{args} =} argnames (@var{fcn}) +## @deftypefn {} {@var{args} =} argnames (@var{fobj}) ## Return a cell array of character strings containing the names of the -## arguments of the inline function @var{fcn}. -## @seealso{inline, formula, vectorize} +## arguments of the inline function object @var{fobj}. +## +## Programming Note: @code{symvar (@var{fobj})} is equivalent to +## @code{argnames (@var{fobj})}. +## @seealso{symvar, formula, vectorize, inline} ## @end deftypefn -function args = argnames (fcn) +function args = argnames (fobj) - args = fcn.args; + args = fobj.args; endfunction diff -r 78c3dcadf130 -r b7edac56a810 scripts/legacy/@inline/cat.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/legacy/@inline/cat.m Wed Apr 06 21:25:58 2022 -0700 @@ -0,0 +1,39 @@ +######################################################################## +## +## Copyright (C) 2022 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or . +## +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . +## +######################################################################## + +## -*- texinfo -*- +## @deftypefn {} {} cat (@var{fobj1}, @var{dots}) +## Concatenate inline function objects. +## +## Concatenating inline function objects is @strong{not} possible; +## Octave emits an error if this function is called. +## @seealso{inline} +## @end deftypefn + +function cat (varargin) + + error ("@inline/cat: concatenating inline function objects is not possible"); + +endfunction diff -r 78c3dcadf130 -r b7edac56a810 scripts/legacy/@inline/char.m --- a/scripts/legacy/@inline/char.m Wed Apr 06 16:30:23 2022 -0700 +++ b/scripts/legacy/@inline/char.m Wed Apr 06 21:25:58 2022 -0700 @@ -24,16 +24,17 @@ ######################################################################## ## -*- texinfo -*- -## @deftypefn {} {@var{fcnstr} =} char (@var{fcn}) -## Return a character string representing the inline function @var{fcn}. +## @deftypefn {} {@var{fcnstr} =} char (@var{fobj}) +## Return a character string representing the inline function object +## @var{fobj}. ## -## Note that @code{char (@var{fcn})} is equivalent to -## @code{formula (@var{fcn})}. -## @seealso{char, argnames, inline, vectorize} +## Programming Note: @code{char (@var{fobj})} is equivalent to +## @code{formula (@var{fobj})}. +## @seealso{formula, argnames, vectorize, inline} ## @end deftypefn -function fcnstr = char (obj) +function fcnstr = char (fobj) - fcnstr = obj.expr; + fcnstr = fobj.expr; endfunction diff -r 78c3dcadf130 -r b7edac56a810 scripts/legacy/@inline/disp.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/legacy/@inline/disp.m Wed Apr 06 21:25:58 2022 -0700 @@ -0,0 +1,42 @@ +######################################################################## +## +## Copyright (C) 2017-2022 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or . +## +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . +## +######################################################################## + +## -*- texinfo -*- +## @deftypefn {} {} disp (@var{fobj}) +## Display an @code{inline} function object. +## @seealso{display} +## @end deftypefn + +function disp (fobj) + + disp ("inline function object:"); + ## FIXME: inputname doesn't work with @class methods + ## str = inputname (1); + ## args = strjoin (fobj.args, ','); + ## str = [str '(' args ')' " = " fobj.expr]; + ## disp (str); + disp (formula (fobj)); + +endfunction diff -r 78c3dcadf130 -r b7edac56a810 scripts/legacy/@inline/exist.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/legacy/@inline/exist.m Wed Apr 06 21:25:58 2022 -0700 @@ -0,0 +1,37 @@ +######################################################################## +## +## Copyright (C) 2022 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or . +## +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . +## +######################################################################## + +## -*- texinfo -*- +## @deftypefn {} {@var{C} =} exist (@var{fobj}) +## Return code 1 indicating @var{fobj} is an Octave variable. +## +## @seealso{inline} +## @end deftypefn + +function retval = exist (fobj) + + retval = 1; + +endfunction diff -r 78c3dcadf130 -r b7edac56a810 scripts/legacy/@inline/feval.m --- a/scripts/legacy/@inline/feval.m Wed Apr 06 16:30:23 2022 -0700 +++ b/scripts/legacy/@inline/feval.m Wed Apr 06 21:25:58 2022 -0700 @@ -23,9 +23,9 @@ ## ######################################################################## -function retval = feval (fcn, varargin) +function retval = feval (fobj, varargin) - fh = eval (sprintf ("@(%s) %s", strjoin (fcn.args, ","), fcn.expr)); + fh = eval (sprintf ("@(%s) %s", strjoin (fobj.args, ","), fobj.expr)); retval = fh (varargin{:}); diff -r 78c3dcadf130 -r b7edac56a810 scripts/legacy/@inline/formula.m --- a/scripts/legacy/@inline/formula.m Wed Apr 06 16:30:23 2022 -0700 +++ b/scripts/legacy/@inline/formula.m Wed Apr 06 21:25:58 2022 -0700 @@ -24,12 +24,12 @@ ######################################################################## ## -*- texinfo -*- -## @deftypefn {} {@var{fcnstr} =} formula (@var{fcn}) -## Return a character string representing the inline function @var{fcn}. +## @deftypefn {} {@var{fcnstr} =} formula (@var{fobj}) +## Return a character string representing the inline function @var{fobj}. ## -## Note that @code{char (@var{fcn})} is equivalent to -## @code{formula (@var{fcn})}. -## @seealso{char, argnames, inline, vectorize} +## Programming Note: @code{char (@var{fobj})} is equivalent to +## @code{formula (@var{fobj})}. +## @seealso{char, argnames, vectorize, inline} ## @end deftypefn function fcnstr = formula (obj) diff -r 78c3dcadf130 -r b7edac56a810 scripts/legacy/@inline/horzcat.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/legacy/@inline/horzcat.m Wed Apr 06 21:25:58 2022 -0700 @@ -0,0 +1,39 @@ +######################################################################## +## +## Copyright (C) 2022 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or . +## +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . +## +######################################################################## + +## -*- texinfo -*- +## @deftypefn {} {} horzcat (@var{fobj1}, @var{dots}) +## Horizontally concatenate inline function objects. +## +## Concatenating inline function objects is @strong{not} possible; +## Octave emits an error if this function is called. +## @seealso{inline} +## @end deftypefn + +function horzcat (varargin) + + error ("@inline/horzcat: concatenating inline function objects is not possible"); + +endfunction diff -r 78c3dcadf130 -r b7edac56a810 scripts/legacy/@inline/inline.m --- a/scripts/legacy/@inline/inline.m Wed Apr 06 16:30:23 2022 -0700 +++ b/scripts/legacy/@inline/inline.m Wed Apr 06 21:25:58 2022 -0700 @@ -37,7 +37,7 @@ ## function are extracted from the function itself. The generated ## function arguments will then be in alphabetical order. It should be ## noted that i and j are ignored as arguments due to the ambiguity -## between their use as a variable or their use as an built-in constant. +## between their use as a variable and their use as an built-in constant. ## All arguments followed by a parenthesis are considered to be ## functions. If no arguments are found, a function taking a single ## argument named @code{x} will be created. diff -r 78c3dcadf130 -r b7edac56a810 scripts/legacy/@inline/nargin.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/legacy/@inline/nargin.m Wed Apr 06 21:25:58 2022 -0700 @@ -0,0 +1,37 @@ +######################################################################## +## +## Copyright (C) 2022 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or . +## +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . +## +######################################################################## + +## -*- texinfo -*- +## @deftypefn {} {@var{n} =} nargin (@var{fobj}) +## Return the number of input arguments for the inline function object +## @var{fobj}. +## @seealso{nargout, argnames, inline} +## @end deftypefn + +function n = nargin (fobj) + + n = fobj.numArgs; + +endfunction diff -r 78c3dcadf130 -r b7edac56a810 scripts/legacy/@inline/nargout.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/legacy/@inline/nargout.m Wed Apr 06 21:25:58 2022 -0700 @@ -0,0 +1,40 @@ +######################################################################## +## +## Copyright (C) 2022 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or . +## +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . +## +######################################################################## + +## -*- texinfo -*- +## @deftypefn {} {@var{n} =} nargout (@var{fobj}) +## Return the number of output arguments for the inline function object +## @var{fobj}. +## +## Programming Note: The return value is always 1 because @code{inline} +## function objects only support one output. +## @seealso{nargin, inline} +## @end deftypefn + +function n = nargout (fobj) + + n = 1; + +endfunction diff -r 78c3dcadf130 -r b7edac56a810 scripts/legacy/@inline/subsref.m --- a/scripts/legacy/@inline/subsref.m Wed Apr 06 16:30:23 2022 -0700 +++ b/scripts/legacy/@inline/subsref.m Wed Apr 06 21:25:58 2022 -0700 @@ -24,11 +24,11 @@ ######################################################################## ## -*- texinfo -*- -## @deftypefn {} {@var{value} =} subsref (@var{fcn}, @var{idx}) -## Perform subscripted function call on the inline function object @var{fcn}. +## @deftypefn {} {@var{value} =} subsref (@var{fobj}, @var{idx}) +## Perform subscripted function call on the inline function object @var{fobj}. ## @end deftypefn -function retval = subsref (fcn, idx) +function retval = subsref (fobj, idx) if (nargin != 2) print_usage (); @@ -41,9 +41,9 @@ if (strcmp (idx(1).type, "()")) args = idx.subs; if (numel (args) > 0) - retval = feval (fcn, args{:}); + retval = feval (fobj, args{:}); else - retval = feval (fcn); + retval = feval (fobj); endif else error ("@inline/subsref: invalid subscript type"); diff -r 78c3dcadf130 -r b7edac56a810 scripts/legacy/@inline/symvar.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/legacy/@inline/symvar.m Wed Apr 06 21:25:58 2022 -0700 @@ -0,0 +1,40 @@ +######################################################################## +## +## Copyright (C) 2022 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or . +## +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . +## +######################################################################## + +## -*- texinfo -*- +## @deftypefn {} {@var{args} =} symvar (@var{fobj}) +## Return a cell array of character strings containing the names of the +## arguments of the inline function object @var{fobj}. +## +## Programming Note: @code{symvar (@var{fobj})} is equivalent to +## @code{argnames (@var{fobj})}. +## @seealso{argnames, formula, vectorize, inline} +## @end deftypefn + +function args = symvar (fobj) + + args = fobj.args; + +endfunction diff -r 78c3dcadf130 -r b7edac56a810 scripts/legacy/@inline/vectorize.m --- a/scripts/legacy/@inline/vectorize.m Wed Apr 06 16:30:23 2022 -0700 +++ b/scripts/legacy/@inline/vectorize.m Wed Apr 06 21:25:58 2022 -0700 @@ -24,8 +24,8 @@ ######################################################################## ## -*- texinfo -*- -## @deftypefn {} {@var{vfcn} =} vectorize (@var{fcn}) -## Create a vectorized version of the inline function @var{fcn} by +## @deftypefn {} {@var{vfcn} =} vectorize (@var{fobj}) +## Create a vectorized version of the inline function @var{fobj} by ## replacing all occurrences of @code{*}, @code{/}, etc., with ## @code{.*}, @code{./}, etc. ## @@ -35,23 +35,17 @@ ## ## @example ## @group -## fcn = vectorize (inline ("x^2 - 1")) -## @result{} fcn = f(x) = x.^2 - 1 -## quadv (fcn, 0, 3) +## fobj = vectorize (inline ("x^2 - 1")) +## @result{} fobj = f(x) = x.^2 - 1 +## quadv (fobj, 0, 3) ## @result{} 6 ## @end group ## @end example ## @seealso{inline, formula, argnames} ## @end deftypefn -## The following function was translated directly from the original C++ -## version. Yes, it will be slow, but the use of inline functions is -## strongly discouraged anyway, and most expressions will probably be -## short. It may also be buggy. Well, don't use this function! Use -## function handles instead! +function vfcn = vectorize (fobj) -function vfcn = vectorize (fcn) - - vfcn = inline (__vectorize__ (fcn.expr)); + vfcn = inline (__vectorize__ (fobj.expr)); endfunction diff -r 78c3dcadf130 -r b7edac56a810 scripts/legacy/@inline/vertcat.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/legacy/@inline/vertcat.m Wed Apr 06 21:25:58 2022 -0700 @@ -0,0 +1,39 @@ +######################################################################## +## +## Copyright (C) 2022 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or . +## +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . +## +######################################################################## + +## -*- texinfo -*- +## @deftypefn {} {} vertcat (@var{fobj1}, @var{dots}) +## Vertically concatenate inline function objects. +## +## Concatenating inline function objects is @strong{not} possible; +## Octave emits an error if this function is called. +## @seealso{inline} +## @end deftypefn + +function vertcat (varargin) + + error ("@inline/vertcat: concatenating inline function objects is not possible"); + +endfunction diff -r 78c3dcadf130 -r b7edac56a810 scripts/legacy/__vectorize__.m --- a/scripts/legacy/__vectorize__.m Wed Apr 06 16:30:23 2022 -0700 +++ b/scripts/legacy/__vectorize__.m Wed Apr 06 21:25:58 2022 -0700 @@ -28,6 +28,11 @@ ## Undocumented internal function. ## @end deftypefn +## The following function was translated directly from the original C++ +## version. Yes, it will be slow, but its use is strongly discouraged +## anyway, and most expressions will probably be short. It may also be +## buggy. Well, don't use this function! + function new_expr = __vectorize__ (expr); new_expr = ""; diff -r 78c3dcadf130 -r b7edac56a810 scripts/legacy/module.mk --- a/scripts/legacy/module.mk Wed Apr 06 16:30:23 2022 -0700 +++ b/scripts/legacy/module.mk Wed Apr 06 21:25:58 2022 -0700 @@ -26,12 +26,20 @@ %canon_reldir%_@inline_FCN_FILES = \ %reldir%/@inline/argnames.m \ + %reldir%/@inline/cat.m \ %reldir%/@inline/char.m \ + %reldir%/@inline/disp.m \ + %reldir%/@inline/exist.m \ %reldir%/@inline/feval.m \ %reldir%/@inline/formula.m \ + %reldir%/@inline/horzcat.m \ %reldir%/@inline/inline.m \ + %reldir%/@inline/nargin.m \ + %reldir%/@inline/nargout.m \ %reldir%/@inline/subsref.m \ - %reldir%/@inline/vectorize.m + %reldir%/@inline/symvar.m \ + %reldir%/@inline/vectorize.m \ + %reldir%/@inline/vertcat.m %canon_reldir%_@inlinedir = $(fcnfiledir)/legacy/@inline diff -r 78c3dcadf130 -r b7edac56a810 scripts/legacy/vectorize.m --- a/scripts/legacy/vectorize.m Wed Apr 06 16:30:23 2022 -0700 +++ b/scripts/legacy/vectorize.m Wed Apr 06 21:25:58 2022 -0700 @@ -34,11 +34,6 @@ ## version of Octave. ## @end deftypefn -## The following function was translated directly from the original C++ -## version. Yes, it will be slow, but its use is strongly discouraged -## anyway, and most expressions will probably be short. It may also be -## buggy. Well, don't use this function! - function vfcn = vectorize (fcn) persistent warned = false;