From eccc1cae4b415190a7d2c3b546de29495d687f16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Tue, 28 Apr 2020 14:15:45 +0200 Subject: [PATCH] Block decomposition: minor fixes to block derivatives output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit — initially allocate correct number of non-zero elements in sparse Jacobian — avoid computing suboptimal temporary terms The ModelTree::derivative_endo structure is actually unused. Derivatives w.r.t. endogenous belonging to the block are stored in ModelTree::blocks_derivatives. --- src/DynamicModel.cc | 8 +------- src/StaticModel.cc | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index f1466355..2b821709 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -306,8 +306,6 @@ DynamicModel::computeTemporaryTermsOrdered() expr_t id = get<3>(it); id->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, block, v_temporary_terms, block_size-1); } - for (const auto &it : derivative_endo[block]) - it.second->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, block, v_temporary_terms, block_size-1); for (const auto &it : derivative_other_endo[block]) it.second->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, block, v_temporary_terms, block_size-1); v_temporary_terms_inuse[block] = {}; @@ -337,8 +335,6 @@ DynamicModel::computeTemporaryTermsOrdered() expr_t id = get<3>(it); id->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, block, v_temporary_terms, block_size-1); } - for (const auto &it : derivative_endo[block]) - it.second->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, block, v_temporary_terms, block_size-1); for (const auto &it : derivative_other_endo[block]) it.second->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, block, v_temporary_terms, block_size-1); } @@ -364,8 +360,6 @@ DynamicModel::computeTemporaryTermsOrdered() expr_t id = get<3>(it); id->collectTemporary_terms(temporary_terms, temporary_terms_in_use, block); } - for (const auto &it : derivative_endo[block]) - it.second->collectTemporary_terms(temporary_terms, temporary_terms_in_use, block); for (const auto &it : derivative_other_endo[block]) it.second->collectTemporary_terms(temporary_terms, temporary_terms_in_use, block); for (const auto &it : derivative_exo[block]) @@ -415,7 +409,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &basename) const //recursive_variables.clear(); feedback_variables.clear(); //For a block composed of a single equation determines wether we have to evaluate or to solve the equation - nze = derivative_endo[block].size(); + nze = blocks_derivatives[block].size(); nze_other_endo = derivative_other_endo[block].size(); nze_exo = derivative_exo[block].size(); nze_exo_det = derivative_exo_det[block].size(); diff --git a/src/StaticModel.cc b/src/StaticModel.cc index a70c9515..99ceef31 100644 --- a/src/StaticModel.cc +++ b/src/StaticModel.cc @@ -410,7 +410,7 @@ StaticModel::writeModelEquationsOrdered_M(const string &basename) const output << " global options_;" << endl; //The Temporary terms if (simulation_type != EVALUATE_BACKWARD && simulation_type != EVALUATE_FORWARD) - output << " g1 = spalloc(" << block_mfs << ", " << block_mfs << ", " << derivative_endo[block].size() << ");" << endl; + output << " g1 = spalloc(" << block_mfs << ", " << block_mfs << ", " << blocks_derivatives[block].size() << ");" << endl; if (v_temporary_terms_inuse[block].size()) { -- GitLab