Bytecode: more simplifications and modernizations

time-shift
Sébastien Villemot 2021-02-09 15:55:36 +01:00
parent f317be1600
commit c9f6d3a626
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
10 changed files with 441 additions and 754 deletions

View File

@ -20,17 +20,22 @@
#ifndef ERROR_HANDLING #ifndef ERROR_HANDLING
#define ERROR_HANDLING #define ERROR_HANDLING
#include <cstring> #include <vector>
#include <iostream> #include <utility>
#include <sstream> #include <string>
#include <map> #include <map>
#include <tuple>
#include <cstddef>
#include <sstream>
#include <iostream>
#include <stack> #include <stack>
#define BYTE_CODE
#include "CodeInterpreter.hh"
#define _USE_MATH_DEFINES #define _USE_MATH_DEFINES
#include <cmath> #include <cmath>
#include <utility>
#include "dynmex.h"
#define BYTE_CODE
#include "CodeInterpreter.hh"
#ifdef OCTAVE_MEX_FILE #ifdef OCTAVE_MEX_FILE
# define CHAR_LENGTH 1 # define CHAR_LENGTH 1
@ -187,9 +192,9 @@ public:
ExpressionType EQN_type; ExpressionType EQN_type;
it_code_type it_code_expr; it_code_type it_code_expr;
/*unsigned int*/ size_t nb_endo, nb_exo, nb_param; size_t nb_endo, nb_exo, nb_param;
char *P_endo_names, *P_exo_names, *P_param_names; char *P_endo_names, *P_exo_names, *P_param_names;
size_t /*unsigned int*/ endo_name_length, exo_name_length, param_name_length; size_t endo_name_length, exo_name_length, param_name_length;
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;
vector<tuple<string, SymbolType, unsigned int>> Variable_list; vector<tuple<string, SymbolType, unsigned int>> Variable_list;
@ -243,10 +248,7 @@ public:
string temp; string temp;
int pos1 = -1, pos2 = -1; int pos1 = -1, pos2 = -1;
string tmp_n(str.length(), ' '); string tmp_n(str.length(), ' ');
string dollar, pound, tilde; string dollar{"$"}, pound{"£"}, tilde{"~"};
dollar = "$";
pound = "£";
tilde = "~";
for (const char & i : str) for (const char & i : str)
{ {
if (dollar.compare(&i) != 0 && pound.compare(&i) != 0) if (dollar.compare(&i) != 0 && pound.compare(&i) != 0)
@ -359,7 +361,7 @@ public:
inline string inline string
error_location(bool evaluate, bool steady_state, int size, int block_num, int it_, int Per_u_) error_location(bool evaluate, bool steady_state, int size, int block_num, int it_, int Per_u_)
{ {
stringstream Error_loc; ostringstream Error_loc;
if (!steady_state) if (!steady_state)
switch (EQN_type) switch (EQN_type)
{ {
@ -406,7 +408,7 @@ public:
Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to parameter " << get_variable(SymbolType::endogenous, EQN_dvar1) << " at time " << it_; Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to parameter " << get_variable(SymbolType::endogenous, EQN_dvar1) << " at time " << it_;
break; break;
default: default:
return ("???"); return "???";
} }
else else
switch (EQN_type) switch (EQN_type)

View File

@ -17,7 +17,6 @@
* along with Dynare. If not, see <http://www.gnu.org/licenses/>. * along with Dynare. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <cstring>
#include <sstream> #include <sstream>
#include <cmath> #include <cmath>
#include <limits> #include <limits>

View File

@ -20,13 +20,13 @@
#ifndef EVALUATE_HH_INCLUDED #ifndef EVALUATE_HH_INCLUDED
#define EVALUATE_HH_INCLUDED #define EVALUATE_HH_INCLUDED
#include <stack>
#include <vector> #include <vector>
#include <string> #include <string>
#include <cmath>
#include "dynmex.h"
#define BYTE_CODE #define BYTE_CODE
#include "CodeInterpreter.hh" #include "CodeInterpreter.hh"
#include <dynmex.h>
#include "ErrorHandling.hh" #include "ErrorHandling.hh"
class Evaluate : public ErrorMsg class Evaluate : public ErrorMsg

View File

@ -17,9 +17,10 @@
* along with Dynare. If not, see <http://www.gnu.org/licenses/>. * along with Dynare. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <cstring>
#include <sstream> #include <sstream>
#include <algorithm> #include <algorithm>
#include <cstring>
#include "Interpreter.hh" #include "Interpreter.hh"
constexpr double BIG = 1.0e+8, SMALL = 1.0e-5; constexpr double BIG = 1.0e+8, SMALL = 1.0e-5;
@ -440,7 +441,7 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_
res1 = 0; res1 = 0;
max_res = 0; max_res = 0;
max_res_idx = 0; max_res_idx = 0;
memcpy(y_save, y, y_size*sizeof(double)*(periods+y_kmax+y_kmin)); copy_n(y, y_size*(periods+y_kmax+y_kmin), y_save);
if (vector_table_conditional_local.size()) if (vector_table_conditional_local.size())
for (auto & it1 : vector_table_conditional_local) for (auto & it1 : vector_table_conditional_local)
if (it1.is_cond) if (it1.is_cond)
@ -450,7 +451,7 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_
if (!(isnan(res1) || isinf(res1))) if (!(isnan(res1) || isinf(res1)))
cvg = (max_res < solve_tolf); cvg = (max_res < solve_tolf);
if (isnan(res1) || isinf(res1) || (stack_solve_algo == 4 && iter > 0)) if (isnan(res1) || isinf(res1) || (stack_solve_algo == 4 && iter > 0))
memcpy(y, y_save, y_size*sizeof(double)*(periods+y_kmax+y_kmin)); copy_n(y_save, y_size*(periods+y_kmax+y_kmin), y);
u_count = u_count_saved; u_count = u_count_saved;
int prev_iter = iter; int prev_iter = iter;
Simulate_Newton_Two_Boundaries(block_num, symbol_table_endo_nbr, y_kmin, y_kmax, size, periods, cvg, minimal_solving_periods, stack_solve_algo, endo_name_length, P_endo_names, vector_table_conditional_local); Simulate_Newton_Two_Boundaries(block_num, symbol_table_endo_nbr, y_kmin, y_kmax, size, periods, cvg, minimal_solving_periods, stack_solve_algo, endo_name_length, P_endo_names, vector_table_conditional_local);
@ -736,9 +737,9 @@ Interpreter::MainLoop(const string &bin_basename, const CodeLoad &code, bool eva
mxFree(T); mxFree(T);
if (global_temporary_terms) if (global_temporary_terms)
{ {
if (GlobalTemporaryTerms == nullptr) if (!GlobalTemporaryTerms)
{ {
mexPrintf("GlobalTemporaryTerms is NULL\n"); mexPrintf("GlobalTemporaryTerms is nullptr\n");
mexEvalString("drawnow;"); mexEvalString("drawnow;");
} }
if (var != static_cast<int>(mxGetNumberOfElements(GlobalTemporaryTerms))) if (var != static_cast<int>(mxGetNumberOfElements(GlobalTemporaryTerms)))

View File

@ -20,15 +20,16 @@
#ifndef INTERPRETER_HH_INCLUDED #ifndef INTERPRETER_HH_INCLUDED
#define INTERPRETER_HH_INCLUDED #define INTERPRETER_HH_INCLUDED
#include <stack>
#include <vector> #include <vector>
#include <string> #include <string>
#include <cmath> #include <cstddef>
#include "dynmex.h"
#include "ErrorHandling.hh"
#include "SparseMatrix.hh"
#define BYTE_CODE #define BYTE_CODE
#include "CodeInterpreter.hh" #include "CodeInterpreter.hh"
#include "SparseMatrix.hh"
#include "Evaluate.hh"
#include <dynmex.h>
using namespace std; using namespace std;

View File

@ -19,6 +19,8 @@
#include "Mem_Mngr.hh" #include "Mem_Mngr.hh"
#include "dynmex.h"
Mem_Mngr::Mem_Mngr() Mem_Mngr::Mem_Mngr()
{ {
swp_f = false; swp_f = false;

View File

@ -20,10 +20,13 @@
#ifndef MEM_MNGR_HH_INCLUDED #ifndef MEM_MNGR_HH_INCLUDED
#define MEM_MNGR_HH_INCLUDED #define MEM_MNGR_HH_INCLUDED
#include "ErrorHandling.hh" #include <string>
#include <vector> #include <vector>
#include <fstream> #include <fstream>
#include <dynmex.h>
#include "ErrorHandling.hh"
using namespace std;
struct NonZeroElem struct NonZeroElem
{ {

File diff suppressed because it is too large Load Diff

View File

@ -20,16 +20,19 @@
#ifndef SPARSEMATRIX_HH_INCLUDED #ifndef SPARSEMATRIX_HH_INCLUDED
#define SPARSEMATRIX_HH_INCLUDED #define SPARSEMATRIX_HH_INCLUDED
#include <stack> #include <utility>
#include <cmath> #include <vector>
#include <map> #include <map>
#include <ctime>
#include <tuple> #include <tuple>
#include "dynblas.h" #include <stack>
#include <fstream>
#include <string>
#include <ctime>
#include "dynumfpack.h" #include "dynumfpack.h"
#include "dynmex.h"
#include "Mem_Mngr.hh" #include "Mem_Mngr.hh"
#include "ErrorHandling.hh"
#include "Evaluate.hh" #include "Evaluate.hh"
using namespace std; using namespace std;
@ -50,7 +53,7 @@ class dynSparseMatrix : public Evaluate
public: public:
dynSparseMatrix(); dynSparseMatrix();
dynSparseMatrix(int y_size_arg, int y_kmin_arg, int y_kmax_arg, bool print_it_arg, bool steady_state_arg, int periods_arg, int minimal_solving_periods_arg, double slowc_arg); dynSparseMatrix(int y_size_arg, int y_kmin_arg, int y_kmax_arg, bool print_it_arg, bool steady_state_arg, int periods_arg, int minimal_solving_periods_arg, double slowc_arg);
void Simulate_Newton_Two_Boundaries(int blck, int y_size, int y_kmin, int y_kmax, int Size, int periods, bool cvg, int minimal_solving_periods, int stack_solve_algo, unsigned int endo_name_length, char *P_endo_names, vector_table_conditional_local_type vector_table_conditional_local); void Simulate_Newton_Two_Boundaries(int blck, int y_size, int y_kmin, int y_kmax, int Size, int periods, bool cvg, int minimal_solving_periods, int stack_solve_algo, unsigned int endo_name_length, const char *P_endo_names, const vector_table_conditional_local_type &vector_table_conditional_local);
void Simulate_Newton_One_Boundary(bool forward); void Simulate_Newton_One_Boundary(bool forward);
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(const string &file_name, int Size, int periods, int y_kmin, int y_kmax, bool two_boundaries, int stack_solve_algo, int solve_algo); void Read_SparseMatrix(const string &file_name, int Size, int periods, int y_kmin, int y_kmax, bool two_boundaries, int stack_solve_algo, int solve_algo);
@ -93,7 +96,6 @@ private:
void solve_non_linear(int block_num, int y_size, int y_kmin, int y_kmax, int size); void solve_non_linear(int block_num, int y_size, int y_kmin, int y_kmax, int size);
string preconditioner_print_out(string s, int preconditioner, bool ss); string preconditioner_print_out(string s, int preconditioner, bool ss);
bool compare(int *save_op, int *save_opa, int *save_opaa, int beg_t, int periods, long nop4, int Size); bool compare(int *save_op, int *save_opa, int *save_opaa, int beg_t, int periods, long nop4, int Size);
void Grad_f_product(int n, mxArray *b_m, double *vectr, mxArray *A_m, SuiteSparse_long *Ap, SuiteSparse_long *Ai, double *Ax, double *b);
void Insert(int r, int c, int u_index, int lag_index); void Insert(int r, int c, int u_index, int lag_index);
void Delete(int r, int c); void Delete(int r, int c);
int At_Row(int r, NonZeroElem **first) const; int At_Row(int r, NonZeroElem **first) const;

View File

@ -16,13 +16,13 @@
* 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/>.
*/ */
#include <cstring>
#include "Interpreter.hh"
#include "ErrorHandling.hh"
#include <ctime> #include <ctime>
#include <cmath> #include <cmath>
#include <cstring>
void (*prev_fn)(int); #include "Interpreter.hh"
#include "ErrorHandling.hh"
string string
Get_Argument(const mxArray *prhs) Get_Argument(const mxArray *prhs)
@ -39,9 +39,6 @@ Get_Argument(const mxArray *prhs)
return f; return f;
} }
//#include <windows.h>
#include <cstdio>
string string
deblank(string x) deblank(string x)
{ {
@ -254,82 +251,42 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
if (extended_path) if (extended_path)
{ {
if (extended_path_struct == nullptr) if (!extended_path_struct)
{ mexErrMsgTxt("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";
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 == nullptr) if (!date_str)
{ mexErrMsgTxt("The extended_path description structure does not contain the member: date_str");
string tmp = "date_str";
tmp.insert(0, "The extended_path description structure does not contain the member: ");
mexErrMsgTxt(tmp.c_str());
}
int nb_periods = mxGetM(date_str) * mxGetN(date_str); int nb_periods = mxGetM(date_str) * mxGetN(date_str);
mxArray *constrained_vars_ = mxGetField(extended_path_struct, 0, "constrained_vars_"); mxArray *constrained_vars_ = mxGetField(extended_path_struct, 0, "constrained_vars_");
if (constrained_vars_ == nullptr) if (!constrained_vars_)
{ mexErrMsgTxt("The extended_path description structure does not contain the member: constrained_vars_");
string tmp = "constrained_vars_";
tmp.insert(0, "The extended_path description structure does not contain the member: ");
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_ == nullptr) if (!constrained_paths_)
{ mexErrMsgTxt("The extended_path description structure does not contain the member: constrained_paths_");
string tmp = "constrained_paths_";
tmp.insert(0, "The extended_path description structure does not contain the member: ");
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_ == nullptr) if (!constrained_int_date_)
{ mexErrMsgTxt("The extended_path description structure does not contain the member: constrained_int_date_");
string tmp = "constrained_int_date_";
tmp.insert(0, "The extended_path description structure does not contain the member: ");
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_ == nullptr) if (!constrained_perfect_foresight_)
{ mexErrMsgTxt("The extended_path description structure does not contain the member: constrained_perfect_foresight_");
string tmp = "constrained_perfect_foresight_";
tmp.insert(0, "The extended_path description structure does not contain the member: ");
mexErrMsgTxt(tmp.c_str());
}
mxArray *shock_var_ = mxGetField(extended_path_struct, 0, "shock_vars_"); mxArray *shock_var_ = mxGetField(extended_path_struct, 0, "shock_vars_");
if (shock_var_ == nullptr) if (!shock_var_)
{ mexErrMsgTxt("The extended_path description structure does not contain the member: shock_vars_");
string tmp = "shock_vars_";
tmp.insert(0, "The extended_path description structure does not contain the member: ");
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_ == nullptr) if (!shock_paths_)
{ mexErrMsgTxt("The extended_path description structure does not contain the member: shock_paths_");
string tmp = "shock_paths_";
tmp.insert(0, "The extended_path description structure does not contain the member: ");
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_ == nullptr) if (!shock_int_date_)
{ mexErrMsgTxt("The extended_path description structure does not contain the member: shock_int_date_");
string tmp = "shock_int_date_";
tmp.insert(0, "The extended_path description structure does not contain the member: ");
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_ == nullptr) if (!shock_str_date_)
{ mexErrMsgTxt("The extended_path description structure does not contain the member: shock_str_date_");
string tmp = "shock_str_date_";
tmp.insert(0, "The extended_path description structure does not contain the member: ");
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;
mxArray *options_cond_fcst_ = mxGetField(extended_path_struct, 0, "options_cond_fcst_"); mxArray *options_cond_fcst_ = mxGetField(extended_path_struct, 0, "options_cond_fcst_");
mxArray *controlled_varexo = nullptr; mxArray *controlled_varexo = nullptr;
if (options_cond_fcst_ != nullptr) if (options_cond_fcst_)
{ {
controlled_varexo = mxGetField(options_cond_fcst_, 0, "controlled_varexo"); controlled_varexo = mxGetField(options_cond_fcst_, 0, "controlled_varexo");
nb_controlled = mxGetM(controlled_varexo) * mxGetN(controlled_varexo); nb_controlled = mxGetM(controlled_varexo) * mxGetN(controlled_varexo);
@ -337,7 +294,7 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
mexErrMsgTxt("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 = nullptr; double *controlled_varexo_value = nullptr;
if (controlled_varexo != nullptr) if (controlled_varexo)
controlled_varexo_value = mxGetPr(controlled_varexo); controlled_varexo_value = mxGetPr(controlled_varexo);
double *constrained_var_value = mxGetPr(constrained_vars_); double *constrained_var_value = mxGetPr(constrained_vars_);
sconditional_extended_path.resize(nb_constrained); sconditional_extended_path.resize(nb_constrained);
@ -372,7 +329,7 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
int *constrained_int_date = static_cast<int *>(mxMalloc(nb_local_periods * sizeof(int))); int *constrained_int_date = static_cast<int *>(mxMalloc(nb_local_periods * sizeof(int)));
error_msg.test_mxMalloc(constrained_int_date, __LINE__, __FILE__, __func__, nb_local_periods * sizeof(int)); error_msg.test_mxMalloc(constrained_int_date, __LINE__, __FILE__, __func__, nb_local_periods * sizeof(int));
if (nb_periods < nb_local_periods) if (nb_periods < nb_local_periods)
mexErrMsgTxt((string{"The total number of simulation periods ("} + to_string(nb_periods) mexErrMsgTxt(("The total number of simulation periods (" + to_string(nb_periods)
+ ") is lesser than the number of periods in the shock definitions (" + ") is lesser than the number of periods in the shock definitions ("
+ to_string(nb_local_periods)).c_str()); + to_string(nb_local_periods)).c_str());
@ -426,10 +383,7 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
char *buf = static_cast<char *>(mxCalloc(buflen, sizeof(char))); char *buf = static_cast<char *>(mxCalloc(buflen, sizeof(char)));
int info = mxGetString(mxGetCell(date_str, i), buf, buflen); int info = mxGetString(mxGetCell(date_str, i), buf, buflen);
if (info) if (info)
{ mexErrMsgTxt("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";
mexErrMsgTxt(tmp.c_str());
}
dates.emplace_back(buf); //string(Dates[i]); dates.emplace_back(buf); //string(Dates[i]);
mxFree(buf); mxFree(buf);
} }
@ -437,12 +391,8 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
if (plan.length() > 0) if (plan.length() > 0)
{ {
mxArray *plan_struct = mexGetVariable("base", plan.c_str()); mxArray *plan_struct = mexGetVariable("base", plan.c_str());
if (plan_struct == nullptr) if (!plan_struct)
{ mexErrMsgTxt(("Can't find the plan: " + plan).c_str());
string tmp = plan;
tmp.insert(0, "Can't find the plan: ");
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);
for (int i = 0; i < static_cast<int>(n_plan); i++) for (int i = 0; i < static_cast<int>(n_plan); i++)
@ -460,12 +410,7 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
if (variable_type == SymbolType::exogenous || variable_type == SymbolType::exogenousDet) if (variable_type == SymbolType::exogenous || variable_type == SymbolType::exogenousDet)
splan[i].var_num = exo_num; splan[i].var_num = exo_num;
else else
{ mexErrMsgTxt(("The variable '" + string{name} + "' defined as var in plan is not an exogenous or a deterministic exogenous\n").c_str());
string tmp = name;
tmp.insert(0, "the variable '");
tmp.append("' defined as var in plan is not an exogenous or a deterministic exogenous\n");
mexErrMsgTxt(tmp.c_str());
}
} }
tmp = mxGetField(plan_struct, i, "var"); tmp = mxGetField(plan_struct, i, "var");
if (tmp) if (tmp)
@ -478,12 +423,7 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
if (variable_type == SymbolType::endogenous) if (variable_type == SymbolType::endogenous)
splan[i].exo_num = exo_num; splan[i].exo_num = exo_num;
else else
{ mexErrMsgTxt(("The variable '" + string{name} + "' defined as exo in plan is not an endogenous variable\n").c_str());
string tmp = name;
tmp.insert(0, "the variable '");
tmp.append("' defined as exo in plan is not an endogenous variable\n");
mexErrMsgTxt(tmp.c_str());
}
} }
tmp = mxGetField(plan_struct, i, "per_value"); tmp = mxGetField(plan_struct, i, "per_value");
if (tmp) if (tmp)
@ -532,12 +472,7 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
if (variable_type == SymbolType::exogenous || variable_type == SymbolType::exogenousDet) if (variable_type == SymbolType::exogenous || variable_type == SymbolType::exogenousDet)
splan[i].var_num = exo_num; splan[i].var_num = exo_num;
else else
{ mexErrMsgTxt(("The variable '" + string{name} + "' defined as var in pfplan is not an exogenous or a deterministic exogenous\n").c_str());
string tmp = name;
tmp.insert(0, "the variable '");
tmp.append("' defined as var in pfplan is not an exogenous or a deterministic exogenous\n");
mexErrMsgTxt(tmp.c_str());
}
} }
tmp = mxGetField(pfplan_struct, i, "exo"); tmp = mxGetField(pfplan_struct, i, "exo");
if (tmp) if (tmp)
@ -550,12 +485,7 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
if (variable_type == SymbolType::endogenous) if (variable_type == SymbolType::endogenous)
spfplan[i].exo_num = exo_num; spfplan[i].exo_num = exo_num;
else else
{ mexErrMsgTxt(("The variable '" + string{name} + "' defined as exo in pfplan is not an endogenous variable\n").c_str());
string tmp = name;
tmp.insert(0, "the variable '");
tmp.append("' defined as exo in pfplan is not an endogenous variable\n");
mexErrMsgTxt(tmp.c_str());
}
} }
tmp = mxGetField(pfplan_struct, i, "per_value"); tmp = mxGetField(pfplan_struct, i, "per_value");
if (tmp) if (tmp)
@ -828,11 +758,7 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
} }
else else
{ {
int out_periods; int out_periods = extended_path ? max_periods + y_kmin : row_y;
if (extended_path)
out_periods = max_periods + y_kmin;
else
out_periods = row_y;
plhs[0] = mxCreateDoubleMatrix(out_periods, static_cast<int>(col_y), mxREAL); plhs[0] = mxCreateDoubleMatrix(out_periods, static_cast<int>(col_y), mxREAL);
pind = mxGetPr(plhs[0]); pind = mxGetPr(plhs[0]);
for (i = 0; i < out_periods*col_y; i++) for (i = 0; i < out_periods*col_y; i++)
@ -841,11 +767,7 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
} }
else else
{ {
int out_periods; int out_periods = extended_path ? max_periods + y_kmin : col_y;
if (extended_path)
out_periods = max_periods + y_kmin;
else
out_periods = col_y;
plhs[0] = mxCreateDoubleMatrix(static_cast<int>(row_y), out_periods, mxREAL); plhs[0] = mxCreateDoubleMatrix(static_cast<int>(row_y), out_periods, mxREAL);
pind = mxGetPr(plhs[0]); pind = mxGetPr(plhs[0]);
if (evaluate) if (evaluate)
@ -862,7 +784,8 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{ {
if (evaluate) if (evaluate)
{ {
int jacob_field_number = 0, jacob_exo_field_number = 0, jacob_exo_det_field_number = 0, jacob_other_endo_field_number = 0; 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) if (!block_structur)
{ {
const char *field_names[] = {"g1", "g1_x", "g1_xd", "g1_o"}; const char *field_names[] = {"g1", "g1_x", "g1_xd", "g1_o"};
@ -895,18 +818,16 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
mexErrMsgTxt("Fatal error in bytecode: in main, cannot add extra field jacob_other_endo to the structArray\n"); mexErrMsgTxt("Fatal error in bytecode: in main, cannot add extra field jacob_other_endo to the structArray\n");
} }
if (!dont_store_a_structure) if (!dont_store_a_structure)
{ for (int i = 0; i < nb_blocks; i++)
for (int i = 0; i < nb_blocks; i++) {
{ mxSetFieldByNumber(plhs[1], i, jacob_field_number, interprete.get_jacob(i));
mxSetFieldByNumber(plhs[1], i, jacob_field_number, interprete.get_jacob(i)); if (!steady_state)
if (!steady_state) {
{ mxSetFieldByNumber(plhs[1], i, jacob_exo_field_number, interprete.get_jacob_exo(i));
mxSetFieldByNumber(plhs[1], i, jacob_exo_field_number, interprete.get_jacob_exo(i)); mxSetFieldByNumber(plhs[1], i, jacob_exo_det_field_number, interprete.get_jacob_exo_det(i));
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[1], i, jacob_other_endo_field_number, interprete.get_jacob_other_endo(i)); }
} }
}
}
} }
else else
{ {