Symbolic detrending engine: correctly handle equations marked [static]

Incidentally, this also fixes a detrending bug in the Occbin engine (since the
latter internally generates a [static] equation).

Ref. dynare#1827

By the way, perform a small code simplification.

(cherry picked from commit 7b8fc8edb7)
5.x
Sébastien Villemot 2021-12-06 12:53:35 +01:00
parent bdbafdc34c
commit ced586febf
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
1 changed files with 26 additions and 12 deletions

View File

@ -5888,18 +5888,28 @@ DynamicModel::detrendEquations()
// We go backwards in the list of trend_vars, to deal correctly with I(2) processes // We go backwards in the list of trend_vars, to deal correctly with I(2) processes
for (auto it = nonstationary_symbols_map.crbegin(); for (auto it = nonstationary_symbols_map.crbegin();
it != nonstationary_symbols_map.crend(); ++it) it != nonstationary_symbols_map.crend(); ++it)
for (auto &equation : equations) {
{ for (auto &equation : equations)
auto substeq = dynamic_cast<BinaryOpNode *>(equation->detrend(it->first, it->second.first, it->second.second)); {
assert(substeq); equation = dynamic_cast<BinaryOpNode *>(equation->detrend(it->first, it->second.first, it->second.second));
equation = dynamic_cast<BinaryOpNode *>(substeq); assert(equation);
} }
for (auto &equation : static_only_equations)
{
equation = dynamic_cast<BinaryOpNode *>(equation->detrend(it->first, it->second.first, it->second.second));
assert(equation);
}
}
for (auto &equation : equations) for (auto &equation : equations)
{ {
auto substeq = dynamic_cast<BinaryOpNode *>(equation->removeTrendLeadLag(trend_symbols_map)); equation = dynamic_cast<BinaryOpNode *>(equation->removeTrendLeadLag(trend_symbols_map));
assert(substeq); assert(equation);
equation = dynamic_cast<BinaryOpNode *>(substeq); }
for (auto &equation : static_only_equations)
{
equation = dynamic_cast<BinaryOpNode *>(equation->removeTrendLeadLag(trend_symbols_map));
assert(equation);
} }
} }
@ -5908,9 +5918,13 @@ DynamicModel::removeTrendVariableFromEquations()
{ {
for (auto &equation : equations) for (auto &equation : equations)
{ {
auto substeq = dynamic_cast<BinaryOpNode *>(equation->replaceTrendVar()); equation = dynamic_cast<BinaryOpNode *>(equation->replaceTrendVar());
assert(substeq); assert(equation);
equation = dynamic_cast<BinaryOpNode *>(substeq); }
for (auto &equation : static_only_equations)
{
equation = dynamic_cast<BinaryOpNode *>(equation->replaceTrendVar());
assert(equation);
} }
} }