Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • normann/preprocessor
  • Dynare/preprocessor
  • FerhatMihoubi/preprocessor
  • MichelJuillard/preprocessor
  • sebastien/preprocessor
  • lnsongxf/preprocessor
  • albop/preprocessor
  • DoraK/preprocessor
  • amg/preprocessor
  • wmutschl/preprocessor
  • JohannesPfeifer/preprocessor
11 results
Select Git revision
Show changes
Commits on Source (5)
/*
* Copyright © 2007-2023 Dynare Team
* Copyright © 2007-2024 Dynare Team
*
* This file is part of Dynare.
*
......@@ -795,9 +795,8 @@ public:
/* Overwrites an existing instruction, given its number.
It is the responsibility of the caller to ensure that the new instruction
occupies exactly as many bytes as the former one. */
template<typename B>
void
overwriteInstruction(int instruction_number, const B& new_instruction)
overwriteInstruction(int instruction_number, const auto& new_instruction)
{
seekp(instructions_positions.at(instruction_number));
*this << new_instruction;
......
/*
* Copyright © 2003-2023 Dynare Team
* Copyright © 2003-2024 Dynare Team
*
* This file is part of Dynare.
*
......@@ -2439,14 +2439,7 @@ void
PlannerObjectiveStatement::writeOutput(ostream& output, const string& basename,
[[maybe_unused]] bool minimal_workspace) const
{
output << "M_.NNZDerivatives_objective = [";
for (int i = 1; i < static_cast<int>(model_tree->getNNZDerivatives().size()); i++)
output << (i > model_tree->getComputedDerivsOrder() ? -1 : model_tree->getNNZDerivatives()[i])
<< ";";
output << "];" << endl << "M_.objective_tmp_nbr = [";
for (const auto& temporary_terms_derivative : model_tree->getTemporaryTermsDerivatives())
output << temporary_terms_derivative.size() << "; ";
output << "];" << endl;
model_tree->writeDriverOutput(output);
model_tree->writeStaticFile(basename + ".objective", false, "", {}, false);
}
......
......@@ -1123,7 +1123,7 @@ DynamicModel::writeDriverOutput(ostream& output, bool compute_xrefs) const
output << (i > computed_derivs_order ? -1 : NNZDerivatives[i]) << "; ";
output << "];" << endl;
writeDriverSparseIndicesHelper<true>(output);
writeDriverSparseIndicesHelper<true, false>(output);
// Write LHS of each equation in text form
output << "M_.lhs = {" << endl;
......
......@@ -195,7 +195,7 @@ ExprNode::collectVariables(SymbolType type, set<int>& result) const
set<pair<int, int>> symbs_lags;
collectDynamicVariables(type, symbs_lags);
transform(symbs_lags.begin(), symbs_lags.end(), inserter(result, result.begin()),
[](auto x) { return x.first; });
[](const auto& x) { return x.first; });
}
void
......
/*
* Copyright © 2010-2023 Dynare Team
* Copyright © 2010-2024 Dynare Team
*
* This file is part of Dynare.
*
......@@ -31,6 +31,19 @@ PlannerObjective::PlannerObjective(SymbolTable& symbol_table_arg,
{
}
void
PlannerObjective::writeDriverOutput(ostream& output) const
{
output << "M_.NNZDerivatives_objective = [";
for (int i = 1; i < static_cast<int>(NNZDerivatives.size()); i++)
output << (i > computed_derivs_order ? -1 : NNZDerivatives[i]) << ";";
output << "];" << endl << "M_.objective_tmp_nbr = [";
for (const auto& it : temporary_terms_derivatives)
output << it.size() << "; ";
output << "];" << endl;
writeDriverSparseIndicesHelper<false, true>(output);
}
void
PlannerObjective::computingPassBlock([[maybe_unused]] const eval_context_t& eval_context,
[[maybe_unused]] bool no_tmp_terms)
......
/*
* Copyright © 2010-2023 Dynare Team
* Copyright © 2010-2024 Dynare Team
*
* This file is part of Dynare.
*
......@@ -31,6 +31,8 @@ class PlannerObjective : public StaticModel
public:
PlannerObjective(SymbolTable& symbol_table_arg, NumericalConstants& num_constants_arg,
ExternalFunctionsTable& external_functions_table_arg);
// NB: masks the method with the same name in StaticModel (not in a virtual fashion)
void writeDriverOutput(ostream& output) const;
protected:
string
......
/*
* Copyright © 2003-2023 Dynare Team
* Copyright © 2003-2024 Dynare Team
*
* This file is part of Dynare.
*
......@@ -351,8 +351,9 @@ protected:
void writeBlockBytecodeHelper(Bytecode::Writer& code_file, int block,
temporary_terms_t& temporary_terms_union) const;
// Helper for writing sparse derivatives indices in MATLAB/Octave driver file
template<bool dynamic>
/* Helper for writing sparse derivatives indices in MATLAB/Octave driver file.
Also supports the planner objective through the corresponding boolean. */
template<bool dynamic, bool objective>
void writeDriverSparseIndicesHelper(ostream& output) const;
// Helper for writing sparse derivatives indices in JSON
......@@ -689,27 +690,6 @@ public:
// Write the definitions of the auxiliary variables (assumed to be in recursive order)
void writeAuxVarRecursiveDefinitions(ostream& output, ExprNodeOutputType output_type) const;
//! Returns the vector of non-zero derivative counts
const vector<int>&
getNNZDerivatives() const
{
return NNZDerivatives;
}
//! Returns the vector of temporary terms derivatives
const vector<temporary_terms_t>&
getTemporaryTermsDerivatives() const
{
return temporary_terms_derivatives;
}
//! Returns the maximum order of computed derivatives
int
getComputedDerivsOrder() const
{
return computed_derivs_order;
}
static string
BlockSim(BlockSimulationType type)
{
......@@ -2267,12 +2247,13 @@ ModelTree::writeJsonParamsDerivativesHelper(bool writeDetails) const
move(rpp_output), move(gpp_output), move(hp_output), move(g3p_output)};
}
template<bool dynamic>
template<bool dynamic, bool objective>
void
ModelTree::writeDriverSparseIndicesHelper(ostream& output) const
{
static_assert(!(objective && dynamic), "There is no such thing as a dynamic planner objective");
// TODO: when C++20 support is complete, mark this constexpr
const string model_name {dynamic ? "dynamic" : "static"};
const string model_name {objective ? "objective" : (dynamic ? "dynamic" : "static")};
// Write indices for the sparse Jacobian (both naive and CSC storage)
output << "M_." << model_name << "_g1_sparse_rowval = int32([";
......@@ -2618,7 +2599,8 @@ ModelTree::writeSparseModelMFiles(const string& basename) const
ttlen += temporary_terms_derivatives[i].size();
open_file(m_dir / (prefix + "g" + to_string(i) + "_tt.m"));
output << "function T = " << prefix << "g" << i << "_tt(y, x, params" << ss_arg << ")" << endl
output << "function [T_order, T] = " << prefix << "g" << i << "_tt(y, x, params" << ss_arg
<< ", T_order, T)" << endl
<< "if T_order >= " << i << endl
<< " return" << endl
<< "end" << endl
......
/*
* Copyright © 2003-2023 Dynare Team
* Copyright © 2003-2024 Dynare Team
*
* This file is part of Dynare.
*
......@@ -564,7 +564,7 @@ StaticModel::writeDriverOutput(ostream& output) const
if (block_decomposed)
writeBlockDriverOutput(output);
writeDriverSparseIndicesHelper<false>(output);
writeDriverSparseIndicesHelper<false, false>(output);
}
void
......