Commit 130f0c86 authored by FerhatMihoubi's avatar FerhatMihoubi

Adds the linear_decomposition model's option to bytecode + handling the cell...

Adds the linear_decomposition model's option to bytecode + handling the cell array instead of char array for variables names
parent 084b7ac5
Pipeline #197 failed with stages
in 43 minutes and 6 seconds
This diff is collapsed.
/*
* Copyright (C) 2013-2017 Dynare Team
* Copyright (C) 2013-2018 Dynare Team
*
* This file is part of Dynare.
*
......@@ -35,7 +35,8 @@ Evaluate::Evaluate()
block = -1;
}
Evaluate::Evaluate(const int y_size_arg, const int y_kmin_arg, const int y_kmax_arg, const bool print_it_arg, const bool steady_state_arg, const int periods_arg, const int minimal_solving_periods_arg, const double slowc_arg) :
Evaluate::Evaluate(const int y_size_arg, const int y_kmin_arg, const int y_kmax_arg, const bool print_it_arg, const bool steady_state_arg, const bool linear_decomposition_arg, const int periods_arg, const int minimal_solving_periods_arg, const double slowc_arg, double* ghx_arg, double* ghu_arg,
int n_state_var_arg, int* state_var_indx_arg, /*int* kstate_arg,*/ int* order_var_arg):
print_it(print_it_arg), minimal_solving_periods(minimal_solving_periods_arg)
{
symbol_table_endo_nbr = 0;
......@@ -49,6 +50,12 @@ Evaluate::Evaluate(const int y_size_arg, const int y_kmin_arg, const int y_kmax_
periods = periods_arg;
steady_state = steady_state_arg;
slowc = slowc_arg;
ghx = ghx_arg;
ghu = ghu_arg;
linear_decomposition = linear_decomposition_arg;
n_state_var = n_state_var_arg;
state_var_indx = state_var_indx_arg;
order_var = order_var_arg;
}
double
......@@ -123,7 +130,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
ExternalFunctionType function_type = ExternalFunctionType::withoutDerivative;
#ifdef DEBUG
mexPrintf("compute_block_time\n");
mexPrintf("compute_block_time evaluate=%d, block_num=%d\n",evaluate,block_num);
#endif
if (evaluate)
{
......@@ -455,7 +462,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
//load a temporary variable in the processor
var = ((FLDT_ *) it_code->second)->get_pos();
#ifdef DEBUG
mexPrintf("T[it_=%d var=%d, y_kmin=%d, y_kmax=%d == %d]=>%f\n", it_, var, y_kmin, y_kmax, var*(periods+y_kmin+y_kmax)+it_, var);
mexPrintf("T[it_=%d var=%d, y_kmin=%d, y_kmax=%d == %d]=>%d T=%x\n", it_, var, y_kmin, y_kmax, var*(periods+y_kmin+y_kmax)+it_, var, T);
tmp_out << " T[" << it_ << ", " << var << "](" << T[var*(periods+y_kmin+y_kmax)+it_] << ")";
#endif
Stack.push(T[var*(periods+y_kmin+y_kmax)+it_]);
......@@ -606,7 +613,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
case FSTPT:
//store in a temporary variable from the processor
#ifdef DEBUG
mexPrintf("FSTPT\n");
mexPrintf("FSTPT[var=%d it_=%d (%d)]= T=%x\n",var, it_, var*(periods+y_kmin+y_kmax)+it_, T);
#endif
var = ((FSTPT_ *) it_code->second)->get_pos();
T[var*(periods+y_kmin+y_kmax)+it_] = Stack.top();
......@@ -748,21 +755,27 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
lag = ((FSTPG3_ *) it_code->second)->get_lag();
pos_col = ((FSTPG3_ *) it_code->second)->get_col_pos();
#ifdef DEBUG
mexPrintf("other_endo eq=%d, pos_col=%d, size=%d\n", eq, pos_col, size);
mexPrintf("other_endo eq=%d, pos_col=%d, size=%d rr=%f\n", eq, pos_col, size, rr);
mexEvalString("drawnow;");
#endif
if (linear_decomposition)
eq = reverse_non_linear_equation[eq];
jacob_other_endo[eq + size*pos_col] = rr;
break;
case FirstExoDerivative:
//eq = ((FSTPG3_ *) it_code->second)->get_row();
eq = EQN_equation;
if (linear_decomposition)
eq = reverse_non_linear_equation[eq];
var = ((FSTPG3_ *) it_code->second)->get_col();
lag = ((FSTPG3_ *) it_code->second)->get_lag();
pos_col = ((FSTPG3_ *) it_code->second)->get_col_pos();
#ifdef DEBUG
mexPrintf("Exo eq=%d, pos_col=%d, size=%d\n", eq, pos_col, size);
mexPrintf("Exo eq=%d, EQN_equation=%d, pos_col=%d, size=%d rr=%f\n", eq, EQN_equation, pos_col, size, rr);
mexEvalString("drawnow;");
#endif
if (linear_decomposition)
eq = reverse_non_linear_equation[eq];
jacob_exo[eq + size*pos_col] = rr;
break;
case FirstExodetDerivative:
......@@ -940,7 +953,6 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
break;
default:
{
mexPrintf("Error\n");
ostringstream tmp;
tmp << " in compute_block_time, unknown binary operator " << op << "\n";
throw FatalExceptionHandling(tmp.str());
......@@ -1646,7 +1658,6 @@ Evaluate::compute_complete_2b(const bool no_derivatives, double *_res1, double *
compute_block_time(Per_u_, false, no_derivatives);
if (!(isnan(res1) || isinf(res1)))
{
{
for (int i = 0; i < size; i++)
{
double rr;
......@@ -1661,7 +1672,6 @@ Evaluate::compute_complete_2b(const bool no_derivatives, double *_res1, double *
*_res1 += fabs(rr);
}
}
}
else
return;
}
......
/*
* Copyright (C) 2007-2017 Dynare Team
* Copyright (C) 2007-2018 Dynare Team
*
* This file is part of Dynare.
*
......@@ -73,7 +73,7 @@ protected:
vector<Block_contain_type> Block_Contain;
int size;
int *index_vara;
int *index_vara, *index_equa;;
bool print_it, forward;
int minimal_solving_periods;
......@@ -82,9 +82,15 @@ protected:
bool Gaussian_Elimination, is_linear;
public:
bool steady_state;
bool linear_decomposition;
double *ghx, *ghu;
int *state_var_indx;
int n_state_var;
int *order_var;
double slowc;
Evaluate();
Evaluate(const int y_size_arg, const int y_kmin_arg, const int y_kmax_arg, const bool print_it_arg, const bool steady_state_arg, const int periods_arg, const int minimal_solving_periods_arg, const double slowc);
Evaluate(const int y_size_arg, const int y_kmin_arg, const int y_kmax_arg, const bool print_it_arg, const bool steady_state_arg, const bool linear_decomposition_arg, const int periods_arg, const int minimal_solving_periods_arg, const double slowc, double* ghx_arg, double* ghu_arg,
int n_state_var_arg, int* state_var_indx_arg, /*int* kstate_arg,*/ int* order_var_arg);
//typedef void (Interpreter::*InterfpreterMemFn)(const int block_num, const int size, const bool steady_state, int it);
void set_block(const int size_arg, const int type_arg, string file_name_arg, string bin_base_name_arg, const int block_num_arg,
const bool is_linear_arg, const int symbol_table_endo_nbr_arg, const int Block_List_Max_Lag_arg, const int Block_List_Max_Lead_arg, const int u_count_int_arg, const int block_arg);
......@@ -93,6 +99,9 @@ public:
void compute_complete_2b(const bool no_derivatives, double *_res1, double *_res2, double *_max_res, int *_max_res_idx);
bool compute_complete(double lambda, double *crit);
vector<int> non_linear_exogenous, non_linear_equation;
map<int, int> reverse_non_linear_equation;
};
#endif
This diff is collapsed.
/*
* Copyright (C) 2007-2017 Dynare Team
* Copyright (C) 2007-2018 Dynare Team
*
* This file is part of Dynare.
*
......@@ -47,8 +47,11 @@ private:
vector<int> previous_block_exogenous;
protected:
void evaluate_a_block(bool initialization);
int simulate_a_block(vector_table_conditional_local_type vector_table_conditional_local);
void print_a_block();
int simulate_a_block(vector_table_conditional_local_type *vector_table_conditional_local, bool to_release);
bool simulate_a_block_decomposed_model(vector_table_conditional_local_type *vector_table_conditional_local, table_conditional_global_type *table_conditional_global, bool to_release);
void Init_simulate_a_block(vector_table_conditional_local_type *vector_table_conditional_local);
void Free_simulate_a_block();
void print_a_block(string bin_base_name);
string elastic(string str, unsigned int len, bool left);
public:
~Interpreter();
......@@ -58,15 +61,19 @@ public:
int maxit_arg_, double solve_tolf_arg, size_t size_of_direction_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 global_temporary_terms_arg, bool print_arg, bool print_error_arg, mxArray *GlobalTemporaryTerms_arg,
bool steady_state_arg, bool print_it_arg, int col_x_arg, int col_y_arg
bool steady_state_arg, bool linear_decomposition, bool print_it_arg, int col_x_arg, int col_y_arg, double* ghx_arg, double* ghu_arg,
int n_state_var_arg, int* state_var_indx_arg, int* order_var_arg, vector<int> &non_linear_exogenous_arg, vector<int> & non_linear_equation_arg,
map<int, int> reverse_non_linear_equation_arg, size_t n_exogenous
#ifdef CUDA
, const int CUDA_device, cublasHandle_t cublas_handle_arg, cusparseHandle_t cusparse_handle_arg, cusparseMatDescr_t descr_arg
#endif
);
bool extended_path(string file_name, string bin_basename, bool evaluate, int block, int &nb_blocks, int nb_periods, vector<s_plan> sextended_path, vector<s_plan> sconstrained_extended_path, vector<string> dates, table_conditional_global_type table_conditional_global);
bool extended_path(string file_name, string bin_basename, bool evaluate, int block, int &nb_blocks, int nb_periods, vector<s_plan> sextended_path,
vector<s_plan> sconstrained_extended_path, vector<string> dates, table_conditional_global_type *table_conditional_global);
bool compute_blocks(string file_name, string bin_basename, bool evaluate, int block, int &nb_blocks);
void check_for_controlled_exo_validity(FBEGINBLOCK_ *fb, vector<s_plan> sconstrained_extended_path);
bool MainLoop(string bin_basename, CodeLoad code, bool evaluate, int block, bool last_call, bool constrained, vector<s_plan> sconstrained_extended_path, vector_table_conditional_local_type vector_table_conditional_local);
void check_for_controlled_exo_validity(FBEGINBLOCK_ *fb,vector<s_plan> sconstrained_extended_path);
void compute_first_order_solution(double* Sol, bool do_not_update_non_linear_equations, table_conditional_global_type *table_conditional_global);
bool MainLoop(string bin_basename, CodeLoad code, bool evaluate, int block, bool last_call, bool constrained, vector<s_plan> sconstrained_extended_path, vector_table_conditional_local_type *vector_table_conditional_local, table_conditional_global_type *table_conditional_global);
void ReadCodeFile(string file_name, CodeLoad &code);
inline mxArray *
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment