Fix orig_lead_lag field for unary op auxiliary variables

Ref. dynare#1843
last-simulation-period
Sébastien Villemot 2022-01-19 15:05:59 +01:00
parent d149d3a76c
commit 064a3dcd77
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
1 changed files with 7 additions and 5 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright © 2007-2021 Dynare Team * Copyright © 2007-2022 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
@ -3525,7 +3525,10 @@ UnaryOpNode::substituteUnaryOpNodes(const lag_equivalence_table_t &nodes, subst_
must be substituted. We create the auxiliary variable and fill the must be substituted. We create the auxiliary variable and fill the
substitution table for all those similar nodes, in an iteration going from substitution table for all those similar nodes, in an iteration going from
leads to lags. */ leads to lags. */
int base_index = 0; int base_index = it->second.rbegin()->first; // Within the equivalence class,
// index of the node that will
// be used as the definition for
// the aux var.
VariableNode *aux_var = nullptr; VariableNode *aux_var = nullptr;
for (auto rit = it->second.rbegin(); rit != it->second.rend(); ++rit) for (auto rit = it->second.rbegin(); rit != it->second.rend(); ++rit)
if (rit == it->second.rbegin()) if (rit == it->second.rbegin())
@ -3540,9 +3543,9 @@ UnaryOpNode::substituteUnaryOpNodes(const lag_equivalence_table_t &nodes, subst_
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
auto argsubst_shifted = argsubst->decreaseLeadsLags(index - base_index);
int symb_id; int symb_id;
auto vn = dynamic_cast<VariableNode *>(argsubst); if (auto vn = dynamic_cast<VariableNode *>(argsubst_shifted); !vn)
if (!vn)
symb_id = datatree.symbol_table.addUnaryOpAuxiliaryVar(this->idx, dynamic_cast<UnaryOpNode *>(rit->second), unary_op); symb_id = datatree.symbol_table.addUnaryOpAuxiliaryVar(this->idx, dynamic_cast<UnaryOpNode *>(rit->second), unary_op);
else else
symb_id = datatree.symbol_table.addUnaryOpAuxiliaryVar(this->idx, dynamic_cast<UnaryOpNode *>(rit->second), unary_op, symb_id = datatree.symbol_table.addUnaryOpAuxiliaryVar(this->idx, dynamic_cast<UnaryOpNode *>(rit->second), unary_op,
@ -3551,7 +3554,6 @@ UnaryOpNode::substituteUnaryOpNodes(const lag_equivalence_table_t &nodes, subst_
neweqs.push_back(datatree.AddEqual(aux_var, neweqs.push_back(datatree.AddEqual(aux_var,
dynamic_cast<UnaryOpNode *>(rit->second))); dynamic_cast<UnaryOpNode *>(rit->second)));
subst_table[rit->second] = dynamic_cast<VariableNode *>(aux_var); subst_table[rit->second] = dynamic_cast<VariableNode *>(aux_var);
base_index = rit->first;
} }
else else
subst_table[rit->second] = dynamic_cast<VariableNode *>(aux_var->decreaseLeadsLags(base_index - rit->first)); subst_table[rit->second] = dynamic_cast<VariableNode *>(aux_var->decreaseLeadsLags(base_index - rit->first));