Remove workaround for errors in MEX files
Because at some point throwing exceptions from MEX files (with mexErrMsgTxt()) was not working under Windows 64-bit, we had designed a workaround to avoid using exceptions. Most MEX files were returning an error code as their first (or sometimes last) argument, and that code would have to be checked from the MATLAB code. Since this workaround is no longer needed, this commit removes it. As a consequence, the interface of many MEX files is modified. For some background, see https://www.dynare.org/pipermail/dev/2010-September/000895.htmltime-shift
parent
8624b4f004
commit
7e770f69e7
|
@ -58,7 +58,7 @@ function [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK,T,R,P,PK,de
|
||||||
% SPECIAL REQUIREMENTS
|
% SPECIAL REQUIREMENTS
|
||||||
% None
|
% None
|
||||||
|
|
||||||
% Copyright (C) 2006-2018 Dynare Team
|
% Copyright (C) 2006-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -185,8 +185,7 @@ elseif options_.lik_init == 3 % Diffuse Kalman filter
|
||||||
end
|
end
|
||||||
[Pstar,Pinf] = compute_Pinf_Pstar(mf,T,R,Q,options_.qz_criterium);
|
[Pstar,Pinf] = compute_Pinf_Pstar(mf,T,R,Q,options_.qz_criterium);
|
||||||
elseif options_.lik_init == 4 % Start from the solution of the Riccati equation.
|
elseif options_.lik_init == 4 % Start from the solution of the Riccati equation.
|
||||||
[err, Pstar] = kalman_steady_state(transpose(T),R*Q*transpose(R),transpose(build_selection_matrix(mf,np,vobs)),H);
|
Pstar = kalman_steady_state(transpose(T),R*Q*transpose(R),transpose(build_selection_matrix(mf,np,vobs)),H);
|
||||||
mexErrCheck('kalman_steady_state',err);
|
|
||||||
Pinf = [];
|
Pinf = [];
|
||||||
if kalman_algo~=2
|
if kalman_algo~=2
|
||||||
kalman_algo = 1;
|
kalman_algo = 1;
|
||||||
|
|
|
@ -2,7 +2,7 @@ function [r, g1] = block_bytecode_mfs_steadystate(y, b, y_all, exo, params, M)
|
||||||
% Wrapper around the *_static.m file, for use with dynare_solve,
|
% Wrapper around the *_static.m file, for use with dynare_solve,
|
||||||
% when block_mfs option is given to steady.
|
% when block_mfs option is given to steady.
|
||||||
|
|
||||||
% Copyright (C) 2009-2012 Dynare Team
|
% Copyright (C) 2009-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -21,4 +21,4 @@ function [r, g1] = block_bytecode_mfs_steadystate(y, b, y_all, exo, params, M)
|
||||||
|
|
||||||
indx = M.block_structure_stat.block(b).variable;
|
indx = M.block_structure_stat.block(b).variable;
|
||||||
y_all(indx) = y;
|
y_all(indx) = y;
|
||||||
[chk, r, g1] = bytecode( y_all, exo, params, y_all, 1, y_all, 'evaluate', 'static', ['block = ' int2str(b) ]);
|
[r, g1] = bytecode( y_all, exo, params, y_all, 1, y_all, 'evaluate', 'static', ['block = ' int2str(b) ]);
|
||||||
|
|
|
@ -2,7 +2,7 @@ function [r, g1] = bytecode_steadystate(y, exo, params)
|
||||||
% Wrapper around the *_static.m file, for use with dynare_solve,
|
% Wrapper around the *_static.m file, for use with dynare_solve,
|
||||||
% when block_mfs option is given to steady.
|
% when block_mfs option is given to steady.
|
||||||
|
|
||||||
% Copyright (C) 2009-2011 Dynare Team
|
% Copyright (C) 2009-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -19,4 +19,4 @@ function [r, g1] = bytecode_steadystate(y, exo, params)
|
||||||
% You should have received a copy of the GNU General Public License
|
% You should have received a copy of the GNU General Public License
|
||||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
eval('[chk, r, g1] = bytecode( y, exo, params, y, 1, exo, ''evaluate'', ''static'');');
|
eval('[r, g1] = bytecode( y, exo, params, y, 1, exo, ''evaluate'', ''static'');');
|
||||||
|
|
|
@ -34,7 +34,7 @@ function [dr,info,M_,options_,oo_] = dr_block(dr,task,M_,options_,oo_,varargin)
|
||||||
% none.
|
% none.
|
||||||
%
|
%
|
||||||
|
|
||||||
% Copyright (C) 2010-2017 Dynare Team
|
% Copyright (C) 2010-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -71,12 +71,10 @@ else
|
||||||
Size = 1;
|
Size = 1;
|
||||||
end
|
end
|
||||||
if (options_.bytecode)
|
if (options_.bytecode)
|
||||||
[chck, zz, data]= bytecode('dynamic','evaluate', z, zx, M_.params, dr.ys, 1, data);
|
[zz, data]= bytecode('dynamic','evaluate', z, zx, M_.params, dr.ys, 1, data);
|
||||||
else
|
else
|
||||||
[r, data] = feval([M_.fname '.dynamic'], options_, M_, oo_, z', zx, M_.params, dr.ys, M_.maximum_lag+1, data);
|
[r, data] = feval([M_.fname '.dynamic'], options_, M_, oo_, z', zx, M_.params, dr.ys, M_.maximum_lag+1, data);
|
||||||
chck = 0;
|
|
||||||
end
|
end
|
||||||
mexErrCheck('bytecode', chck);
|
|
||||||
dr.full_rank = 1;
|
dr.full_rank = 1;
|
||||||
dr.eigval = [];
|
dr.eigval = [];
|
||||||
dr.nd = 0;
|
dr.nd = 0;
|
||||||
|
@ -440,7 +438,7 @@ for i = 1:Size
|
||||||
D = [[aa(row_indx,index_0m) zeros(n_dynamic,n_both) aa(row_indx,index_p)] ; [zeros(n_both, n_pred) eye(n_both) zeros(n_both, n_both + n_fwrd)]];
|
D = [[aa(row_indx,index_0m) zeros(n_dynamic,n_both) aa(row_indx,index_p)] ; [zeros(n_both, n_pred) eye(n_both) zeros(n_both, n_both + n_fwrd)]];
|
||||||
E = [-aa(row_indx,[index_m index_0p]) ; [zeros(n_both, n_both + n_pred) eye(n_both, n_both + n_fwrd) ] ];
|
E = [-aa(row_indx,[index_m index_0p]) ; [zeros(n_both, n_both + n_pred) eye(n_both, n_both + n_fwrd) ] ];
|
||||||
|
|
||||||
[err, ss, tt, w, sdim, data(i).eigval, info1] = mjdgges(E,D,options_.qz_criterium,options_.qz_zero_threshold);
|
[ss, tt, w, sdim, data(i).eigval, info1] = mjdgges(E,D,options_.qz_criterium,options_.qz_zero_threshold);
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
disp('eigval');
|
disp('eigval');
|
||||||
|
@ -591,7 +589,7 @@ for i = 1:Size
|
||||||
elseif options_.sylvester_fp
|
elseif options_.sylvester_fp
|
||||||
ghx_other = gensylv_fp(A_, B_, C_, D_, i, options_.sylvester_fixed_point_tol);
|
ghx_other = gensylv_fp(A_, B_, C_, D_, i, options_.sylvester_fixed_point_tol);
|
||||||
else
|
else
|
||||||
[err, ghx_other] = gensylv(1, A_, B_, C_, -D_);
|
ghx_other = gensylv(1, A_, B_, C_, -D_);
|
||||||
end
|
end
|
||||||
if options_.aim_solver ~= 1
|
if options_.aim_solver ~= 1
|
||||||
% Necessary when using Sims' routines for QZ
|
% Necessary when using Sims' routines for QZ
|
||||||
|
|
|
@ -115,7 +115,7 @@ function [fval,info,exit_flag,DLIK,Hess,SteadyState,trend_coeff,Model,DynareOpti
|
||||||
%! @end deftypefn
|
%! @end deftypefn
|
||||||
%@eod:
|
%@eod:
|
||||||
|
|
||||||
% Copyright (C) 2004-2019 Dynare Team
|
% Copyright (C) 2004-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -150,7 +150,9 @@ if DynareOptions.estimation_dll
|
||||||
[fval,exit_flag,SteadyState,trend_coeff,info,params,H,Q] ...
|
[fval,exit_flag,SteadyState,trend_coeff,info,params,H,Q] ...
|
||||||
= logposterior(xparam1,DynareDataset, DynareOptions,Model, ...
|
= logposterior(xparam1,DynareDataset, DynareOptions,Model, ...
|
||||||
EstimatedParameters,BayesInfo,DynareResults);
|
EstimatedParameters,BayesInfo,DynareResults);
|
||||||
mexErrCheck('logposterior', exit_flag);
|
if exit_flag
|
||||||
|
error("Error encountered in logposterior")
|
||||||
|
end
|
||||||
Model.params = params;
|
Model.params = params;
|
||||||
if ~isequal(Model.H,0)
|
if ~isequal(Model.H,0)
|
||||||
Model.H = H;
|
Model.H = H;
|
||||||
|
@ -455,12 +457,14 @@ switch DynareOptions.lik_init
|
||||||
if kalman_algo ~= 2
|
if kalman_algo ~= 2
|
||||||
kalman_algo = 1;
|
kalman_algo = 1;
|
||||||
end
|
end
|
||||||
if isequal(H,0)
|
try
|
||||||
[err,Pstar] = kalman_steady_state(transpose(T),R*Q*transpose(R),transpose(build_selection_matrix(Z,mm,length(Z))));
|
if isequal(H,0)
|
||||||
else
|
Pstar = kalman_steady_state(transpose(T),R*Q*transpose(R),transpose(build_selection_matrix(Z,mm,length(Z))));
|
||||||
[err,Pstar] = kalman_steady_state(transpose(T),R*Q*transpose(R),transpose(build_selection_matrix(Z,mm,length(Z))),H);
|
else
|
||||||
end
|
Pstar = kalman_steady_state(transpose(T),R*Q*transpose(R),transpose(build_selection_matrix(Z,mm,length(Z))),H);
|
||||||
if err
|
end
|
||||||
|
catch ME
|
||||||
|
disp(ME.message)
|
||||||
disp(['dsge_likelihood:: I am not able to solve the Riccati equation, so I switch to lik_init=1!']);
|
disp(['dsge_likelihood:: I am not able to solve the Riccati equation, so I switch to lik_init=1!']);
|
||||||
DynareOptions.lik_init = 1;
|
DynareOptions.lik_init = 1;
|
||||||
Pstar=lyapunov_solver(T,R,Q,DynareOptions);
|
Pstar=lyapunov_solver(T,R,Q,DynareOptions);
|
||||||
|
@ -647,8 +651,7 @@ singularity_has_been_detected = false;
|
||||||
if ((kalman_algo==1) || (kalman_algo==3))% Multivariate Kalman Filter
|
if ((kalman_algo==1) || (kalman_algo==3))% Multivariate Kalman Filter
|
||||||
if no_missing_data_flag
|
if no_missing_data_flag
|
||||||
if DynareOptions.block
|
if DynareOptions.block
|
||||||
[err, LIK] = block_kalman_filter(T,R,Q,H,Pstar,Y,start,Z,kalman_tol,riccati_tol, Model.nz_state_var, Model.n_diag, Model.nobs_non_statevar);
|
LIK = block_kalman_filter(T,R,Q,H,Pstar,Y,start,Z,kalman_tol,riccati_tol, Model.nz_state_var, Model.n_diag, Model.nobs_non_statevar);
|
||||||
mexErrCheck('block_kalman_filter', err);
|
|
||||||
elseif DynareOptions.fast_kalman_filter
|
elseif DynareOptions.fast_kalman_filter
|
||||||
if diffuse_periods
|
if diffuse_periods
|
||||||
%kalman_algo==3 requires no diffuse periods (stationary
|
%kalman_algo==3 requires no diffuse periods (stationary
|
||||||
|
@ -677,8 +680,8 @@ if ((kalman_algo==1) || (kalman_algo==3))% Multivariate Kalman Filter
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if 0 %DynareOptions.block
|
if 0 %DynareOptions.block
|
||||||
[err, LIK,lik] = block_kalman_filter(DatasetInfo.missing.aindex,DatasetInfo.missing.number_of_observations,DatasetInfo.missing.no_more_missing_observations,...
|
[LIK,lik] = block_kalman_filter(DatasetInfo.missing.aindex,DatasetInfo.missing.number_of_observations,DatasetInfo.missing.no_more_missing_observations,...
|
||||||
T,R,Q,H,Pstar,Y,start,Z,kalman_tol,riccati_tol, Model.nz_state_var, Model.n_diag, Model.nobs_non_statevar);
|
T,R,Q,H,Pstar,Y,start,Z,kalman_tol,riccati_tol, Model.nz_state_var, Model.n_diag, Model.nobs_non_statevar);
|
||||||
else
|
else
|
||||||
[LIK,lik] = missing_observations_kalman_filter(DatasetInfo.missing.aindex,DatasetInfo.missing.number_of_observations,DatasetInfo.missing.no_more_missing_observations,Y,diffuse_periods+1,size(Y,2), ...
|
[LIK,lik] = missing_observations_kalman_filter(DatasetInfo.missing.aindex,DatasetInfo.missing.number_of_observations,DatasetInfo.missing.no_more_missing_observations,Y,diffuse_periods+1,size(Y,2), ...
|
||||||
a, Pstar, ...
|
a, Pstar, ...
|
||||||
|
|
|
@ -21,7 +21,7 @@ function [dr, info] = dyn_first_order_solver(jacobia, DynareModel, dr, DynareOpt
|
||||||
% info=5 -> Blanchard and Kahn conditions are not satisfied: indeterminacy due to rank failure,
|
% info=5 -> Blanchard and Kahn conditions are not satisfied: indeterminacy due to rank failure,
|
||||||
% info=7 -> One of the eigenvalues is close to 0/0 (infinity of complex solutions)
|
% info=7 -> One of the eigenvalues is close to 0/0 (infinity of complex solutions)
|
||||||
|
|
||||||
% Copyright (C) 2001-2018 Dynare Team
|
% Copyright (C) 2001-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -187,8 +187,7 @@ else
|
||||||
E(row_indx_de_1,index_e1) = -aa(row_indx,index_e);
|
E(row_indx_de_1,index_e1) = -aa(row_indx,index_e);
|
||||||
E(row_indx_de_2,index_e2) = eye(nboth);
|
E(row_indx_de_2,index_e2) = eye(nboth);
|
||||||
|
|
||||||
[err, ss, tt, w, sdim, dr.eigval, info1] = mjdgges(E, D, DynareOptions.qz_criterium, DynareOptions.qz_zero_threshold);
|
[ss, tt, w, sdim, dr.eigval, info1] = mjdgges(E, D, DynareOptions.qz_criterium, DynareOptions.qz_zero_threshold);
|
||||||
mexErrCheck('mjdgges', err);
|
|
||||||
|
|
||||||
if info1
|
if info1
|
||||||
if info1 == -30
|
if info1 == -30
|
||||||
|
|
|
@ -18,7 +18,7 @@ function [steady_state,params,check] = dyn_ramsey_static(ys_init,M,options_,oo)
|
||||||
% SPECIAL REQUIREMENTS
|
% SPECIAL REQUIREMENTS
|
||||||
% none
|
% none
|
||||||
|
|
||||||
% Copyright (C) 2003-2018 Dynare Team
|
% Copyright (C) 2003-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -156,8 +156,8 @@ Uyy = reshape(Uyy,endo_nbr,endo_nbr);
|
||||||
% set multipliers and auxiliary variables that
|
% set multipliers and auxiliary variables that
|
||||||
% depends on multipliers to 0 to compute residuals
|
% depends on multipliers to 0 to compute residuals
|
||||||
if (options_.bytecode)
|
if (options_.bytecode)
|
||||||
[chck, res, junk] = bytecode('static',xx,[oo.exo_steady_state oo.exo_det_steady_state], ...
|
[res, junk] = bytecode('static',xx,[oo.exo_steady_state oo.exo_det_steady_state], ...
|
||||||
params, 'evaluate');
|
params, 'evaluate');
|
||||||
fJ = junk.g1;
|
fJ = junk.g1;
|
||||||
else
|
else
|
||||||
[res,fJ] = feval([fname '.static'],xx,[oo.exo_steady_state oo.exo_det_steady_state], ...
|
[res,fJ] = feval([fname '.static'],xx,[oo.exo_steady_state oo.exo_det_steady_state], ...
|
||||||
|
@ -194,8 +194,8 @@ end
|
||||||
function result = check_static_model(ys,M,options_,oo)
|
function result = check_static_model(ys,M,options_,oo)
|
||||||
result = false;
|
result = false;
|
||||||
if (options_.bytecode)
|
if (options_.bytecode)
|
||||||
[chck, res, ~] = bytecode('static',ys,[oo.exo_steady_state oo.exo_det_steady_state], ...
|
[res, ~] = bytecode('static',ys,[oo.exo_steady_state oo.exo_det_steady_state], ...
|
||||||
M.params, 'evaluate');
|
M.params, 'evaluate');
|
||||||
else
|
else
|
||||||
res = feval([M.fname '.static'],ys,[oo.exo_steady_state oo.exo_det_steady_state], ...
|
res = feval([M.fname '.static'],ys,[oo.exo_steady_state oo.exo_det_steady_state], ...
|
||||||
M.params);
|
M.params);
|
||||||
|
|
|
@ -341,8 +341,7 @@ if nargout > 1
|
||||||
nu2 = exo_nbr*(exo_nbr+1)/2;
|
nu2 = exo_nbr*(exo_nbr+1)/2;
|
||||||
nu3 = exo_nbr*(exo_nbr+1)*(exo_nbr+2)/3;
|
nu3 = exo_nbr*(exo_nbr+1)*(exo_nbr+2)/3;
|
||||||
M_np.NZZDerivatives = [nnz(d1_np); nnz(d2_np); nnz(d3_np)];
|
M_np.NZZDerivatives = [nnz(d1_np); nnz(d2_np); nnz(d3_np)];
|
||||||
[err, dynpp_derivs] = k_order_perturbation(dr_np,M_np,options,d1_np,d2_np,d3_np);
|
dynpp_derivs = k_order_perturbation(dr_np,M_np,options,d1_np,d2_np,d3_np);
|
||||||
mexErrCheck('k_order_perturbation', err);
|
|
||||||
g_0 = dynpp_derivs.g_0;
|
g_0 = dynpp_derivs.g_0;
|
||||||
g_1 = dynpp_derivs.g_1;
|
g_1 = dynpp_derivs.g_1;
|
||||||
g_2 = dynpp_derivs.g_2;
|
g_2 = dynpp_derivs.g_2;
|
||||||
|
|
|
@ -36,7 +36,7 @@ function dr = dyn_second_order_solver(jacobia,hessian_mat,dr,M,threads_BC)
|
||||||
%! @end deftypefn
|
%! @end deftypefn
|
||||||
%@eod:
|
%@eod:
|
||||||
|
|
||||||
% Copyright (C) 2001-2019 Dynare Team
|
% Copyright (C) 2001-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -85,29 +85,23 @@ zu = [zeros(length(ic),M.exo_nbr);
|
||||||
dr.ghx(klead~=0,:)*dr.ghu(ic,:);
|
dr.ghx(klead~=0,:)*dr.ghu(ic,:);
|
||||||
eye(M.exo_nbr);
|
eye(M.exo_nbr);
|
||||||
zeros(M.exo_det_nbr,M.exo_nbr)];
|
zeros(M.exo_det_nbr,M.exo_nbr)];
|
||||||
[rhs, err] = sparse_hessian_times_B_kronecker_C(hessian_mat(:,kk2(kk1,kk1)),zx,threads_BC); %hessian_mat: reordering to DR order
|
rhs = sparse_hessian_times_B_kronecker_C(hessian_mat(:,kk2(kk1,kk1)),zx,threads_BC); %hessian_mat: reordering to DR order
|
||||||
mexErrCheck('sparse_hessian_times_B_kronecker_C', err);
|
|
||||||
rhs = -rhs;
|
rhs = -rhs;
|
||||||
[err, dr.ghxx] = gensylv(2,A,B,C,rhs);
|
dr.ghxx = gensylv(2,A,B,C,rhs);
|
||||||
mexErrCheck('gensylv', err);
|
|
||||||
|
|
||||||
|
|
||||||
%% ghxu
|
%% ghxu
|
||||||
%rhs
|
%rhs
|
||||||
[rhs, err] = sparse_hessian_times_B_kronecker_C(hessian_mat(:,kk2(kk1,kk1)),zx,zu,threads_BC); %hessian_mat: reordering to DR order
|
rhs = sparse_hessian_times_B_kronecker_C(hessian_mat(:,kk2(kk1,kk1)),zx,zu,threads_BC); %hessian_mat: reordering to DR order
|
||||||
mexErrCheck('sparse_hessian_times_B_kronecker_C', err);
|
abcOut = A_times_B_kronecker_C(dr.ghxx, dr.ghx(ic,:), dr.ghu(ic,:));
|
||||||
[abcOut,err] = A_times_B_kronecker_C(dr.ghxx, dr.ghx(ic,:), dr.ghu(ic,:));
|
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
|
||||||
rhs = -rhs-B*abcOut;
|
rhs = -rhs-B*abcOut;
|
||||||
%lhs
|
%lhs
|
||||||
dr.ghxu = A\rhs;
|
dr.ghxu = A\rhs;
|
||||||
|
|
||||||
%% ghuu
|
%% ghuu
|
||||||
%rhs
|
%rhs
|
||||||
[rhs, err] = sparse_hessian_times_B_kronecker_C(hessian_mat(:,kk2(kk1,kk1)),zu,threads_BC); %hessian_mat: reordering to DR order
|
rhs = sparse_hessian_times_B_kronecker_C(hessian_mat(:,kk2(kk1,kk1)),zu,threads_BC); %hessian_mat: reordering to DR order
|
||||||
mexErrCheck('sparse_hessian_times_B_kronecker_C', err);
|
B1 = A_times_B_kronecker_C(B*dr.ghxx,dr.ghu(ic,:));
|
||||||
[B1, err] = A_times_B_kronecker_C(B*dr.ghxx,dr.ghu(ic,:));
|
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
|
||||||
rhs = -rhs-B1;
|
rhs = -rhs-B1;
|
||||||
%lhs
|
%lhs
|
||||||
dr.ghuu = A\rhs;
|
dr.ghuu = A\rhs;
|
||||||
|
@ -120,8 +114,7 @@ LHS = zeros(M.endo_nbr,M.endo_nbr);
|
||||||
LHS(:,kcurr~=0) = jacobia(:,nonzeros(kcurr));
|
LHS(:,kcurr~=0) = jacobia(:,nonzeros(kcurr));
|
||||||
RHS = zeros(M.endo_nbr,M.exo_nbr^2);
|
RHS = zeros(M.endo_nbr,M.exo_nbr^2);
|
||||||
E = eye(M.endo_nbr);
|
E = eye(M.endo_nbr);
|
||||||
[B1, err] = sparse_hessian_times_B_kronecker_C(hessian_mat(:,kk2(nonzeros(klead),nonzeros(klead))), dr.ghu(klead~=0,:),threads_BC); %hessian_mat:focus only on forward variables and reorder to DR order
|
B1 = sparse_hessian_times_B_kronecker_C(hessian_mat(:,kk2(nonzeros(klead),nonzeros(klead))), dr.ghu(klead~=0,:),threads_BC); %hessian_mat:focus only on forward variables and reorder to DR order
|
||||||
mexErrCheck('sparse_hessian_times_B_kronecker_C', err);
|
|
||||||
RHS = RHS + jacobia(:,nonzeros(klead))*dr.ghuu(klead~=0,:)+B1;
|
RHS = RHS + jacobia(:,nonzeros(klead))*dr.ghuu(klead~=0,:)+B1;
|
||||||
% LHS
|
% LHS
|
||||||
LHS = LHS + jacobia(:,nonzeros(klead))*(E(klead~=0,:)+[O1(klead~=0,:) dr.ghx(klead~=0,:) O2(klead~=0,:)]);
|
LHS = LHS + jacobia(:,nonzeros(klead))*(E(klead~=0,:)+[O1(klead~=0,:) dr.ghx(klead~=0,:) O2(klead~=0,:)]);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
function [x,info] = dynare_solve_block_or_bytecode(y, exo, params, options, M)
|
function [x,info] = dynare_solve_block_or_bytecode(y, exo, params, options, M)
|
||||||
% Copyright (C) 2010-2017 Dynare Team
|
% Copyright (C) 2010-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -51,9 +51,10 @@ if options.block && ~options.bytecode
|
||||||
end
|
end
|
||||||
elseif options.bytecode
|
elseif options.bytecode
|
||||||
if options.solve_algo > 4
|
if options.solve_algo > 4
|
||||||
[check, x] = bytecode('static', x, exo, params);
|
try
|
||||||
% mexErrCheck('bytecode', check);
|
x = bytecode('static', x, exo, params);
|
||||||
if check
|
catch ME
|
||||||
|
disp(ME.message);
|
||||||
info = 1;
|
info = 1;
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -73,10 +74,12 @@ elseif options.bytecode
|
||||||
end
|
end
|
||||||
x(M.block_structure_stat.block(b).variable) = y;
|
x(M.block_structure_stat.block(b).variable) = y;
|
||||||
else
|
else
|
||||||
[chk, nulldev, nulldev1, x] = bytecode( x, exo, params, ...
|
try
|
||||||
x, 1, x, 'evaluate', 'static', ...
|
[nulldev, nulldev1, x] = bytecode(x, exo, params, ...
|
||||||
['block = ' int2str(b)]);
|
x, 1, x, 'evaluate', 'static', ...
|
||||||
if chk
|
['block = ' int2str(b)]);
|
||||||
|
catch ME
|
||||||
|
disp(ME.message);
|
||||||
info = 1;
|
info = 1;
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,7 @@ function [y, info_convergence, endogenousvariablespaths] = extended_path_core(pe
|
||||||
debug,bytecode_flag,order,M,pfm,algo,solve_algo,stack_solve_algo,...
|
debug,bytecode_flag,order,M,pfm,algo,solve_algo,stack_solve_algo,...
|
||||||
olmmcp,options,oo,initialguess)
|
olmmcp,options,oo,initialguess)
|
||||||
|
|
||||||
% Copyright (C) 2016-2019 Dynare Team
|
% Copyright (C) 2016-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -41,7 +41,13 @@ if debug
|
||||||
end
|
end
|
||||||
|
|
||||||
if bytecode_flag && ~ep.stochastic.order
|
if bytecode_flag && ~ep.stochastic.order
|
||||||
[flag, tmp] = bytecode('dynamic', endo_simul, exo_simul, M_.params, endo_simul, periods);
|
try
|
||||||
|
tmp = bytecode('dynamic', endo_simul, exo_simul, M_.params, endo_simul, periods);
|
||||||
|
flag = false;
|
||||||
|
catch ME
|
||||||
|
disp(ME.message);
|
||||||
|
flag = true;
|
||||||
|
end
|
||||||
else
|
else
|
||||||
flag = true;
|
flag = true;
|
||||||
end
|
end
|
||||||
|
@ -86,4 +92,4 @@ else
|
||||||
y = NaN(size(endo_nbr,1));
|
y = NaN(size(endo_nbr,1));
|
||||||
end
|
end
|
||||||
|
|
||||||
endogenousvariablespaths = tmp.endo_simul;
|
endogenousvariablespaths = tmp.endo_simul;
|
||||||
|
|
|
@ -11,7 +11,7 @@ function planner_objective_value = evaluate_planner_objective(M,options,oo)
|
||||||
% SPECIAL REQUIREMENTS
|
% SPECIAL REQUIREMENTS
|
||||||
% none
|
% none
|
||||||
|
|
||||||
% Copyright (C) 2007-2018 Dynare Team
|
% Copyright (C) 2007-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -57,21 +57,16 @@ ys = oo.dr.ys;
|
||||||
%second order terms
|
%second order terms
|
||||||
Uyy = full(Uyy);
|
Uyy = full(Uyy);
|
||||||
|
|
||||||
[Uyygygy, err] = A_times_B_kronecker_C(Uyy,gy,gy);
|
Uyygygy = A_times_B_kronecker_C(Uyy,gy,gy);
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
Uyygugu = A_times_B_kronecker_C(Uyy,gu,gu);
|
||||||
[Uyygugu, err] = A_times_B_kronecker_C(Uyy,gu,gu);
|
Uyygygu = A_times_B_kronecker_C(Uyy,gy,gu);
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
|
||||||
[Uyygygu, err] = A_times_B_kronecker_C(Uyy,gy,gu);
|
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
|
||||||
|
|
||||||
Wbar =U/(1-beta); %steady state welfare
|
Wbar =U/(1-beta); %steady state welfare
|
||||||
Wy = Uy*gy/(eye(nspred)-beta*Gy);
|
Wy = Uy*gy/(eye(nspred)-beta*Gy);
|
||||||
Wu = Uy*gu+beta*Wy*Gu;
|
Wu = Uy*gu+beta*Wy*Gu;
|
||||||
Wyy = Uyygygy/(eye(nspred*nspred)-beta*kron(Gy,Gy));
|
Wyy = Uyygygy/(eye(nspred*nspred)-beta*kron(Gy,Gy));
|
||||||
[Wyygugu, err] = A_times_B_kronecker_C(Wyy,Gu,Gu);
|
Wyygugu = A_times_B_kronecker_C(Wyy,Gu,Gu);
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
Wyygygu = A_times_B_kronecker_C(Wyy,Gy,Gu);
|
||||||
[Wyygygu,err] = A_times_B_kronecker_C(Wyy,Gy,Gu);
|
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
|
||||||
Wuu = Uyygugu+beta*Wyygugu;
|
Wuu = Uyygugu+beta*Wyygugu;
|
||||||
Wyu = Uyygygu+beta*Wyygygu;
|
Wyu = Uyygygu+beta*Wyygygu;
|
||||||
Wss = beta*Wuu*M.Sigma_e(:)/(1-beta); % at period 0, we are in steady state, so the deviation term only starts in period 1, thus the beta in front
|
Wss = beta*Wuu*M.Sigma_e(:)/(1-beta); % at period 0, we are in steady state, so the deviation term only starts in period 1, thus the beta in front
|
||||||
|
@ -93,20 +88,15 @@ end
|
||||||
yhat1 = yhat1(dr.order_var(nstatic+(1:nspred)),1)-dr.ys(dr.order_var(nstatic+(1:nspred)));
|
yhat1 = yhat1(dr.order_var(nstatic+(1:nspred)),1)-dr.ys(dr.order_var(nstatic+(1:nspred)));
|
||||||
u = oo.exo_simul(1,:)';
|
u = oo.exo_simul(1,:)';
|
||||||
|
|
||||||
[Wyyyhatyhat1, err] = A_times_B_kronecker_C(Wyy,yhat1,yhat1);
|
Wyyyhatyhat1 = A_times_B_kronecker_C(Wyy,yhat1,yhat1);
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
Wuuuu = A_times_B_kronecker_C(Wuu,u,u);
|
||||||
[Wuuuu, err] = A_times_B_kronecker_C(Wuu,u,u);
|
Wyuyhatu1 = A_times_B_kronecker_C(Wyu,yhat1,u);
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
|
||||||
[Wyuyhatu1, err] = A_times_B_kronecker_C(Wyu,yhat1,u);
|
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
|
||||||
planner_objective_value(1) = Wbar+Wy*yhat1+Wu*u+Wyuyhatu1 ...
|
planner_objective_value(1) = Wbar+Wy*yhat1+Wu*u+Wyuyhatu1 ...
|
||||||
+ 0.5*(Wyyyhatyhat1 + Wuuuu+Wss);
|
+ 0.5*(Wyyyhatyhat1 + Wuuuu+Wss);
|
||||||
if options.ramsey_policy
|
if options.ramsey_policy
|
||||||
yhat2 = yhat2(dr.order_var(nstatic+(1:nspred)),1)-dr.ys(dr.order_var(nstatic+(1:nspred)));
|
yhat2 = yhat2(dr.order_var(nstatic+(1:nspred)),1)-dr.ys(dr.order_var(nstatic+(1:nspred)));
|
||||||
[Wyyyhatyhat2, err] = A_times_B_kronecker_C(Wyy,yhat2,yhat2);
|
Wyyyhatyhat2 = A_times_B_kronecker_C(Wyy,yhat2,yhat2);
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
Wyuyhatu2 = A_times_B_kronecker_C(Wyu,yhat2,u);
|
||||||
[Wyuyhatu2, err] = A_times_B_kronecker_C(Wyu,yhat2,u);
|
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
|
||||||
planner_objective_value(2) = Wbar+Wy*yhat2+Wu*u+Wyuyhatu2 ...
|
planner_objective_value(2) = Wbar+Wy*yhat2+Wu*u+Wyuyhatu2 ...
|
||||||
+ 0.5*(Wyyyhatyhat2 + Wuuuu+Wss);
|
+ 0.5*(Wyyyhatyhat2 + Wuuuu+Wss);
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,7 +20,7 @@ function [residuals,check1,jacob] = evaluate_static_model(ys,exo_ss,params,M,opt
|
||||||
% SPECIAL REQUIREMENTS
|
% SPECIAL REQUIREMENTS
|
||||||
% none
|
% none
|
||||||
|
|
||||||
% Copyright (C) 2001-2017 Dynare Team
|
% Copyright (C) 2001-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -39,9 +39,8 @@ function [residuals,check1,jacob] = evaluate_static_model(ys,exo_ss,params,M,opt
|
||||||
|
|
||||||
check1 = 0;
|
check1 = 0;
|
||||||
if options.bytecode
|
if options.bytecode
|
||||||
[check1, residuals] = bytecode('evaluate','static',ys,...
|
residuals = bytecode('evaluate','static',ys,...
|
||||||
exo_ss, params, ys, 1);
|
exo_ss, params, ys, 1);
|
||||||
mexErrCheck('bytecode', check1);
|
|
||||||
else
|
else
|
||||||
fh_static = str2func([M.fname '.static']);
|
fh_static = str2func([M.fname '.static']);
|
||||||
if options.block
|
if options.block
|
||||||
|
|
|
@ -22,7 +22,7 @@ function [ys,params,info] = evaluate_steady_state(ys_init,M,options,oo,steadysta
|
||||||
% SPECIAL REQUIREMENTS
|
% SPECIAL REQUIREMENTS
|
||||||
% none
|
% none
|
||||||
|
|
||||||
% Copyright (C) 2001-2018 Dynare Team
|
% Copyright (C) 2001-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -307,8 +307,7 @@ if M.static_and_dynamic_models_differ
|
||||||
z = repmat(ys,1,M.maximum_lead + M.maximum_lag + 1);
|
z = repmat(ys,1,M.maximum_lead + M.maximum_lag + 1);
|
||||||
zx = repmat([exo_ss'], M.maximum_lead + M.maximum_lag + 1, 1);
|
zx = repmat([exo_ss'], M.maximum_lead + M.maximum_lag + 1, 1);
|
||||||
if options.bytecode
|
if options.bytecode
|
||||||
[chck, r, ~]= bytecode('dynamic','evaluate', z, zx, params, ys, 1);
|
[r, ~]= bytecode('dynamic','evaluate', z, zx, params, ys, 1);
|
||||||
mexErrCheck('bytecode', chck);
|
|
||||||
elseif options.block
|
elseif options.block
|
||||||
[r, oo.dr] = feval([M.fname '.dynamic'], z', zx, params, ys, M.maximum_lag+1, oo.dr);
|
[r, oo.dr] = feval([M.fname '.dynamic'], z', zx, params, ys, M.maximum_lag+1, oo.dr);
|
||||||
else
|
else
|
||||||
|
|
|
@ -97,7 +97,7 @@ function DERIVS = get_perturbation_params_derivs(M, options, estim_params, oo, i
|
||||||
% * sylvester3a
|
% * sylvester3a
|
||||||
% * get_perturbation_params_derivs_numerical_objective
|
% * get_perturbation_params_derivs_numerical_objective
|
||||||
% =========================================================================
|
% =========================================================================
|
||||||
% Copyright (C) 2019 Dynare Team
|
% Copyright (C) 2019-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -821,9 +821,9 @@ if order > 1
|
||||||
dghx(kcurr~=0,:,jp);
|
dghx(kcurr~=0,:,jp);
|
||||||
dghx(klead~=0,:,jp)*oo.dr.ghx(idx_states,:) + oo.dr.ghx(klead~=0,:)*dghx(idx_states,:,jp);
|
dghx(klead~=0,:,jp)*oo.dr.ghx(idx_states,:) + oo.dr.ghx(klead~=0,:)*dghx(idx_states,:,jp);
|
||||||
zeros(M.exo_nbr,M.nspred)];
|
zeros(M.exo_nbr,M.nspred)];
|
||||||
[dRHS_1, err] = sparse_hessian_times_B_kronecker_C(dg2(:,k2yy0ex0(kyy0,kyy0)+(jp-1)*yy0ex0_nbr^2),zx(1:yy0_nbr,:),threads_BC); mexErrCheck('sparse_hessian_times_B_kronecker_C', err);
|
dRHS_1 = sparse_hessian_times_B_kronecker_C(dg2(:,k2yy0ex0(kyy0,kyy0)+(jp-1)*yy0ex0_nbr^2),zx(1:yy0_nbr,:),threads_BC);
|
||||||
[dRHS_2, err] = sparse_hessian_times_B_kronecker_C(g2(:,k2yy0ex0(kyy0,kyy0)),dzx(1:yy0_nbr,:,jp),zx(1:yy0_nbr,:),threads_BC); mexErrCheck('sparse_hessian_times_B_kronecker_C', err);
|
dRHS_2 = sparse_hessian_times_B_kronecker_C(g2(:,k2yy0ex0(kyy0,kyy0)),dzx(1:yy0_nbr,:,jp),zx(1:yy0_nbr,:),threads_BC);
|
||||||
[dRHS_3, err] = sparse_hessian_times_B_kronecker_C(g2(:,k2yy0ex0(kyy0,kyy0)),zx(1:yy0_nbr,:),dzx(1:yy0_nbr,:,jp),threads_BC); mexErrCheck('sparse_hessian_times_B_kronecker_C', err);
|
dRHS_3 = sparse_hessian_times_B_kronecker_C(g2(:,k2yy0ex0(kyy0,kyy0)),zx(1:yy0_nbr,:),dzx(1:yy0_nbr,:,jp),threads_BC);
|
||||||
dG_x_x(:,:,jp) = kron(dghx(idx_states,:,jp),oo.dr.ghx(idx_states,:)) + kron(oo.dr.ghx(idx_states,:),dghx(idx_states,:,jp));
|
dG_x_x(:,:,jp) = kron(dghx(idx_states,:,jp),oo.dr.ghx(idx_states,:)) + kron(oo.dr.ghx(idx_states,:),dghx(idx_states,:,jp));
|
||||||
dRHSghxx(:,:,jp) = -( (dRHS_1+dRHS_2+dRHS_3) + dA(:,:,jp)*oo.dr.ghxx + dB(:,:,jp)*oo.dr.ghxx*G_x_x + B*oo.dr.ghxx*dG_x_x(:,:,jp) );
|
dRHSghxx(:,:,jp) = -( (dRHS_1+dRHS_2+dRHS_3) + dA(:,:,jp)*oo.dr.ghxx + dB(:,:,jp)*oo.dr.ghxx*G_x_x + B*oo.dr.ghxx*dG_x_x(:,:,jp) );
|
||||||
end
|
end
|
||||||
|
@ -838,9 +838,9 @@ if order > 1
|
||||||
oo.dr.ghu(kcurr~=0,:);
|
oo.dr.ghu(kcurr~=0,:);
|
||||||
oo.dr.ghx(klead~=0,:)*oo.dr.ghu(idx_states,:);
|
oo.dr.ghx(klead~=0,:)*oo.dr.ghu(idx_states,:);
|
||||||
eye(M.exo_nbr)];
|
eye(M.exo_nbr)];
|
||||||
[abcOutxu,err] = A_times_B_kronecker_C(oo.dr.ghxx,oo.dr.ghx(idx_states,:),oo.dr.ghu(idx_states,:)); mexErrCheck('A_times_B_kronecker_C', err); %auxiliary expressions for dghxu
|
abcOutxu = A_times_B_kronecker_C(oo.dr.ghxx,oo.dr.ghx(idx_states,:),oo.dr.ghu(idx_states,:)); %auxiliary expressions for dghxu
|
||||||
[abcOutuu, err] = A_times_B_kronecker_C(oo.dr.ghxx,oo.dr.ghu(idx_states,:)); mexErrCheck('A_times_B_kronecker_C', err); %auxiliary expressions for dghuu
|
abcOutuu = A_times_B_kronecker_C(oo.dr.ghxx,oo.dr.ghu(idx_states,:)); %auxiliary expressions for dghuu
|
||||||
[RHSs2, err] = sparse_hessian_times_B_kronecker_C(g2(:,k2yy0ex0(nonzeros(klead),nonzeros(klead))), oo.dr.ghu(klead~=0,:),threads_BC); mexErrCheck('sparse_hessian_times_B_kronecker_C', err);
|
RHSs2 = sparse_hessian_times_B_kronecker_C(g2(:,k2yy0ex0(nonzeros(klead),nonzeros(klead))), oo.dr.ghu(klead~=0,:),threads_BC);
|
||||||
RHSs2 = RHSs2 + g1(:,nonzeros(klead))*oo.dr.ghuu(klead~=0,:);
|
RHSs2 = RHSs2 + g1(:,nonzeros(klead))*oo.dr.ghuu(klead~=0,:);
|
||||||
dzu = zeros(size(zu,1),size(zu,2),modparam_nbr);
|
dzu = zeros(size(zu,1),size(zu,2),modparam_nbr);
|
||||||
dghxu = zeros(M.endo_nbr,M.nspred*M.exo_nbr,modparam_nbr);
|
dghxu = zeros(M.endo_nbr,M.nspred*M.exo_nbr,modparam_nbr);
|
||||||
|
@ -852,25 +852,25 @@ if order > 1
|
||||||
dghx(klead~=0,:,jp)*oo.dr.ghu(idx_states,:) + oo.dr.ghx(klead~=0,:)*dghu(idx_states,:,jp);
|
dghx(klead~=0,:,jp)*oo.dr.ghu(idx_states,:) + oo.dr.ghx(klead~=0,:)*dghu(idx_states,:,jp);
|
||||||
zeros(M.exo_nbr,M.exo_nbr)];
|
zeros(M.exo_nbr,M.exo_nbr)];
|
||||||
%compute dghxu
|
%compute dghxu
|
||||||
[dRHS_1, err] = sparse_hessian_times_B_kronecker_C(dg2(:,k2yy0ex0(kyy0ex0,kyy0ex0)+(jp-1)*yy0ex0_nbr^2),zx,zu,threads_BC); mexErrCheck('sparse_hessian_times_B_kronecker_C', err);
|
dRHS_1 = sparse_hessian_times_B_kronecker_C(dg2(:,k2yy0ex0(kyy0ex0,kyy0ex0)+(jp-1)*yy0ex0_nbr^2),zx,zu,threads_BC);
|
||||||
[dRHS_2, err] = sparse_hessian_times_B_kronecker_C(g2(:,k2yy0ex0(kyy0ex0,kyy0ex0)),dzx(:,:,jp),zu,threads_BC); mexErrCheck('sparse_hessian_times_B_kronecker_C', err);
|
dRHS_2 = sparse_hessian_times_B_kronecker_C(g2(:,k2yy0ex0(kyy0ex0,kyy0ex0)),dzx(:,:,jp),zu,threads_BC);
|
||||||
[dRHS_3, err] = sparse_hessian_times_B_kronecker_C(g2(:,k2yy0ex0(kyy0ex0,kyy0ex0)),zx,dzu(:,:,jp),threads_BC); mexErrCheck('sparse_hessian_times_B_kronecker_C', err);
|
dRHS_3 = sparse_hessian_times_B_kronecker_C(g2(:,k2yy0ex0(kyy0ex0,kyy0ex0)),zx,dzu(:,:,jp),threads_BC);
|
||||||
[dabcOut_1,err] = A_times_B_kronecker_C(dghxx(:,:,jp),oo.dr.ghx(idx_states,:),oo.dr.ghu(idx_states,:)); mexErrCheck('A_times_B_kronecker_C', err);
|
dabcOut_1 = A_times_B_kronecker_C(dghxx(:,:,jp),oo.dr.ghx(idx_states,:),oo.dr.ghu(idx_states,:));
|
||||||
[dabcOut_2,err] = A_times_B_kronecker_C(oo.dr.ghxx,dghx(idx_states,:,jp),oo.dr.ghu(idx_states,:)); mexErrCheck('A_times_B_kronecker_C', err);
|
dabcOut_2 = A_times_B_kronecker_C(oo.dr.ghxx,dghx(idx_states,:,jp),oo.dr.ghu(idx_states,:));
|
||||||
[dabcOut_3,err] = A_times_B_kronecker_C(oo.dr.ghxx,oo.dr.ghx(idx_states,:),dghu(idx_states,:,jp)); mexErrCheck('A_times_B_kronecker_C', err);
|
dabcOut_3 = A_times_B_kronecker_C(oo.dr.ghxx,oo.dr.ghx(idx_states,:),dghu(idx_states,:,jp));
|
||||||
dghxu(:,:,jp) = -invA * ( dA(:,:,jp)*oo.dr.ghxu + (dRHS_1+dRHS_2+dRHS_3) + dB(:,:,jp)*abcOutxu + B*(dabcOut_1+dabcOut_2+dabcOut_3) );
|
dghxu(:,:,jp) = -invA * ( dA(:,:,jp)*oo.dr.ghxu + (dRHS_1+dRHS_2+dRHS_3) + dB(:,:,jp)*abcOutxu + B*(dabcOut_1+dabcOut_2+dabcOut_3) );
|
||||||
%compute dghuu
|
%compute dghuu
|
||||||
[dRHS_1, err] = sparse_hessian_times_B_kronecker_C(dg2(:,k2yy0ex0(kyy0ex0,kyy0ex0)+(jp-1)*yy0ex0_nbr^2),zu,threads_BC); mexErrCheck('sparse_hessian_times_B_kronecker_C', err);
|
dRHS_1 = sparse_hessian_times_B_kronecker_C(dg2(:,k2yy0ex0(kyy0ex0,kyy0ex0)+(jp-1)*yy0ex0_nbr^2),zu,threads_BC);
|
||||||
[dRHS_2, err] = sparse_hessian_times_B_kronecker_C(g2(:,k2yy0ex0(kyy0ex0,kyy0ex0)),dzu(:,:,jp),zu,threads_BC); mexErrCheck('sparse_hessian_times_B_kronecker_C', err);
|
dRHS_2 = sparse_hessian_times_B_kronecker_C(g2(:,k2yy0ex0(kyy0ex0,kyy0ex0)),dzu(:,:,jp),zu,threads_BC);
|
||||||
[dRHS_3, err] = sparse_hessian_times_B_kronecker_C(g2(:,k2yy0ex0(kyy0ex0,kyy0ex0)),zu,dzu(:,:,jp),threads_BC); mexErrCheck('sparse_hessian_times_B_kronecker_C', err);
|
dRHS_3 = sparse_hessian_times_B_kronecker_C(g2(:,k2yy0ex0(kyy0ex0,kyy0ex0)),zu,dzu(:,:,jp),threads_BC);
|
||||||
[dabcOut_1, err] = A_times_B_kronecker_C(dghxx(:,:,jp),oo.dr.ghu(idx_states,:)); mexErrCheck('A_times_B_kronecker_C', err);
|
dabcOut_1 = A_times_B_kronecker_C(dghxx(:,:,jp),oo.dr.ghu(idx_states,:));
|
||||||
[dabcOut_2, err] = A_times_B_kronecker_C(oo.dr.ghxx,dghu(idx_states,:,jp),oo.dr.ghu(idx_states,:)); mexErrCheck('A_times_B_kronecker_C', err);
|
dabcOut_2 = A_times_B_kronecker_C(oo.dr.ghxx,dghu(idx_states,:,jp),oo.dr.ghu(idx_states,:));
|
||||||
[dabcOut_3, err] = A_times_B_kronecker_C(oo.dr.ghxx,oo.dr.ghu(idx_states,:),dghu(idx_states,:,jp)); mexErrCheck('A_times_B_kronecker_C', err);
|
dabcOut_3 = A_times_B_kronecker_C(oo.dr.ghxx,oo.dr.ghu(idx_states,:),dghu(idx_states,:,jp));
|
||||||
dghuu(:,:,jp) = -invA * ( dA(:,:,jp)*oo.dr.ghuu + (dRHS_1+dRHS_2+dRHS_3) + dB(:,:,jp)*abcOutuu + B*(dabcOut_1+dabcOut_2+dabcOut_3) );
|
dghuu(:,:,jp) = -invA * ( dA(:,:,jp)*oo.dr.ghuu + (dRHS_1+dRHS_2+dRHS_3) + dB(:,:,jp)*abcOutuu + B*(dabcOut_1+dabcOut_2+dabcOut_3) );
|
||||||
%compute dghs2
|
%compute dghs2
|
||||||
[dRHS_1, err] = sparse_hessian_times_B_kronecker_C(dg2(:,k2yy0ex0(nonzeros(klead),nonzeros(klead))+(jp-1)*yy0ex0_nbr^2), oo.dr.ghu(klead~=0,:),threads_BC); mexErrCheck('sparse_hessian_times_B_kronecker_C', err);
|
dRHS_1 = sparse_hessian_times_B_kronecker_C(dg2(:,k2yy0ex0(nonzeros(klead),nonzeros(klead))+(jp-1)*yy0ex0_nbr^2), oo.dr.ghu(klead~=0,:),threads_BC);
|
||||||
[dRHS_2, err] = sparse_hessian_times_B_kronecker_C(g2(:,k2yy0ex0(nonzeros(klead),nonzeros(klead))), dghu(klead~=0,:,jp), oo.dr.ghu(klead~=0,:),threads_BC); mexErrCheck('sparse_hessian_times_B_kronecker_C', err);
|
dRHS_2 = sparse_hessian_times_B_kronecker_C(g2(:,k2yy0ex0(nonzeros(klead),nonzeros(klead))), dghu(klead~=0,:,jp), oo.dr.ghu(klead~=0,:),threads_BC);
|
||||||
[dRHS_3, err] = sparse_hessian_times_B_kronecker_C(g2(:,k2yy0ex0(nonzeros(klead),nonzeros(klead))), oo.dr.ghu(klead~=0,:), dghu(klead~=0,:,jp),threads_BC); mexErrCheck('sparse_hessian_times_B_kronecker_C', err);
|
dRHS_3 = sparse_hessian_times_B_kronecker_C(g2(:,k2yy0ex0(nonzeros(klead),nonzeros(klead))), oo.dr.ghu(klead~=0,:), dghu(klead~=0,:,jp),threads_BC);
|
||||||
dghs2(:,stderrparam_nbr+corrparam_nbr+jp) = -invS * ( dS(:,:,jp)*oo.dr.ghs2 + ( (dRHS_1+dRHS_2+dRHS_3) + dg1(:,nonzeros(klead),jp)*oo.dr.ghuu(klead~=0,:) + g1(:,nonzeros(klead))*dghuu(klead~=0,:,jp) )*M.Sigma_e(:) );
|
dghs2(:,stderrparam_nbr+corrparam_nbr+jp) = -invS * ( dS(:,:,jp)*oo.dr.ghs2 + ( (dRHS_1+dRHS_2+dRHS_3) + dg1(:,nonzeros(klead),jp)*oo.dr.ghuu(klead~=0,:) + g1(:,nonzeros(klead))*dghuu(klead~=0,:,jp) )*M.Sigma_e(:) );
|
||||||
end
|
end
|
||||||
%add contributions by dSigma_e to dghs2
|
%add contributions by dSigma_e to dghs2
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
function [dr,info] = k_order_pert(dr,M,options)
|
function [dr,info] = k_order_pert(dr,M,options)
|
||||||
% Compute decision rules using the k-order DLL from Dynare++
|
% Compute decision rules using the k-order DLL from Dynare++
|
||||||
|
|
||||||
% Copyright (C) 2009-2018 Dynare Team
|
% Copyright (C) 2009-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -30,8 +30,9 @@ if M.maximum_endo_lead == 0 && order>1
|
||||||
'backward models'])
|
'backward models'])
|
||||||
end
|
end
|
||||||
|
|
||||||
[err, dynpp_derivs, dyn_derivs] = k_order_perturbation(dr,M,options);
|
try
|
||||||
if err
|
[dynpp_derivs, dyn_derivs] = k_order_perturbation(dr,M,options);
|
||||||
|
catch
|
||||||
info(1)=9;
|
info(1)=9;
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
% [err, dynpp_derivs, dyn_derivs] = k_order_perturbation(dr,DynareModel,DynareOptions,g1,g2,g3)
|
% [dynpp_derivs, dyn_derivs] = k_order_perturbation(dr,DynareModel,DynareOptions,g1,g2,g3)
|
||||||
% computes a k_order_petrubation solution for k=1,2,3
|
% computes a k_order_petrubation solution for k=1,2,3
|
||||||
%
|
%
|
||||||
% INPUTS
|
% INPUTS
|
||||||
|
@ -10,7 +10,6 @@
|
||||||
% g3: matrix Third order derivatives of the model (optional)
|
% g3: matrix Third order derivatives of the model (optional)
|
||||||
%
|
%
|
||||||
% OUTPUTS
|
% OUTPUTS
|
||||||
% err: double error code
|
|
||||||
% dynpp_derivs struct Derivatives of the decision rule in Dynare++ format.
|
% dynpp_derivs struct Derivatives of the decision rule in Dynare++ format.
|
||||||
% The tensors are folded and the Taylor coefficients (1/n!) are
|
% The tensors are folded and the Taylor coefficients (1/n!) are
|
||||||
% included.
|
% included.
|
||||||
|
@ -29,7 +28,7 @@
|
||||||
% dynare/mex/sources/k_order_perturbation.cc and it uses code provided by
|
% dynare/mex/sources/k_order_perturbation.cc and it uses code provided by
|
||||||
% dynare++
|
% dynare++
|
||||||
|
|
||||||
% Copyright (C) 2013-2017 Dynare Team
|
% Copyright (C) 2013-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
function mexErrCheck(mexFunctionName, err)
|
|
||||||
% function mexErrCheck(mexFunctionName, err)
|
|
||||||
% this function halts processing if err is equal to 1.
|
|
||||||
%
|
|
||||||
% INPUTS
|
|
||||||
% mexFunctionName [char] Name of the mexFunction
|
|
||||||
% err [double] error code returned from mexFunction
|
|
||||||
%
|
|
||||||
% OUTPUTS
|
|
||||||
% none.
|
|
||||||
%
|
|
||||||
% ALGORITHM
|
|
||||||
% ...
|
|
||||||
%
|
|
||||||
% SPECIAL REQUIREMENTS
|
|
||||||
% none.
|
|
||||||
%
|
|
||||||
|
|
||||||
% Copyright (C) 2010 Dynare Team
|
|
||||||
%
|
|
||||||
% This file is part of Dynare.
|
|
||||||
%
|
|
||||||
% Dynare 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.
|
|
||||||
%
|
|
||||||
% Dynare 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 Dynare. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
if ~ischar(mexFunctionName) || ~isscalar(err)
|
|
||||||
error('The first argument must be a char and the second a scalar');
|
|
||||||
end
|
|
||||||
|
|
||||||
if err
|
|
||||||
error(['Error encountered in: ' mexFunctionName '.']);
|
|
||||||
end
|
|
|
@ -1,5 +1,5 @@
|
||||||
function [err, E] = gensylv(kron_prod,A,B,C0,D)
|
function E = gensylv(kron_prod,A,B,C0,D)
|
||||||
%function [err, E] = gensylv(fake,A,B,C,D)
|
%function E = gensylv(fake,A,B,C,D)
|
||||||
% Solves a Sylvester equation.
|
% Solves a Sylvester equation.
|
||||||
%
|
%
|
||||||
% INPUTS
|
% INPUTS
|
||||||
|
@ -19,7 +19,7 @@ function [err, E] = gensylv(kron_prod,A,B,C0,D)
|
||||||
% SPECIAL REQUIREMENTS
|
% SPECIAL REQUIREMENTS
|
||||||
% none.
|
% none.
|
||||||
|
|
||||||
% Copyright (C) 1996-2017 Dynare Team
|
% Copyright (C) 1996-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -42,4 +42,3 @@ end
|
||||||
|
|
||||||
x0 = sylvester3(A,B,C,D);
|
x0 = sylvester3(A,B,C,D);
|
||||||
E = sylvester3a(x0,A,B,C,D);
|
E = sylvester3a(x0,A,B,C,D);
|
||||||
err = 0;
|
|
|
@ -1,4 +1,4 @@
|
||||||
function [D, err] = A_times_B_kronecker_C(A,B,C)
|
function D = A_times_B_kronecker_C(A,B,C)
|
||||||
|
|
||||||
%@info:
|
%@info:
|
||||||
%! @deftypefn {Function File} {[@var{D}, @var{err}] =} A_times_B_kronecker_C (@var{A},@var{B},@var{C})
|
%! @deftypefn {Function File} {[@var{D}, @var{err}] =} A_times_B_kronecker_C (@var{A},@var{B},@var{C})
|
||||||
|
@ -41,7 +41,7 @@ function [D, err] = A_times_B_kronecker_C(A,B,C)
|
||||||
%! @end deftypefn
|
%! @end deftypefn
|
||||||
%@eod:
|
%@eod:
|
||||||
|
|
||||||
% Copyright (C) 1996-2012 Dynare Team
|
% Copyright (C) 1996-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -109,4 +109,4 @@ else
|
||||||
D = A * kron(B,B);
|
D = A * kron(B,B);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
err = 0;
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
function [D, err] = sparse_hessian_times_B_kronecker_C(varargin)
|
function D = sparse_hessian_times_B_kronecker_C(varargin)
|
||||||
|
|
||||||
%@info:
|
%@info:
|
||||||
%! @deftypefn {Function File} {[@var{D}, @var{err}] =} sparse_hessian_times_B_kronecker_C (@var{A},@var{B},@var{C},@var{fake})
|
%! @deftypefn {Function File} {@var{D} =} sparse_hessian_times_B_kronecker_C (@var{A},@var{B},@var{C},@var{fake})
|
||||||
%! @anchor{kronecker/sparse_hessian_times_B_kronecker_C}
|
%! @anchor{kronecker/sparse_hessian_times_B_kronecker_C}
|
||||||
%! @sp 1
|
%! @sp 1
|
||||||
%! Computes A*kron(B,C) where A is hessian matrix in sparse format.
|
%! Computes A*kron(B,C) where A is hessian matrix in sparse format.
|
||||||
|
@ -24,8 +24,6 @@ function [D, err] = sparse_hessian_times_B_kronecker_C(varargin)
|
||||||
%! @table @ @var
|
%! @table @ @var
|
||||||
%! @item D
|
%! @item D
|
||||||
%! mA*(nC*nB) or mA*(nB*nB) matrix of doubles.
|
%! mA*(nC*nB) or mA*(nB*nB) matrix of doubles.
|
||||||
%! @item err
|
|
||||||
%! Integer scalar equal to zero (if all goes well).
|
|
||||||
%! @end table
|
%! @end table
|
||||||
%! @sp 2
|
%! @sp 2
|
||||||
%! @strong{Remarks}
|
%! @strong{Remarks}
|
||||||
|
@ -45,7 +43,7 @@ function [D, err] = sparse_hessian_times_B_kronecker_C(varargin)
|
||||||
%! @end deftypefn
|
%! @end deftypefn
|
||||||
%@eod:
|
%@eod:
|
||||||
|
|
||||||
% Copyright (C) 1996-2012 Dynare Team
|
% Copyright (C) 1996-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -71,10 +69,9 @@ fake = varargin{nargin};
|
||||||
|
|
||||||
switch nargin
|
switch nargin
|
||||||
case 4
|
case 4
|
||||||
[D, fake] = A_times_B_kronecker_C(A,B,C,fake);
|
D = A_times_B_kronecker_C(A,B,C,fake);
|
||||||
case 3
|
case 3
|
||||||
[D, fake] = A_times_B_kronecker_C(A,B,C);
|
D = A_times_B_kronecker_C(A,B,C);
|
||||||
otherwise
|
otherwise
|
||||||
error('Two or Three input arguments required!')
|
error('Two or Three input arguments required!')
|
||||||
end
|
end
|
||||||
err = 0;
|
|
|
@ -1,4 +1,4 @@
|
||||||
function [err, ss, tt, zz, sdim, eigval, info] = mjdgges(e, d, qz_criterium, zhreshold)
|
function [ss, tt, zz, sdim, eigval, info] = mjdgges(e, d, qz_criterium, zhreshold)
|
||||||
%
|
%
|
||||||
% INPUTS
|
% INPUTS
|
||||||
% e [double] real square (n*n) matrix.
|
% e [double] real square (n*n) matrix.
|
||||||
|
@ -8,7 +8,6 @@ function [err, ss, tt, zz, sdim, eigval, info] = mjdgges(e, d, qz_criterium, zhr
|
||||||
% detecting eigenvalues too close to 0/0)
|
% detecting eigenvalues too close to 0/0)
|
||||||
%
|
%
|
||||||
% OUTPUTS
|
% OUTPUTS
|
||||||
% err [integer] scalar: 1 indicates failure, 0 indicates success
|
|
||||||
% ss [double] (n*n) quasi-triangular matrix.
|
% ss [double] (n*n) quasi-triangular matrix.
|
||||||
% tt [double] (n*n) quasi-triangular matrix.
|
% tt [double] (n*n) quasi-triangular matrix.
|
||||||
% zz [double] (n*n) orthogonal matrix.
|
% zz [double] (n*n) orthogonal matrix.
|
||||||
|
@ -19,7 +18,7 @@ function [err, ss, tt, zz, sdim, eigval, info] = mjdgges(e, d, qz_criterium, zhr
|
||||||
% SPECIAL REQUIREMENTS
|
% SPECIAL REQUIREMENTS
|
||||||
% none.
|
% none.
|
||||||
|
|
||||||
% Copyright (C) 1996-2018 Dynare Team
|
% Copyright (C) 1996-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -66,5 +65,3 @@ try
|
||||||
catch
|
catch
|
||||||
info = 1; % Not as precise as lapack's info!
|
info = 1; % Not as precise as lapack's info!
|
||||||
end
|
end
|
||||||
|
|
||||||
err = 0;
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ function model_diagnostics(M,options,oo)
|
||||||
% none.
|
% none.
|
||||||
%
|
%
|
||||||
|
|
||||||
% Copyright (C) 1996-2018 Dynare Team
|
% Copyright (C) 1996-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -107,11 +107,11 @@ exo = [oo.exo_steady_state; oo.exo_det_steady_state];
|
||||||
for b=1:nb
|
for b=1:nb
|
||||||
if options.bytecode
|
if options.bytecode
|
||||||
if nb == 1
|
if nb == 1
|
||||||
[chk, res, jacob] = bytecode(dr.ys, exo, M.params, dr.ys, 1, exo, ...
|
[res, jacob] = bytecode(dr.ys, exo, M.params, dr.ys, 1, exo, ...
|
||||||
'evaluate', 'static');
|
'evaluate', 'static');
|
||||||
else
|
else
|
||||||
[chk, res, jacob] = bytecode(dr.ys, exo, M.params, dr.ys, 1, exo, ...
|
[res, jacob] = bytecode(dr.ys, exo, M.params, dr.ys, 1, exo, ...
|
||||||
'evaluate', 'static',['block=' ...
|
'evaluate', 'static',['block=' ...
|
||||||
int2str(b)]);
|
int2str(b)]);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@ -204,8 +204,8 @@ z = repmat(dr.ys,1,klen);
|
||||||
if ~options.block
|
if ~options.block
|
||||||
if options.order == 1
|
if options.order == 1
|
||||||
if (options.bytecode)
|
if (options.bytecode)
|
||||||
[chck, ~, loc_dr] = bytecode('dynamic','evaluate', z,exo_simul, ...
|
[~, loc_dr] = bytecode('dynamic','evaluate', z,exo_simul, ...
|
||||||
M.params, dr.ys, 1);
|
M.params, dr.ys, 1);
|
||||||
jacobia_ = [loc_dr.g1 loc_dr.g1_x loc_dr.g1_xd];
|
jacobia_ = [loc_dr.g1 loc_dr.g1_x loc_dr.g1_xd];
|
||||||
else
|
else
|
||||||
[~,jacobia_] = feval([M.fname '.dynamic'],z(iyr0),exo_simul, ...
|
[~,jacobia_] = feval([M.fname '.dynamic'],z(iyr0),exo_simul, ...
|
||||||
|
@ -213,8 +213,8 @@ if ~options.block
|
||||||
end
|
end
|
||||||
elseif options.order >= 2
|
elseif options.order >= 2
|
||||||
if (options.bytecode)
|
if (options.bytecode)
|
||||||
[chck, ~, loc_dr] = bytecode('dynamic','evaluate', z,exo_simul, ...
|
[~, loc_dr] = bytecode('dynamic','evaluate', z,exo_simul, ...
|
||||||
M.params, dr.ys, 1);
|
M.params, dr.ys, 1);
|
||||||
jacobia_ = [loc_dr.g1 loc_dr.g1_x];
|
jacobia_ = [loc_dr.g1 loc_dr.g1_x];
|
||||||
else
|
else
|
||||||
[~,jacobia_,hessian1] = feval([M.fname '.dynamic'],z(iyr0),...
|
[~,jacobia_,hessian1] = feval([M.fname '.dynamic'],z(iyr0),...
|
||||||
|
|
|
@ -14,7 +14,7 @@ function [options_, oo_]=ms_compute_mdd(M_, options_, oo_)
|
||||||
% SPECIAL REQUIREMENTS
|
% SPECIAL REQUIREMENTS
|
||||||
% none
|
% none
|
||||||
|
|
||||||
% Copyright (C) 2011-2013 Dynare Team
|
% Copyright (C) 2011-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -51,8 +51,7 @@ if options_.ms.use_mean_center
|
||||||
end
|
end
|
||||||
|
|
||||||
% compute mdd
|
% compute mdd
|
||||||
[err] = ms_sbvar_command_line(opt);
|
ms_sbvar_command_line(opt);
|
||||||
mexErrCheck('ms_compute_mdd',err);
|
|
||||||
|
|
||||||
% grab the muller/bridge log mdd from the output file
|
% grab the muller/bridge log mdd from the output file
|
||||||
mull_exp = 'Muller \w+\(\w+\) \= (\d+.\d+e\+\d+)';
|
mull_exp = 'Muller \w+\(\w+\) \= (\d+.\d+e\+\d+)';
|
||||||
|
|
|
@ -14,7 +14,7 @@ function [options_, oo_]=ms_compute_probabilities(M_, options_, oo_)
|
||||||
% SPECIAL REQUIREMENTS
|
% SPECIAL REQUIREMENTS
|
||||||
% none
|
% none
|
||||||
|
|
||||||
% Copyright (C) 2011 Dynare Team
|
% Copyright (C) 2011-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -53,8 +53,7 @@ else
|
||||||
end
|
end
|
||||||
|
|
||||||
% compute probabilities
|
% compute probabilities
|
||||||
[err] = ms_sbvar_command_line(opt);
|
ms_sbvar_command_line(opt);
|
||||||
mexErrCheck('ms_compute_probabilities',err);
|
|
||||||
|
|
||||||
% now we want to plot the probabilities for each chain
|
% now we want to plot the probabilities for each chain
|
||||||
if ischar(prob_out_file)
|
if ischar(prob_out_file)
|
||||||
|
|
|
@ -14,7 +14,7 @@ function [options_, oo_]=ms_estimation(M_, options_, oo_)
|
||||||
% SPECIAL REQUIREMENTS
|
% SPECIAL REQUIREMENTS
|
||||||
% none
|
% none
|
||||||
|
|
||||||
% Copyright (C) 2011-2017 Dynare Team
|
% Copyright (C) 2011-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -73,8 +73,7 @@ opt = [opt ' -random_tol_obj ' num2str(options_.ms.random_function_convergence_c
|
||||||
opt = [opt ' -random_tol_parms ' num2str(options_.ms.random_parameter_convergence_criterion)];
|
opt = [opt ' -random_tol_parms ' num2str(options_.ms.random_parameter_convergence_criterion)];
|
||||||
|
|
||||||
% estimation
|
% estimation
|
||||||
[err] = ms_sbvar_command_line(opt);
|
ms_sbvar_command_line(opt);
|
||||||
mexErrCheck('ms_estimation', err);
|
|
||||||
|
|
||||||
[options_, oo_] = set_ms_estimation_file(options_.ms.output_file_tag, options_, oo_);
|
[options_, oo_] = set_ms_estimation_file(options_.ms.output_file_tag, options_, oo_);
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,7 +14,7 @@ function [options_, oo_]=ms_forecast(M_, options_, oo_)
|
||||||
% SPECIAL REQUIREMENTS
|
% SPECIAL REQUIREMENTS
|
||||||
% none
|
% none
|
||||||
|
|
||||||
% Copyright (C) 2011-2017 Dynare Team
|
% Copyright (C) 2011-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -75,8 +75,7 @@ else
|
||||||
end
|
end
|
||||||
|
|
||||||
% forecast
|
% forecast
|
||||||
[err] = ms_sbvar_command_line(opt);
|
ms_sbvar_command_line(opt);
|
||||||
mexErrCheck('ms_forecast',err);
|
|
||||||
|
|
||||||
% Plot Forecasts
|
% Plot Forecasts
|
||||||
if options_.ms.regimes
|
if options_.ms.regimes
|
||||||
|
|
|
@ -15,7 +15,7 @@ function [options_, oo_]=ms_irf(varlist, M_, options_, oo_)
|
||||||
% SPECIAL REQUIREMENTS
|
% SPECIAL REQUIREMENTS
|
||||||
% none
|
% none
|
||||||
|
|
||||||
% Copyright (C) 2011-2017 Dynare Team
|
% Copyright (C) 2011-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -77,8 +77,7 @@ else
|
||||||
end
|
end
|
||||||
|
|
||||||
% irf
|
% irf
|
||||||
[err] = ms_sbvar_command_line(opt);
|
ms_sbvar_command_line(opt);
|
||||||
mexErrCheck('ms_irf',err);
|
|
||||||
|
|
||||||
% Plot IRFs
|
% Plot IRFs
|
||||||
if options_.ms.regimes
|
if options_.ms.regimes
|
||||||
|
|
|
@ -11,7 +11,7 @@ function ms_sbvar_setup(options_)
|
||||||
% SPECIAL REQUIREMENTS
|
% SPECIAL REQUIREMENTS
|
||||||
% none
|
% none
|
||||||
|
|
||||||
% Copyright (C) 2003-2017 Dynare Team
|
% Copyright (C) 2003-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -428,6 +428,5 @@ fclose(fidForC);
|
||||||
%======================================================================
|
%======================================================================
|
||||||
ms_write_markov_file(markov_file,options_)
|
ms_write_markov_file(markov_file,options_)
|
||||||
create_init_file = [matlab_filename,' ',markov_file,' ',options_.ms.file_tag];
|
create_init_file = [matlab_filename,' ',markov_file,' ',options_.ms.file_tag];
|
||||||
[err] = ms_sbvar_create_init_file(create_init_file);
|
ms_sbvar_create_init_file(create_init_file);
|
||||||
mexErrCheck('ms_sbvar_create_init_file',err);
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,7 +14,7 @@ function [options_, oo_]=ms_simulation(M_, options_, oo_)
|
||||||
% SPECIAL REQUIREMENTS
|
% SPECIAL REQUIREMENTS
|
||||||
% none
|
% none
|
||||||
|
|
||||||
% Copyright (C) 2011-2013 Dynare Team
|
% Copyright (C) 2011-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -50,6 +50,5 @@ if options_.ms.save_draws
|
||||||
end
|
end
|
||||||
|
|
||||||
% simulation
|
% simulation
|
||||||
[err] = ms_sbvar_command_line(opt);
|
ms_sbvar_command_line(opt);
|
||||||
mexErrCheck('ms_simulation',err);
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,7 +14,7 @@ function [options_, oo_]=ms_variance_decomposition(M_, options_, oo_)
|
||||||
% SPECIAL REQUIREMENTS
|
% SPECIAL REQUIREMENTS
|
||||||
% none
|
% none
|
||||||
|
|
||||||
% Copyright (C) 2011-2017 Dynare Team
|
% Copyright (C) 2011-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -78,8 +78,7 @@ if options_.ms.error_bands
|
||||||
end
|
end
|
||||||
|
|
||||||
% variance_decomposition
|
% variance_decomposition
|
||||||
[err] = ms_sbvar_command_line(opt);
|
ms_sbvar_command_line(opt);
|
||||||
mexErrCheck('ms_variance_decomposition',err);
|
|
||||||
|
|
||||||
if options_.ms.regime || options_.ms.regimes
|
if options_.ms.regime || options_.ms.regimes
|
||||||
outfile = [outfile 'regime_'];
|
outfile = [outfile 'regime_'];
|
||||||
|
|
|
@ -2,7 +2,7 @@ function ys1 = add_auxiliary_variables_to_steadystate(ys,aux_vars,fname, ...
|
||||||
exo_steady_state, exo_det_steady_state,params, byte_code)
|
exo_steady_state, exo_det_steady_state,params, byte_code)
|
||||||
% Add auxiliary variables to the steady state vector
|
% Add auxiliary variables to the steady state vector
|
||||||
|
|
||||||
% Copyright (C) 2009-2017 Dynare Team
|
% Copyright (C) 2009-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -23,9 +23,9 @@ ys1 = [ys;zeros(n,1)];
|
||||||
|
|
||||||
for i=1:n+1
|
for i=1:n+1
|
||||||
if byte_code
|
if byte_code
|
||||||
[info, res] = bytecode('static','evaluate',ys1,...
|
res = bytecode('static','evaluate',ys1,...
|
||||||
[exo_steady_state; ...
|
[exo_steady_state; ...
|
||||||
exo_det_steady_state],params);
|
exo_det_steady_state],params);
|
||||||
else
|
else
|
||||||
res = feval([fname '.static'],ys1,...
|
res = feval([fname '.static'],ys1,...
|
||||||
[exo_steady_state; ...
|
[exo_steady_state; ...
|
||||||
|
|
|
@ -12,7 +12,7 @@ function data_set = det_cond_forecast(varargin)
|
||||||
% dataset [dseries] Returns a dseries containing the forecasted endgenous variables and shocks
|
% dataset [dseries] Returns a dseries containing the forecasted endgenous variables and shocks
|
||||||
%
|
%
|
||||||
|
|
||||||
% Copyright (C) 2013-2018 Dynare Team
|
% Copyright (C) 2013-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -158,13 +158,12 @@ else
|
||||||
if options_.bytecode
|
if options_.bytecode
|
||||||
save_options_dynatol_f = options_.dynatol.f;
|
save_options_dynatol_f = options_.dynatol.f;
|
||||||
options_.dynatol.f = 1e-7;
|
options_.dynatol.f = 1e-7;
|
||||||
[Info, endo, exo] = bytecode('extended_path', plan, oo_.endo_simul, oo_.exo_simul, M_.params, oo_.steady_state, options_.periods);
|
[endo, exo] = bytecode('extended_path', plan, oo_.endo_simul, oo_.exo_simul, M_.params, oo_.steady_state, options_.periods);
|
||||||
options_.dynatol.f = save_options_dynatol_f;
|
options_.dynatol.f = save_options_dynatol_f;
|
||||||
|
|
||||||
if Info == 0
|
oo_.endo_simul = endo;
|
||||||
oo_.endo_simul = endo;
|
oo_.exo_simul = exo;
|
||||||
oo_.exo_simul = exo;
|
|
||||||
end
|
|
||||||
endo = endo';
|
endo = endo';
|
||||||
endo_l = size(endo(1+M_.maximum_lag:end,:),1);
|
endo_l = size(endo(1+M_.maximum_lag:end,:),1);
|
||||||
jrng = dates(plan.date(1)):dates(plan.date(1)+endo_l);
|
jrng = dates(plan.date(1)):dates(plan.date(1)+endo_l);
|
||||||
|
@ -473,14 +472,12 @@ if pf && ~surprise
|
||||||
end
|
end
|
||||||
data1 = M_;
|
data1 = M_;
|
||||||
if (options_.bytecode)
|
if (options_.bytecode)
|
||||||
[chck, zz, data1]= bytecode('dynamic','evaluate', z, zx, M_.params, oo_.steady_state, k, data1);
|
[zz, data1]= bytecode('dynamic','evaluate', z, zx, M_.params, oo_.steady_state, k, data1);
|
||||||
else
|
else
|
||||||
[zz, g1b] = feval([M_.fname '.dynamic'], z', zx, M_.params, oo_.steady_state, k);
|
[zz, g1b] = feval([M_.fname '.dynamic'], z', zx, M_.params, oo_.steady_state, k);
|
||||||
data1.g1_x = g1b(:,end - M_.exo_nbr + 1:end);
|
data1.g1_x = g1b(:,end - M_.exo_nbr + 1:end);
|
||||||
data1.g1 = g1b(:,1 : end - M_.exo_nbr);
|
data1.g1 = g1b(:,1 : end - M_.exo_nbr);
|
||||||
chck = 0;
|
|
||||||
end
|
end
|
||||||
mexErrCheck('bytecode', chck);
|
|
||||||
end
|
end
|
||||||
if k == 1
|
if k == 1
|
||||||
g1(1:M_.endo_nbr,-M_.endo_nbr + [cur_indx lead_indx]) = data1.g1(:,M_.nspred + 1:end);
|
g1(1:M_.endo_nbr,-M_.endo_nbr + [cur_indx lead_indx]) = data1.g1(:,M_.nspred + 1:end);
|
||||||
|
@ -745,14 +742,12 @@ else
|
||||||
end
|
end
|
||||||
data1 = M_;
|
data1 = M_;
|
||||||
if (options_.bytecode)
|
if (options_.bytecode)
|
||||||
[chck, zz, data1]= bytecode('dynamic','evaluate', z, zx, M_.params, oo_.steady_state, k, data1);
|
[zz, data1]= bytecode('dynamic','evaluate', z, zx, M_.params, oo_.steady_state, k, data1);
|
||||||
else
|
else
|
||||||
[zz, g1b] = feval([M_.fname '.dynamic'], z', zx, M_.params, oo_.steady_state, k);
|
[zz, g1b] = feval([M_.fname '.dynamic'], z', zx, M_.params, oo_.steady_state, k);
|
||||||
data1.g1_x = g1b(:,end - M_.exo_nbr + 1:end);
|
data1.g1_x = g1b(:,end - M_.exo_nbr + 1:end);
|
||||||
data1.g1 = g1b(:,1 : end - M_.exo_nbr);
|
data1.g1 = g1b(:,1 : end - M_.exo_nbr);
|
||||||
chck = 0;
|
|
||||||
end
|
end
|
||||||
mexErrCheck('bytecode', chck);
|
|
||||||
end
|
end
|
||||||
if k == 1
|
if k == 1
|
||||||
g1(1:M_.endo_nbr,-M_.endo_nbr + [cur_indx lead_indx]) = data1.g1(:,M_.nspred + 1:end);
|
g1(1:M_.endo_nbr,-M_.endo_nbr + [cur_indx lead_indx]) = data1.g1(:,M_.nspred + 1:end);
|
||||||
|
|
|
@ -11,7 +11,7 @@ function [oo_, maxerror] = perfect_foresight_solver_core(M_, options_, oo_)
|
||||||
% - oo_ [struct] contains results
|
% - oo_ [struct] contains results
|
||||||
% - maxerror [double] contains the maximum absolute error
|
% - maxerror [double] contains the maximum absolute error
|
||||||
|
|
||||||
% Copyright (C) 2015-2019 Dynare Team
|
% Copyright (C) 2015-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -50,18 +50,14 @@ end
|
||||||
if options_.block
|
if options_.block
|
||||||
if options_.bytecode
|
if options_.bytecode
|
||||||
try
|
try
|
||||||
[info, tmp] = bytecode('dynamic', oo_.endo_simul, oo_.exo_simul, M_.params, repmat(oo_.steady_state,1, periods+2), periods);
|
oo_.endo_simul = bytecode('dynamic', oo_.endo_simul, oo_.exo_simul, M_.params, repmat(oo_.steady_state,1, periods+2), periods);
|
||||||
catch
|
|
||||||
info = 1;
|
|
||||||
end
|
|
||||||
if info
|
|
||||||
oo_.deterministic_simulation.status = false;
|
|
||||||
else
|
|
||||||
oo_.endo_simul = tmp;
|
|
||||||
oo_.deterministic_simulation.status = true;
|
oo_.deterministic_simulation.status = true;
|
||||||
end
|
catch ME
|
||||||
if options_.no_homotopy
|
disp(ME.message)
|
||||||
mexErrCheck('bytecode', info);
|
if options_.no_homotopy
|
||||||
|
error('Error in bytecode')
|
||||||
|
end
|
||||||
|
oo_.deterministic_simulation.status = false;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
oo_ = feval([M_.fname '.dynamic'], options_, M_, oo_);
|
oo_ = feval([M_.fname '.dynamic'], options_, M_, oo_);
|
||||||
|
@ -69,18 +65,14 @@ if options_.block
|
||||||
else
|
else
|
||||||
if options_.bytecode
|
if options_.bytecode
|
||||||
try
|
try
|
||||||
[info, tmp] = bytecode('dynamic', oo_.endo_simul, oo_.exo_simul, M_.params, repmat(oo_.steady_state, 1, periods+2), periods);
|
oo_.endo_simul = bytecode('dynamic', oo_.endo_simul, oo_.exo_simul, M_.params, repmat(oo_.steady_state, 1, periods+2), periods);
|
||||||
catch
|
|
||||||
info = 1;
|
|
||||||
end
|
|
||||||
if info
|
|
||||||
oo_.deterministic_simulation.status = false;
|
|
||||||
else
|
|
||||||
oo_.endo_simul = tmp;
|
|
||||||
oo_.deterministic_simulation.status = true;
|
oo_.deterministic_simulation.status = true;
|
||||||
end
|
catch ME
|
||||||
if options_.no_homotopy
|
disp(ME.message)
|
||||||
mexErrCheck('bytecode', info);
|
if options_.no_homotopy
|
||||||
|
error('Error in bytecode')
|
||||||
|
end
|
||||||
|
oo_.deterministic_simulation.status = false;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if M_.maximum_endo_lead == 0 % Purely backward model
|
if M_.maximum_endo_lead == 0 % Purely backward model
|
||||||
|
@ -128,7 +120,7 @@ if nargout>1
|
||||||
maxerror = oo_.deterministic_simulation.error;
|
maxerror = oo_.deterministic_simulation.error;
|
||||||
else
|
else
|
||||||
if options_.bytecode
|
if options_.bytecode
|
||||||
[~, residuals]= bytecode('dynamic','evaluate', oo_.endo_simul, oo_.exo_simul, M_.params, oo_.steady_state, 1);
|
residuals = bytecode('dynamic','evaluate', oo_.endo_simul, oo_.exo_simul, M_.params, oo_.steady_state, 1);
|
||||||
else
|
else
|
||||||
if M_.maximum_lag > 0
|
if M_.maximum_lag > 0
|
||||||
y0 = oo_.endo_simul(:, M_.maximum_lag);
|
y0 = oo_.endo_simul(:, M_.maximum_lag);
|
||||||
|
|
|
@ -12,7 +12,7 @@ function z = resid(junk)
|
||||||
% SPECIAL REQUIREMENTS
|
% SPECIAL REQUIREMENTS
|
||||||
% none
|
% none
|
||||||
|
|
||||||
% Copyright (C) 2001-2018 Dynare Team
|
% Copyright (C) 2001-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -79,8 +79,7 @@ if options_.block && ~options_.bytecode
|
||||||
z(idx) = r;
|
z(idx) = r;
|
||||||
end
|
end
|
||||||
elseif options_.bytecode
|
elseif options_.bytecode
|
||||||
[check, z] = bytecode('evaluate','static');
|
z = bytecode('evaluate','static');
|
||||||
mexErrCheck('bytecode', check);
|
|
||||||
else
|
else
|
||||||
z = feval([M_.fname '.static'],...
|
z = feval([M_.fname '.static'],...
|
||||||
oo_.steady_state,...
|
oo_.steady_state,...
|
||||||
|
|
|
@ -17,7 +17,7 @@ function y_=simult_(M_,options_,y0,dr,ex_,iorder)
|
||||||
% SPECIAL REQUIREMENTS
|
% SPECIAL REQUIREMENTS
|
||||||
% none
|
% none
|
||||||
|
|
||||||
% Copyright (C) 2001-2019 Dynare Team
|
% Copyright (C) 2001-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -53,10 +53,9 @@ end
|
||||||
|
|
||||||
if options_.k_order_solver && ~options_.pruning % Call dynare++ routines.
|
if options_.k_order_solver && ~options_.pruning % Call dynare++ routines.
|
||||||
ex_ = [zeros(M_.maximum_lag,M_.exo_nbr); ex_];
|
ex_ = [zeros(M_.maximum_lag,M_.exo_nbr); ex_];
|
||||||
[err, y_] = dynare_simul_(options_.order,M_.nstatic,M_.npred,M_.nboth,M_.nfwrd,exo_nbr, ...
|
y_ = dynare_simul_(options_.order,M_.nstatic,M_.npred,M_.nboth,M_.nfwrd,exo_nbr, ...
|
||||||
y_(dr.order_var,1),ex_',M_.Sigma_e,options_.DynareRandomStreams.seed, ...
|
y_(dr.order_var,1),ex_',M_.Sigma_e,options_.DynareRandomStreams.seed, ...
|
||||||
dr.ys(dr.order_var),dr);
|
dr.ys(dr.order_var),dr);
|
||||||
mexErrCheck('dynare_simul_', err);
|
|
||||||
y_(dr.order_var,:) = y_;
|
y_(dr.order_var,:) = y_;
|
||||||
else
|
else
|
||||||
if options_.block
|
if options_.block
|
||||||
|
@ -98,12 +97,9 @@ else
|
||||||
yhat1 = y__(order_var(k2))-dr.ys(order_var(k2));
|
yhat1 = y__(order_var(k2))-dr.ys(order_var(k2));
|
||||||
yhat2 = y_(order_var(k2),i-1)-dr.ys(order_var(k2));
|
yhat2 = y_(order_var(k2),i-1)-dr.ys(order_var(k2));
|
||||||
epsilon = ex_(i-1,:)';
|
epsilon = ex_(i-1,:)';
|
||||||
[abcOut1, err] = A_times_B_kronecker_C(.5*dr.ghxx,yhat1);
|
abcOut1 = A_times_B_kronecker_C(.5*dr.ghxx,yhat1);
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
abcOut2 = A_times_B_kronecker_C(.5*dr.ghuu,epsilon);
|
||||||
[abcOut2, err] = A_times_B_kronecker_C(.5*dr.ghuu,epsilon);
|
abcOut3 = A_times_B_kronecker_C(dr.ghxu,yhat1,epsilon);
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
|
||||||
[abcOut3, err] = A_times_B_kronecker_C(dr.ghxu,yhat1,epsilon);
|
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
|
||||||
y_(order_var,i) = constant + dr.ghx*yhat2 + dr.ghu*epsilon ...
|
y_(order_var,i) = constant + dr.ghx*yhat2 + dr.ghu*epsilon ...
|
||||||
+ abcOut1 + abcOut2 + abcOut3;
|
+ abcOut1 + abcOut2 + abcOut3;
|
||||||
y__(order_var) = dr.ys(order_var) + dr.ghx*yhat1 + dr.ghu*epsilon;
|
y__(order_var) = dr.ys(order_var) + dr.ghx*yhat1 + dr.ghu*epsilon;
|
||||||
|
@ -112,12 +108,9 @@ else
|
||||||
for i = 2:iter+M_.maximum_lag
|
for i = 2:iter+M_.maximum_lag
|
||||||
yhat = y_(order_var(k2),i-1)-dr.ys(order_var(k2));
|
yhat = y_(order_var(k2),i-1)-dr.ys(order_var(k2));
|
||||||
epsilon = ex_(i-1,:)';
|
epsilon = ex_(i-1,:)';
|
||||||
[abcOut1, err] = A_times_B_kronecker_C(.5*dr.ghxx,yhat);
|
abcOut1 = A_times_B_kronecker_C(.5*dr.ghxx,yhat);
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
abcOut2 = A_times_B_kronecker_C(.5*dr.ghuu,epsilon);
|
||||||
[abcOut2, err] = A_times_B_kronecker_C(.5*dr.ghuu,epsilon);
|
abcOut3 = A_times_B_kronecker_C(dr.ghxu,yhat,epsilon);
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
|
||||||
[abcOut3, err] = A_times_B_kronecker_C(dr.ghxu,yhat,epsilon);
|
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
|
||||||
y_(dr.order_var,i) = constant + dr.ghx*yhat + dr.ghu*epsilon ...
|
y_(dr.order_var,i) = constant + dr.ghx*yhat + dr.ghu*epsilon ...
|
||||||
+ abcOut1 + abcOut2 + abcOut3;
|
+ abcOut1 + abcOut2 + abcOut3;
|
||||||
end
|
end
|
||||||
|
@ -150,30 +143,21 @@ else
|
||||||
u = ex_(i-1,:)';
|
u = ex_(i-1,:)';
|
||||||
%construct terms of order 2 from second order part, based
|
%construct terms of order 2 from second order part, based
|
||||||
%on linear component yhat1
|
%on linear component yhat1
|
||||||
[gyy, err] = A_times_B_kronecker_C(ghxx,yhat1);
|
gyy = A_times_B_kronecker_C(ghxx,yhat1);
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
guu = A_times_B_kronecker_C(ghuu,u);
|
||||||
[guu, err] = A_times_B_kronecker_C(ghuu,u);
|
gyu = A_times_B_kronecker_C(ghxu,yhat1,u);
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
|
||||||
[gyu, err] = A_times_B_kronecker_C(ghxu,yhat1,u);
|
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
|
||||||
%construct terms of order 3 from second order part, based
|
%construct terms of order 3 from second order part, based
|
||||||
%on order 2 component yhat2
|
%on order 2 component yhat2
|
||||||
[gyy12, err] = A_times_B_kronecker_C(ghxx,yhat1,yhat2);
|
gyy12 = A_times_B_kronecker_C(ghxx,yhat1,yhat2);
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
gy2u = A_times_B_kronecker_C(ghxu,yhat2,u);
|
||||||
[gy2u, err] = A_times_B_kronecker_C(ghxu,yhat2,u);
|
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
|
||||||
%construct terms of order 3, all based on first order component yhat1
|
%construct terms of order 3, all based on first order component yhat1
|
||||||
y2a = kron(yhat1,yhat1);
|
y2a = kron(yhat1,yhat1);
|
||||||
[gyyy, err] = A_times_B_kronecker_C(ghxxx,y2a,yhat1);
|
gyyy = A_times_B_kronecker_C(ghxxx,y2a,yhat1);
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
|
||||||
u2a = kron(u,u);
|
u2a = kron(u,u);
|
||||||
[guuu, err] = A_times_B_kronecker_C(ghuuu,u2a,u);
|
guuu = A_times_B_kronecker_C(ghuuu,u2a,u);
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
|
||||||
yu = kron(yhat1,u);
|
yu = kron(yhat1,u);
|
||||||
[gyyu, err] = A_times_B_kronecker_C(ghxxu,yhat1,yu);
|
gyyu = A_times_B_kronecker_C(ghxxu,yhat1,yu);
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
gyuu = A_times_B_kronecker_C(ghxuu,yu,u);
|
||||||
[gyuu, err] = A_times_B_kronecker_C(ghxuu,yu,u);
|
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
|
||||||
%add all terms of order 3, linear component based on third
|
%add all terms of order 3, linear component based on third
|
||||||
%order yhat3
|
%order yhat3
|
||||||
yhat3 = ghx*yhat3 +gyy12 ... % prefactor is 1/2*2=1, see (65) Appendix Andreasen et al.
|
yhat3 = ghx*yhat3 +gyy12 ... % prefactor is 1/2*2=1, see (65) Appendix Andreasen et al.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
function [flag,endo_simul,err] = solve_perfect_foresight_model(endo_simul,exo_simul,pfm)
|
function [flag,endo_simul,err] = solve_perfect_foresight_model(endo_simul,exo_simul,pfm)
|
||||||
|
|
||||||
% Copyright (C) 2012-2017 Dynare Team
|
% Copyright (C) 2012-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -33,7 +33,13 @@ if pfm.verbose
|
||||||
end
|
end
|
||||||
|
|
||||||
if pfm.use_bytecode
|
if pfm.use_bytecode
|
||||||
[flag, endo_simul]=bytecode(Y, exo_simul, pfm.params);
|
try
|
||||||
|
endo_simul=bytecode(Y, exo_simul, pfm.params);
|
||||||
|
flag = 0;
|
||||||
|
catch ME
|
||||||
|
disp(ME.message);
|
||||||
|
flag = 1;
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -120,4 +126,4 @@ if nan_flag
|
||||||
end
|
end
|
||||||
if pfm.verbose
|
if pfm.verbose
|
||||||
disp (['-----------------------------------------------------']) ;
|
disp (['-----------------------------------------------------']) ;
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,7 +24,7 @@ function [dr, info] = stochastic_solvers(dr, task, M_, options_, oo_)
|
||||||
% info=6 -> The jacobian matrix evaluated at the steady state is complex.
|
% info=6 -> The jacobian matrix evaluated at the steady state is complex.
|
||||||
% info=9 -> k_order_pert was unable to compute the solution
|
% info=9 -> k_order_pert was unable to compute the solution
|
||||||
|
|
||||||
% Copyright (C) 1996-2019 Dynare Team
|
% Copyright (C) 1996-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -111,8 +111,8 @@ it_ = M_.maximum_lag + 1;
|
||||||
z = repmat(dr.ys,1,klen);
|
z = repmat(dr.ys,1,klen);
|
||||||
if local_order == 1
|
if local_order == 1
|
||||||
if (options_.bytecode)
|
if (options_.bytecode)
|
||||||
[chck, ~, loc_dr] = bytecode('dynamic','evaluate', z,exo_simul, ...
|
[~, loc_dr] = bytecode('dynamic','evaluate', z,exo_simul, ...
|
||||||
M_.params, dr.ys, 1);
|
M_.params, dr.ys, 1);
|
||||||
jacobia_ = [loc_dr.g1 loc_dr.g1_x loc_dr.g1_xd];
|
jacobia_ = [loc_dr.g1 loc_dr.g1_x loc_dr.g1_xd];
|
||||||
else
|
else
|
||||||
[~,jacobia_] = feval([M_.fname '.dynamic'],z(iyr0),exo_simul, ...
|
[~,jacobia_] = feval([M_.fname '.dynamic'],z(iyr0),exo_simul, ...
|
||||||
|
@ -120,8 +120,8 @@ if local_order == 1
|
||||||
end
|
end
|
||||||
elseif local_order == 2
|
elseif local_order == 2
|
||||||
if (options_.bytecode)
|
if (options_.bytecode)
|
||||||
[chck, ~, loc_dr] = bytecode('dynamic','evaluate', z,exo_simul, ...
|
[~, loc_dr] = bytecode('dynamic','evaluate', z,exo_simul, ...
|
||||||
M_.params, dr.ys, 1);
|
M_.params, dr.ys, 1);
|
||||||
jacobia_ = [loc_dr.g1 loc_dr.g1_x];
|
jacobia_ = [loc_dr.g1 loc_dr.g1_x];
|
||||||
else
|
else
|
||||||
[~,jacobia_,hessian1] = feval([M_.fname '.dynamic'],z(iyr0),...
|
[~,jacobia_,hessian1] = feval([M_.fname '.dynamic'],z(iyr0),...
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2007-2019 Dynare Team
|
* Copyright © 2007-2020 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -143,10 +143,10 @@ det(const double *F, int dim, const lapack_int *ipiv)
|
||||||
|
|
||||||
BlockKalmanFilter::BlockKalmanFilter(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
BlockKalmanFilter::BlockKalmanFilter(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
||||||
{
|
{
|
||||||
if (nlhs > 3)
|
if (nlhs > 2)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("block_kalman_filter provides at most 3 output argument.");
|
mexErrMsgTxt("block_kalman_filter provides at most 2 output argument.");
|
||||||
if (nrhs != 13 && nrhs != 16)
|
if (nrhs != 13 && nrhs != 16)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("block_kalman_filter requires exactly \n 13 input arguments for standard Kalman filter \nor\n 16 input arguments for missing observations Kalman filter.");
|
mexErrMsgTxt("block_kalman_filter requires exactly \n 13 input arguments for standard Kalman filter \nor\n 16 input arguments for missing observations Kalman filter.");
|
||||||
if (nrhs == 16)
|
if (nrhs == 16)
|
||||||
missing_observations = true;
|
missing_observations = true;
|
||||||
else
|
else
|
||||||
|
@ -154,13 +154,13 @@ BlockKalmanFilter::BlockKalmanFilter(int nlhs, mxArray *plhs[], int nrhs, const
|
||||||
if (missing_observations)
|
if (missing_observations)
|
||||||
{
|
{
|
||||||
if (!mxIsCell(prhs[0]))
|
if (!mxIsCell(prhs[0]))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("the first input argument of block_missing_observations_kalman_filter must be a Cell Array.");
|
mexErrMsgTxt("the first input argument of block_missing_observations_kalman_filter must be a Cell Array.");
|
||||||
pdata_index = prhs[0];
|
pdata_index = prhs[0];
|
||||||
if (!mxIsDouble(prhs[1]))
|
if (!mxIsDouble(prhs[1]))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("the second input argument of block_missing_observations_kalman_filter must be a scalar.");
|
mexErrMsgTxt("the second input argument of block_missing_observations_kalman_filter must be a scalar.");
|
||||||
number_of_observations = ceil(mxGetScalar(prhs[1]));
|
number_of_observations = ceil(mxGetScalar(prhs[1]));
|
||||||
if (!mxIsDouble(prhs[2]))
|
if (!mxIsDouble(prhs[2]))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("the third input argument of block_missing_observations_kalman_filter must be a scalar.");
|
mexErrMsgTxt("the third input argument of block_missing_observations_kalman_filter must be a scalar.");
|
||||||
no_more_missing_observations = ceil(mxGetScalar(prhs[2]));
|
no_more_missing_observations = ceil(mxGetScalar(prhs[2]));
|
||||||
pT = mxDuplicateArray(prhs[3]);
|
pT = mxDuplicateArray(prhs[3]);
|
||||||
pR = mxDuplicateArray(prhs[4]);
|
pR = mxDuplicateArray(prhs[4]);
|
||||||
|
@ -218,7 +218,7 @@ BlockKalmanFilter::BlockKalmanFilter(int nlhs, mxArray *plhs[], int nrhs, const
|
||||||
|
|
||||||
if (missing_observations)
|
if (missing_observations)
|
||||||
if (mxGetNumberOfElements(pdata_index) != static_cast<unsigned int>(smpl))
|
if (mxGetNumberOfElements(pdata_index) != static_cast<unsigned int>(smpl))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("the number of element in the cell array passed to block_missing_observation_kalman_filter as first argument has to be equal to the smpl size");
|
mexErrMsgTxt("the number of element in the cell array passed to block_missing_observation_kalman_filter as first argument has to be equal to the smpl size");
|
||||||
|
|
||||||
i_nz_state_var = std::make_unique<int[]>(n);
|
i_nz_state_var = std::make_unique<int[]>(n);
|
||||||
for (int i = 0; i < n; i++)
|
for (int i = 0; i < n; i++)
|
||||||
|
@ -436,7 +436,7 @@ BlockKalmanFilter::block_kalman_filter(int nlhs, mxArray *plhs[])
|
||||||
{
|
{
|
||||||
mexPrintf("error: F singular\n");
|
mexPrintf("error: F singular\n");
|
||||||
LIK = Inf;
|
LIK = Inf;
|
||||||
if (nlhs == 3)
|
if (nlhs == 2)
|
||||||
for (int i = t; i < smpl; i++)
|
for (int i = t; i < smpl; i++)
|
||||||
lik[i] = Inf;
|
lik[i] = Inf;
|
||||||
// info = 0
|
// info = 0
|
||||||
|
@ -817,17 +817,15 @@ BlockKalmanFilter::block_kalman_filter(int nlhs, mxArray *plhs[])
|
||||||
void
|
void
|
||||||
BlockKalmanFilter::return_results_and_clean(int nlhs, mxArray *plhs[])
|
BlockKalmanFilter::return_results_and_clean(int nlhs, mxArray *plhs[])
|
||||||
{
|
{
|
||||||
plhs[0] = mxCreateDoubleScalar(0);
|
if (nlhs >= 1)
|
||||||
|
|
||||||
if (nlhs >= 2)
|
|
||||||
{
|
{
|
||||||
plhs[1] = mxCreateDoubleMatrix(1, 1, mxREAL);
|
plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL);
|
||||||
double *pind = mxGetPr(plhs[1]);
|
double *pind = mxGetPr(plhs[0]);
|
||||||
pind[0] = LIK;
|
pind[0] = LIK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nlhs == 3)
|
if (nlhs == 2)
|
||||||
plhs[2] = plik;
|
plhs[1] = plik;
|
||||||
else
|
else
|
||||||
mxDestroyArray(plik);
|
mxDestroyArray(plik);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2007-2017 Dynare Team
|
* Copyright © 2007-2020 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -21,37 +21,6 @@
|
||||||
#include "ErrorHandling.hh"
|
#include "ErrorHandling.hh"
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#ifdef DYN_MEX_FUNC_ERR_MSG_TXT
|
|
||||||
# undef DYN_MEX_FUNC_ERR_MSG_TXT
|
|
||||||
#endif // DYN_MEX_FUNC_ERR_MSG_TXT
|
|
||||||
|
|
||||||
#define DYN_MEX_FUNC_ERR_MSG_TXT(str) \
|
|
||||||
do { \
|
|
||||||
mexPrintf("%s\n", str); \
|
|
||||||
if (nlhs > 0) \
|
|
||||||
{ \
|
|
||||||
plhs[0] = mxCreateDoubleScalar(1); \
|
|
||||||
if (nlhs > 1) \
|
|
||||||
{ \
|
|
||||||
double *pind; \
|
|
||||||
plhs[1] = mxCreateDoubleMatrix(int (row_y), int (col_y), mxREAL); \
|
|
||||||
pind = mxGetPr(plhs[1]); \
|
|
||||||
if (evaluate) \
|
|
||||||
{ \
|
|
||||||
for (unsigned int i = 0; i < row_y*col_y; i++) \
|
|
||||||
pind[i] = 0; \
|
|
||||||
} \
|
|
||||||
else \
|
|
||||||
{ \
|
|
||||||
for (unsigned int i = 0; i < row_y*col_y; i++) \
|
|
||||||
pind[i] = yd[i]; \
|
|
||||||
} \
|
|
||||||
for (int i = 2; i < nlhs; i++) \
|
|
||||||
plhs[i] = mxCreateDoubleScalar(1); \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
return; \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#ifdef DEBUG_EX
|
#ifdef DEBUG_EX
|
||||||
|
|
||||||
|
@ -492,13 +461,13 @@ main(int nrhs, const char *prhs[])
|
||||||
}
|
}
|
||||||
catch (GeneralExceptionHandling &feh)
|
catch (GeneralExceptionHandling &feh)
|
||||||
{
|
{
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(feh.GetErrorMsg().c_str());
|
mexErrMsgTxt(feh.GetErrorMsg().c_str());
|
||||||
}
|
}
|
||||||
if (!count_array_argument)
|
if (!count_array_argument)
|
||||||
{
|
{
|
||||||
int field = mxGetFieldNumber(M_, "params");
|
int field = mxGetFieldNumber(M_, "params");
|
||||||
if (field < 0)
|
if (field < 0)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("params is not a field of M_");
|
mexErrMsgTxt("params is not a field of M_");
|
||||||
params = mxGetPr(mxGetFieldByNumber(M_, 0, field));
|
params = mxGetPr(mxGetFieldByNumber(M_, 0, field));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -510,14 +479,14 @@ main(int nrhs, const char *prhs[])
|
||||||
if (extended_path_struct == NULL)
|
if (extended_path_struct == NULL)
|
||||||
{
|
{
|
||||||
string tmp = "The 'extended_path' option must be followed by the extended_path descriptor";
|
string tmp = "The 'extended_path' option must be followed by the extended_path descriptor";
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(tmp.c_str());
|
mexErrMsgTxt(tmp.c_str());
|
||||||
}
|
}
|
||||||
mxArray *date_str = mxGetField(extended_path_struct, 0, "date_str");
|
mxArray *date_str = mxGetField(extended_path_struct, 0, "date_str");
|
||||||
if (date_str == NULL)
|
if (date_str == NULL)
|
||||||
{
|
{
|
||||||
string tmp = "date_str";
|
string tmp = "date_str";
|
||||||
tmp.insert(0, "The extended_path description structure does not contain the member: ");
|
tmp.insert(0, "The extended_path description structure does not contain the member: ");
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(tmp.c_str());
|
mexErrMsgTxt(tmp.c_str());
|
||||||
}
|
}
|
||||||
int nb_periods = mxGetM(date_str) * mxGetN(date_str);
|
int nb_periods = mxGetM(date_str) * mxGetN(date_str);
|
||||||
|
|
||||||
|
@ -526,28 +495,28 @@ main(int nrhs, const char *prhs[])
|
||||||
{
|
{
|
||||||
string tmp = "constrained_vars_";
|
string tmp = "constrained_vars_";
|
||||||
tmp.insert(0, "The extended_path description structure does not contain the member: ");
|
tmp.insert(0, "The extended_path description structure does not contain the member: ");
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(tmp.c_str());
|
mexErrMsgTxt(tmp.c_str());
|
||||||
}
|
}
|
||||||
mxArray *constrained_paths_ = mxGetField(extended_path_struct, 0, "constrained_paths_");
|
mxArray *constrained_paths_ = mxGetField(extended_path_struct, 0, "constrained_paths_");
|
||||||
if (constrained_paths_ == NULL)
|
if (constrained_paths_ == NULL)
|
||||||
{
|
{
|
||||||
string tmp = "constrained_paths_";
|
string tmp = "constrained_paths_";
|
||||||
tmp.insert(0, "The extended_path description structure does not contain the member: ");
|
tmp.insert(0, "The extended_path description structure does not contain the member: ");
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(tmp.c_str());
|
mexErrMsgTxt(tmp.c_str());
|
||||||
}
|
}
|
||||||
mxArray *constrained_int_date_ = mxGetField(extended_path_struct, 0, "constrained_int_date_");
|
mxArray *constrained_int_date_ = mxGetField(extended_path_struct, 0, "constrained_int_date_");
|
||||||
if (constrained_int_date_ == NULL)
|
if (constrained_int_date_ == NULL)
|
||||||
{
|
{
|
||||||
string tmp = "constrained_int_date_";
|
string tmp = "constrained_int_date_";
|
||||||
tmp.insert(0, "The extended_path description structure does not contain the member: ");
|
tmp.insert(0, "The extended_path description structure does not contain the member: ");
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(tmp.c_str());
|
mexErrMsgTxt(tmp.c_str());
|
||||||
}
|
}
|
||||||
mxArray *constrained_perfect_foresight_ = mxGetField(extended_path_struct, 0, "constrained_perfect_foresight_");
|
mxArray *constrained_perfect_foresight_ = mxGetField(extended_path_struct, 0, "constrained_perfect_foresight_");
|
||||||
if (constrained_perfect_foresight_ == NULL)
|
if (constrained_perfect_foresight_ == NULL)
|
||||||
{
|
{
|
||||||
string tmp = "constrained_perfect_foresight_";
|
string tmp = "constrained_perfect_foresight_";
|
||||||
tmp.insert(0, "The extended_path description structure does not contain the member: ");
|
tmp.insert(0, "The extended_path description structure does not contain the member: ");
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(tmp.c_str());
|
mexErrMsgTxt(tmp.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
mxArray *shock_var_ = mxGetField(extended_path_struct, 0, "shock_vars_");
|
mxArray *shock_var_ = mxGetField(extended_path_struct, 0, "shock_vars_");
|
||||||
|
@ -555,28 +524,28 @@ main(int nrhs, const char *prhs[])
|
||||||
{
|
{
|
||||||
string tmp = "shock_vars_";
|
string tmp = "shock_vars_";
|
||||||
tmp.insert(0, "The extended_path description structure does not contain the member: ");
|
tmp.insert(0, "The extended_path description structure does not contain the member: ");
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(tmp.c_str());
|
mexErrMsgTxt(tmp.c_str());
|
||||||
}
|
}
|
||||||
mxArray *shock_paths_ = mxGetField(extended_path_struct, 0, "shock_paths_");
|
mxArray *shock_paths_ = mxGetField(extended_path_struct, 0, "shock_paths_");
|
||||||
if (shock_paths_ == NULL)
|
if (shock_paths_ == NULL)
|
||||||
{
|
{
|
||||||
string tmp = "shock_paths_";
|
string tmp = "shock_paths_";
|
||||||
tmp.insert(0, "The extended_path description structure does not contain the member: ");
|
tmp.insert(0, "The extended_path description structure does not contain the member: ");
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(tmp.c_str());
|
mexErrMsgTxt(tmp.c_str());
|
||||||
}
|
}
|
||||||
mxArray *shock_int_date_ = mxGetField(extended_path_struct, 0, "shock_int_date_");
|
mxArray *shock_int_date_ = mxGetField(extended_path_struct, 0, "shock_int_date_");
|
||||||
if (shock_int_date_ == NULL)
|
if (shock_int_date_ == NULL)
|
||||||
{
|
{
|
||||||
string tmp = "shock_int_date_";
|
string tmp = "shock_int_date_";
|
||||||
tmp.insert(0, "The extended_path description structure does not contain the member: ");
|
tmp.insert(0, "The extended_path description structure does not contain the member: ");
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(tmp.c_str());
|
mexErrMsgTxt(tmp.c_str());
|
||||||
}
|
}
|
||||||
mxArray *shock_str_date_ = mxGetField(extended_path_struct, 0, "shock_str_date_");
|
mxArray *shock_str_date_ = mxGetField(extended_path_struct, 0, "shock_str_date_");
|
||||||
if (shock_str_date_ == NULL)
|
if (shock_str_date_ == NULL)
|
||||||
{
|
{
|
||||||
string tmp = "shock_str_date_";
|
string tmp = "shock_str_date_";
|
||||||
tmp.insert(0, "The extended_path description structure does not contain the member: ");
|
tmp.insert(0, "The extended_path description structure does not contain the member: ");
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(tmp.c_str());
|
mexErrMsgTxt(tmp.c_str());
|
||||||
}
|
}
|
||||||
int nb_constrained = mxGetM(constrained_vars_) * mxGetN(constrained_vars_);
|
int nb_constrained = mxGetM(constrained_vars_) * mxGetN(constrained_vars_);
|
||||||
int nb_controlled = 0;
|
int nb_controlled = 0;
|
||||||
|
@ -588,7 +557,7 @@ main(int nrhs, const char *prhs[])
|
||||||
nb_controlled = mxGetM(controlled_varexo) * mxGetN(controlled_varexo);
|
nb_controlled = mxGetM(controlled_varexo) * mxGetN(controlled_varexo);
|
||||||
if (nb_controlled != nb_constrained)
|
if (nb_controlled != nb_constrained)
|
||||||
{
|
{
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("The number of exogenized variables and the number of exogenous controlled variables should be equal.");
|
mexErrMsgTxt("The number of exogenized variables and the number of exogenous controlled variables should be equal.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
double *controlled_varexo_value = NULL;
|
double *controlled_varexo_value = NULL;
|
||||||
|
@ -637,7 +606,7 @@ main(int nrhs, const char *prhs[])
|
||||||
string tmp1 = oss.str();
|
string tmp1 = oss.str();
|
||||||
tmp.append(tmp1);
|
tmp.append(tmp1);
|
||||||
tmp.append(")");
|
tmp.append(")");
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(tmp.c_str());
|
mexErrMsgTxt(tmp.c_str());
|
||||||
}
|
}
|
||||||
(sconditional_extended_path[i]).per_value.resize(nb_local_periods);
|
(sconditional_extended_path[i]).per_value.resize(nb_local_periods);
|
||||||
(sconditional_extended_path[i]).value.resize(nb_periods);
|
(sconditional_extended_path[i]).value.resize(nb_periods);
|
||||||
|
@ -680,7 +649,7 @@ main(int nrhs, const char *prhs[])
|
||||||
string tmp1 = oss.str();
|
string tmp1 = oss.str();
|
||||||
tmp.append(tmp1);
|
tmp.append(tmp1);
|
||||||
tmp.append(")");
|
tmp.append(")");
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(tmp.c_str());
|
mexErrMsgTxt(tmp.c_str());
|
||||||
}
|
}
|
||||||
(sextended_path[i]).per_value.resize(nb_local_periods);
|
(sextended_path[i]).per_value.resize(nb_local_periods);
|
||||||
(sextended_path[i]).value.resize(nb_periods);
|
(sextended_path[i]).value.resize(nb_periods);
|
||||||
|
@ -702,7 +671,7 @@ main(int nrhs, const char *prhs[])
|
||||||
if (info)
|
if (info)
|
||||||
{
|
{
|
||||||
string tmp = "Can not allocated memory to store the date_str in the extended path descriptor";
|
string tmp = "Can not allocated memory to store the date_str in the extended path descriptor";
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(tmp.c_str());
|
mexErrMsgTxt(tmp.c_str());
|
||||||
}
|
}
|
||||||
dates.push_back(string(buf)); //string(Dates[i]);
|
dates.push_back(string(buf)); //string(Dates[i]);
|
||||||
mxFree(buf);
|
mxFree(buf);
|
||||||
|
@ -715,7 +684,7 @@ main(int nrhs, const char *prhs[])
|
||||||
{
|
{
|
||||||
string tmp = plan;
|
string tmp = plan;
|
||||||
tmp.insert(0, "Can't find the plan: ");
|
tmp.insert(0, "Can't find the plan: ");
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(tmp.c_str());
|
mexErrMsgTxt(tmp.c_str());
|
||||||
}
|
}
|
||||||
size_t n_plan = mxGetN(plan_struct);
|
size_t n_plan = mxGetN(plan_struct);
|
||||||
splan.resize(n_plan);
|
splan.resize(n_plan);
|
||||||
|
@ -738,7 +707,7 @@ main(int nrhs, const char *prhs[])
|
||||||
string tmp = name;
|
string tmp = name;
|
||||||
tmp.insert(0, "the variable '");
|
tmp.insert(0, "the variable '");
|
||||||
tmp.append("' defined as var in plan is not an exogenous or a deterministic exogenous\n");
|
tmp.append("' defined as var in plan is not an exogenous or a deterministic exogenous\n");
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(tmp.c_str());
|
mexErrMsgTxt(tmp.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tmp = mxGetField(plan_struct, i, "var");
|
tmp = mxGetField(plan_struct, i, "var");
|
||||||
|
@ -756,7 +725,7 @@ main(int nrhs, const char *prhs[])
|
||||||
string tmp = name;
|
string tmp = name;
|
||||||
tmp.insert(0, "the variable '");
|
tmp.insert(0, "the variable '");
|
||||||
tmp.append("' defined as exo in plan is not an endogenous variable\n");
|
tmp.append("' defined as exo in plan is not an endogenous variable\n");
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(tmp.c_str());
|
mexErrMsgTxt(tmp.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tmp = mxGetField(plan_struct, i, "per_value");
|
tmp = mxGetField(plan_struct, i, "per_value");
|
||||||
|
@ -793,7 +762,7 @@ main(int nrhs, const char *prhs[])
|
||||||
{
|
{
|
||||||
string tmp = pfplan;
|
string tmp = pfplan;
|
||||||
tmp.insert(0, "Can't find the pfplan: ");
|
tmp.insert(0, "Can't find the pfplan: ");
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(tmp.c_str());
|
mexErrMsgTxt(tmp.c_str());
|
||||||
}
|
}
|
||||||
size_t n_plan = mxGetN(pfplan_struct);
|
size_t n_plan = mxGetN(pfplan_struct);
|
||||||
spfplan.resize(n_plan);
|
spfplan.resize(n_plan);
|
||||||
|
@ -816,7 +785,7 @@ main(int nrhs, const char *prhs[])
|
||||||
string tmp = name;
|
string tmp = name;
|
||||||
tmp.insert(0, "the variable '");
|
tmp.insert(0, "the variable '");
|
||||||
tmp.append("' defined as var in pfplan is not an exogenous or a deterministic exogenous\n");
|
tmp.append("' defined as var in pfplan is not an exogenous or a deterministic exogenous\n");
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(tmp.c_str());
|
mexErrMsgTxt(tmp.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tmp = mxGetField(pfplan_struct, i, "exo");
|
tmp = mxGetField(pfplan_struct, i, "exo");
|
||||||
|
@ -834,7 +803,7 @@ main(int nrhs, const char *prhs[])
|
||||||
string tmp = name;
|
string tmp = name;
|
||||||
tmp.insert(0, "the variable '");
|
tmp.insert(0, "the variable '");
|
||||||
tmp.append("' defined as exo in pfplan is not an endogenous variable\n");
|
tmp.append("' defined as exo in pfplan is not an endogenous variable\n");
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(tmp.c_str());
|
mexErrMsgTxt(tmp.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tmp = mxGetField(pfplan_struct, i, "per_value");
|
tmp = mxGetField(pfplan_struct, i, "per_value");
|
||||||
|
@ -866,20 +835,20 @@ main(int nrhs, const char *prhs[])
|
||||||
|
|
||||||
int field_steady_state = mxGetFieldNumber(oo_, "steady_state");
|
int field_steady_state = mxGetFieldNumber(oo_, "steady_state");
|
||||||
if (field_steady_state < 0)
|
if (field_steady_state < 0)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("steady_state is not a field of oo_");
|
mexErrMsgTxt("steady_state is not a field of oo_");
|
||||||
int field_exo_steady_state = mxGetFieldNumber(oo_, "exo_steady_state");
|
int field_exo_steady_state = mxGetFieldNumber(oo_, "exo_steady_state");
|
||||||
if (field_exo_steady_state < 0)
|
if (field_exo_steady_state < 0)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("exo_steady_state is not a field of oo_");
|
mexErrMsgTxt("exo_steady_state is not a field of oo_");
|
||||||
|
|
||||||
if (!steady_state)
|
if (!steady_state)
|
||||||
{
|
{
|
||||||
int field_endo_simul = mxGetFieldNumber(oo_, "endo_simul");
|
int field_endo_simul = mxGetFieldNumber(oo_, "endo_simul");
|
||||||
if (field_endo_simul < 0)
|
if (field_endo_simul < 0)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("endo_simul is not a field of oo_");
|
mexErrMsgTxt("endo_simul is not a field of oo_");
|
||||||
|
|
||||||
int field_exo_simul = mxGetFieldNumber(oo_, "exo_simul");
|
int field_exo_simul = mxGetFieldNumber(oo_, "exo_simul");
|
||||||
if (field_exo_simul < 0)
|
if (field_exo_simul < 0)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("exo_simul is not a field of oo_");
|
mexErrMsgTxt("exo_simul is not a field of oo_");
|
||||||
|
|
||||||
if (!count_array_argument)
|
if (!count_array_argument)
|
||||||
{
|
{
|
||||||
|
@ -897,17 +866,17 @@ main(int nrhs, const char *prhs[])
|
||||||
if (field >= 0)
|
if (field >= 0)
|
||||||
y_kmin = int (floor(*(mxGetPr(mxGetFieldByNumber(M_, 0, field)))));
|
y_kmin = int (floor(*(mxGetPr(mxGetFieldByNumber(M_, 0, field)))));
|
||||||
else
|
else
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("maximum_lag is not a field of M_");
|
mexErrMsgTxt("maximum_lag is not a field of M_");
|
||||||
field = mxGetFieldNumber(M_, "maximum_lead");
|
field = mxGetFieldNumber(M_, "maximum_lead");
|
||||||
if (field >= 0)
|
if (field >= 0)
|
||||||
y_kmax = int (floor(*(mxGetPr(mxGetFieldByNumber(M_, 0, field)))));
|
y_kmax = int (floor(*(mxGetPr(mxGetFieldByNumber(M_, 0, field)))));
|
||||||
else
|
else
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("maximum_lead is not a field of M_");
|
mexErrMsgTxt("maximum_lead is not a field of M_");
|
||||||
field = mxGetFieldNumber(M_, "maximum_endo_lag");
|
field = mxGetFieldNumber(M_, "maximum_endo_lag");
|
||||||
if (field >= 0)
|
if (field >= 0)
|
||||||
y_decal = max(0, y_kmin-int (floor(*(mxGetPr(mxGetFieldByNumber(M_, 0, field))))));
|
y_decal = max(0, y_kmin-int (floor(*(mxGetPr(mxGetFieldByNumber(M_, 0, field))))));
|
||||||
else
|
else
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("maximum_endo_lag is not a field of M_");
|
mexErrMsgTxt("maximum_endo_lag is not a field of M_");
|
||||||
|
|
||||||
if (!count_array_argument)
|
if (!count_array_argument)
|
||||||
{
|
{
|
||||||
|
@ -915,7 +884,7 @@ main(int nrhs, const char *prhs[])
|
||||||
if (field >= 0)
|
if (field >= 0)
|
||||||
periods = int (floor(*(mxGetPr(mxGetFieldByNumber(options_, 0, field)))));
|
periods = int (floor(*(mxGetPr(mxGetFieldByNumber(options_, 0, field)))));
|
||||||
else
|
else
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("options_ is not a field of options_");
|
mexErrMsgTxt("options_ is not a field of options_");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!steady_yd)
|
if (!steady_yd)
|
||||||
|
@ -948,7 +917,7 @@ main(int nrhs, const char *prhs[])
|
||||||
if (field >= 0)
|
if (field >= 0)
|
||||||
verbose = int (*mxGetPr((mxGetFieldByNumber(options_, 0, field))));
|
verbose = int (*mxGetPr((mxGetFieldByNumber(options_, 0, field))));
|
||||||
else
|
else
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("verbosity is not a field of options_");
|
mexErrMsgTxt("verbosity is not a field of options_");
|
||||||
if (verbose)
|
if (verbose)
|
||||||
print_it = true;
|
print_it = true;
|
||||||
if (!steady_state)
|
if (!steady_state)
|
||||||
|
@ -961,34 +930,34 @@ main(int nrhs, const char *prhs[])
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!steady_state)
|
if (!steady_state)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("simul is not a field of options_");
|
mexErrMsgTxt("simul is not a field of options_");
|
||||||
else
|
else
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("steady is not a field of options_");
|
mexErrMsgTxt("steady is not a field of options_");
|
||||||
}
|
}
|
||||||
field = mxGetFieldNumber(temporaryfield, "maxit");
|
field = mxGetFieldNumber(temporaryfield, "maxit");
|
||||||
if (field < 0)
|
if (field < 0)
|
||||||
{
|
{
|
||||||
if (!steady_state)
|
if (!steady_state)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("maxit is not a field of options_.simul");
|
mexErrMsgTxt("maxit is not a field of options_.simul");
|
||||||
else
|
else
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("maxit is not a field of options_.steady");
|
mexErrMsgTxt("maxit is not a field of options_.steady");
|
||||||
}
|
}
|
||||||
int maxit_ = int (floor(*(mxGetPr(mxGetFieldByNumber(temporaryfield, 0, field)))));
|
int maxit_ = int (floor(*(mxGetPr(mxGetFieldByNumber(temporaryfield, 0, field)))));
|
||||||
field = mxGetFieldNumber(options_, "slowc");
|
field = mxGetFieldNumber(options_, "slowc");
|
||||||
if (field < 0)
|
if (field < 0)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("slows is not a field of options_");
|
mexErrMsgTxt("slows is not a field of options_");
|
||||||
double slowc = double (*(mxGetPr(mxGetFieldByNumber(options_, 0, field))));
|
double slowc = double (*(mxGetPr(mxGetFieldByNumber(options_, 0, field))));
|
||||||
field = mxGetFieldNumber(options_, "markowitz");
|
field = mxGetFieldNumber(options_, "markowitz");
|
||||||
if (field < 0)
|
if (field < 0)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("markowitz is not a field of options_");
|
mexErrMsgTxt("markowitz is not a field of options_");
|
||||||
double markowitz_c = double (*(mxGetPr(mxGetFieldByNumber(options_, 0, field))));
|
double markowitz_c = double (*(mxGetPr(mxGetFieldByNumber(options_, 0, field))));
|
||||||
field = mxGetFieldNumber(options_, "minimal_solving_periods");
|
field = mxGetFieldNumber(options_, "minimal_solving_periods");
|
||||||
if (field < 0)
|
if (field < 0)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("minimal_solving_periods is not a field of options_");
|
mexErrMsgTxt("minimal_solving_periods is not a field of options_");
|
||||||
int minimal_solving_periods = int (*(mxGetPr(mxGetFieldByNumber(options_, 0, field))));
|
int minimal_solving_periods = int (*(mxGetPr(mxGetFieldByNumber(options_, 0, field))));
|
||||||
field = mxGetFieldNumber(options_, "stack_solve_algo");
|
field = mxGetFieldNumber(options_, "stack_solve_algo");
|
||||||
if (field < 0)
|
if (field < 0)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("stack_solve_algo is not a field of options_");
|
mexErrMsgTxt("stack_solve_algo is not a field of options_");
|
||||||
int stack_solve_algo = int (*(mxGetPr(mxGetFieldByNumber(options_, 0, field))));
|
int stack_solve_algo = int (*(mxGetPr(mxGetFieldByNumber(options_, 0, field))));
|
||||||
int solve_algo;
|
int solve_algo;
|
||||||
double solve_tolf;
|
double solve_tolf;
|
||||||
|
@ -999,12 +968,12 @@ main(int nrhs, const char *prhs[])
|
||||||
if (field >= 0)
|
if (field >= 0)
|
||||||
solve_algo = int (*(mxGetPr(mxGetFieldByNumber(options_, 0, field))));
|
solve_algo = int (*(mxGetPr(mxGetFieldByNumber(options_, 0, field))));
|
||||||
else
|
else
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("solve_algo is not a field of options_");
|
mexErrMsgTxt("solve_algo is not a field of options_");
|
||||||
field = mxGetFieldNumber(options_, "solve_tolf");
|
field = mxGetFieldNumber(options_, "solve_tolf");
|
||||||
if (field >= 0)
|
if (field >= 0)
|
||||||
solve_tolf = *(mxGetPr(mxGetFieldByNumber(options_, 0, field)));
|
solve_tolf = *(mxGetPr(mxGetFieldByNumber(options_, 0, field)));
|
||||||
else
|
else
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("solve_tolf is not a field of options_");
|
mexErrMsgTxt("solve_tolf is not a field of options_");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1014,19 +983,19 @@ main(int nrhs, const char *prhs[])
|
||||||
if (field >= 0)
|
if (field >= 0)
|
||||||
dynatol = mxGetFieldByNumber(options_, 0, field);
|
dynatol = mxGetFieldByNumber(options_, 0, field);
|
||||||
else
|
else
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("dynatol is not a field of options_");
|
mexErrMsgTxt("dynatol is not a field of options_");
|
||||||
field = mxGetFieldNumber(dynatol, "f");
|
field = mxGetFieldNumber(dynatol, "f");
|
||||||
if (field >= 0)
|
if (field >= 0)
|
||||||
solve_tolf = *mxGetPr((mxGetFieldByNumber(dynatol, 0, field)));
|
solve_tolf = *mxGetPr((mxGetFieldByNumber(dynatol, 0, field)));
|
||||||
else
|
else
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("f is not a field of options_.dynatol");
|
mexErrMsgTxt("f is not a field of options_.dynatol");
|
||||||
}
|
}
|
||||||
field = mxGetFieldNumber(M_, "fname");
|
field = mxGetFieldNumber(M_, "fname");
|
||||||
mxArray *mxa;
|
mxArray *mxa;
|
||||||
if (field >= 0)
|
if (field >= 0)
|
||||||
mxa = mxGetFieldByNumber(M_, 0, field);
|
mxa = mxGetFieldByNumber(M_, 0, field);
|
||||||
else
|
else
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("fname is not a field of M_");
|
mexErrMsgTxt("fname is not a field of M_");
|
||||||
size_t buflen = mxGetM(mxa) * mxGetN(mxa) + 1;
|
size_t buflen = mxGetM(mxa) * mxGetN(mxa) + 1;
|
||||||
char *fname;
|
char *fname;
|
||||||
fname = static_cast<char *>(mxCalloc(buflen+1, sizeof(char)));
|
fname = static_cast<char *>(mxCalloc(buflen+1, sizeof(char)));
|
||||||
|
@ -1044,11 +1013,11 @@ main(int nrhs, const char *prhs[])
|
||||||
}
|
}
|
||||||
catch (GeneralExceptionHandling &feh)
|
catch (GeneralExceptionHandling &feh)
|
||||||
{
|
{
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(feh.GetErrorMsg().c_str());
|
mexErrMsgTxt(feh.GetErrorMsg().c_str());
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (stack_solve_algo == 7 && !steady_state)
|
if (stack_solve_algo == 7 && !steady_state)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("bytecode has not been compiled with CUDA option. Bytecode Can't use options_.stack_solve_algo=7\n");
|
mexErrMsgTxt("bytecode has not been compiled with CUDA option. Bytecode Can't use options_.stack_solve_algo=7\n");
|
||||||
#endif
|
#endif
|
||||||
size_t size_of_direction = col_y*row_y*sizeof(double);
|
size_t size_of_direction = col_y*row_y*sizeof(double);
|
||||||
double *y = static_cast<double *>(mxMalloc(size_of_direction));
|
double *y = static_cast<double *>(mxMalloc(size_of_direction));
|
||||||
|
@ -1085,7 +1054,6 @@ main(int nrhs, const char *prhs[])
|
||||||
mxFree(fname);
|
mxFree(fname);
|
||||||
int nb_blocks = 0;
|
int nb_blocks = 0;
|
||||||
double *pind;
|
double *pind;
|
||||||
bool no_error = true;
|
|
||||||
|
|
||||||
if (extended_path)
|
if (extended_path)
|
||||||
{
|
{
|
||||||
|
@ -1095,7 +1063,7 @@ main(int nrhs, const char *prhs[])
|
||||||
}
|
}
|
||||||
catch (GeneralExceptionHandling &feh)
|
catch (GeneralExceptionHandling &feh)
|
||||||
{
|
{
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(feh.GetErrorMsg().c_str());
|
mexErrMsgTxt(feh.GetErrorMsg().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1106,7 +1074,7 @@ main(int nrhs, const char *prhs[])
|
||||||
}
|
}
|
||||||
catch (GeneralExceptionHandling &feh)
|
catch (GeneralExceptionHandling &feh)
|
||||||
{
|
{
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(feh.GetErrorMsg().c_str());
|
mexErrMsgTxt(feh.GetErrorMsg().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1116,42 +1084,21 @@ main(int nrhs, const char *prhs[])
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
clock_t t1 = clock();
|
clock_t t1 = clock();
|
||||||
if (!steady_state && !evaluate && no_error && print)
|
if (!steady_state && !evaluate && print)
|
||||||
mexPrintf("Simulation Time=%f milliseconds\n", 1000.0*(double (t1)-double (t0))/double (CLOCKS_PER_SEC));
|
mexPrintf("Simulation Time=%f milliseconds\n", 1000.0*(double (t1)-double (t0))/double (CLOCKS_PER_SEC));
|
||||||
#ifndef DEBUG_EX
|
#ifndef DEBUG_EX
|
||||||
bool dont_store_a_structure = false;
|
bool dont_store_a_structure = false;
|
||||||
if (nlhs > 0)
|
if (nlhs > 0)
|
||||||
{
|
{
|
||||||
plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL);
|
if (block >= 0)
|
||||||
pind = mxGetPr(plhs[0]);
|
|
||||||
if (no_error)
|
|
||||||
pind[0] = 0;
|
|
||||||
else
|
|
||||||
pind[0] = 1;
|
|
||||||
if (nlhs > 1)
|
|
||||||
{
|
{
|
||||||
if (block >= 0)
|
if (evaluate)
|
||||||
{
|
{
|
||||||
if (evaluate)
|
vector<double> residual = interprete.get_residual();
|
||||||
{
|
plhs[0] = mxCreateDoubleMatrix(int (residual.size()/double (col_y)), int (col_y), mxREAL);
|
||||||
vector<double> residual = interprete.get_residual();
|
pind = mxGetPr(plhs[0]);
|
||||||
plhs[1] = mxCreateDoubleMatrix(int (residual.size()/double (col_y)), int (col_y), mxREAL);
|
for (i = 0; i < residual.size(); i++)
|
||||||
pind = mxGetPr(plhs[1]);
|
pind[i] = residual[i];
|
||||||
for (i = 0; i < residual.size(); i++)
|
|
||||||
pind[i] = residual[i];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int out_periods;
|
|
||||||
if (extended_path)
|
|
||||||
out_periods = max_periods + y_kmin;
|
|
||||||
else
|
|
||||||
out_periods = row_y;
|
|
||||||
plhs[1] = mxCreateDoubleMatrix(out_periods, int (col_y), mxREAL);
|
|
||||||
pind = mxGetPr(plhs[1]);
|
|
||||||
for (i = 0; i < out_periods*col_y; i++)
|
|
||||||
pind[i] = y[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1159,99 +1106,111 @@ main(int nrhs, const char *prhs[])
|
||||||
if (extended_path)
|
if (extended_path)
|
||||||
out_periods = max_periods + y_kmin;
|
out_periods = max_periods + y_kmin;
|
||||||
else
|
else
|
||||||
out_periods = col_y;
|
out_periods = row_y;
|
||||||
plhs[1] = mxCreateDoubleMatrix(int (row_y), out_periods, mxREAL);
|
plhs[0] = mxCreateDoubleMatrix(out_periods, int (col_y), mxREAL);
|
||||||
pind = mxGetPr(plhs[1]);
|
pind = mxGetPr(plhs[0]);
|
||||||
if (evaluate)
|
for (i = 0; i < out_periods*col_y; i++)
|
||||||
|
pind[i] = y[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int out_periods;
|
||||||
|
if (extended_path)
|
||||||
|
out_periods = max_periods + y_kmin;
|
||||||
|
else
|
||||||
|
out_periods = col_y;
|
||||||
|
plhs[0] = mxCreateDoubleMatrix(int (row_y), out_periods, mxREAL);
|
||||||
|
pind = mxGetPr(plhs[0]);
|
||||||
|
if (evaluate)
|
||||||
|
{
|
||||||
|
vector<double> residual = interprete.get_residual();
|
||||||
|
for (i = 0; i < residual.size(); i++)
|
||||||
|
pind[i] = residual[i];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
for (i = 0; i < row_y*out_periods; i++)
|
||||||
|
pind[i] = y[i];
|
||||||
|
}
|
||||||
|
if (nlhs > 1)
|
||||||
|
{
|
||||||
|
if (evaluate)
|
||||||
|
{
|
||||||
|
int jacob_field_number = 0, jacob_exo_field_number = 0, jacob_exo_det_field_number = 0, jacob_other_endo_field_number = 0;
|
||||||
|
if (!block_structur)
|
||||||
{
|
{
|
||||||
vector<double> residual = interprete.get_residual();
|
const char *field_names[] = {"g1", "g1_x", "g1_xd", "g1_o"};
|
||||||
for (i = 0; i < residual.size(); i++)
|
jacob_field_number = 0;
|
||||||
pind[i] = residual[i];
|
jacob_exo_field_number = 1;
|
||||||
|
jacob_exo_det_field_number = 2;
|
||||||
|
jacob_other_endo_field_number = 3;
|
||||||
|
mwSize dims[1] = {static_cast<mwSize>(nb_blocks) };
|
||||||
|
plhs[1] = mxCreateStructArray(1, dims, 4, field_names);
|
||||||
|
}
|
||||||
|
else if (!mxIsStruct(block_structur))
|
||||||
|
{
|
||||||
|
plhs[1] = interprete.get_jacob(0);
|
||||||
|
//mexCallMATLAB(0,NULL, 1, &plhs[1], "disp");
|
||||||
|
dont_store_a_structure = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
for (i = 0; i < row_y*out_periods; i++)
|
|
||||||
pind[i] = y[i];
|
|
||||||
}
|
|
||||||
if (nlhs > 2)
|
|
||||||
{
|
|
||||||
if (evaluate)
|
|
||||||
{
|
{
|
||||||
int jacob_field_number = 0, jacob_exo_field_number = 0, jacob_exo_det_field_number = 0, jacob_other_endo_field_number = 0;
|
plhs[1] = block_structur;
|
||||||
if (!block_structur)
|
jacob_field_number = mxAddField(plhs[1], "g1");
|
||||||
|
if (jacob_field_number == -1)
|
||||||
|
mexErrMsgTxt("Fatal error in bytecode: in main, cannot add extra field jacob to the structArray\n");
|
||||||
|
jacob_exo_field_number = mxAddField(plhs[1], "g1_x");
|
||||||
|
if (jacob_exo_field_number == -1)
|
||||||
|
mexErrMsgTxt("Fatal error in bytecode: in main, cannot add extra field jacob_exo to the structArray\n");
|
||||||
|
jacob_exo_det_field_number = mxAddField(plhs[1], "g1_xd");
|
||||||
|
if (jacob_exo_det_field_number == -1)
|
||||||
|
mexErrMsgTxt("Fatal error in bytecode: in main, cannot add extra field jacob_exo_det to the structArray\n");
|
||||||
|
jacob_other_endo_field_number = mxAddField(plhs[1], "g1_o");
|
||||||
|
if (jacob_other_endo_field_number == -1)
|
||||||
|
mexErrMsgTxt("Fatal error in bytecode: in main, cannot add extra field jacob_other_endo to the structArray\n");
|
||||||
|
}
|
||||||
|
if (!dont_store_a_structure)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < nb_blocks; i++)
|
||||||
{
|
{
|
||||||
const char *field_names[] = {"g1", "g1_x", "g1_xd", "g1_o"};
|
mxSetFieldByNumber(plhs[1], i, jacob_field_number, interprete.get_jacob(i));
|
||||||
jacob_field_number = 0;
|
if (!steady_state)
|
||||||
jacob_exo_field_number = 1;
|
|
||||||
jacob_exo_det_field_number = 2;
|
|
||||||
jacob_other_endo_field_number = 3;
|
|
||||||
mwSize dims[1] = {static_cast<mwSize>(nb_blocks) };
|
|
||||||
plhs[2] = mxCreateStructArray(1, dims, 4, field_names);
|
|
||||||
}
|
|
||||||
else if (!mxIsStruct(block_structur))
|
|
||||||
{
|
|
||||||
plhs[2] = interprete.get_jacob(0);
|
|
||||||
//mexCallMATLAB(0,NULL, 1, &plhs[2], "disp");
|
|
||||||
dont_store_a_structure = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
plhs[2] = block_structur;
|
|
||||||
jacob_field_number = mxAddField(plhs[2], "g1");
|
|
||||||
if (jacob_field_number == -1)
|
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Fatal error in bytecode: in main, cannot add extra field jacob to the structArray\n");
|
|
||||||
jacob_exo_field_number = mxAddField(plhs[2], "g1_x");
|
|
||||||
if (jacob_exo_field_number == -1)
|
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Fatal error in bytecode: in main, cannot add extra field jacob_exo to the structArray\n");
|
|
||||||
jacob_exo_det_field_number = mxAddField(plhs[2], "g1_xd");
|
|
||||||
if (jacob_exo_det_field_number == -1)
|
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Fatal error in bytecode: in main, cannot add extra field jacob_exo_det to the structArray\n");
|
|
||||||
jacob_other_endo_field_number = mxAddField(plhs[2], "g1_o");
|
|
||||||
if (jacob_other_endo_field_number == -1)
|
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Fatal error in bytecode: in main, cannot add extra field jacob_other_endo to the structArray\n");
|
|
||||||
}
|
|
||||||
if (!dont_store_a_structure)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < nb_blocks; i++)
|
|
||||||
{
|
{
|
||||||
mxSetFieldByNumber(plhs[2], i, jacob_field_number, interprete.get_jacob(i));
|
mxSetFieldByNumber(plhs[1], i, jacob_exo_field_number, interprete.get_jacob_exo(i));
|
||||||
if (!steady_state)
|
mxSetFieldByNumber(plhs[1], i, jacob_exo_det_field_number, interprete.get_jacob_exo_det(i));
|
||||||
{
|
mxSetFieldByNumber(plhs[1], i, jacob_other_endo_field_number, interprete.get_jacob_other_endo(i));
|
||||||
mxSetFieldByNumber(plhs[2], i, jacob_exo_field_number, interprete.get_jacob_exo(i));
|
|
||||||
mxSetFieldByNumber(plhs[2], i, jacob_exo_det_field_number, interprete.get_jacob_exo_det(i));
|
|
||||||
mxSetFieldByNumber(plhs[2], i, jacob_other_endo_field_number, interprete.get_jacob_other_endo(i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
plhs[1] = mxCreateDoubleMatrix(int (row_x), int (col_x), mxREAL);
|
||||||
|
pind = mxGetPr(plhs[1]);
|
||||||
|
for (i = 0; i < row_x*col_x; i++)
|
||||||
{
|
{
|
||||||
plhs[2] = mxCreateDoubleMatrix(int (row_x), int (col_x), mxREAL);
|
pind[i] = x[i];
|
||||||
pind = mxGetPr(plhs[2]);
|
|
||||||
for (i = 0; i < row_x*col_x; i++)
|
|
||||||
{
|
|
||||||
pind[i] = x[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if (nlhs > 3)
|
|
||||||
{
|
|
||||||
plhs[3] = mxCreateDoubleMatrix(int (row_y), int (col_y), mxREAL);
|
|
||||||
pind = mxGetPr(plhs[3]);
|
|
||||||
for (i = 0; i < row_y*col_y; i++)
|
|
||||||
pind[i] = y[i];
|
|
||||||
if (nlhs > 4)
|
|
||||||
{
|
|
||||||
mxArray *GlobalTemporaryTerms = interprete.get_Temporary_Terms();
|
|
||||||
size_t nb_temp_terms = mxGetM(GlobalTemporaryTerms);
|
|
||||||
plhs[4] = mxCreateDoubleMatrix(int (nb_temp_terms), 1, mxREAL);
|
|
||||||
pind = mxGetPr(plhs[4]);
|
|
||||||
double *tt = mxGetPr(GlobalTemporaryTerms);
|
|
||||||
for (i = 0; i < nb_temp_terms; i++)
|
|
||||||
pind[i] = tt[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (nlhs > 2)
|
||||||
|
{
|
||||||
|
plhs[2] = mxCreateDoubleMatrix(int (row_y), int (col_y), mxREAL);
|
||||||
|
pind = mxGetPr(plhs[2]);
|
||||||
|
for (i = 0; i < row_y*col_y; i++)
|
||||||
|
pind[i] = y[i];
|
||||||
|
if (nlhs > 3)
|
||||||
|
{
|
||||||
|
mxArray *GlobalTemporaryTerms = interprete.get_Temporary_Terms();
|
||||||
|
size_t nb_temp_terms = mxGetM(GlobalTemporaryTerms);
|
||||||
|
plhs[3] = mxCreateDoubleMatrix(int (nb_temp_terms), 1, mxREAL);
|
||||||
|
pind = mxGetPr(plhs[3]);
|
||||||
|
double *tt = mxGetPr(GlobalTemporaryTerms);
|
||||||
|
for (i = 0; i < nb_temp_terms; i++)
|
||||||
|
pind[i] = tt[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2007-2017 Dynare Team
|
* Copyright © 2007-2020 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -29,13 +29,6 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#if !defined(DYN_MEX_FUNC_ERR_MSG_TXT)
|
|
||||||
# define DYN_MEX_FUNC_ERR_MSG_TXT(str) \
|
|
||||||
do { \
|
|
||||||
mexPrintf("%s\n", str); \
|
|
||||||
} while (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef unsigned int mwIndex;
|
typedef unsigned int mwIndex;
|
||||||
typedef unsigned int mwSize;
|
typedef unsigned int mwSize;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2005-2011 Ondra Kamenik
|
* Copyright © 2005-2011 Ondra Kamenik
|
||||||
* Copyright © 2019 Dynare Team
|
* Copyright © 2019-2020 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -51,8 +51,8 @@ extern "C" {
|
||||||
mexFunction(int nlhs, mxArray *plhs[],
|
mexFunction(int nlhs, mxArray *plhs[],
|
||||||
int nhrs, const mxArray *prhs[])
|
int nhrs, const mxArray *prhs[])
|
||||||
{
|
{
|
||||||
if (nhrs != 12 || nlhs != 2)
|
if (nhrs != 12 || nlhs != 1)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("dynare_simul_ must have at exactly 12 input parameters and 2 output arguments.\n");
|
mexErrMsgTxt("dynare_simul_ must have at exactly 12 input parameters and 1 output argument.");
|
||||||
|
|
||||||
int order = static_cast<int>(mxGetScalar(prhs[0]));
|
int order = static_cast<int>(mxGetScalar(prhs[0]));
|
||||||
int nstat = static_cast<int>(mxGetScalar(prhs[1]));
|
int nstat = static_cast<int>(mxGetScalar(prhs[1]));
|
||||||
|
@ -74,22 +74,22 @@ extern "C" {
|
||||||
|
|
||||||
int ny = nstat + npred + nboth + nforw;
|
int ny = nstat + npred + nboth + nforw;
|
||||||
if (ny != static_cast<int>(ystart_dim[0]))
|
if (ny != static_cast<int>(ystart_dim[0]))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("ystart has wrong number of rows.\n");
|
mexErrMsgTxt("ystart has wrong number of rows.\n");
|
||||||
if (1 != ystart_dim[1])
|
if (1 != ystart_dim[1])
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("ystart has wrong number of cols.\n");
|
mexErrMsgTxt("ystart has wrong number of cols.\n");
|
||||||
int nper = shocks_dim[1];
|
int nper = shocks_dim[1];
|
||||||
if (nexog != static_cast<int>(shocks_dim[0]))
|
if (nexog != static_cast<int>(shocks_dim[0]))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("shocks has a wrong number of rows.\n");
|
mexErrMsgTxt("shocks has a wrong number of rows.\n");
|
||||||
if (nexog != static_cast<int>(vcov_dim[0]))
|
if (nexog != static_cast<int>(vcov_dim[0]))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("vcov has a wrong number of rows.\n");
|
mexErrMsgTxt("vcov has a wrong number of rows.\n");
|
||||||
if (nexog != static_cast<int>(vcov_dim[1]))
|
if (nexog != static_cast<int>(vcov_dim[1]))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("vcov has a wrong number of cols.\n");
|
mexErrMsgTxt("vcov has a wrong number of cols.\n");
|
||||||
if (ny != static_cast<int>(ysteady_dim[0]))
|
if (ny != static_cast<int>(ysteady_dim[0]))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("ysteady has wrong number of rows.\n");
|
mexErrMsgTxt("ysteady has wrong number of rows.\n");
|
||||||
if (1 != ysteady_dim[1])
|
if (1 != ysteady_dim[1])
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("ysteady has wrong number of cols.\n");
|
mexErrMsgTxt("ysteady has wrong number of cols.\n");
|
||||||
|
|
||||||
plhs[1] = mxCreateDoubleMatrix(ny, nper, mxREAL);
|
plhs[0] = mxCreateDoubleMatrix(ny, nper, mxREAL);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -102,13 +102,13 @@ extern "C" {
|
||||||
{
|
{
|
||||||
const mxArray *gk_m = mxGetField(dr, 0, ("g_" + std::to_string(dim)).c_str());
|
const mxArray *gk_m = mxGetField(dr, 0, ("g_" + std::to_string(dim)).c_str());
|
||||||
if (!gk_m)
|
if (!gk_m)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(("Can't find field `g_" + std::to_string(dim) + "' in structured passed as last argument").c_str());
|
mexErrMsgTxt(("Can't find field `g_" + std::to_string(dim) + "' in structured passed as last argument").c_str());
|
||||||
ConstTwoDMatrix gk(gk_m);
|
ConstTwoDMatrix gk(gk_m);
|
||||||
FFSTensor ft(ny, npred+nboth+nexog, dim);
|
FFSTensor ft(ny, npred+nboth+nexog, dim);
|
||||||
if (ft.ncols() != gk.ncols())
|
if (ft.ncols() != gk.ncols())
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(("Wrong number of columns for folded tensor: got " + std::to_string(gk.ncols()) + " but i want " + std::to_string(ft.ncols()) + '\n').c_str());
|
mexErrMsgTxt(("Wrong number of columns for folded tensor: got " + std::to_string(gk.ncols()) + " but i want " + std::to_string(ft.ncols()) + '\n').c_str());
|
||||||
if (ft.nrows() != gk.nrows())
|
if (ft.nrows() != gk.nrows())
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(("Wrong number of rows for folded tensor: got " + std::to_string(gk.nrows()) + " but i want " + std::to_string(ft.nrows()) + '\n').c_str());
|
mexErrMsgTxt(("Wrong number of rows for folded tensor: got " + std::to_string(gk.nrows()) + " but i want " + std::to_string(ft.nrows()) + '\n').c_str());
|
||||||
ft.zeros();
|
ft.zeros();
|
||||||
ft.add(1.0, gk);
|
ft.add(1.0, gk);
|
||||||
pol.insert(std::make_unique<UFSTensor>(ft));
|
pol.insert(std::make_unique<UFSTensor>(ft));
|
||||||
|
@ -123,21 +123,20 @@ extern "C" {
|
||||||
// simulate and copy the results
|
// simulate and copy the results
|
||||||
TwoDMatrix res_mat{dr.simulate(DecisionRule::emethod::horner, nper,
|
TwoDMatrix res_mat{dr.simulate(DecisionRule::emethod::horner, nper,
|
||||||
ConstVector{ystart}, sr)};
|
ConstVector{ystart}, sr)};
|
||||||
TwoDMatrix res_tmp_mat{plhs[1]};
|
TwoDMatrix res_tmp_mat{plhs[0]};
|
||||||
res_tmp_mat = const_cast<const TwoDMatrix &>(res_mat);
|
res_tmp_mat = const_cast<const TwoDMatrix &>(res_mat);
|
||||||
}
|
}
|
||||||
catch (const KordException &e)
|
catch (const KordException &e)
|
||||||
{
|
{
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Caught Kord exception.");
|
mexErrMsgTxt("Caught Kord exception.");
|
||||||
}
|
}
|
||||||
catch (const TLException &e)
|
catch (const TLException &e)
|
||||||
{
|
{
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Caught TL exception.");
|
mexErrMsgTxt("Caught TL exception.");
|
||||||
}
|
}
|
||||||
catch (SylvException &e)
|
catch (SylvException &e)
|
||||||
{
|
{
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Caught Sylv exception.");
|
mexErrMsgTxt("Caught Sylv exception.");
|
||||||
}
|
}
|
||||||
plhs[0] = mxCreateDoubleScalar(0);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2009-2019 Dynare Team
|
* Copyright © 2009-2020 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -26,20 +26,6 @@
|
||||||
|
|
||||||
#include <mex.h>
|
#include <mex.h>
|
||||||
|
|
||||||
/*
|
|
||||||
* Fix for trac ticket Ticket #137
|
|
||||||
*/
|
|
||||||
#if !defined(DYN_MEX_FUNC_ERR_MSG_TXT)
|
|
||||||
# define DYN_MEX_FUNC_ERR_MSG_TXT(str) \
|
|
||||||
do { \
|
|
||||||
mexPrintf("%s\n", str); \
|
|
||||||
int i; \
|
|
||||||
for (i = 0; i < nlhs; i++) \
|
|
||||||
plhs[i] = mxCreateDoubleScalar(1); \
|
|
||||||
return; \
|
|
||||||
} while (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MATLAB_MEX_FILE) && MATLAB_VERSION < 0x0805
|
#if defined(MATLAB_MEX_FILE) && MATLAB_VERSION < 0x0805
|
||||||
# define mxIsScalar(x) (mxGetM(x) == 1 && mxGetN(x) == 1)
|
# define mxIsScalar(x) (mxGetM(x) == 1 && mxGetN(x) == 1)
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2005-2011 Ondra Kamenik
|
* Copyright © 2005-2011 Ondra Kamenik
|
||||||
* Copyright © 2019 Dynare Team
|
* Copyright © 2019-2020 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -51,8 +51,8 @@ extern "C" {
|
||||||
mexFunction(int nlhs, mxArray *plhs[],
|
mexFunction(int nlhs, mxArray *plhs[],
|
||||||
int nhrs, const mxArray *prhs[])
|
int nhrs, const mxArray *prhs[])
|
||||||
{
|
{
|
||||||
if (nhrs != 5 || nlhs > 3 || nlhs < 2)
|
if (nhrs != 5 || nlhs > 2 || nlhs < 1)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Gensylv: Must have exactly 5 input args and either 2 or 3 output args.");
|
mexErrMsgTxt("Gensylv: Must have exactly 5 input args and either 1 or 2 output args.");
|
||||||
|
|
||||||
auto order = static_cast<int>(mxGetScalar(prhs[0]));
|
auto order = static_cast<int>(mxGetScalar(prhs[0]));
|
||||||
const mxArray *const A = prhs[1];
|
const mxArray *const A = prhs[1];
|
||||||
|
@ -65,17 +65,17 @@ extern "C" {
|
||||||
const mwSize *const Ddims = mxGetDimensions(D);
|
const mwSize *const Ddims = mxGetDimensions(D);
|
||||||
|
|
||||||
if (Adims[0] != Adims[1])
|
if (Adims[0] != Adims[1])
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Matrix A must be a square matrix.");
|
mexErrMsgTxt("Matrix A must be a square matrix.");
|
||||||
if (Adims[0] != Bdims[0])
|
if (Adims[0] != Bdims[0])
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Matrix A and matrix B must have the same number of rows.");
|
mexErrMsgTxt("Matrix A and matrix B must have the same number of rows.");
|
||||||
if (Adims[0] != Ddims[0])
|
if (Adims[0] != Ddims[0])
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Matrix A and matrix B must have the same number of rows.");
|
mexErrMsgTxt("Matrix A and matrix B must have the same number of rows.");
|
||||||
if (Cdims[0] != Cdims[1])
|
if (Cdims[0] != Cdims[1])
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Matrix C must be square.");
|
mexErrMsgTxt("Matrix C must be square.");
|
||||||
if (Bdims[0] < Bdims[1])
|
if (Bdims[0] < Bdims[1])
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Matrix B must not have more columns than rows.");
|
mexErrMsgTxt("Matrix B must not have more columns than rows.");
|
||||||
if (Ddims[1] != static_cast<mwSize>(power(Cdims[0], order)))
|
if (Ddims[1] != static_cast<mwSize>(power(Cdims[0], order)))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Matrix D has wrong number of columns.");
|
mexErrMsgTxt("Matrix D has wrong number of columns.");
|
||||||
|
|
||||||
auto n = static_cast<int>(Adims[0]);
|
auto n = static_cast<int>(Adims[0]);
|
||||||
auto m = static_cast<int>(Cdims[0]);
|
auto m = static_cast<int>(Cdims[0]);
|
||||||
|
@ -88,16 +88,15 @@ extern "C" {
|
||||||
// solve (or solve and check)
|
// solve (or solve and check)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (nlhs == 2)
|
if (nlhs == 1)
|
||||||
gen_sylv_solve(order, n, m, zero_cols, Avec, Bvec, Cvec, Xvec);
|
gen_sylv_solve(order, n, m, zero_cols, Avec, Bvec, Cvec, Xvec);
|
||||||
else if (nlhs == 3)
|
else if (nlhs == 2)
|
||||||
plhs[2] = gen_sylv_solve_and_check(order, n, m, zero_cols, Avec, Bvec, Cvec, Dvec, Xvec);
|
plhs[1] = gen_sylv_solve_and_check(order, n, m, zero_cols, Avec, Bvec, Cvec, Dvec, Xvec);
|
||||||
}
|
}
|
||||||
catch (const SylvException &e)
|
catch (const SylvException &e)
|
||||||
{
|
{
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(e.getMessage().c_str());
|
mexErrMsgTxt(e.getMessage().c_str());
|
||||||
}
|
}
|
||||||
plhs[1] = X;
|
plhs[0] = X;
|
||||||
plhs[0] = mxCreateDoubleScalar(0);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2008-2019 Dynare Team
|
* Copyright © 2008-2020 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -82,8 +82,8 @@ extern "C" {
|
||||||
mexFunction(int nlhs, mxArray *plhs[],
|
mexFunction(int nlhs, mxArray *plhs[],
|
||||||
int nrhs, const mxArray *prhs[])
|
int nrhs, const mxArray *prhs[])
|
||||||
{
|
{
|
||||||
if (nrhs < 3 || nlhs < 2 || nlhs > 3)
|
if (nrhs < 3 || nlhs < 1 || nlhs > 2)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Must have at least 3 input parameters and takes 2 or 3 output parameters.");
|
mexErrMsgTxt("Must have at least 3 input parameters and takes 1 or 2 output parameters.");
|
||||||
|
|
||||||
// Give explicit names to input arguments
|
// Give explicit names to input arguments
|
||||||
const mxArray *dr_mx = prhs[0];
|
const mxArray *dr_mx = prhs[0];
|
||||||
|
@ -101,11 +101,11 @@ extern "C" {
|
||||||
// Extract various fields from options_
|
// Extract various fields from options_
|
||||||
const int kOrder = get_int_field(options_mx, "order");
|
const int kOrder = get_int_field(options_mx, "order");
|
||||||
if (kOrder < 1)
|
if (kOrder < 1)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("options_.order must be at least 1");
|
mexErrMsgTxt("options_.order must be at least 1");
|
||||||
|
|
||||||
const mxArray *use_dll_mx = mxGetField(options_mx, 0, "use_dll");
|
const mxArray *use_dll_mx = mxGetField(options_mx, 0, "use_dll");
|
||||||
if (!(use_dll_mx && mxIsLogicalScalar(use_dll_mx)))
|
if (!(use_dll_mx && mxIsLogicalScalar(use_dll_mx)))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("options_.use_dll should be a logical scalar");
|
mexErrMsgTxt("options_.use_dll should be a logical scalar");
|
||||||
bool use_dll = static_cast<bool>(mxGetScalar(use_dll_mx));
|
bool use_dll = static_cast<bool>(mxGetScalar(use_dll_mx));
|
||||||
|
|
||||||
double qz_criterium = 1+1e-6;
|
double qz_criterium = 1+1e-6;
|
||||||
|
@ -115,31 +115,31 @@ extern "C" {
|
||||||
|
|
||||||
const mxArray *threads_mx = mxGetField(options_mx, 0, "threads");
|
const mxArray *threads_mx = mxGetField(options_mx, 0, "threads");
|
||||||
if (!threads_mx)
|
if (!threads_mx)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Can't find field options_.threads");
|
mexErrMsgTxt("Can't find field options_.threads");
|
||||||
const mxArray *num_threads_mx = mxGetField(threads_mx, 0, "k_order_perturbation");
|
const mxArray *num_threads_mx = mxGetField(threads_mx, 0, "k_order_perturbation");
|
||||||
if (!(num_threads_mx && mxIsScalar(num_threads_mx) && mxIsNumeric(num_threads_mx)))
|
if (!(num_threads_mx && mxIsScalar(num_threads_mx) && mxIsNumeric(num_threads_mx)))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("options_.threads.k_order_perturbation be a numeric scalar");
|
mexErrMsgTxt("options_.threads.k_order_perturbation be a numeric scalar");
|
||||||
int num_threads = static_cast<int>(mxGetScalar(num_threads_mx));
|
int num_threads = static_cast<int>(mxGetScalar(num_threads_mx));
|
||||||
|
|
||||||
// Extract various fields from M_
|
// Extract various fields from M_
|
||||||
const mxArray *fname_mx = mxGetField(M_mx, 0, "fname");
|
const mxArray *fname_mx = mxGetField(M_mx, 0, "fname");
|
||||||
if (!(fname_mx && mxIsChar(fname_mx) && mxGetM(fname_mx) == 1))
|
if (!(fname_mx && mxIsChar(fname_mx) && mxGetM(fname_mx) == 1))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("M_.fname should be a character string");
|
mexErrMsgTxt("M_.fname should be a character string");
|
||||||
std::string fname{mxArrayToString(fname_mx)};
|
std::string fname{mxArrayToString(fname_mx)};
|
||||||
|
|
||||||
const mxArray *params_mx = mxGetField(M_mx, 0, "params");
|
const mxArray *params_mx = mxGetField(M_mx, 0, "params");
|
||||||
if (!(params_mx && mxIsDouble(params_mx)))
|
if (!(params_mx && mxIsDouble(params_mx)))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("M_.params should be a double precision array");
|
mexErrMsgTxt("M_.params should be a double precision array");
|
||||||
Vector modParams{ConstVector{params_mx}};
|
Vector modParams{ConstVector{params_mx}};
|
||||||
if (!modParams.isFinite())
|
if (!modParams.isFinite())
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("M_.params contains NaN or Inf");
|
mexErrMsgTxt("M_.params contains NaN or Inf");
|
||||||
|
|
||||||
const mxArray *sigma_e_mx = mxGetField(M_mx, 0, "Sigma_e");
|
const mxArray *sigma_e_mx = mxGetField(M_mx, 0, "Sigma_e");
|
||||||
if (!(sigma_e_mx && mxIsDouble(sigma_e_mx) && mxGetM(sigma_e_mx) == mxGetN(sigma_e_mx)))
|
if (!(sigma_e_mx && mxIsDouble(sigma_e_mx) && mxGetM(sigma_e_mx) == mxGetN(sigma_e_mx)))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("M_.Sigma_e should be a double precision square matrix");
|
mexErrMsgTxt("M_.Sigma_e should be a double precision square matrix");
|
||||||
TwoDMatrix vCov{ConstTwoDMatrix{sigma_e_mx}};
|
TwoDMatrix vCov{ConstTwoDMatrix{sigma_e_mx}};
|
||||||
if (!vCov.isFinite())
|
if (!vCov.isFinite())
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("M_.Sigma_e contains NaN or Inf");
|
mexErrMsgTxt("M_.Sigma_e contains NaN or Inf");
|
||||||
|
|
||||||
const int nStat = get_int_field(M_mx, "nstatic");
|
const int nStat = get_int_field(M_mx, "nstatic");
|
||||||
const int nPred = get_int_field(M_mx, "npred");
|
const int nPred = get_int_field(M_mx, "npred");
|
||||||
|
@ -153,42 +153,42 @@ extern "C" {
|
||||||
const mxArray *lead_lag_incidence_mx = mxGetField(M_mx, 0, "lead_lag_incidence");
|
const mxArray *lead_lag_incidence_mx = mxGetField(M_mx, 0, "lead_lag_incidence");
|
||||||
if (!(lead_lag_incidence_mx && mxIsDouble(lead_lag_incidence_mx) && mxGetM(lead_lag_incidence_mx) == 3
|
if (!(lead_lag_incidence_mx && mxIsDouble(lead_lag_incidence_mx) && mxGetM(lead_lag_incidence_mx) == 3
|
||||||
&& mxGetN(lead_lag_incidence_mx) == static_cast<size_t>(nEndo)))
|
&& mxGetN(lead_lag_incidence_mx) == static_cast<size_t>(nEndo)))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("M_.lead_lag_incidence should be a double precision matrix with 3 rows and M_.endo_nbr columns");
|
mexErrMsgTxt("M_.lead_lag_incidence should be a double precision matrix with 3 rows and M_.endo_nbr columns");
|
||||||
ConstTwoDMatrix llincidence{lead_lag_incidence_mx};
|
ConstTwoDMatrix llincidence{lead_lag_incidence_mx};
|
||||||
|
|
||||||
const mxArray *nnzderivatives_mx = mxGetField(M_mx, 0, "NNZDerivatives");
|
const mxArray *nnzderivatives_mx = mxGetField(M_mx, 0, "NNZDerivatives");
|
||||||
if (!(nnzderivatives_mx && mxIsDouble(nnzderivatives_mx)))
|
if (!(nnzderivatives_mx && mxIsDouble(nnzderivatives_mx)))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("M_.NNZDerivatives should be a double precision array");
|
mexErrMsgTxt("M_.NNZDerivatives should be a double precision array");
|
||||||
ConstVector NNZD{nnzderivatives_mx};
|
ConstVector NNZD{nnzderivatives_mx};
|
||||||
if (NNZD.length() < kOrder || NNZD[kOrder-1] == -1)
|
if (NNZD.length() < kOrder || NNZD[kOrder-1] == -1)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("The derivatives were not computed for the required order. Make sure that you used the right order option inside the `stoch_simul' command");
|
mexErrMsgTxt("The derivatives were not computed for the required order. Make sure that you used the right order option inside the `stoch_simul' command");
|
||||||
|
|
||||||
const mxArray *endo_names_mx = mxGetField(M_mx, 0, "endo_names");
|
const mxArray *endo_names_mx = mxGetField(M_mx, 0, "endo_names");
|
||||||
if (!(endo_names_mx && mxIsCell(endo_names_mx) && mxGetNumberOfElements(endo_names_mx) == static_cast<size_t>(nEndo)))
|
if (!(endo_names_mx && mxIsCell(endo_names_mx) && mxGetNumberOfElements(endo_names_mx) == static_cast<size_t>(nEndo)))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("M_.endo_names should be a cell array of M_.endo_nbr elements");
|
mexErrMsgTxt("M_.endo_names should be a cell array of M_.endo_nbr elements");
|
||||||
std::vector<std::string> endoNames = DynareMxArrayToString(endo_names_mx);
|
std::vector<std::string> endoNames = DynareMxArrayToString(endo_names_mx);
|
||||||
|
|
||||||
const mxArray *exo_names_mx = mxGetField(M_mx, 0, "exo_names");
|
const mxArray *exo_names_mx = mxGetField(M_mx, 0, "exo_names");
|
||||||
if (!(exo_names_mx && mxIsCell(exo_names_mx) && mxGetNumberOfElements(exo_names_mx) == static_cast<size_t>(nExog)))
|
if (!(exo_names_mx && mxIsCell(exo_names_mx) && mxGetNumberOfElements(exo_names_mx) == static_cast<size_t>(nExog)))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("M_.exo_names should be a cell array of M_.exo_nbr elements");
|
mexErrMsgTxt("M_.exo_names should be a cell array of M_.exo_nbr elements");
|
||||||
std::vector<std::string> exoNames = DynareMxArrayToString(exo_names_mx);
|
std::vector<std::string> exoNames = DynareMxArrayToString(exo_names_mx);
|
||||||
|
|
||||||
const mxArray *dynamic_tmp_nbr_mx = mxGetField(M_mx, 0, "dynamic_tmp_nbr");
|
const mxArray *dynamic_tmp_nbr_mx = mxGetField(M_mx, 0, "dynamic_tmp_nbr");
|
||||||
if (!(dynamic_tmp_nbr_mx && mxIsDouble(dynamic_tmp_nbr_mx) && mxGetNumberOfElements(dynamic_tmp_nbr_mx) >= static_cast<size_t>(kOrder+1)))
|
if (!(dynamic_tmp_nbr_mx && mxIsDouble(dynamic_tmp_nbr_mx) && mxGetNumberOfElements(dynamic_tmp_nbr_mx) >= static_cast<size_t>(kOrder+1)))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("M_.dynamic_tmp_nbr should be a double precision array with strictly more elements than the order of derivation");
|
mexErrMsgTxt("M_.dynamic_tmp_nbr should be a double precision array with strictly more elements than the order of derivation");
|
||||||
int ntt = std::accumulate(mxGetPr(dynamic_tmp_nbr_mx), mxGetPr(dynamic_tmp_nbr_mx)+kOrder+1, 0);
|
int ntt = std::accumulate(mxGetPr(dynamic_tmp_nbr_mx), mxGetPr(dynamic_tmp_nbr_mx)+kOrder+1, 0);
|
||||||
|
|
||||||
// Extract various fields from dr
|
// Extract various fields from dr
|
||||||
const mxArray *ys_mx = mxGetField(dr_mx, 0, "ys"); // and not in order of dr.order_var
|
const mxArray *ys_mx = mxGetField(dr_mx, 0, "ys"); // and not in order of dr.order_var
|
||||||
if (!(ys_mx && mxIsDouble(ys_mx)))
|
if (!(ys_mx && mxIsDouble(ys_mx)))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("dr.ys should be a double precision array");
|
mexErrMsgTxt("dr.ys should be a double precision array");
|
||||||
Vector ySteady{ConstVector{ys_mx}};
|
Vector ySteady{ConstVector{ys_mx}};
|
||||||
if (!ySteady.isFinite())
|
if (!ySteady.isFinite())
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("dr.ys contains NaN or Inf");
|
mexErrMsgTxt("dr.ys contains NaN or Inf");
|
||||||
|
|
||||||
const mxArray *order_var_mx = mxGetField(dr_mx, 0, "order_var");
|
const mxArray *order_var_mx = mxGetField(dr_mx, 0, "order_var");
|
||||||
if (!(order_var_mx && mxIsDouble(order_var_mx) && mxGetNumberOfElements(order_var_mx) == static_cast<size_t>(nEndo)))
|
if (!(order_var_mx && mxIsDouble(order_var_mx) && mxGetNumberOfElements(order_var_mx) == static_cast<size_t>(nEndo)))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("dr.order_var should be a double precision array of M_.endo_nbr elements");
|
mexErrMsgTxt("dr.order_var should be a double precision array of M_.endo_nbr elements");
|
||||||
std::vector<int> dr_order(nEndo);
|
std::vector<int> dr_order(nEndo);
|
||||||
std::transform(mxGetPr(order_var_mx), mxGetPr(order_var_mx)+nEndo, dr_order.begin(),
|
std::transform(mxGetPr(order_var_mx), mxGetPr(order_var_mx)+nEndo, dr_order.begin(),
|
||||||
[](double x) { return static_cast<int>(x)-1; });
|
[](double x) { return static_cast<int>(x)-1; });
|
||||||
|
@ -241,7 +241,7 @@ extern "C" {
|
||||||
const char *g_fieldnames_c[kOrder+1];
|
const char *g_fieldnames_c[kOrder+1];
|
||||||
for (int i = 0; i <= kOrder; i++)
|
for (int i = 0; i <= kOrder; i++)
|
||||||
g_fieldnames_c[i] = g_fieldnames[i].c_str();
|
g_fieldnames_c[i] = g_fieldnames[i].c_str();
|
||||||
plhs[1] = mxCreateStructMatrix(1, 1, kOrder+1, g_fieldnames_c);
|
plhs[0] = mxCreateStructMatrix(1, 1, kOrder+1, g_fieldnames_c);
|
||||||
|
|
||||||
// Fill that structure
|
// Fill that structure
|
||||||
for (int i = 0; i <= kOrder; i++)
|
for (int i = 0; i <= kOrder; i++)
|
||||||
|
@ -251,10 +251,10 @@ extern "C" {
|
||||||
const ConstVector &vec = t.getData();
|
const ConstVector &vec = t.getData();
|
||||||
assert(vec.skip() == 1);
|
assert(vec.skip() == 1);
|
||||||
std::copy_n(vec.base(), vec.length(), mxGetPr(tmp));
|
std::copy_n(vec.base(), vec.length(), mxGetPr(tmp));
|
||||||
mxSetField(plhs[1], 0, ("g_" + std::to_string(i)).c_str(), tmp);
|
mxSetField(plhs[0], 0, ("g_" + std::to_string(i)).c_str(), tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nlhs > 2)
|
if (nlhs > 1)
|
||||||
{
|
{
|
||||||
/* Return as 3rd argument a struct containing derivatives in Dynare
|
/* Return as 3rd argument a struct containing derivatives in Dynare
|
||||||
format (unfolded matrices, without Taylor coefficient) up to 3rd
|
format (unfolded matrices, without Taylor coefficient) up to 3rd
|
||||||
|
@ -264,51 +264,50 @@ extern "C" {
|
||||||
size_t nfields = (kOrder == 1 ? 2 : (kOrder == 2 ? 6 : 12));
|
size_t nfields = (kOrder == 1 ? 2 : (kOrder == 2 ? 6 : 12));
|
||||||
const char *c_fieldnames[] = { "gy", "gu", "gyy", "gyu", "guu", "gss",
|
const char *c_fieldnames[] = { "gy", "gu", "gyy", "gyu", "guu", "gss",
|
||||||
"gyyy", "gyyu", "gyuu", "guuu", "gyss", "guss" };
|
"gyyy", "gyyu", "gyuu", "guuu", "gyss", "guss" };
|
||||||
plhs[2] = mxCreateStructMatrix(1, 1, nfields, c_fieldnames);
|
plhs[1] = mxCreateStructMatrix(1, 1, nfields, c_fieldnames);
|
||||||
|
|
||||||
copy_derivatives(plhs[2], Symmetry{1, 0, 0, 0}, derivs, "gy");
|
copy_derivatives(plhs[1], Symmetry{1, 0, 0, 0}, derivs, "gy");
|
||||||
copy_derivatives(plhs[2], Symmetry{0, 1, 0, 0}, derivs, "gu");
|
copy_derivatives(plhs[1], Symmetry{0, 1, 0, 0}, derivs, "gu");
|
||||||
if (kOrder >= 2)
|
if (kOrder >= 2)
|
||||||
{
|
{
|
||||||
copy_derivatives(plhs[2], Symmetry{2, 0, 0, 0}, derivs, "gyy");
|
copy_derivatives(plhs[1], Symmetry{2, 0, 0, 0}, derivs, "gyy");
|
||||||
copy_derivatives(plhs[2], Symmetry{0, 2, 0, 0}, derivs, "guu");
|
copy_derivatives(plhs[1], Symmetry{0, 2, 0, 0}, derivs, "guu");
|
||||||
copy_derivatives(plhs[2], Symmetry{1, 1, 0, 0}, derivs, "gyu");
|
copy_derivatives(plhs[1], Symmetry{1, 1, 0, 0}, derivs, "gyu");
|
||||||
copy_derivatives(plhs[2], Symmetry{0, 0, 0, 2}, derivs, "gss");
|
copy_derivatives(plhs[1], Symmetry{0, 0, 0, 2}, derivs, "gss");
|
||||||
}
|
}
|
||||||
if (kOrder >= 3)
|
if (kOrder >= 3)
|
||||||
{
|
{
|
||||||
copy_derivatives(plhs[2], Symmetry{3, 0, 0, 0}, derivs, "gyyy");
|
copy_derivatives(plhs[1], Symmetry{3, 0, 0, 0}, derivs, "gyyy");
|
||||||
copy_derivatives(plhs[2], Symmetry{0, 3, 0, 0}, derivs, "guuu");
|
copy_derivatives(plhs[1], Symmetry{0, 3, 0, 0}, derivs, "guuu");
|
||||||
copy_derivatives(plhs[2], Symmetry{2, 1, 0, 0}, derivs, "gyyu");
|
copy_derivatives(plhs[1], Symmetry{2, 1, 0, 0}, derivs, "gyyu");
|
||||||
copy_derivatives(plhs[2], Symmetry{1, 2, 0, 0}, derivs, "gyuu");
|
copy_derivatives(plhs[1], Symmetry{1, 2, 0, 0}, derivs, "gyuu");
|
||||||
copy_derivatives(plhs[2], Symmetry{1, 0, 0, 2}, derivs, "gyss");
|
copy_derivatives(plhs[1], Symmetry{1, 0, 0, 2}, derivs, "gyss");
|
||||||
copy_derivatives(plhs[2], Symmetry{0, 1, 0, 2}, derivs, "guss");
|
copy_derivatives(plhs[1], Symmetry{0, 1, 0, 2}, derivs, "guss");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const KordException &e)
|
catch (const KordException &e)
|
||||||
{
|
{
|
||||||
e.print();
|
e.print();
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(("dynare:k_order_perturbation: Caught Kord exception: " + e.get_message()).c_str());
|
mexErrMsgTxt(("dynare:k_order_perturbation: Caught Kord exception: " + e.get_message()).c_str());
|
||||||
}
|
}
|
||||||
catch (const TLException &e)
|
catch (const TLException &e)
|
||||||
{
|
{
|
||||||
e.print();
|
e.print();
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("dynare:k_order_perturbation: Caught TL exception");
|
mexErrMsgTxt("dynare:k_order_perturbation: Caught TL exception");
|
||||||
}
|
}
|
||||||
catch (SylvException &e)
|
catch (SylvException &e)
|
||||||
{
|
{
|
||||||
e.printMessage();
|
e.printMessage();
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("dynare:k_order_perturbation: Caught Sylv exception");
|
mexErrMsgTxt("dynare:k_order_perturbation: Caught Sylv exception");
|
||||||
}
|
}
|
||||||
catch (const DynareException &e)
|
catch (const DynareException &e)
|
||||||
{
|
{
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(("dynare:k_order_perturbation: Caught KordDynare exception: " + e.message()).c_str());
|
mexErrMsgTxt(("dynare:k_order_perturbation: Caught KordDynare exception: " + e.message()).c_str());
|
||||||
}
|
}
|
||||||
catch (const ogu::Exception &e)
|
catch (const ogu::Exception &e)
|
||||||
{
|
{
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(("dynare:k_order_perturbation: Caught general exception: " + e.message()).c_str());
|
mexErrMsgTxt(("dynare:k_order_perturbation: Caught general exception: " + e.message()).c_str());
|
||||||
}
|
}
|
||||||
plhs[0] = mxCreateDoubleScalar(0);
|
|
||||||
} // end of mexFunction()
|
} // end of mexFunction()
|
||||||
} // end of extern C
|
} // end of extern C
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2009-2019 Dynare Team.
|
* Copyright © 2009-2020 Dynare Team.
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -76,10 +76,10 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
||||||
// Check the number of arguments and set some flags.
|
// Check the number of arguments and set some flags.
|
||||||
bool measurement_error_flag = true;
|
bool measurement_error_flag = true;
|
||||||
if (nrhs < 3 || 4 < nrhs)
|
if (nrhs < 3 || 4 < nrhs)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("kalman_steady_state accepts either 3 or 4 input arguments!");
|
mexErrMsgTxt("kalman_steady_state accepts either 3 or 4 input arguments!");
|
||||||
|
|
||||||
if (nlhs < 1 || 2 < nlhs)
|
if (nlhs != 1)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("kalman_steady_state requires at least 1, but no more than 2, output arguments!");
|
mexErrMsgTxt("kalman_steady_state accepts exactly one output argument!");
|
||||||
|
|
||||||
if (nrhs == 3)
|
if (nrhs == 3)
|
||||||
measurement_error_flag = false;
|
measurement_error_flag = false;
|
||||||
|
@ -87,30 +87,30 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
||||||
// Check the type of the input arguments and get the size of the matrices.
|
// Check the type of the input arguments and get the size of the matrices.
|
||||||
lapack_int n = mxGetM(prhs[0]);
|
lapack_int n = mxGetM(prhs[0]);
|
||||||
if (static_cast<size_t>(n) != mxGetN(prhs[0]))
|
if (static_cast<size_t>(n) != mxGetN(prhs[0]))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("kalman_steady_state: The first input argument (T) must be a square matrix!");
|
mexErrMsgTxt("kalman_steady_state: The first input argument (T) must be a square matrix!");
|
||||||
if (mxIsNumeric(prhs[0]) == 0 || mxIsComplex(prhs[0]) == 1)
|
if (mxIsNumeric(prhs[0]) == 0 || mxIsComplex(prhs[0]) == 1)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("kalman_steady_state: The first input argument (T) must be a real matrix!");
|
mexErrMsgTxt("kalman_steady_state: The first input argument (T) must be a real matrix!");
|
||||||
|
|
||||||
lapack_int q = mxGetM(prhs[1]);
|
lapack_int q = mxGetM(prhs[1]);
|
||||||
if (static_cast<size_t>(q) != mxGetN(prhs[1]))
|
if (static_cast<size_t>(q) != mxGetN(prhs[1]))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("kalman_steady_state: The second input argument (QQ) must be a square matrix!");
|
mexErrMsgTxt("kalman_steady_state: The second input argument (QQ) must be a square matrix!");
|
||||||
if (mxIsNumeric(prhs[1]) == 0 || mxIsComplex(prhs[1]) == 1)
|
if (mxIsNumeric(prhs[1]) == 0 || mxIsComplex(prhs[1]) == 1)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("kalman_steady_state: The second input argument (QQ) must be a real matrix!");
|
mexErrMsgTxt("kalman_steady_state: The second input argument (QQ) must be a real matrix!");
|
||||||
if (q != n)
|
if (q != n)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("kalman_steady_state: The size of the second input argument (QQ) must match the size of the first argument (T)!");
|
mexErrMsgTxt("kalman_steady_state: The size of the second input argument (QQ) must match the size of the first argument (T)!");
|
||||||
lapack_int p = mxGetN(prhs[2]);
|
lapack_int p = mxGetN(prhs[2]);
|
||||||
if (mxGetM(prhs[2]) != static_cast<size_t>(n))
|
if (mxGetM(prhs[2]) != static_cast<size_t>(n))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("kalman_steady_state: The number of rows of the third argument (Z) must match the number of rows of the first argument (T)!");
|
mexErrMsgTxt("kalman_steady_state: The number of rows of the third argument (Z) must match the number of rows of the first argument (T)!");
|
||||||
if (mxIsNumeric(prhs[2]) == 0 || mxIsComplex(prhs[2]) == 1)
|
if (mxIsNumeric(prhs[2]) == 0 || mxIsComplex(prhs[2]) == 1)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("kalman_steady_state: The third input argument (Z) must be a real matrix!");
|
mexErrMsgTxt("kalman_steady_state: The third input argument (Z) must be a real matrix!");
|
||||||
if (measurement_error_flag)
|
if (measurement_error_flag)
|
||||||
{
|
{
|
||||||
if (mxGetM(prhs[3]) != mxGetN(prhs[3]))
|
if (mxGetM(prhs[3]) != mxGetN(prhs[3]))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("kalman_steady_state: The fourth input argument (H) must be a square matrix!");
|
mexErrMsgTxt("kalman_steady_state: The fourth input argument (H) must be a square matrix!");
|
||||||
if (mxGetM(prhs[3]) != static_cast<size_t>(p))
|
if (mxGetM(prhs[3]) != static_cast<size_t>(p))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("kalman_steady_state: The number of rows of the fourth input argument (H) must match the number of rows of the third input argument!");
|
mexErrMsgTxt("kalman_steady_state: The number of rows of the fourth input argument (H) must match the number of rows of the third input argument!");
|
||||||
if (mxIsNumeric(prhs[3]) == 0 || mxIsComplex(prhs[3]) == 1)
|
if (mxIsNumeric(prhs[3]) == 0 || mxIsComplex(prhs[3]) == 1)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("kalman_steady_state: The fifth input argument (H) must be a real matrix!");
|
mexErrMsgTxt("kalman_steady_state: The fifth input argument (H) must be a real matrix!");
|
||||||
}
|
}
|
||||||
// Get input matrices.
|
// Get input matrices.
|
||||||
const double *T = mxGetPr(prhs[0]);
|
const double *T = mxGetPr(prhs[0]);
|
||||||
|
@ -147,8 +147,8 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
||||||
auto DWORK = std::make_unique<double[]>(LDWORK);
|
auto DWORK = std::make_unique<double[]>(LDWORK);
|
||||||
auto BWORK = std::make_unique<lapack_int[]>(nn);
|
auto BWORK = std::make_unique<lapack_int[]>(nn);
|
||||||
// Initialize the output of the mex file
|
// Initialize the output of the mex file
|
||||||
plhs[1] = mxCreateDoubleMatrix(n, n, mxREAL);
|
plhs[0] = mxCreateDoubleMatrix(n, n, mxREAL);
|
||||||
double *P = mxGetPr(plhs[1]);
|
double *P = mxGetPr(plhs[0]);
|
||||||
// Call the slicot routine
|
// Call the slicot routine
|
||||||
sb02od("D", // We want to solve a discrete Riccati equation.
|
sb02od("D", // We want to solve a discrete Riccati equation.
|
||||||
"B", // Matrices Z and H are given.
|
"B", // Matrices Z and H are given.
|
||||||
|
@ -164,25 +164,24 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("The computed extended matrix pencil is singular, possibly due to rounding errors.\n");
|
mexErrMsgTxt("The computed extended matrix pencil is singular, possibly due to rounding errors.");
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("The QZ (or QR) algorithm failed!\n");
|
mexErrMsgTxt("The QZ (or QR) algorithm failed!");
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("The reordering of the (generalized) eigenvalues failed!\n");
|
mexErrMsgTxt("The reordering of the (generalized) eigenvalues failed!");
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("After reordering, roundoff changed values of some complex eigenvalues so that leading eigenvalues\n in the (generalized) Schur form no longer satisfy the stability condition; this could also be caused due to scaling.");
|
mexErrMsgTxt("After reordering, roundoff changed values of some complex eigenvalues so that leading eigenvalues\n in the (generalized) Schur form no longer satisfy the stability condition; this could also be caused due to scaling.");
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("The computed dimension of the solution does not equal n!\n");
|
mexErrMsgTxt("The computed dimension of the solution does not equal n!");
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("A singular matrix was encountered during the computation of the solution matrix P!\n");
|
mexErrMsgTxt("A singular matrix was encountered during the computation of the solution matrix P!");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Unknown problem!\n");
|
mexErrMsgTxt("Unknown problem!");
|
||||||
}
|
}
|
||||||
plhs[0] = mxCreateDoubleScalar(0);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2007-2019 Dynare Team
|
* Copyright © 2007-2020 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -68,8 +68,11 @@ void
|
||||||
mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
||||||
{
|
{
|
||||||
// Check input and output:
|
// Check input and output:
|
||||||
if (nrhs > 3 || nrhs < 2)
|
if (nrhs > 3 || nrhs < 2 || nlhs != 1)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("A_times_B_kronecker_C takes 2 or 3 input arguments and provides 2 output arguments.");
|
{
|
||||||
|
mexErrMsgTxt("A_times_B_kronecker_C takes 2 or 3 input arguments and provides 1 output argument.");
|
||||||
|
return; // Needed to shut up some GCC warnings
|
||||||
|
}
|
||||||
|
|
||||||
// Get & Check dimensions (columns and rows):
|
// Get & Check dimensions (columns and rows):
|
||||||
size_t mA = mxGetM(prhs[0]);
|
size_t mA = mxGetM(prhs[0]);
|
||||||
|
@ -82,12 +85,12 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
||||||
mC = mxGetM(prhs[2]);
|
mC = mxGetM(prhs[2]);
|
||||||
nC = mxGetN(prhs[2]);
|
nC = mxGetN(prhs[2]);
|
||||||
if (mB*mC != nA)
|
if (mB*mC != nA)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Input dimension error!");
|
mexErrMsgTxt("Input dimension error!");
|
||||||
}
|
}
|
||||||
else // A·(B⊗B) is to be computed.
|
else // A·(B⊗B) is to be computed.
|
||||||
{
|
{
|
||||||
if (mB*mB != nA)
|
if (mB*mB != nA)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Input dimension error!");
|
mexErrMsgTxt("Input dimension error!");
|
||||||
}
|
}
|
||||||
// Get input matrices:
|
// Get input matrices:
|
||||||
const double *A = mxGetPr(prhs[0]);
|
const double *A = mxGetPr(prhs[0]);
|
||||||
|
@ -108,6 +111,4 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
||||||
full_A_times_kronecker_B_B(A, B, D, mA, nA, mB, nB);
|
full_A_times_kronecker_B_B(A, B, D, mA, nA, mB, nB);
|
||||||
else
|
else
|
||||||
full_A_times_kronecker_B_C(A, B, C, D, mA, nA, mB, nB, mC, nC);
|
full_A_times_kronecker_B_C(A, B, C, D, mA, nA, mB, nB, mC, nC);
|
||||||
|
|
||||||
plhs[1] = mxCreateDoubleScalar(0);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2007-2019 Dynare Team
|
* Copyright © 2007-2020 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -135,11 +135,14 @@ void
|
||||||
mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
||||||
{
|
{
|
||||||
// Check input and output:
|
// Check input and output:
|
||||||
if (nrhs > 4 || nrhs < 3)
|
if (nrhs > 4 || nrhs < 3 || nlhs != 1)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("sparse_hessian_times_B_kronecker_C takes 3 or 4 input arguments and provides 2 output arguments.");
|
{
|
||||||
|
mexErrMsgTxt("sparse_hessian_times_B_kronecker_C takes 3 or 4 input arguments and provides 1 output argument.");
|
||||||
|
return; // Needed to shut up some GCC warnings
|
||||||
|
}
|
||||||
|
|
||||||
if (!mxIsSparse(prhs[0]))
|
if (!mxIsSparse(prhs[0]))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("sparse_hessian_times_B_kronecker_C: First input must be a sparse (dynare) hessian matrix.");
|
mexErrMsgTxt("sparse_hessian_times_B_kronecker_C: First input must be a sparse (dynare) hessian matrix.");
|
||||||
|
|
||||||
// Get & Check dimensions (columns and rows):
|
// Get & Check dimensions (columns and rows):
|
||||||
size_t mA = mxGetM(prhs[0]);
|
size_t mA = mxGetM(prhs[0]);
|
||||||
|
@ -152,12 +155,12 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
||||||
mC = mxGetM(prhs[2]);
|
mC = mxGetM(prhs[2]);
|
||||||
nC = mxGetN(prhs[2]);
|
nC = mxGetN(prhs[2]);
|
||||||
if (mB*mC != nA)
|
if (mB*mC != nA)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Input dimension error!");
|
mexErrMsgTxt("Input dimension error!");
|
||||||
}
|
}
|
||||||
else // A·(B⊗B) is to be computed.
|
else // A·(B⊗B) is to be computed.
|
||||||
{
|
{
|
||||||
if (mB*mB != nA)
|
if (mB*mB != nA)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Input dimension error!");
|
mexErrMsgTxt("Input dimension error!");
|
||||||
}
|
}
|
||||||
// Get input matrices:
|
// Get input matrices:
|
||||||
int numthreads;
|
int numthreads;
|
||||||
|
@ -185,6 +188,4 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
||||||
sparse_hessian_times_B_kronecker_B(isparseA, jsparseA, vsparseA, B, D, mA, nA, mB, nB, numthreads);
|
sparse_hessian_times_B_kronecker_B(isparseA, jsparseA, vsparseA, B, D, mA, nA, mB, nB, numthreads);
|
||||||
else
|
else
|
||||||
sparse_hessian_times_B_kronecker_C(isparseA, jsparseA, vsparseA, B, C, D, mA, nA, mB, nB, mC, nC, numthreads);
|
sparse_hessian_times_B_kronecker_C(isparseA, jsparseA, vsparseA, B, C, D, mA, nA, mB, nB, mC, nC, numthreads);
|
||||||
|
|
||||||
plhs[1] = mxCreateDoubleScalar(0);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,8 +60,8 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction')
|
||||||
real(real64), dimension(:), allocatable, target :: vsl_target
|
real(real64), dimension(:), allocatable, target :: vsl_target
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (nrhs < 2 .or. nrhs > 4 .or. nlhs /= 7) then
|
if (nrhs < 2 .or. nrhs > 4 .or. nlhs /= 6) then
|
||||||
call mexErrMsgTxt("MJDGGES: takes 2, 3 or 4 input arguments and exactly 7 output arguments.")
|
call mexErrMsgTxt("MJDGGES: takes 2, 3 or 4 input arguments and exactly 6 output arguments.")
|
||||||
return
|
return
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
@ -95,24 +95,24 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction')
|
||||||
zhreshold = 1e-6_real64
|
zhreshold = 1e-6_real64
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
plhs(1) = mxCreateDoubleMatrix(n1, n1, mxREAL)
|
||||||
plhs(2) = mxCreateDoubleMatrix(n1, n1, mxREAL)
|
plhs(2) = mxCreateDoubleMatrix(n1, n1, mxREAL)
|
||||||
plhs(3) = mxCreateDoubleMatrix(n1, n1, mxREAL)
|
plhs(3) = mxCreateDoubleMatrix(n1, n1, mxREAL)
|
||||||
plhs(4) = mxCreateDoubleMatrix(n1, n1, mxREAL)
|
plhs(4) = mxCreateDoubleMatrix(1_mwSize, 1_mwSize, mxREAL)
|
||||||
plhs(5) = mxCreateDoubleMatrix(1_mwSize, 1_mwSize, mxREAL)
|
plhs(5) = mxCreateDoubleMatrix(n1, 1_mwSize, mxCOMPLEX)
|
||||||
plhs(6) = mxCreateDoubleMatrix(n1, 1_mwSize, mxCOMPLEX)
|
plhs(6) = mxCreateDoubleMatrix(1_mwSize, 1_mwSize, mxREAL)
|
||||||
plhs(7) = mxCreateDoubleMatrix(1_mwSize, 1_mwSize, mxREAL)
|
|
||||||
|
|
||||||
s => mxGetPr(plhs(2))
|
s => mxGetPr(plhs(1))
|
||||||
t => mxGetPr(plhs(3))
|
t => mxGetPr(plhs(2))
|
||||||
sdim => mxGetPr(plhs(5))
|
sdim => mxGetPr(plhs(4))
|
||||||
#if MX_HAS_INTERLEAVED_COMPLEX
|
#if MX_HAS_INTERLEAVED_COMPLEX
|
||||||
gev => mxGetComplexDoubles(plhs(6))
|
gev => mxGetComplexDoubles(plhs(5))
|
||||||
#else
|
#else
|
||||||
gev_r => mxGetPr(plhs(6))
|
gev_r => mxGetPr(plhs(5))
|
||||||
gev_i => mxGetPi(plhs(6))
|
gev_i => mxGetPi(plhs(5))
|
||||||
#endif
|
#endif
|
||||||
info => mxGetPr(plhs(7))
|
info => mxGetPr(plhs(6))
|
||||||
z => mxGetPr(plhs(4))
|
z => mxGetPr(plhs(3))
|
||||||
#if defined(MATLAB_MEX_FILE) && MATLAB_VERSION < 0x0904
|
#if defined(MATLAB_MEX_FILE) && MATLAB_VERSION < 0x0904
|
||||||
! The left Schur vectors (VSL) are normally not computed, since JOBVSL="N".
|
! The left Schur vectors (VSL) are normally not computed, since JOBVSL="N".
|
||||||
! But old MKL versions (at least the one shipped with MATLAB R2009b/7.9,
|
! But old MKL versions (at least the one shipped with MATLAB R2009b/7.9,
|
||||||
|
@ -162,6 +162,4 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction')
|
||||||
! error number (only if no other error)
|
! error number (only if no other error)
|
||||||
if (any(abs(alpha_r) <= zhreshold .and. abs(beta) <= zhreshold) .and. info_bl == 0) &
|
if (any(abs(alpha_r) <= zhreshold .and. abs(beta) <= zhreshold) .and. info_bl == 0) &
|
||||||
info = 30
|
info = 30
|
||||||
|
|
||||||
plhs(1) = mxCreateDoubleScalar(0._real64)
|
|
||||||
end subroutine mexFunction
|
end subroutine mexFunction
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2010-2017 Dynare Team
|
* Copyright © 2010-2020 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -42,8 +42,8 @@ mexFunction(int nlhs, mxArray *plhs[],
|
||||||
/*
|
/*
|
||||||
* Check args
|
* Check args
|
||||||
*/
|
*/
|
||||||
if (nrhs != 1 || !mxIsChar(prhs[0]) || nlhs != 1)
|
if (nrhs != 1 || !mxIsChar(prhs[0]) || nlhs != 0)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Error in MS-SBVAR MEX file: this function takes 1 string input argument and returns 1 output argument.");
|
mexErrMsgTxt("Error in MS-SBVAR MEX file: this function takes 1 string input argument and returns no output argument.");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate memory
|
* Allocate memory
|
||||||
|
@ -52,24 +52,24 @@ mexFunction(int nlhs, mxArray *plhs[],
|
||||||
argument = static_cast<char *>(mxCalloc(mxGetN(prhs[0])+1, sizeof(char)));
|
argument = static_cast<char *>(mxCalloc(mxGetN(prhs[0])+1, sizeof(char)));
|
||||||
args = static_cast<char **>(mxCalloc(maxnargs, sizeof(char *)));
|
args = static_cast<char **>(mxCalloc(maxnargs, sizeof(char *)));
|
||||||
if (argument == NULL || args == NULL)
|
if (argument == NULL || args == NULL)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Error in MS-SBVAR MEX file: could not allocate memory. (1)");
|
mexErrMsgTxt("Error in MS-SBVAR MEX file: could not allocate memory. (1)");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create argument string from prhs and parse to create args / nargs
|
* Create argument string from prhs and parse to create args / nargs
|
||||||
*/
|
*/
|
||||||
if (!(args[nargs] = static_cast<char *>(mxCalloc(strlen(mainarg)+1, sizeof(char)))))
|
if (!(args[nargs] = static_cast<char *>(mxCalloc(strlen(mainarg)+1, sizeof(char)))))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Error in MS-SBVAR MEX file: could not allocate memory. (2)");
|
mexErrMsgTxt("Error in MS-SBVAR MEX file: could not allocate memory. (2)");
|
||||||
|
|
||||||
strncpy(args[nargs++], mainarg, strlen(mainarg));
|
strncpy(args[nargs++], mainarg, strlen(mainarg));
|
||||||
|
|
||||||
if (mxGetString(prhs[0], argument, mxGetN(prhs[0])+1))
|
if (mxGetString(prhs[0], argument, mxGetN(prhs[0])+1))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Error in MS-SBVAR MEX file: error using mxGetString.\n");
|
mexErrMsgTxt("Error in MS-SBVAR MEX file: error using mxGetString.\n");
|
||||||
|
|
||||||
beginarg = &argument[0];
|
beginarg = &argument[0];
|
||||||
while ((n = strcspn(beginarg, " ")))
|
while ((n = strcspn(beginarg, " ")))
|
||||||
{
|
{
|
||||||
if (!(args[nargs] = static_cast<char *>(mxCalloc(n+1, sizeof(char)))))
|
if (!(args[nargs] = static_cast<char *>(mxCalloc(n+1, sizeof(char)))))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("Error in MS-SBVAR MEX file: could not allocate memory. (3)");
|
mexErrMsgTxt("Error in MS-SBVAR MEX file: could not allocate memory. (3)");
|
||||||
|
|
||||||
strncpy(args[nargs++], beginarg, n);
|
strncpy(args[nargs++], beginarg, n);
|
||||||
beginarg += (isspace(beginarg[n]) || isblank(beginarg[n]) ? ++n : n);
|
beginarg += (isspace(beginarg[n]) || isblank(beginarg[n]) ? ++n : n);
|
||||||
|
@ -85,7 +85,7 @@ mexFunction(int nlhs, mxArray *plhs[],
|
||||||
}
|
}
|
||||||
catch (const char *str)
|
catch (const char *str)
|
||||||
{
|
{
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(str);
|
mexErrMsgTxt(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -94,6 +94,4 @@ mexFunction(int nlhs, mxArray *plhs[],
|
||||||
for (n = 0; n < nargs; n++)
|
for (n = 0; n < nargs; n++)
|
||||||
mxFree(args[n]);
|
mxFree(args[n]);
|
||||||
mxFree(args);
|
mxFree(args);
|
||||||
|
|
||||||
plhs[0] = mxCreateDoubleScalar(0);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
** Computes Quasi Monte-Carlo sequence.
|
** Computes Quasi Monte-Carlo sequence.
|
||||||
**
|
**
|
||||||
** Copyright © 2010-2017 Dynare Team
|
** Copyright © 2010-2020 Dynare Team
|
||||||
**
|
**
|
||||||
** This file is part of Dynare (can be used outside Dynare).
|
** This file is part of Dynare (can be used outside Dynare).
|
||||||
**
|
**
|
||||||
|
@ -52,23 +52,23 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
||||||
** Check the number of input and output arguments.
|
** Check the number of input and output arguments.
|
||||||
*/
|
*/
|
||||||
if (nrhs < 3 || nrhs > 5)
|
if (nrhs < 3 || nrhs > 5)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("qmc_sequence:: Five, four or three input arguments are required!");
|
mexErrMsgTxt("qmc_sequence:: Five, four or three input arguments are required!");
|
||||||
|
|
||||||
if (nlhs == 0)
|
if (nlhs == 0)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("qmc_sequence:: At least one output argument is required!");
|
mexErrMsgTxt("qmc_sequence:: At least one output argument is required!");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Test the first input argument and assign it to dimension.
|
** Test the first input argument and assign it to dimension.
|
||||||
*/
|
*/
|
||||||
if (!mxIsNumeric(prhs[0]))
|
if (!mxIsNumeric(prhs[0]))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("qmc_sequence:: First input (dimension) has to be a positive integer!");
|
mexErrMsgTxt("qmc_sequence:: First input (dimension) has to be a positive integer!");
|
||||||
|
|
||||||
int dimension = static_cast<int>(mxGetScalar(prhs[0]));
|
int dimension = static_cast<int>(mxGetScalar(prhs[0]));
|
||||||
/*
|
/*
|
||||||
** Test the second input argument and assign it to seed.
|
** Test the second input argument and assign it to seed.
|
||||||
*/
|
*/
|
||||||
if (!(mxIsNumeric(prhs[1]) && mxIsClass(prhs[1], "int64")))
|
if (!(mxIsNumeric(prhs[1]) && mxIsClass(prhs[1], "int64")))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("qmc_sequence:: Second input (seed) has to be an integer [int64]!");
|
mexErrMsgTxt("qmc_sequence:: Second input (seed) has to be an integer [int64]!");
|
||||||
|
|
||||||
int64_T seed = static_cast<int64_T>(mxGetScalar(prhs[1]));
|
int64_T seed = static_cast<int64_T>(mxGetScalar(prhs[1]));
|
||||||
/*
|
/*
|
||||||
|
@ -83,22 +83,22 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
||||||
error_flag_3 = 1;
|
error_flag_3 = 1;
|
||||||
|
|
||||||
if (error_flag_3 == 1)
|
if (error_flag_3 == 1)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("qmc_sequence:: Third input (type of QMC sequence) has to be an integer equal to 0, 1 or 2!");
|
mexErrMsgTxt("qmc_sequence:: Third input (type of QMC sequence) has to be an integer equal to 0, 1 or 2!");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Test dimension ≥ 2 when type==2
|
** Test dimension ≥ 2 when type==2
|
||||||
*/
|
*/
|
||||||
if (type == 2 && dimension < 2)
|
if (type == 2 && dimension < 2)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("qmc_sequence:: First input (dimension) has to be greater than 1 for a uniform QMC on an hypershere!");
|
mexErrMsgTxt("qmc_sequence:: First input (dimension) has to be greater than 1 for a uniform QMC on an hypershere!");
|
||||||
|
|
||||||
else if (dimension > DIM_MAX)
|
else if (dimension > DIM_MAX)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT(("qmc_sequence:: First input (dimension) has to be smaller than " + to_string(DIM_MAX) + " !").c_str());
|
mexErrMsgTxt(("qmc_sequence:: First input (dimension) has to be smaller than " + to_string(DIM_MAX) + " !").c_str());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Test the optional fourth input argument and assign it to sequence_size.
|
** Test the optional fourth input argument and assign it to sequence_size.
|
||||||
*/
|
*/
|
||||||
if (nrhs > 3 && !mxIsNumeric(prhs[3]))
|
if (nrhs > 3 && !mxIsNumeric(prhs[3]))
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("qmc_sequence:: Fourth input (qmc sequence size) has to be a positive integer!");
|
mexErrMsgTxt("qmc_sequence:: Fourth input (qmc sequence size) has to be a positive integer!");
|
||||||
|
|
||||||
int sequence_size;
|
int sequence_size;
|
||||||
if (nrhs > 3)
|
if (nrhs > 3)
|
||||||
|
@ -110,17 +110,17 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
||||||
** Test the optional fifth input argument and assign it to lower_and_upper_bounds.
|
** Test the optional fifth input argument and assign it to lower_and_upper_bounds.
|
||||||
*/
|
*/
|
||||||
if (nrhs > 4 && type == 0 && mxGetN(prhs[4]) != 2) // Sequence of uniformly distributed numbers in an hypercube
|
if (nrhs > 4 && type == 0 && mxGetN(prhs[4]) != 2) // Sequence of uniformly distributed numbers in an hypercube
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("qmc_sequence:: The fifth input argument must be an array with two columns!");
|
mexErrMsgTxt("qmc_sequence:: The fifth input argument must be an array with two columns!");
|
||||||
|
|
||||||
if (nrhs > 4 && type == 0 && static_cast<int>(mxGetM(prhs[4])) != dimension)
|
if (nrhs > 4 && type == 0 && static_cast<int>(mxGetM(prhs[4])) != dimension)
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("qmc_sequence:: The fourth input argument must be an array with a number of lines equal to dimension (first input argument)!");
|
mexErrMsgTxt("qmc_sequence:: The fourth input argument must be an array with a number of lines equal to dimension (first input argument)!");
|
||||||
|
|
||||||
if (nrhs > 4 && type == 1 && !(static_cast<int>(mxGetN(prhs[4])) == dimension
|
if (nrhs > 4 && type == 1 && !(static_cast<int>(mxGetN(prhs[4])) == dimension
|
||||||
&& static_cast<int>(mxGetM(prhs[4])) == dimension)) // Sequence of normally distributed numbers
|
&& static_cast<int>(mxGetM(prhs[4])) == dimension)) // Sequence of normally distributed numbers
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("qmc_sequence:: The fifth input argument must be a squared matrix (whose dimension is given by the first input argument)!");
|
mexErrMsgTxt("qmc_sequence:: The fifth input argument must be a squared matrix (whose dimension is given by the first input argument)!");
|
||||||
|
|
||||||
if (nrhs > 4 && type == 2 && !(mxGetN(prhs[4]) == 1 && mxGetM(prhs[4]) == 1)) // Sequence of uniformly distributed numbers on a hypershere
|
if (nrhs > 4 && type == 2 && !(mxGetN(prhs[4]) == 1 && mxGetM(prhs[4]) == 1)) // Sequence of uniformly distributed numbers on a hypershere
|
||||||
DYN_MEX_FUNC_ERR_MSG_TXT("qmc_sequence:: The fifth input argument must be a positive scalar!");
|
mexErrMsgTxt("qmc_sequence:: The fifth input argument must be a positive scalar!");
|
||||||
|
|
||||||
const double *lower_bounds = nullptr, *upper_bounds = nullptr;
|
const double *lower_bounds = nullptr, *upper_bounds = nullptr;
|
||||||
int unit_hypercube_flag = 1;
|
int unit_hypercube_flag = 1;
|
||||||
|
|
|
@ -17,8 +17,7 @@ for i=1:100
|
||||||
Z(1,1) = 1;
|
Z(1,1) = 1;
|
||||||
Z(2,3) = 1;
|
Z(2,3) = 1;
|
||||||
Z(3,6) = 1;
|
Z(3,6) = 1;
|
||||||
[err P] = kalman_steady_state(transpose(T),QQ,transpose(Z),H);
|
P = kalman_steady_state(transpose(T),QQ,transpose(Z),H);
|
||||||
mexErrCheck('kalman_steady_state',err);
|
|
||||||
end
|
end
|
||||||
|
|
||||||
% Without measurment errors.
|
% Without measurment errors.
|
||||||
|
@ -35,6 +34,5 @@ for i=1:100
|
||||||
Z(1,1) = 1;
|
Z(1,1) = 1;
|
||||||
Z(2,3) = 1;
|
Z(2,3) = 1;
|
||||||
Z(3,6) = 1;
|
Z(3,6) = 1;
|
||||||
[err P] = kalman_steady_state(transpose(T),QQ,transpose(Z),H);
|
P = kalman_steady_state(transpose(T),QQ,transpose(Z),H);
|
||||||
mexErrCheck('kalman_steady_state',err);
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
function info = test_kron(test,number_of_threads)
|
function info = test_kron(test,number_of_threads)
|
||||||
% Copyright (C) 2007-2010 Dynare Team
|
% Copyright (C) 2007-2020 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -52,14 +52,12 @@ if test == 1
|
||||||
disp('')
|
disp('')
|
||||||
disp('Computation of A*kron(B,B) with the mex file (v1):')
|
disp('Computation of A*kron(B,B) with the mex file (v1):')
|
||||||
tic
|
tic
|
||||||
[err, D1] = sparse_hessian_times_B_kronecker_C(A,B,number_of_threads);
|
D1 = sparse_hessian_times_B_kronecker_C(A,B,number_of_threads);
|
||||||
mexErrCheck('sparse_hessian_times_B_kronecker_C', err);
|
|
||||||
toc
|
toc
|
||||||
disp('')
|
disp('')
|
||||||
disp('Computation of A*kron(B,B) with the mex file (v2):')
|
disp('Computation of A*kron(B,B) with the mex file (v2):')
|
||||||
tic
|
tic
|
||||||
[err, D2] = sparse_hessian_times_B_kronecker_C(A,B,B,number_of_threads);
|
D2 = sparse_hessian_times_B_kronecker_C(A,B,B,number_of_threads);
|
||||||
mexErrCheck('sparse_hessian_times_B_kronecker_C', err);
|
|
||||||
toc
|
toc
|
||||||
disp('');
|
disp('');
|
||||||
disp(['Difference between D1 and D2 = ' num2str(max(max(abs(D1-D2))))]);
|
disp(['Difference between D1 and D2 = ' num2str(max(max(abs(D1-D2))))]);
|
||||||
|
@ -120,14 +118,12 @@ if test==2
|
||||||
disp(' ')
|
disp(' ')
|
||||||
disp('Computation of A*kron(B,B) with the mex file (v1):')
|
disp('Computation of A*kron(B,B) with the mex file (v1):')
|
||||||
tic
|
tic
|
||||||
[err, D1] = sparse_hessian_times_B_kronecker_C(hessian,zx,number_of_threads);
|
D1 = sparse_hessian_times_B_kronecker_C(hessian,zx,number_of_threads);
|
||||||
mexErrCheck('sparse_hessian_times_B_kronecker_C', err);
|
|
||||||
toc
|
toc
|
||||||
disp(' ')
|
disp(' ')
|
||||||
disp('Computation of A*kron(B,B) with the mex file (v2):')
|
disp('Computation of A*kron(B,B) with the mex file (v2):')
|
||||||
tic
|
tic
|
||||||
[err, D2] = sparse_hessian_times_B_kronecker_C(hessian,zx,zx,number_of_threads);
|
D2 = sparse_hessian_times_B_kronecker_C(hessian,zx,zx,number_of_threads);
|
||||||
mexErrCheck('sparse_hessian_times_B_kronecker_C', err);
|
|
||||||
toc
|
toc
|
||||||
disp(' ');
|
disp(' ');
|
||||||
disp(['Difference between D1 and D2 = ' num2str(max(max(abs(D1-D2))))]);
|
disp(['Difference between D1 and D2 = ' num2str(max(max(abs(D1-D2))))]);
|
||||||
|
@ -167,8 +163,7 @@ if test==3
|
||||||
disp('Test with full format matrix -- 1(a)')
|
disp('Test with full format matrix -- 1(a)')
|
||||||
D1 = A*kron(B,C);
|
D1 = A*kron(B,C);
|
||||||
tic
|
tic
|
||||||
[err, D2] = A_times_B_kronecker_C(A,B,C,number_of_threads);
|
D2 = A_times_B_kronecker_C(A,B,C,number_of_threads);
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
|
||||||
toc
|
toc
|
||||||
disp(['Difference between D1 and D2 = ' num2str(max(max(abs(D1-D2))))]);
|
disp(['Difference between D1 and D2 = ' num2str(max(max(abs(D1-D2))))]);
|
||||||
if max(max(abs(D1-D2)))>1e-10
|
if max(max(abs(D1-D2)))>1e-10
|
||||||
|
@ -177,8 +172,7 @@ if test==3
|
||||||
disp('Test with full format matrix -- 1(b)')
|
disp('Test with full format matrix -- 1(b)')
|
||||||
D1 = A*kron(B,B);
|
D1 = A*kron(B,B);
|
||||||
tic
|
tic
|
||||||
[err, D2] = A_times_B_kronecker_C(A,B,number_of_threads);
|
D2 = A_times_B_kronecker_C(A,B,number_of_threads);
|
||||||
mexErrCheck('A_times_B_kronecker_C', err);
|
|
||||||
toc
|
toc
|
||||||
disp(['Difference between D1 and D2 = ' num2str(max(max(abs(D1-D2))))]);
|
disp(['Difference between D1 and D2 = ' num2str(max(max(abs(D1-D2))))]);
|
||||||
if max(max(abs(D1-D2)))>1e-10
|
if max(max(abs(D1-D2)))>1e-10
|
||||||
|
@ -187,4 +181,4 @@ if test==3
|
||||||
if ~(test3_1 && test3_2)
|
if ~(test3_1 && test3_2)
|
||||||
info = 0;
|
info = 0;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue