From fac9e4436c1c1f7d97e03d5fee77f7fb45dff54a Mon Sep 17 00:00:00 2001 From: Houtan Bastani <houtan@dynare.org> Date: Mon, 7 Oct 2019 15:57:19 +0200 Subject: [PATCH] fix bug in `fast` option: printing temporary terms hid changes in model when the temporary term changed as the temporary terms themselves were not printed. closes dynare#1661 Furthermore, modifications to model local variables were not taken into account. To fix, take checksum of model local variables, temporary terms, and equations Also, use existing functions to print these to a stringstream instead of repeating print functionality in this function --- src/DynamicModel.cc | 49 +++++++++------------------------------------ 1 file changed, 9 insertions(+), 40 deletions(-) diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index 610f37e7..c04d4081 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -6586,51 +6586,20 @@ DynamicModel::isChecksumMatching(const string &basename, bool block) const for (const auto & equation_tag : equation_tags) buffer << " " << equation_tag.first + 1 << equation_tag.second.first - << equation_tag.second.second; + << equation_tag.second.second << endl; ExprNodeOutputType buffer_type = block ? ExprNodeOutputType::matlabDynamicModelSparse : ExprNodeOutputType::CDynamicModel; - for (int eq = 0; eq < static_cast<int>(equations.size()); eq++) - { - BinaryOpNode *eq_node = equations[eq]; - expr_t lhs = eq_node->arg1; - expr_t rhs = eq_node->arg2; + deriv_node_temp_terms_t tef_terms; + temporary_terms_t temp_term_union; + writeModelLocalVariableTemporaryTerms(temp_term_union, temporary_terms_idxs, + buffer, buffer_type, tef_terms); - // Test if the right hand side of the equation is empty. - double vrhs = 1.0; - try - { - vrhs = rhs->eval(eval_context_t()); - } - catch (ExprNode::EvalException &e) - { - } + writeTemporaryTerms(temporary_terms_derivatives[0], + temp_term_union, temporary_terms_idxs, + buffer, buffer_type, tef_terms); - if (vrhs != 0) // The right hand side of the equation is not empty ==> residual=lhs-rhs; - { - buffer << "lhs ="; - lhs->writeOutput(buffer, buffer_type, temporary_terms, temporary_terms_idxs); - buffer << ";" << endl; - - buffer << "rhs ="; - rhs->writeOutput(buffer, buffer_type, temporary_terms, temporary_terms_idxs); - buffer << ";" << endl; - - buffer << "residual" << LEFT_ARRAY_SUBSCRIPT(buffer_type) - << eq + ARRAY_SUBSCRIPT_OFFSET(buffer_type) - << RIGHT_ARRAY_SUBSCRIPT(buffer_type) - << "= lhs-rhs;" << endl; - } - else // The right hand side of the equation is empty ==> residual=lhs; - { - buffer << "residual" << LEFT_ARRAY_SUBSCRIPT(buffer_type) - << eq + ARRAY_SUBSCRIPT_OFFSET(buffer_type) - << RIGHT_ARRAY_SUBSCRIPT(buffer_type) - << " = "; - lhs->writeOutput(buffer, buffer_type, temporary_terms, temporary_terms_idxs); - buffer << ";" << endl; - } - } + writeModelEquations(buffer, buffer_type, temp_term_union); size_t result = hash<string>{}(buffer.str()); -- GitLab