diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index ff55ca3491afaa6b6e711a169e761b18b99f2b1a..a8eac14688ce5f3ab4d063141962c27aa1be015c 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -735,7 +735,7 @@ DynamicModel::writeDynamicJuliaFile(const string &basename) const << "# from " << basename << ".mod" << endl << "#" << endl << "using StatsFuns" << endl << endl - << "export tmp_nbr, dynamic!, dynamicResid!, dynamicG1!, dynamicG2!, dynamicG3!" << endl << endl + << "export dynamic!, dynamicResid!, dynamicG1!, dynamicG2!, dynamicG3!" << endl << endl << "#=" << endl << "# The comments below apply to all functions contained in this module #" << endl << " NB: The arguments contained on the first line of the function" << endl @@ -747,9 +747,6 @@ DynamicModel::writeDynamicJuliaFile(const string &basename) const << " dynamicG1! : Computes the dynamic model Jacobian" << endl << " dynamicG2! : Computes the dynamic model Hessian" << endl << " dynamicG3! : Computes the dynamic model third derivatives" << endl << endl - << "## Exported Variables ##" << endl - << " tmp_nbr : Vector{Int}(4) respectively the number of temporary variables" << endl - << " for the residuals, g1, g2 and g3." << endl << endl << "## Local Functions ##" << endl << " dynamicResidTT! : Computes the dynamic model temporary terms for the residuals" << endl << " dynamicG1TT! : Computes the dynamic model temporary terms for the Jacobian" << endl @@ -781,13 +778,6 @@ DynamicModel::writeDynamicJuliaFile(const string &basename) const << " residuals, the jacobian and hessian matrices, then `T` must have at least `sum(tmp_nbr[1:3])` elements." << endl << "=#" << endl << endl; - // Write the number of temporary terms - output << "tmp_nbr = zeros(Int,4)" << endl - << "tmp_nbr[1] = " << temporary_terms_derivatives[0].size() << "# Number of temporary terms for the residuals" << endl - << "tmp_nbr[2] = " << temporary_terms_derivatives[1].size() << "# Number of temporary terms for g1 (jacobian)" << endl - << "tmp_nbr[3] = " << temporary_terms_derivatives[2].size() << "# Number of temporary terms for g2 (hessian)" << endl - << "tmp_nbr[4] = " << temporary_terms_derivatives[3].size() << "# Number of temporary terms for g3 (third order derivates)" << endl << endl; - // dynamicResidTT! output << "function dynamicResidTT!(T::Vector{<: Real}," << endl << " y::Vector{<: Real}, x::Matrix{<: Real}, " @@ -4664,7 +4654,15 @@ DynamicModel::writeJsonOutput(ostream &output) const writeJsonAST(output); output << ", "; writeJsonVariableMapping(output); - output << ", "; + output << R"(, "dynamic_tmp_nbr": [)"; + for (bool printed_something {false}; + const auto &tts : temporary_terms_derivatives) + { + if (exchange(printed_something, true)) + output << ", "; + output << tts.size(); + } + output << "], "; writeJsonSparseIndicesHelper<true>(output); } diff --git a/src/StaticModel.cc b/src/StaticModel.cc index 83da54b978248b54f8bb8bd8e44dce082150925b..b9faf9d093ebfe93ceb4c93d40531650425b3583 100644 --- a/src/StaticModel.cc +++ b/src/StaticModel.cc @@ -622,7 +622,7 @@ StaticModel::writeStaticJuliaFile(const string &basename) const << "# from " << basename << ".mod" << endl << "#" << endl << "using StatsFuns" << endl << endl - << "export tmp_nbr, static!, staticResid!, staticG1!, staticG2!, staticG3!" << endl << endl + << "export static!, staticResid!, staticG1!, staticG2!, staticG3!" << endl << endl << "#=" << endl << "# The comments below apply to all functions contained in this module #" << endl << " NB: The arguments contained on the first line of the function" << endl @@ -634,9 +634,6 @@ StaticModel::writeStaticJuliaFile(const string &basename) const << " staticG1! : Computes the static model Jacobian" << endl << " staticG2! : Computes the static model Hessian" << endl << " staticG3! : Computes the static model third derivatives" << endl << endl - << "## Exported Variables ##" << endl - << " tmp_nbr : Vector{Int}(4) respectively the number of temporary variables" << endl - << " for the residuals, g1, g2 and g3." << endl << endl << "## Local Functions ##" << endl << " staticResidTT! : Computes the static model temporary terms for the residuals" << endl << " staticG1TT! : Computes the static model temporary terms for the Jacobian" << endl @@ -667,13 +664,6 @@ StaticModel::writeStaticJuliaFile(const string &basename) const << " residuals, and the jacobian and hessian matrices, then `T` must have at least `sum(tmp_nbr[1:3])` elements." << endl << "=#" << endl << endl; - // Write the number of temporary terms - output << "tmp_nbr = zeros(Int,4)" << endl - << "tmp_nbr[1] = " << temporary_terms_derivatives[0].size() << "# Number of temporary terms for the residuals" << endl - << "tmp_nbr[2] = " << temporary_terms_derivatives[1].size() << "# Number of temporary terms for g1 (jacobian)" << endl - << "tmp_nbr[3] = " << temporary_terms_derivatives[2].size() << "# Number of temporary terms for g2 (hessian)" << endl - << "tmp_nbr[4] = " << temporary_terms_derivatives[3].size() << "# Number of temporary terms for g3 (third order derivates)" << endl << endl; - // staticResidTT! output << "function staticResidTT!(T::Vector{<: Real}," << endl << " y::Vector{<: Real}, x::Vector{<: Real}, params::Vector{<: Real})" << endl @@ -1310,6 +1300,15 @@ StaticModel::writeJsonAuxVarRecursiveDefinitions(ostream &output) const void StaticModel::writeJsonOutput(ostream &output) const { + output << R"("static_tmp_nbr": [)"; + for (bool printed_something {false}; + const auto &tts : temporary_terms_derivatives) + { + if (exchange(printed_something, true)) + output << ", "; + output << tts.size(); + } + output << "], "; writeJsonSparseIndicesHelper<false>(output); }