From e22972849b74de7a3835b41fb13eb8f5522e6a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Tue, 18 Apr 2023 15:59:03 +0200 Subject: [PATCH] Bytecode: make Evaluate::{symbol_table, steady_state} private and const --- mex/sources/bytecode/Evaluate.cc | 2 +- mex/sources/bytecode/Evaluate.hh | 8 ++++---- mex/sources/bytecode/Interpreter.cc | 2 +- mex/sources/bytecode/Interpreter.hh | 2 +- mex/sources/bytecode/SparseMatrix.cc | 4 +++- mex/sources/bytecode/SparseMatrix.hh | 5 ++++- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/mex/sources/bytecode/Evaluate.cc b/mex/sources/bytecode/Evaluate.cc index 2fb0e8cdcd..b1b3ec3fdd 100644 --- a/mex/sources/bytecode/Evaluate.cc +++ b/mex/sources/bytecode/Evaluate.cc @@ -29,7 +29,7 @@ #include "CommonEnums.hh" #include "ErrorHandling.hh" -Evaluate::Evaluate(bool steady_state_arg, BasicSymbolTable &symbol_table_arg) : +Evaluate::Evaluate(bool steady_state_arg, const BasicSymbolTable &symbol_table_arg) : symbol_table {symbol_table_arg}, steady_state {steady_state_arg} { diff --git a/mex/sources/bytecode/Evaluate.hh b/mex/sources/bytecode/Evaluate.hh index 09d5accbae..2d6a0f8697 100644 --- a/mex/sources/bytecode/Evaluate.hh +++ b/mex/sources/bytecode/Evaluate.hh @@ -36,6 +36,9 @@ private: using instructions_list_t = vector<BytecodeInstruction *>; using it_code_type = instructions_list_t::const_iterator; + const BasicSymbolTable &symbol_table; + const bool steady_state; // Whether this is a static or dynamic .cod file + // Memory copy of the contents of the .cod file unique_ptr<char[]> raw_bytecode; @@ -76,11 +79,8 @@ private: } protected: - BasicSymbolTable &symbol_table; void evaluateBlock(int it_, double *__restrict__ y, const double *__restrict__ ya, int y_size, double *__restrict__ x, int nb_row_x, double *__restrict__ params, const double *__restrict__ steady_y, double *__restrict__ u, int Per_u_, double *__restrict__ T, int T_nrows, map<int, double> &TEF, map<pair<int, int>, double> &TEFD, map<tuple<int, int, int>, double> &TEFDD, double *__restrict__ r, double *__restrict__ g1, double *__restrict__ jacob, double *__restrict__ jacob_exo, double *__restrict__ jacob_exo_det, bool evaluate, bool no_derivatives); - bool steady_state; - /* Prints a bytecode expression in human readable form. If faulty_op is not default constructed, it should point to a tag within the expression that created a floating point exception, in which case the @@ -147,7 +147,7 @@ protected: } public: - Evaluate(bool steady_state_arg, BasicSymbolTable &symbol_table_arg); + Evaluate(bool steady_state_arg, const BasicSymbolTable &symbol_table_arg); // TODO: integrate into the constructor void loadCodeFile(const filesystem::path &codfile); diff --git a/mex/sources/bytecode/Interpreter.cc b/mex/sources/bytecode/Interpreter.cc index eeae7b364c..60476d7250 100644 --- a/mex/sources/bytecode/Interpreter.cc +++ b/mex/sources/bytecode/Interpreter.cc @@ -34,7 +34,7 @@ Interpreter::Interpreter(double *params_arg, double *y_arg, double *ya_arg, doub int maxit_arg_, double solve_tolf_arg, size_t size_of_direction_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 block_decomposed_arg, bool print_it_arg, int col_x_arg, int col_y_arg, BasicSymbolTable &symbol_table_arg) + bool steady_state_arg, bool block_decomposed_arg, bool print_it_arg, int col_x_arg, int col_y_arg, const BasicSymbolTable &symbol_table_arg) : dynSparseMatrix {y_size_arg, y_kmin_arg, y_kmax_arg, print_it_arg, steady_state_arg, block_decomposed_arg, periods_arg, minimal_solving_periods_arg, symbol_table_arg, print_error_arg} { params = params_arg; diff --git a/mex/sources/bytecode/Interpreter.hh b/mex/sources/bytecode/Interpreter.hh index c77291a275..efe90d3426 100644 --- a/mex/sources/bytecode/Interpreter.hh +++ b/mex/sources/bytecode/Interpreter.hh @@ -57,7 +57,7 @@ public: int maxit_arg_, double solve_tolf_arg, size_t size_of_direction_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 block_decomposed_arg, bool print_it_arg, int col_x_arg, int col_y_arg, BasicSymbolTable &symbol_table_arg); + bool steady_state_arg, bool block_decomposed_arg, bool print_it_arg, int col_x_arg, int col_y_arg, const BasicSymbolTable &symbol_table_arg); pair<bool, vector<int>> extended_path(const string &file_name, bool evaluate, int block, int nb_periods, const vector<s_plan> &sextended_path, const vector<s_plan> &sconstrained_extended_path, const vector<string> &dates, const table_conditional_global_type &table_conditional_global); pair<bool, vector<int>> compute_blocks(const string &file_name, bool evaluate, int block); void check_for_controlled_exo_validity(int current_block, const vector<s_plan> &sconstrained_extended_path); diff --git a/mex/sources/bytecode/SparseMatrix.cc b/mex/sources/bytecode/SparseMatrix.cc index 574dacde79..f9f2ccfa33 100644 --- a/mex/sources/bytecode/SparseMatrix.cc +++ b/mex/sources/bytecode/SparseMatrix.cc @@ -25,9 +25,11 @@ #include "SparseMatrix.hh" dynSparseMatrix::dynSparseMatrix(int y_size_arg, int y_kmin_arg, int y_kmax_arg, bool print_it_arg, bool steady_state_arg, bool block_decomposed_arg, int periods_arg, - int minimal_solving_periods_arg, BasicSymbolTable &symbol_table_arg, + int minimal_solving_periods_arg, const BasicSymbolTable &symbol_table_arg, bool print_error_arg) : Evaluate {steady_state_arg, symbol_table_arg}, + symbol_table {symbol_table_arg}, + steady_state {steady_state_arg}, block_decomposed {block_decomposed_arg}, minimal_solving_periods {minimal_solving_periods_arg}, print_it {print_it_arg}, diff --git a/mex/sources/bytecode/SparseMatrix.hh b/mex/sources/bytecode/SparseMatrix.hh index 2f69253f47..6d26f6d7e6 100644 --- a/mex/sources/bytecode/SparseMatrix.hh +++ b/mex/sources/bytecode/SparseMatrix.hh @@ -68,7 +68,7 @@ constexpr double mem_increasing_factor = 1.1; class dynSparseMatrix : public Evaluate { public: - dynSparseMatrix(int y_size_arg, int y_kmin_arg, int y_kmax_arg, bool print_it_arg, bool steady_state_arg, bool block_decomposed_arg, int periods_arg, int minimal_solving_periods_arg, BasicSymbolTable &symbol_table_arg, bool print_error_arg); + dynSparseMatrix(int y_size_arg, int y_kmin_arg, int y_kmax_arg, bool print_it_arg, bool steady_state_arg, bool block_decomposed_arg, int periods_arg, int minimal_solving_periods_arg, const BasicSymbolTable &symbol_table_arg, bool print_error_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, const vector_table_conditional_local_type &vector_table_conditional_local); void Simulate_Newton_One_Boundary(bool forward); void fixe_u(double **u, int u_count_int, int max_lag_plus_max_lead_plus_1); @@ -141,6 +141,9 @@ private: // Computes A−B where A and B are dense. The result is dense. static mxArray *subtract_A_B(const mxArray *A_m, const mxArray *B_m); protected: + const BasicSymbolTable &symbol_table; + const bool steady_state; // Whether this is a static or dynamic model + // Whether to use the block-decomposed version of the bytecode file bool block_decomposed; -- GitLab