From df3a1533565cdd3cc90be721b996702716df49d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 4 Jan 2023 14:43:57 +0100 Subject: [PATCH] Simplify residuals output (MATLAB/Octave and C) by dropping lhs/rhs temporary variables --- src/ModelTree.hh | 48 +++++++++++++++--------------------------------- 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/src/ModelTree.hh b/src/ModelTree.hh index a68bb22b..3e1533f6 100644 --- a/src/ModelTree.hh +++ b/src/ModelTree.hh @@ -1,5 +1,5 @@ /* - * Copyright © 2003-2022 Dynare Team + * Copyright © 2003-2023 Dynare Team * * This file is part of Dynare. * @@ -758,30 +758,16 @@ ModelTree::writeModelEquations(ostream &output, const temporary_terms_t &tempora } if (vrhs != 0) // The right hand side of the equation is not empty ==> residual=lhs-rhs; - if constexpr(isJuliaOutput(output_type)) - { - output << " residual" << LEFT_ARRAY_SUBSCRIPT(output_type) - << eq + ARRAY_SUBSCRIPT_OFFSET(output_type) - << RIGHT_ARRAY_SUBSCRIPT(output_type) - << " = ("; - lhs->writeOutput(output, output_type, temporary_terms, temporary_terms_idxs); - output << ") - ("; - rhs->writeOutput(output, output_type, temporary_terms, temporary_terms_idxs); - output << ")" << endl; - } - else - { - output << "lhs = "; - lhs->writeOutput(output, output_type, temporary_terms, temporary_terms_idxs); - output << ";" << endl - << "rhs = "; - rhs->writeOutput(output, output_type, temporary_terms, temporary_terms_idxs); - output << ";" << endl - << "residual" << LEFT_ARRAY_SUBSCRIPT(output_type) - << eq + ARRAY_SUBSCRIPT_OFFSET(output_type) - << RIGHT_ARRAY_SUBSCRIPT(output_type) - << " = lhs - rhs;" << endl; - } + { + output << " residual" << LEFT_ARRAY_SUBSCRIPT(output_type) + << eq + ARRAY_SUBSCRIPT_OFFSET(output_type) + << RIGHT_ARRAY_SUBSCRIPT(output_type) + << " = ("; + lhs->writeOutput(output, output_type, temporary_terms, temporary_terms_idxs); + output << ") - ("; + rhs->writeOutput(output, output_type, temporary_terms, temporary_terms_idxs); + output << ");" << endl; + } else // The right hand side of the equation is empty ==> residual=lhs; { output << "residual" << LEFT_ARRAY_SUBSCRIPT(output_type) @@ -1056,10 +1042,8 @@ ModelTree::writeModelCFile(const string &basename, const string &mexext, writePowerDerivHeader(output); output << endl << prototype_main << endl - << "{" << endl; - if (i == 0) - output << " double lhs, rhs;" << endl; - output << d_output[i].str() + << "{" << endl + << d_output[i].str() << "}" << endl << endl; output.close(); @@ -2801,10 +2785,8 @@ ModelTree::writeSparseModelCFiles(const string &basename, const string &mexext, writePowerDerivHeader(output); output << endl << prototype_main << endl - << "{" << endl; - if (i == 0) - output << " double lhs, rhs;" << endl; - output << d_sparse_output[i].str() + << "{" << endl + << d_sparse_output[i].str() << "}" << endl << endl; output.close();