Commit 0a3c8a4b authored by Ferhat Mihoubi's avatar Ferhat Mihoubi Committed by Sébastien Villemot
Browse files

- compute the jacobian matrix for exogenous, det_exogenous and previous blocks endogenous

- preprocessor provides informations about the dynamic structure of each block
- extends the algorithms available with bytecode: stack_solve_algo = 1, 2, 3 and 4 is compatible the bytecode. Speed and memory requirement are improved with stack_solve_algo = 1 or 4 for large scale models.
- bytecode can be used to evaluate a model
parent f268513f
...@@ -34,7 +34,7 @@ if(isfield(M_,'block_structure')) ...@@ -34,7 +34,7 @@ if(isfield(M_,'block_structure'))
end; end;
for j=1:size_block for j=1:size_block
if(j==1) if(j==1)
fprintf('| %3d (%4d) | %10d | %30s | %14d | %-6d %24s |\n',i,M_.block_structure.block(i).num,size_block,Sym_type(M_.block_structure.block(i).Simulation_Type),M_.block_structure.block(i).equation(j),M_.block_structure.block(i).variable(j),M_.endo_names(M_.block_structure.block(i).variable(j),:)); fprintf('| %10d | %10d | %30s | %14d | %-6d %24s |\n',i,size_block,Sym_type(M_.block_structure.block(i).Simulation_Type),M_.block_structure.block(i).equation(j),M_.block_structure.block(i).variable(j),M_.endo_names(M_.block_structure.block(i).variable(j),:));
else else
fprintf('| %10s | %10s | %30s | %14d | %-6d %24s |\n','','','',M_.block_structure.block(i).equation(j),M_.block_structure.block(i).variable(j),M_.endo_names(M_.block_structure.block(i).variable(j),:)); fprintf('| %10s | %10s | %30s | %14d | %-6d %24s |\n','','','',M_.block_structure.block(i).equation(j),M_.block_structure.block(i).variable(j),M_.endo_names(M_.block_structure.block(i).variable(j),:));
end; end;
......
...@@ -43,7 +43,7 @@ if size(oo_.endo_simul,2) < M_.maximum_lag+M_.maximum_lead+options_.periods ...@@ -43,7 +43,7 @@ if size(oo_.endo_simul,2) < M_.maximum_lag+M_.maximum_lead+options_.periods
positions = [positions ; strmatch(chopped,M_.endo_names,'exact')]; positions = [positions ; strmatch(chopped,M_.endo_names,'exact')];
end end
Values=fscanf(fid,'%f',inf); Values=fscanf(fid,'%f',inf);
Values=reshape(Values,M_.endo_nbr,size(Values,1)/M_.endo_nbr); Values=reshape(Values,M_.orig_endo_nbr,size(Values,1)/M_.orig_endo_nbr);
oo_.endo_simul=Values(positions,:); oo_.endo_simul=Values(positions,:);
fclose(fid); fclose(fid);
end end
......
...@@ -63,8 +63,8 @@ end ...@@ -63,8 +63,8 @@ end
if options_.block && ~options_.bytecode && (options_.stack_solve_algo == 0 || options_.stack_solve_algo == 5) if options_.block && ~options_.bytecode && (options_.stack_solve_algo == 0 || options_.stack_solve_algo == 5)
error('SIMUL: for the moment, you must use stack_solve_algo={1,2,3,4} when using block without bytecode option') error('SIMUL: for the moment, you must use stack_solve_algo={1,2,3,4} when using block without bytecode option')
end end
if options_.bytecode && options_.stack_solve_algo ~= 5 if options_.bytecode && (options_.stack_solve_algo ~= 1 && options_.stack_solve_algo ~= 2 && options_.stack_solve_algo ~= 3 && options_.stack_solve_algo ~= 4 && options_.stack_solve_algo ~= 5)
error('SIMUL: for the moment, you must use stack_solve_algo=5 with bytecode option') error('SIMUL: for the moment, you must use stack_solve_algo= 1, 2, 3, 4 or 5 with bytecode option')
end end
if exist('OCTAVE_VERSION') && options_.stack_solve_algo == 2 if exist('OCTAVE_VERSION') && options_.stack_solve_algo == 2
......
...@@ -29,7 +29,8 @@ function steady_() ...@@ -29,7 +29,8 @@ function steady_()
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
global M_ oo_ it_ options_ global M_ oo_ it_ options_
if options_.bytecode && options_.solve_algo ~= 5 if options_.bytecode && ...
(options_.solve_algo ~= 1 && options_.solve_algo ~= 2 && options_.solve_algo ~= 3 && options_.solve_algo ~= 4 && options_.solve_algo ~= 5)
error('STEADY: for the moment, you must use solve_algo=5 with bytecode option') error('STEADY: for the moment, you must use solve_algo=5 with bytecode option')
end end
if ~options_.bytecode && options_.solve_algo == 5 if ~options_.bytecode && options_.solve_algo == 5
...@@ -75,7 +76,9 @@ if options_.steadystate_flag ...@@ -75,7 +76,9 @@ if options_.steadystate_flag
check1 = 1; check1 = 1;
end end
elseif options_.block && options_.bytecode elseif options_.block && options_.bytecode
[residuals, check1] = bytecode('evaluate','static'); [residuals, check1] = bytecode('evaluate','static',oo_.steady_state,...
[oo_.exo_steady_state; ...
oo_.exo_det_steady_state], M_.params, 1);
else else
check1 = 0; check1 = 0;
check1 = max(abs(feval([M_.fname '_static'],... check1 = max(abs(feval([M_.fname '_static'],...
......
This diff is collapsed.
...@@ -41,12 +41,15 @@ ...@@ -41,12 +41,15 @@
using namespace std; using namespace std;
#define pow_ pow #define pow_ pow
typedef vector<pair<Tags, void * > > code_liste_type;
typedef vector<pair<Tags, void * > >::const_iterator it_code_type; typedef code_liste_type::const_iterator it_code_type;
class Interpreter : SparseMatrix class Interpreter : SparseMatrix
{ {
private: private:
#ifndef DEBUG_EX
vector<mxArray*> jacobian_block, jacobian_other_endo_block, jacobian_exo_block, jacobian_det_exo_block;
#endif
ExpressionType EQN_type; ExpressionType EQN_type;
unsigned int EQN_equation, EQN_block, EQN_block_number; unsigned int EQN_equation, EQN_block, EQN_block_number;
unsigned int EQN_dvar1, EQN_dvar2, EQN_dvar3; unsigned int EQN_dvar1, EQN_dvar2, EQN_dvar3;
...@@ -58,9 +61,9 @@ private: ...@@ -58,9 +61,9 @@ private:
double log10_1(double a, bool evaluate); double log10_1(double a, bool evaluate);
string remove_white(string str); string remove_white(string str);
string add_underscore_to_fpe(string str); string add_underscore_to_fpe(string str);
string get_variable(SymbolType variable_type, int variable_num); string get_variable(SymbolType variable_type, unsigned int variable_num);
string error_location(bool evaluate); string error_location(bool evaluate);
void compute_block_time(int Per_u_, bool evaluate, int block_num); void compute_block_time(int Per_u_, bool evaluate, int block_num, int size, bool steady_state);
string print_expression(it_code_type it_code, bool evaluate); string print_expression(it_code_type it_code, bool evaluate);
void evaluate_a_block(const int size, const int type, string bin_basename, bool steady_state, int block_num, void evaluate_a_block(const int size, const int type, string bin_basename, bool steady_state, int block_num,
const bool is_linear = false, const int symbol_table_endo_nbr = 0, const int Block_List_Max_Lag = 0, const int Block_List_Max_Lead = 0, const int u_count_int = 0); const bool is_linear = false, const int symbol_table_endo_nbr = 0, const int Block_List_Max_Lag = 0, const int Block_List_Max_Lead = 0, const int u_count_int = 0);
...@@ -68,7 +71,7 @@ private: ...@@ -68,7 +71,7 @@ private:
const bool is_linear = false, const int symbol_table_endo_nbr = 0, const int Block_List_Max_Lag = 0, const int Block_List_Max_Lead = 0, const int u_count_int = 0); const bool is_linear = false, const int symbol_table_endo_nbr = 0, const int Block_List_Max_Lag = 0, const int Block_List_Max_Lead = 0, const int u_count_int = 0);
double *T; double *T;
vector<Block_contain_type> Block_Contain; vector<Block_contain_type> Block_Contain;
vector<pair<Tags, void * > > code_liste; code_liste_type code_liste;
it_code_type it_code; it_code_type it_code;
stack<double> Stack; stack<double> Stack;
int Block_Count, Per_u_, Per_y_; int Block_Count, Per_u_, Per_y_;
...@@ -82,13 +85,20 @@ private: ...@@ -82,13 +85,20 @@ private:
int equation, derivative_equation, derivative_variable; int equation, derivative_equation, derivative_variable;
string filename; string filename;
int minimal_solving_periods; int minimal_solving_periods;
int stack_solve_algo, solve_algo;
public: public:
~Interpreter(); ~Interpreter();
Interpreter(double *params_arg, double *y_arg, double *ya_arg, double *x_arg, double *steady_y_arg, double *steady_x_arg, Interpreter(double *params_arg, double *y_arg, double *ya_arg, double *x_arg, double *steady_y_arg, double *steady_x_arg,
double *direction_arg, int y_size_arg, int nb_row_x_arg, double *direction_arg, int y_size_arg, int nb_row_x_arg,
int nb_row_xd_arg, int periods_arg, int y_kmin_arg, int y_kmax_arg, int maxit_arg_, double solve_tolf_arg, int size_o_direction_arg, int nb_row_xd_arg, int periods_arg, int y_kmin_arg, int y_kmax_arg, int maxit_arg_, double solve_tolf_arg, int size_o_direction_arg,
double slowc_arg, int y_decal_arg, double markowitz_c_arg, string &filename_arg, int minimal_solving_periods_arg); double slowc_arg, int y_decal_arg, double markowitz_c_arg, string &filename_arg, int minimal_solving_periods_arg, int stack_solve_algo_arg, int solve_algo_arg);
bool compute_blocks(string file_name, string bin_basename, bool steady_state, bool evaluate); bool compute_blocks(string file_name, string bin_basename, bool steady_state, bool evaluate, bool block, int &nb_blocks);
#ifndef DEBUG_EX
inline mxArray* get_jacob(int block_num) {return jacobian_block[block_num];};
inline mxArray* get_jacob_exo(int block_num) {return jacobian_exo_block[block_num];};
inline mxArray* get_jacob_exo_det(int block_num) {return jacobian_det_exo_block[block_num];};
inline mxArray* get_jacob_other_endo(int block_num) {return jacobian_other_endo_block[block_num];};
#endif
}; };
#endif #endif
...@@ -27,7 +27,7 @@ Mem_Mngr::Mem_Mngr() ...@@ -27,7 +27,7 @@ Mem_Mngr::Mem_Mngr()
void void
Mem_Mngr::Print_heap() Mem_Mngr::Print_heap()
{ {
int i; unsigned int i;
mexPrintf("i :"); mexPrintf("i :");
for (i = 0; i < CHUNK_SIZE; i++) for (i = 0; i < CHUNK_SIZE; i++)
mexPrintf("%3d ", i); mexPrintf("%3d ", i);
...@@ -61,7 +61,7 @@ Mem_Mngr::init_CHUNK_BLCK_SIZE(int u_count) ...@@ -61,7 +61,7 @@ Mem_Mngr::init_CHUNK_BLCK_SIZE(int u_count)
NonZeroElem * NonZeroElem *
Mem_Mngr::mxMalloc_NZE() Mem_Mngr::mxMalloc_NZE()
{ {
long int i; long unsigned int i;
if (!Chunk_Stack.empty()) /*An unused block of memory available inside the heap*/ if (!Chunk_Stack.empty()) /*An unused block of memory available inside the heap*/
{ {
NonZeroElem *p1 = Chunk_Stack.back(); NonZeroElem *p1 = Chunk_Stack.back();
...@@ -102,7 +102,7 @@ Mem_Mngr::mxMalloc_NZE() ...@@ -102,7 +102,7 @@ Mem_Mngr::mxMalloc_NZE()
void void
Mem_Mngr::mxFree_NZE(void *pos) Mem_Mngr::mxFree_NZE(void *pos)
{ {
int i; unsigned int i;
size_t gap; size_t gap;
for (i = 0; i < Nb_CHUNK; i++) for (i = 0; i < Nb_CHUNK; i++)
{ {
......
...@@ -52,8 +52,8 @@ public: ...@@ -52,8 +52,8 @@ public:
bool swp_f; bool swp_f;
private: private:
v_NonZeroElem Chunk_Stack; v_NonZeroElem Chunk_Stack;
int CHUNK_SIZE, CHUNK_BLCK_SIZE, Nb_CHUNK; unsigned int CHUNK_SIZE, CHUNK_BLCK_SIZE, Nb_CHUNK;
int CHUNK_heap_pos; unsigned int CHUNK_heap_pos;
NonZeroElem **NZE_Mem_add; NonZeroElem **NZE_Mem_add;
NonZeroElem *NZE_Mem; NonZeroElem *NZE_Mem;
vector<NonZeroElem *> NZE_Mem_Allocated; vector<NonZeroElem *> NZE_Mem_Allocated;
......
This diff is collapsed.
...@@ -33,7 +33,10 @@ using namespace std; ...@@ -33,7 +33,10 @@ using namespace std;
#ifdef _MSC_VER #ifdef _MSC_VER
# include <limits> # include <limits>
#include <boost/math/special_functions/erf.hpp>
#define M_SQRT2 1.4142135623730950488016887242097
#define M_PI 3.1415926535897932384626433832795
#define erf(x) boost::math::erf(x)
extern unsigned long _nan[2]; extern unsigned long _nan[2];
extern double NAN; extern double NAN;
...@@ -100,18 +103,23 @@ class SparseMatrix ...@@ -100,18 +103,23 @@ class SparseMatrix
{ {
public: public:
SparseMatrix(); SparseMatrix();
int simulate_NG1(int blck, int y_size, int it_, int y_kmin, int y_kmax, int Size, int periods, bool print_it, bool cvg, int &iter, int minimal_solving_periods, int Block_number); int simulate_NG1(int blck, int y_size, int it_, int y_kmin, int y_kmax, int Size, int periods, bool print_it, bool cvg, int &iter, int minimal_solving_periods, int Block_number, int stack_solve_algo);
bool simulate_NG(int blck, int y_size, int it_, int y_kmin, int y_kmax, int Size, bool print_it, bool cvg, int &iter, bool steady_state, int Block_number); bool simulate_NG(int blck, int y_size, int it_, int y_kmin, int y_kmax, int Size, bool print_it, bool cvg, int &iter, bool steady_state, int Block_number, int solve_algo);
void Direct_Simulate(int blck, int y_size, int it_, int y_kmin, int y_kmax, int Size, int periods, bool print_it, int iter); void Direct_Simulate(int blck, int y_size, int it_, int y_kmin, int y_kmax, int Size, int periods, bool print_it, int iter);
void fixe_u(double **u, int u_count_int, int max_lag_plus_max_lead_plus_1); void fixe_u(double **u, int u_count_int, int max_lag_plus_max_lead_plus_1);
void Read_SparseMatrix(string file_name, const int Size, int periods, int y_kmin, int y_kmax, bool steady_state, bool two_boundaries); void Read_SparseMatrix(string file_name, const int Size, int periods, int y_kmin, int y_kmax, bool steady_state, bool two_boundaries, int stack_solve_algo, int solve_algo);
void Read_file(string file_name, int periods, int u_size1, int y_size, int y_kmin, int y_kmax, int &nb_endo, int &u_count, int &u_count_init, double *u); void Read_file(string file_name, int periods, int u_size1, int y_size, int y_kmin, int y_kmax, int &nb_endo, int &u_count, int &u_count_init, double *u);
double g0, gp0, glambda2, try_at_iteration; double g0, gp0, glambda2, try_at_iteration;
private: private:
void Init(int periods, int y_kmin, int y_kmax, int Size, map<pair<pair<int, int>, int>, int> &IM); void Init_GE(int periods, int y_kmin, int y_kmax, int Size, map<pair<pair<int, int>, int>, int> &IM);
void ShortInit(int periods, int y_kmin, int y_kmax, int Size, map<pair<pair<int, int>, int>, int> &IM); void Init_Matlab_Sparse(int periods, int y_kmin, int y_kmax, int Size, map<pair<pair<int, int>, int>, int> &IM, mxArray *A_m, mxArray *b_m);
void Init_Matlab_Sparse_Simple(int Size, map<pair<pair<int, int>, int>, int> &IM, mxArray *A_m, mxArray *b_m);
void Simple_Init(int it_, int y_kmin, int y_kmax, int Size, std::map<std::pair<std::pair<int, int>, int>, int> &IM); void Simple_Init(int it_, int y_kmin, int y_kmax, int Size, std::map<std::pair<std::pair<int, int>, int>, int> &IM);
void End(int Size); void End_GE(int Size);
void Solve_Matlab_LU_UMFPack(mxArray* A_m, mxArray* b_m, int Size, double slowc_l);
void Solve_Matlab_GMRES(mxArray* A_m, mxArray* b_m, int Size, double slowc, int block);
void Solve_Matlab_BiCGStab(mxArray* A_m, mxArray* b_m, int Size, double slowc, int block);
bool compare(int *save_op, int *save_opa, int *save_opaa, int beg_t, int periods, long int nop4, int Size bool compare(int *save_op, int *save_opa, int *save_opaa, int beg_t, int periods, long int nop4, int Size
#ifdef PROFILER #ifdef PROFILER
, long int *ndiv, long int *nsub , long int *ndiv, long int *nsub
...@@ -173,6 +181,8 @@ private: ...@@ -173,6 +181,8 @@ private:
protected: protected:
int u_count_alloc, u_count_alloc_save; int u_count_alloc, u_count_alloc_save;
double *u, *y, *ya; double *u, *y, *ya;
vector<double*> jac;
double *jcb;
double res1, res2, max_res, max_res_idx; double res1, res2, max_res, max_res_idx;
double slowc, slowc_save, prev_slowc_save, markowitz_c; double slowc, slowc_save, prev_slowc_save, markowitz_c;
int y_kmin, y_kmax, y_size, periods, y_decal; int y_kmin, y_kmax, y_size, periods, y_decal;
...@@ -184,6 +194,8 @@ protected: ...@@ -184,6 +194,8 @@ protected:
int restart; int restart;
bool error_not_printed; bool error_not_printed;
double g_lambda1, g_lambda2, gp_0; double g_lambda1, g_lambda2, gp_0;
double lu_inc_tol;
bool reduced;
}; };
#endif #endif
...@@ -54,15 +54,8 @@ main(int argc, const char *argv[]) ...@@ -54,15 +54,8 @@ main(int argc, const char *argv[])
FILE *fid; FILE *fid;
bool steady_state = false; bool steady_state = false;
bool evaluate = false; bool evaluate = false;
printf("argc=%d\n", argc); bool block = false;
/*fexcept_t *flagp;
flagp = (fexcept_t*) mxMalloc(sizeof(fexcept_t));
if (fegetexceptflag(flagp, FE_ALL_EXCEPT))
mexPrintf("fegetexceptflag failed\n");
if (fesetexceptflag(flagp,FE_INVALID | FE_DIVBYZERO))
mexPrintf("fesetexceptflag failed\n");
mxFree(flagp);
feclearexcept (FE_ALL_EXCEPT);*/
if (argc < 2) if (argc < 2)
{ {
mexPrintf("model filename expected\n"); mexPrintf("model filename expected\n");
...@@ -72,7 +65,7 @@ main(int argc, const char *argv[]) ...@@ -72,7 +65,7 @@ main(int argc, const char *argv[])
float f_tmp; float f_tmp;
ostringstream tmp_out(""); ostringstream tmp_out("");
tmp_out << argv[1] << "_options.txt"; tmp_out << argv[1] << "_options.txt";
cout << tmp_out.str().c_str() << "\n";
int nb_params; int nb_params;
int i, row_y, col_y, row_x, col_x; int i, row_y, col_y, row_x, col_x;
double *yd, *xd; double *yd, *xd;
...@@ -81,6 +74,7 @@ main(int argc, const char *argv[]) ...@@ -81,6 +74,7 @@ main(int argc, const char *argv[])
string file_name(argv[1]); string file_name(argv[1]);
int count_array_argument = 0;
for (i = 2; i < argc; i++) for (i = 2; i < argc; i++)
{ {
if (Get_Argument(argv[i]) == "static") if (Get_Argument(argv[i]) == "static")
...@@ -89,6 +83,8 @@ main(int argc, const char *argv[]) ...@@ -89,6 +83,8 @@ main(int argc, const char *argv[])
steady_state = false; steady_state = false;
else if (Get_Argument(argv[i]) == "evaluate") else if (Get_Argument(argv[i]) == "evaluate")
evaluate = true; evaluate = true;
else if (Get_Argument(argv[i]) == "block")
block = true;
else else
{ {
mexPrintf("Unknown argument : "); mexPrintf("Unknown argument : ");
...@@ -99,6 +95,7 @@ main(int argc, const char *argv[]) ...@@ -99,6 +95,7 @@ main(int argc, const char *argv[])
mexErrMsgTxt(f.c_str()); mexErrMsgTxt(f.c_str());
} }
} }
fid = fopen(tmp_out.str().c_str(), "r"); fid = fopen(tmp_out.str().c_str(), "r");
int periods = 1; int periods = 1;
if (!steady_state) if (!steady_state)
...@@ -143,10 +140,12 @@ main(int argc, const char *argv[]) ...@@ -143,10 +140,12 @@ main(int argc, const char *argv[])
params[i] = f_tmp; params[i] = f_tmp;
} }
fclose(fid); fclose(fid);
yd = (double *) malloc(row_y*col_y*sizeof(yd[0])); yd = (double *) malloc(row_y*col_y*sizeof(yd[0]));
xd = (double *) malloc(row_x*col_x*sizeof(xd[0])); xd = (double *) malloc(row_x*col_x*sizeof(xd[0]));
tmp_out.str(""); tmp_out.str("");
tmp_out << argv[1] << "_oo.txt"; tmp_out << argv[1] << "_oo.txt";
fid = fopen(tmp_out.str().c_str(), "r"); fid = fopen(tmp_out.str().c_str(), "r");
for (i = 0; i < col_y*row_y; i++) for (i = 0; i < col_y*row_y; i++)
{ {
...@@ -193,7 +192,8 @@ main(int argc, const char *argv[]) ...@@ -193,7 +192,8 @@ main(int argc, const char *argv[])
Interpreter interprete(params, y, ya, x, steady_yd, steady_xd, direction, y_size, nb_row_x, nb_row_xd, periods, y_kmin, y_kmax, maxit_, solve_tolf, size_of_direction, slowc, y_decal, markowitz_c, file_name, minimal_solving_periods); Interpreter interprete(params, y, ya, x, steady_yd, steady_xd, direction, y_size, nb_row_x, nb_row_xd, periods, y_kmin, y_kmax, maxit_, solve_tolf, size_of_direction, slowc, y_decal, markowitz_c, file_name, minimal_solving_periods);
string f(file_name); string f(file_name);
interprete.compute_blocks(f, f, steady_state, evaluate); int nb_blocks = 0;
interprete.compute_blocks(f, f, steady_state, evaluate, block, nb_blocks);
clock_t t1 = clock(); clock_t t1 = clock();
if (!evaluate) if (!evaluate)
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));
...@@ -235,29 +235,56 @@ void ...@@ -235,29 +235,56 @@ void
mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{ {
mxArray *M_, *oo_, *options_; mxArray *M_, *oo_, *options_;
int i, row_y, col_y, row_x, col_x, nb_row_xd; mxArray *block_structur = NULL;
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; 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, periods = 1; int y_kmin = 0, y_kmax = 0, y_decal = 0, periods = 1;
double *pind; double *pind;
double *direction; double *direction;
bool steady_state = false; bool steady_state = false;
bool evaluate = false; bool evaluate = false;
/*fexcept_t *flagp; bool block = false;
flagp = (fexcept_t*) mxMalloc(sizeof(fexcept_t)); double *params = NULL;
if(fegetexceptflag(flagp, FE_ALL_EXCEPT)) double *yd = NULL, *xd = NULL;
mexPrintf("fegetexceptflag failed\n"); int count_array_argument = 0;
if(fesetexceptflag(flagp,FE_INVALID | FE_DIVBYZERO))
mexPrintf("fesetexceptflag failed\n");
mxFree(flagp);
feclearexcept (FE_ALL_EXCEPT);*/
for (i = 0; i < nrhs; i++) for (i = 0; i < nrhs; i++)
{ {
if (Get_Argument(prhs[i]) == "static") if (!mxIsChar(prhs[i]))
{
switch (count_array_argument)
{
case 0:
yd = mxGetPr(prhs[i]);
row_y = mxGetM(prhs[i]);
col_y = mxGetN(prhs[i]);
break;
case 1:
xd = mxGetPr(prhs[i]);
row_x = mxGetM(prhs[i]);
col_x = mxGetN(prhs[i]);
break;
case 2:
params = mxGetPr(prhs[i]);
break;
case 3:
periods = mxGetScalar(prhs[i]);
break;
case 4:
block_structur = mxDuplicateArray(prhs[i]);
break;
default:
mexPrintf("Unknown argument\n");
}
count_array_argument++;
}
else if (Get_Argument(prhs[i]) == "static")
steady_state = true; steady_state = true;
else if (Get_Argument(prhs[i]) == "dynamic") else if (Get_Argument(prhs[i]) == "dynamic")
steady_state = false; steady_state = false;
else if (Get_Argument(prhs[i]) == "evaluate") else if (Get_Argument(prhs[i]) == "evaluate")
evaluate = true; evaluate = true;
else if (Get_Argument(prhs[i]) == "block")
block = true;
else else
{ {
mexPrintf("Unknown argument : "); mexPrintf("Unknown argument : ");
...@@ -267,6 +294,12 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -267,6 +294,12 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
mexErrMsgTxt(f.c_str()); mexErrMsgTxt(f.c_str());
} }
} }
if (count_array_argument > 0 && count_array_argument < 4)
{
mexPrintf("Missing arguments. All the following arguments have to be indicated y, x, params, it_\n");
mexErrMsgTxt("end of bytecode\n");
}
M_ = mexGetVariable("global", "M_"); M_ = mexGetVariable("global", "M_");
if (M_ == NULL) if (M_ == NULL)
{ {
...@@ -286,22 +319,30 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -286,22 +319,30 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
mexPrintf("Global variable not found : "); mexPrintf("Global variable not found : ");
mexErrMsgTxt("options_ \n"); mexErrMsgTxt("options_ \n");
} }
double *params = mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "params"))); if (!count_array_argument)
double *yd, *xd, *steady_yd = NULL, *steady_xd = NULL; params = mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "params")));
double *steady_yd = NULL, *steady_xd = NULL;
if (!steady_state) if (!steady_state)
{ {
yd = mxGetPr(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "endo_simul"))); if (!count_array_argument)
row_y = mxGetM(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "endo_simul"))); {
col_y = mxGetN(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "endo_simul")));; yd = mxGetPr(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "endo_simul")));
xd = mxGetPr(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "exo_simul"))); row_y = mxGetM(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "endo_simul")));
row_x = mxGetM(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "exo_simul"))); col_y = mxGetN(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "endo_simul")));;
col_x = mxGetN(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "exo_simul"))); }
if (!count_array_argument)
{
xd = mxGetPr(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "exo_simul")));
row_x = mxGetM(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "exo_simul")));
col_x = mxGetN(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "exo_simul")));
}
nb_row_xd = int (floor(*(mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "exo_det_nbr")))))); nb_row_xd = int (floor(*(mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "exo_det_nbr"))))));
y_kmin = int (floor(*(mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "maximum_lag")))))); y_kmin = int (floor(*(mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "maximum_lag"))))));
y_kmax = int (floor(*(mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "maximum_lead")))))); y_kmax = int (floor(*(mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "maximum_lead"))))));
y_decal = max(0, y_kmin-int (floor(*(mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "maximum_endo_lag"))))))); y_decal = max(0, y_kmin-int (floor(*(mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "maximum_endo_lag")))))));
periods = int (floor(*(mxGetPr(mxGetFieldByNumber(options_, 0, mxGetFieldNumber(options_, "periods")))))); 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_yd = mxGetPr(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "steady_state")));
steady_row_y = mxGetM(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "steady_state"))); steady_row_y = mxGetM(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "steady_state")));
...@@ -313,18 +354,26 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -313,18 +354,26 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
} }
else else
{ {
yd = mxGetPr(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "steady_state"))); if (!count_array_argument)
row_y = mxGetM(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_, "steady_state")));