Block decomposition: drop unused max lead/lag fields

Note that DynamicModel::determineBlockDerivativesType(), it’s legitimate to
replace max_{lead,lag} by max_endo_{lead,lag}, because for exogenous
lag=lead=0, and we no longer compute derivatives w.r.t. to endogenous that do
not belong to the block (so-called “other” endogenous).
master
Sébastien Villemot 2023-01-17 14:41:02 +01:00
parent 2e09df90e7
commit 4bba274f39
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
6 changed files with 6 additions and 67 deletions

View File

@ -82,8 +82,6 @@ operator<<(BytecodeWriter &code_file, const FBEGINBLOCK_ &instr)
{
code_file.write(reinterpret_cast<const char *>(&instr.is_linear), sizeof instr.is_linear);
code_file.write(reinterpret_cast<const char *>(&instr.endo_nbr), sizeof instr.endo_nbr);
code_file.write(reinterpret_cast<const char *>(&instr.Max_Lag), sizeof instr.Max_Lag);
code_file.write(reinterpret_cast<const char *>(&instr.Max_Lead), sizeof instr.Max_Lead);
code_file.write(reinterpret_cast<const char *>(&instr.u_count_int), sizeof instr.u_count_int);
}
code_file.write(reinterpret_cast<const char *>(&instr.nb_col_jacob), sizeof instr.nb_col_jacob);

View File

@ -899,8 +899,6 @@ private:
bool is_linear{false};
vector<Block_contain_type> Block_Contain_;
int endo_nbr{0};
int Max_Lag{0};
int Max_Lead{0};
int u_count_int{0};
int nb_col_jacob{0};
int det_exo_size, exo_size;
@ -914,7 +912,7 @@ public:
derivatives w.r.t. endogenous not belonging to the block) */
FBEGINBLOCK_(int size_arg, BlockSimulationType type_arg, int first_element, int block_size,
const vector<int> &variable_arg, const vector<int> &equation_arg,
bool is_linear_arg, int endo_nbr_arg, int Max_Lag_arg, int Max_Lead_arg, int u_count_int_arg, int nb_col_jacob_arg,
bool is_linear_arg, int endo_nbr_arg, int u_count_int_arg, int nb_col_jacob_arg,
int det_exo_size_arg, int exo_size_arg,
vector<int> det_exogenous_arg, vector<int> exogenous_arg) :
BytecodeInstruction{Tags::FBEGINBLOCK},
@ -926,8 +924,6 @@ public:
det_exogenous{move(det_exogenous_arg)},
is_linear{is_linear_arg},
endo_nbr{endo_nbr_arg},
Max_Lag{Max_Lag_arg},
Max_Lead{Max_Lead_arg},
u_count_int{u_count_int_arg},
nb_col_jacob{nb_col_jacob_arg},
det_exo_size{det_exo_size_arg},
@ -937,7 +933,7 @@ public:
// Constructor when derivatives w.r.t. exogenous are absent
FBEGINBLOCK_(int size_arg, BlockSimulationType type_arg, int first_element, int block_size,
const vector<int> &variable_arg, const vector<int> &equation_arg,
bool is_linear_arg, int endo_nbr_arg, int Max_Lag_arg, int Max_Lead_arg, int u_count_int_arg, int nb_col_jacob_arg) :
bool is_linear_arg, int endo_nbr_arg, int u_count_int_arg, int nb_col_jacob_arg) :
BytecodeInstruction{Tags::FBEGINBLOCK},
size{size_arg},
type{type_arg},
@ -945,8 +941,6 @@ public:
equation{equation_arg.begin()+first_element, equation_arg.begin()+(first_element+block_size)},
is_linear{is_linear_arg},
endo_nbr{endo_nbr_arg},
Max_Lag{Max_Lag_arg},
Max_Lead{Max_Lead_arg},
u_count_int{u_count_int_arg},
nb_col_jacob{nb_col_jacob_arg},
det_exo_size{0},
@ -974,16 +968,6 @@ public:
return endo_nbr;
};
int
get_Max_Lag()
{
return Max_Lag;
};
int
get_Max_Lead()
{
return Max_Lead;
};
int
get_u_count_int()
{
return u_count_int;
@ -1040,8 +1024,6 @@ public:
{
memcpy(&is_linear, code, sizeof(is_linear)); code += sizeof(is_linear);
memcpy(&endo_nbr, code, sizeof(endo_nbr)); code += sizeof(endo_nbr);
memcpy(&Max_Lag, code, sizeof(Max_Lag)); code += sizeof(Max_Lag);
memcpy(&Max_Lead, code, sizeof(Max_Lead)); code += sizeof(Max_Lead);
memcpy(&u_count_int, code, sizeof(u_count_int)); code += sizeof(u_count_int);
}
memcpy(&nb_col_jacob, code, sizeof(nb_col_jacob)); code += sizeof(nb_col_jacob);

View File

@ -182,8 +182,6 @@ DynamicModel::writeDynamicBytecode(const string &basename) const
eq_idx,
false,
symbol_table.endo_nbr(),
max_endo_lag,
max_endo_lead,
u_count_int,
jacobian_ncols_endo,
symbol_table.exo_det_nbr(),
@ -230,8 +228,6 @@ DynamicModel::writeDynamicBlockBytecode(const string &basename) const
eq_idx_block2orig,
blocks[block].linear,
symbol_table.endo_nbr(),
blocks[block].max_lag,
blocks[block].max_lead,
u_count,
static_cast<int>(blocks_jacob_cols_endo[block].size())};
@ -2309,8 +2305,8 @@ DynamicModel::determineBlockDerivativesType(int blk)
map<tuple<int, int, int>, BlockDerivativeType> derivType;
int size = blocks[blk].size;
int nb_recursive = blocks[blk].getRecursiveSize();
for (int lag {time_recursive_block_decomposition ? 0 : -blocks[blk].max_lag};
lag <= (time_recursive_block_decomposition ? 0 : blocks[blk].max_lead);
for (int lag {time_recursive_block_decomposition ? 0 : -blocks[blk].max_endo_lag};
lag <= (time_recursive_block_decomposition ? 0 : blocks[blk].max_endo_lead);
lag++)
for (int eq = 0; eq < size; eq++)
{

View File

@ -536,16 +536,13 @@ ModelTree::computeDynamicStructureOfBlock(int blk)
{
vector max_endo_lag_lead(blocks[blk].size, pair{0, 0});
blocks[blk].max_endo_lag = blocks[blk].max_endo_lead = 0;
blocks[blk].max_other_endo_lag = blocks[blk].max_other_endo_lead = 0;
blocks[blk].max_exo_lag = blocks[blk].max_exo_lead = 0;
blocks[blk].max_exo_det_lag = blocks[blk].max_exo_det_lead = 0;
for (int eq = 0; eq < blocks[blk].size; eq++)
{
set<pair<int, int>> endos_and_lags;
expr_t e = getBlockEquationExpr(blk, eq);
/* Compute max lags/leads for endogenous. Also fill per-variable structure
for endos belonging to this block */
/* Compute max lags/leads and per-variable structure for endos belonging
to this block */
e->collectEndogenous(endos_and_lags);
for (auto [endo, lag] : endos_and_lags)
if (endo2block[endo] == blk)
@ -556,33 +553,7 @@ ModelTree::computeDynamicStructureOfBlock(int blk)
max_endo_lag = max(max_endo_lag, -lag);
max_endo_lead = max(max_endo_lead, lag);
}
else
{
blocks[blk].max_other_endo_lag = max(blocks[blk].max_other_endo_lag, -lag);
blocks[blk].max_other_endo_lead = max(blocks[blk].max_other_endo_lead, lag);
}
// Compute max lags/leads for exogenous
blocks[blk].max_exo_lag = max(e->maxExoLag(), blocks[blk].max_exo_lag);
blocks[blk].max_exo_lead = max(e->maxExoLead(), blocks[blk].max_exo_lead);
// Compute max lags/leads for deterministic exogenous
set<pair<int, int>> dynvars;
e->collectDynamicVariables(SymbolType::exogenousDet, dynvars);
for (auto [symb_id, lag] : dynvars)
{
blocks[blk].max_exo_det_lag = max(-lag, blocks[blk].max_exo_det_lag);
blocks[blk].max_exo_det_lead = max(lag, blocks[blk].max_exo_det_lead);
}
}
// Compute max lags/leads over all variables
blocks[blk].max_lag = max(blocks[blk].max_endo_lag, max(blocks[blk].max_other_endo_lag,
max(blocks[blk].max_exo_lag,
blocks[blk].max_exo_det_lag)));
blocks[blk].max_lead = max(blocks[blk].max_endo_lead, max(blocks[blk].max_other_endo_lead,
max(blocks[blk].max_exo_lead,
blocks[blk].max_exo_det_lead)));
}
void

View File

@ -196,10 +196,6 @@ protected:
int mfs_size{0}; // Size of the minimal feedback set
bool linear{true}; // Whether the block is linear in endogenous variable
int max_endo_lag{0}, max_endo_lead{0}; // Maximum lag/lead on endos that appear in and *that belong to* the block
int max_other_endo_lag{0}, max_other_endo_lead{0}; // Maximum lag/lead on endos that appear in but do not belong to the block
int max_exo_lag{0}, max_exo_lead{0};
int max_exo_det_lag{0}, max_exo_det_lead{0};
int max_lag{0}, max_lead{0}; // The max over all endo/exo variables
int
getRecursiveSize() const

View File

@ -118,8 +118,6 @@ StaticModel::writeStaticBytecode(const string &basename) const
eq_idx,
false,
symbol_table.endo_nbr(),
0,
0,
u_count_int,
symbol_table.endo_nbr()};
@ -160,8 +158,6 @@ StaticModel::writeStaticBlockBytecode(const string &basename) const
eq_idx_block2orig,
blocks[block].linear,
symbol_table.endo_nbr(),
0,
0,
u_count,
block_size};