From f48aa28e390e5b84569dd69cf6d6f6efb05fad98 Mon Sep 17 00:00:00 2001 From: Ferhat Mihoubi <ferhat.mihoubi@univ-evry.fr> Date: Mon, 14 Mar 2011 17:46:00 +0100 Subject: [PATCH] Corrections for steady_state operator bug with bytecode. bytecode is now fixed. --- matlab/block_bytecode_mfs_steadystate.m | 2 +- matlab/bytecode_steadystate.m | 2 +- matlab/dr1.m | 4 +-- matlab/dynare_solve_block_or_bytecode.m | 2 +- matlab/steady_.m | 2 +- mex/sources/bytecode/bytecode.cc | 38 ++++++++++++++++--------- 6 files changed, 31 insertions(+), 19 deletions(-) diff --git a/matlab/block_bytecode_mfs_steadystate.m b/matlab/block_bytecode_mfs_steadystate.m index fd944f5cc7..d06fb1b8b2 100644 --- a/matlab/block_bytecode_mfs_steadystate.m +++ b/matlab/block_bytecode_mfs_steadystate.m @@ -23,4 +23,4 @@ global M_ oo_ indx = M_.blocksMFS{b}; y_all(indx) = y; x = [oo_.exo_steady_state; oo_.exo_det_steady_state]; -[chk, r, g1] = bytecode( y_all, x, M_.params, 1, y_all, 'evaluate', 'static', ['block = ' int2str(b) ]); +[chk, r, g1] = bytecode( y_all, x, M_.params, y_all, 1, y_all, 'evaluate', 'static', ['block = ' int2str(b) ]); diff --git a/matlab/bytecode_steadystate.m b/matlab/bytecode_steadystate.m index 92c79fe3f3..2aa2715a31 100644 --- a/matlab/bytecode_steadystate.m +++ b/matlab/bytecode_steadystate.m @@ -21,4 +21,4 @@ function [r, g1] = bytecode_steadystate(y) global M_ oo_ x = [oo_.exo_steady_state; oo_.exo_det_steady_state]; -eval('[chk, r, g1] = bytecode( y, x, M_.params, 1, x, ''evaluate'', ''static'', ''block = 1'');'); \ No newline at end of file +eval('[chk, r, g1] = bytecode( y, x, M_.params, oo_.steady_state, 1, x, ''evaluate'', ''static'', ''block = 1'');'); \ No newline at end of file diff --git a/matlab/dr1.m b/matlab/dr1.m index 9ebad62d03..da08dc8522 100644 --- a/matlab/dr1.m +++ b/matlab/dr1.m @@ -159,7 +159,7 @@ else if options_.order == 1 if (options_.bytecode) [chck, junk, loc_dr] = bytecode('dynamic','evaluate', z,[oo_.exo_simul ... - oo_.exo_det_simul], M_.params, 1); + oo_.exo_det_simul], M_.params, dr.ys, 1); jacobia_ = [loc_dr.g1 loc_dr.g1_x]; else [junk,jacobia_] = feval([M_.fname '_dynamic'],z,[oo_.exo_simul ... @@ -168,7 +168,7 @@ else elseif options_.order == 2 if (options_.bytecode) [chck, junk, loc_dr] = bytecode('dynamic','evaluate', z,[oo_.exo_simul ... - oo_.exo_det_simul], M_.params, 1); + oo_.exo_det_simul], M_.params, dr.ys, 1); jacobia_ = [loc_dr.g1 loc_dr.g1_x]; else [junk,jacobia_,hessian1] = feval([M_.fname '_dynamic'],z,... diff --git a/matlab/dynare_solve_block_or_bytecode.m b/matlab/dynare_solve_block_or_bytecode.m index e49bea2d40..7e5a9c9aa1 100644 --- a/matlab/dynare_solve_block_or_bytecode.m +++ b/matlab/dynare_solve_block_or_bytecode.m @@ -59,7 +59,7 @@ elseif options_.bytecode end x(M_.blocksMFS{b}) = y; else - [chk, nulldev, nulldev1, x] = bytecode( x, exo, params, 1, x, 'evaluate', 'static', ['block = ' int2str(b)]); + [chk, nulldev, nulldev1, x] = bytecode( x, exo, params, x, 1, x, 'evaluate', 'static', ['block = ' int2str(b)]); end; end else diff --git a/matlab/steady_.m b/matlab/steady_.m index 3d0cd580bd..f090816d7f 100644 --- a/matlab/steady_.m +++ b/matlab/steady_.m @@ -88,7 +88,7 @@ if options_.steadystate_flag elseif options_.bytecode [check1, residuals] = bytecode('evaluate','static',oo_.steady_state,... [oo_.exo_steady_state; ... - oo_.exo_det_steady_state], M_.params, 1); + oo_.exo_det_steady_state], M_.params, oo_.steady_state, 1); mexErrCheck('bytecode', check1); check1 = max(abs(residuals)) > options_.dynatol ; else diff --git a/mex/sources/bytecode/bytecode.cc b/mex/sources/bytecode/bytecode.cc index 965766267c..d46335fdf1 100644 --- a/mex/sources/bytecode/bytecode.cc +++ b/mex/sources/bytecode/bytecode.cc @@ -59,7 +59,9 @@ Get_Arguments_and_global_variables(int nrhs, int &count_array_argument, double *yd[], unsigned int &row_y, unsigned int &col_y, double *xd[], unsigned int &row_x, unsigned int &col_x, - double *params[], unsigned int &periods, + double *params[], + double *steady_yd[], unsigned int &steady_row_y, unsigned int &steady_col_y, + unsigned int &periods, #ifndef DEBUG_EX mxArray *block_structur[], #endif @@ -93,12 +95,17 @@ Get_Arguments_and_global_variables(int nrhs, *params = mxGetPr(prhs[i]); break; case 3: - periods = mxGetScalar(prhs[i]); + *steady_yd = mxGetPr(prhs[i]); + steady_row_y = mxGetM(prhs[i]); + steady_col_y = mxGetN(prhs[i]); break; case 4: - *block_structur = mxDuplicateArray(prhs[i]); + periods = mxGetScalar(prhs[i]); break; case 5: + *block_structur = mxDuplicateArray(prhs[i]); + break; + case 6: global_temporary_terms = true; *GlobalTemporaryTerms = mxDuplicateArray(prhs[i]); break; @@ -140,14 +147,14 @@ Get_Arguments_and_global_variables(int nrhs, } } } - if (count_array_argument > 0 && count_array_argument < 4) + if (count_array_argument > 0 && count_array_argument < 5) { if (count_array_argument == 3 && steady_state) periods = 1; else { ostringstream tmp; - tmp << " in main, missing arguments. All the following arguments have to be indicated y, x, params, it_\n"; + tmp << " in main, missing arguments. All the following arguments have to be indicated y, x, params, it_, ys\n"; throw FatalExceptionHandling(tmp.str()); } } @@ -195,7 +202,7 @@ main(int nrhs, const char *prhs[]) #endif //ErrorHandlingException error_handling; unsigned int i, row_y = 0, col_y = 0, row_x = 0, col_x = 0, nb_row_xd = 0; - int steady_row_y, steady_col_y, steady_row_x, steady_col_x, steady_nb_row_xd; + unsigned int steady_row_y, steady_col_y, steady_row_x, steady_col_x, steady_nb_row_xd; int y_kmin = 0, y_kmax = 0, y_decal = 0; unsigned int periods = 1; double *direction; @@ -207,13 +214,16 @@ main(int nrhs, const char *prhs[]) int count_array_argument = 0; bool global_temporary_terms = false; bool print = false; - + double *steady_yd = NULL, *steady_xd = NULL; + try { Get_Arguments_and_global_variables(nrhs, prhs, count_array_argument, &yd, row_y, col_y, &xd, row_x, col_x, - ¶ms, periods, + ¶ms, + &steady_yd, steady_row_y, steady_col_y, + periods, #ifndef DEBUG_EX &block_structur, #endif @@ -229,7 +239,7 @@ main(int nrhs, const char *prhs[]) if (!count_array_argument) params = mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "params"))); - double *steady_yd = NULL, *steady_xd = NULL; + if (!steady_state) { if (!count_array_argument) @@ -248,10 +258,12 @@ main(int nrhs, const char *prhs[]) y_decal = max(0, y_kmin-int (floor(*(mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "maximum_endo_lag"))))))); if (!count_array_argument) periods = int (floor(*(mxGetPr(mxGetFieldByNumber(options_, 0, mxGetFieldNumber(options_, "periods")))))); - - steady_yd = mxGetPr(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "steady_state"))); - steady_row_y = mxGetM(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "steady_state"))); - steady_col_y = mxGetN(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "steady_state")));; + if (!steady_yd ) + { + steady_yd = mxGetPr(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "steady_state"))); + steady_row_y = mxGetM(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "steady_state"))); + steady_col_y = mxGetN(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "steady_state")));; + } steady_xd = mxGetPr(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "exo_steady_state"))); steady_row_x = mxGetM(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "exo_steady_state"))); steady_col_x = mxGetN(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "exo_steady_state"))); -- GitLab