Octave 7 compatibility fix: “arguments” is a reserved keyword

This confuses the Octave 7 parser in the context of anonymous functions.

Simply rename the variable to “args”.
fix-tolerance-parameters
Sébastien Villemot 2022-04-15 14:32:54 +02:00
parent 2f6120de0c
commit a0e78957da
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
1 changed files with 34 additions and 34 deletions

View File

@ -64,15 +64,15 @@ if ismember(options.solve_algo, [12, 14])
isauxdiffloggedrhs = varargin{2}; isauxdiffloggedrhs = varargin{2};
endo_names = varargin{3}; endo_names = varargin{3};
lhs = varargin{4}; lhs = varargin{4};
arguments = varargin(5:end); args = varargin(5:end);
else else
arguments = varargin; args = varargin;
end end
% checking initial values % checking initial values
% TODO We should have an option to deactivate the randomization. % TODO We should have an option to deactivate the randomization.
if jacobian_flag if jacobian_flag
[fvec, fjac] = feval(f, x, arguments{:}); [fvec, fjac] = feval(f, x, args{:});
wrong_initial_guess_flag = false; wrong_initial_guess_flag = false;
if ~all(isfinite(fvec)) || any(isinf(fjac(:))) || any(isnan((fjac(:)))) || any(~isreal(fvec)) || any(~isreal(fjac(:))) if ~all(isfinite(fvec)) || any(isinf(fjac(:))) || any(isnan((fjac(:)))) || any(~isreal(fvec)) || any(~isreal(fjac(:)))
if ~ismember(options.solve_algo,[10,11]) && max(abs(fvec))< tolf if ~ismember(options.solve_algo,[10,11]) && max(abs(fvec))< tolf
@ -88,7 +88,7 @@ if jacobian_flag
while wrong_initial_guess_flag && tentative_number<=in0*10 while wrong_initial_guess_flag && tentative_number<=in0*10
tentative_number = tentative_number+1; tentative_number = tentative_number+1;
x(idx) = rand(in0, 1)*10; x(idx) = rand(in0, 1)*10;
[fvec, fjac] = feval(f, x, arguments{:}); [fvec, fjac] = feval(f, x, args{:});
wrong_initial_guess_flag = ~all(isfinite(fvec)) || any(isinf(fjac(:))) || any(isnan((fjac(:)))); wrong_initial_guess_flag = ~all(isfinite(fvec)) || any(isinf(fjac(:))) || any(isnan((fjac(:))));
end end
% If all previous attempts failed, try with real numbers. % If all previous attempts failed, try with real numbers.
@ -96,7 +96,7 @@ if jacobian_flag
while wrong_initial_guess_flag && tentative_number<=in0*10 while wrong_initial_guess_flag && tentative_number<=in0*10
tentative_number = tentative_number+1; tentative_number = tentative_number+1;
x(idx) = randn(in0, 1)*10; x(idx) = randn(in0, 1)*10;
[fvec, fjac] = feval(f, x, arguments{:}); [fvec, fjac] = feval(f, x, args{:});
wrong_initial_guess_flag = ~all(isfinite(fvec)) || any(isinf(fjac(:))) || any(isnan((fjac(:)))); wrong_initial_guess_flag = ~all(isfinite(fvec)) || any(isinf(fjac(:))) || any(isnan((fjac(:))));
end end
% Last tentative, ff all previous attempts failed, try with negative numbers. % Last tentative, ff all previous attempts failed, try with negative numbers.
@ -104,12 +104,12 @@ if jacobian_flag
while wrong_initial_guess_flag && tentative_number<=in0*10 while wrong_initial_guess_flag && tentative_number<=in0*10
tentative_number = tentative_number+1; tentative_number = tentative_number+1;
x(idx) = -rand(in0, 1)*10; x(idx) = -rand(in0, 1)*10;
[fvec, fjac] = feval(f, x, arguments{:}); [fvec, fjac] = feval(f, x, args{:});
wrong_initial_guess_flag = ~all(isfinite(fvec)) || any(isinf(fjac(:))) || any(isnan((fjac(:)))); wrong_initial_guess_flag = ~all(isfinite(fvec)) || any(isinf(fjac(:))) || any(isnan((fjac(:))));
end end
end end
else else
fvec = feval(f, x, arguments{:}); fvec = feval(f, x, args{:});
fjac = zeros(nn, nn); fjac = zeros(nn, nn);
if ~ismember(options.solve_algo,[10,11]) && max(abs(fvec)) < tolf if ~ismember(options.solve_algo,[10,11]) && max(abs(fvec)) < tolf
% return if initial value solves the problem except if a mixed complementarity problem is to be solved (complementarity conditions may not be satisfied) % return if initial value solves the problem except if a mixed complementarity problem is to be solved (complementarity conditions may not be satisfied)
@ -125,7 +125,7 @@ else
while wrong_initial_guess_flag && tentative_number<=in0*10 while wrong_initial_guess_flag && tentative_number<=in0*10
tentative_number = tentative_number+1; tentative_number = tentative_number+1;
x(idx) = rand(in0, 1)*10; x(idx) = rand(in0, 1)*10;
fvec = feval(f, x, arguments{:}); fvec = feval(f, x, args{:});
wrong_initial_guess_flag = ~all(isfinite(fvec)); wrong_initial_guess_flag = ~all(isfinite(fvec));
end end
% If all previous attempts failed, try with real numbers. % If all previous attempts failed, try with real numbers.
@ -133,7 +133,7 @@ else
while wrong_initial_guess_flag && tentative_number<=in0*10 while wrong_initial_guess_flag && tentative_number<=in0*10
tentative_number = tentative_number+1; tentative_number = tentative_number+1;
x(idx) = randn(in0, 1)*10; x(idx) = randn(in0, 1)*10;
fvec = feval(f, x, arguments{:}); fvec = feval(f, x, args{:});
wrong_initial_guess_flag = ~all(isfinite(fvec)); wrong_initial_guess_flag = ~all(isfinite(fvec));
end end
% Last tentative, ff all previous attempts failed, try with negative numbers. % Last tentative, ff all previous attempts failed, try with negative numbers.
@ -141,7 +141,7 @@ else
while wrong_initial_guess_flag && tentative_number<=in0*10 while wrong_initial_guess_flag && tentative_number<=in0*10
tentative_number = tentative_number+1; tentative_number = tentative_number+1;
x(idx) = -rand(in0, 1)*10; x(idx) = -rand(in0, 1)*10;
fvec = feval(f, x, arguments{:}); fvec = feval(f, x, args{:});
wrong_initial_guess_flag = ~all(isfinite(fvec)); wrong_initial_guess_flag = ~all(isfinite(fvec));
end end
end end
@ -176,7 +176,7 @@ if options.solve_algo == 0
options4fsolve.Jacobian = 'off'; options4fsolve.Jacobian = 'off';
end end
if ~isoctave if ~isoctave
[x, ~, errorcode] = fsolve(f, x, options4fsolve, arguments{:}); [x, ~, errorcode] = fsolve(f, x, options4fsolve, args{:});
else else
% Under Octave, use a wrapper, since fsolve() does not have a 4th arg % Under Octave, use a wrapper, since fsolve() does not have a 4th arg
if ischar(f) if ischar(f)
@ -184,7 +184,7 @@ if options.solve_algo == 0
else else
f2 = f; f2 = f;
end end
f = @(x) f2(x, arguments{:}); f = @(x) f2(x, args{:});
[x, ~, errorcode] = fsolve(f, x, options4fsolve); [x, ~, errorcode] = fsolve(f, x, options4fsolve);
end end
if errorcode==1 if errorcode==1
@ -196,7 +196,7 @@ if options.solve_algo == 0
else else
f2 = f; f2 = f;
end end
f = @(x) f2(x, arguments{:}); f = @(x) f2(x, args{:});
end end
if max(abs(fvec)) > tolf if max(abs(fvec)) > tolf
errorflag = true; errorflag = true;
@ -206,13 +206,13 @@ if options.solve_algo == 0
else else
errorflag = true; errorflag = true;
end end
[fvec, fjac] = feval(f, x, arguments{:}); [fvec, fjac] = feval(f, x, args{:});
elseif options.solve_algo==1 elseif options.solve_algo==1
[x, errorflag, errorcode] = solve1(f, x, 1:nn, 1:nn, jacobian_flag, options.gstep, tolf, tolx, maxit, [], options.debug, arguments{:}); [x, errorflag, errorcode] = solve1(f, x, 1:nn, 1:nn, jacobian_flag, options.gstep, tolf, tolx, maxit, [], options.debug, args{:});
[fvec, fjac] = feval(f, x, arguments{:}); [fvec, fjac] = feval(f, x, args{:});
elseif options.solve_algo==9 elseif options.solve_algo==9
[x, errorflag, errorcode] = trust_region(f, x, 1:nn, 1:nn, jacobian_flag, options.gstep, tolf, tolx, maxit, options.trust_region_initial_step_bound_factor, options.debug, arguments{:}); [x, errorflag, errorcode] = trust_region(f, x, 1:nn, 1:nn, jacobian_flag, options.gstep, tolf, tolx, maxit, options.trust_region_initial_step_bound_factor, options.debug, args{:});
[fvec, fjac] = feval(f, x, arguments{:}); [fvec, fjac] = feval(f, x, args{:});
elseif ismember(options.solve_algo, [2, 12, 4]) elseif ismember(options.solve_algo, [2, 12, 4])
if ismember(options.solve_algo, [2, 12]) if ismember(options.solve_algo, [2, 12])
solver = @solve1; solver = @solve1;
@ -226,7 +226,7 @@ elseif ismember(options.solve_algo, [2, 12, 4])
for j = 1:nn for j = 1:nn
xdh = x ; xdh = x ;
xdh(j) = xdh(j)+dh(j) ; xdh(j) = xdh(j)+dh(j) ;
fjac(:,j) = (feval(f, xdh, arguments{:})-fvec)./dh(j) ; fjac(:,j) = (feval(f, xdh, args{:})-fvec)./dh(j) ;
end end
end end
[j1,j2,r,s] = dmperm(fjac); [j1,j2,r,s] = dmperm(fjac);
@ -251,13 +251,13 @@ elseif ismember(options.solve_algo, [2, 12, 4])
if fre || any(JAC(r(i), s(i)+(1:l))) if fre || any(JAC(r(i), s(i)+(1:l)))
% Reevaluation of the residuals is required because the current RHS depends on % Reevaluation of the residuals is required because the current RHS depends on
% variables that potentially have been updated previously. % variables that potentially have been updated previously.
z = feval(f, x, arguments{:}); z = feval(f, x, args{:});
l = 0; l = 0;
fre = false; fre = false;
end end
else else
% First iteration requires the evaluation of the residuals. % First iteration requires the evaluation of the residuals.
z = feval(f, x, arguments{:}); z = feval(f, x, args{:});
end end
l = l+1; l = l+1;
if isequal(lhs{j1(j)}, endo_names{j2(j)}) || isequal(lhs{j1(j)}, sprintf('log(%s)', endo_names{j2(j)})) if isequal(lhs{j1(j)}, endo_names{j2(j)}) || isequal(lhs{j1(j)}, sprintf('log(%s)', endo_names{j2(j)}))
@ -292,43 +292,43 @@ elseif ismember(options.solve_algo, [2, 12, 4])
options.gstep, ... options.gstep, ...
tolf, options.solve_tolx, maxit, ... tolf, options.solve_tolx, maxit, ...
options.trust_region_initial_step_bound_factor, ... options.trust_region_initial_step_bound_factor, ...
options.debug, arguments{:}); options.debug, args{:});
fre = true; fre = true;
if errorflag if errorflag
return return
end end
end end
fvec = feval(f, x, arguments{:}); fvec = feval(f, x, args{:});
if max(abs(fvec))>tolf if max(abs(fvec))>tolf
disp_verbose('Call solver on the full nonlinear problem.',options.verbosity) disp_verbose('Call solver on the full nonlinear problem.',options.verbosity)
[x, errorflag, errorcode] = solver(f, x, 1:nn, 1:nn, jacobian_flag, ... [x, errorflag, errorcode] = solver(f, x, 1:nn, 1:nn, jacobian_flag, ...
options.gstep, tolf, options.solve_tolx, maxit, ... options.gstep, tolf, options.solve_tolx, maxit, ...
options.trust_region_initial_step_bound_factor, ... options.trust_region_initial_step_bound_factor, ...
options.debug, arguments{:}); options.debug, args{:});
end end
[fvec, fjac] = feval(f, x, arguments{:}); [fvec, fjac] = feval(f, x, args{:});
elseif options.solve_algo==3 elseif options.solve_algo==3
if jacobian_flag if jacobian_flag
[x, errorcode] = csolve(f, x, f, tolf, maxit, arguments{:}); [x, errorcode] = csolve(f, x, f, tolf, maxit, args{:});
else else
[x, errorcode] = csolve(f, x, [], tolf, maxit, arguments{:}); [x, errorcode] = csolve(f, x, [], tolf, maxit, args{:});
end end
if errorcode==0 if errorcode==0
errorflag = false; errorflag = false;
else else
errorflag = true; errorflag = true;
end end
[fvec, fjac] = feval(f, x, arguments{:}); [fvec, fjac] = feval(f, x, args{:});
elseif options.solve_algo==10 elseif options.solve_algo==10
% LMMCP % LMMCP
olmmcp = options.lmmcp; olmmcp = options.lmmcp;
[x, fvec, errorcode, ~, fjac] = lmmcp(f, x, olmmcp.lb, olmmcp.ub, olmmcp, arguments{:}); [x, fvec, errorcode, ~, fjac] = lmmcp(f, x, olmmcp.lb, olmmcp.ub, olmmcp, args{:});
if errorcode==1 if errorcode==1
errorflag = false; errorflag = false;
else else
errorflag = true; errorflag = true;
end end
[fvec, fjac] = feval(f, x, arguments{:}); [fvec, fjac] = feval(f, x, args{:});
elseif options.solve_algo == 11 elseif options.solve_algo == 11
% PATH mixed complementary problem % PATH mixed complementary problem
% PATH linear mixed complementary problem % PATH linear mixed complementary problem
@ -340,14 +340,14 @@ elseif options.solve_algo == 11
omcppath = options.mcppath; omcppath = options.mcppath;
global mcp_data global mcp_data
mcp_data.func = f; mcp_data.func = f;
mcp_data.args = arguments; mcp_data.args = args;
try try
[x, fval, jac, mu] = pathmcp(x,omcppath.lb,omcppath.ub,'mcp_func',omcppath.A,omcppath.b,omcppath.t,omcppath.mu0); [x, fval, jac, mu] = pathmcp(x,omcppath.lb,omcppath.ub,'mcp_func',omcppath.A,omcppath.b,omcppath.t,omcppath.mu0);
catch catch
errorflag = true; errorflag = true;
end end
errorcode = nan; % There is no error code for this algorithm, as PATH is closed source it is unlikely we can fix that. errorcode = nan; % There is no error code for this algorithm, as PATH is closed source it is unlikely we can fix that.
[fvec, fjac] = feval(f, x, arguments{:}); [fvec, fjac] = feval(f, x, args{:});
elseif ismember(options.solve_algo, [13, 14]) elseif ismember(options.solve_algo, [13, 14])
if ~jacobian_flag if ~jacobian_flag
error('DYNARE_SOLVE: option solve_algo=13|14 needs computed Jacobian') error('DYNARE_SOLVE: option solve_algo=13|14 needs computed Jacobian')
@ -359,8 +359,8 @@ elseif ismember(options.solve_algo, [13, 14])
auxstruct.isloggedlhs = isloggedlhs; auxstruct.isloggedlhs = isloggedlhs;
auxstruct.isauxdiffloggedrhs = isauxdiffloggedrhs; auxstruct.isauxdiffloggedrhs = isauxdiffloggedrhs;
end end
[x, errorflag, errorcode] = block_trust_region(f, x, tolf, options.solve_tolx, maxit, options.trust_region_initial_step_bound_factor, options.debug, auxstruct, arguments{:}); [x, errorflag, errorcode] = block_trust_region(f, x, tolf, options.solve_tolx, maxit, options.trust_region_initial_step_bound_factor, options.debug, auxstruct, args{:});
[fvec, fjac] = feval(f, x, arguments{:}); [fvec, fjac] = feval(f, x, args{:});
else else
error('DYNARE_SOLVE: option solve_algo must be one of [0,1,2,3,4,9,10,11,12,13,14]') error('DYNARE_SOLVE: option solve_algo must be one of [0,1,2,3,4,9,10,11,12,13,14]')
end end