Various minor simplifications

fix-tolerance-parameters
Sébastien Villemot 2022-05-04 14:42:03 +02:00
parent e0c3cb72b7
commit ef02b79486
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
9 changed files with 59 additions and 94 deletions

View File

@ -362,12 +362,10 @@ StochSimulStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli
|| mod_file_struct.order_option >= 3)
mod_file_struct.k_order_solver = true;
if (auto it = options_list.num_options.find("hp_filter"),
it1 = options_list.num_options.find("bandpass.indicator"),
it2 = options_list.num_options.find("one_sided_hp_filter");
(it != options_list.num_options.end() && it1 != options_list.num_options.end())
|| (it != options_list.num_options.end() && it2 != options_list.num_options.end())
|| (it1 != options_list.num_options.end() && it2 != options_list.num_options.end()))
if (bool hp = options_list.num_options.find("hp_filter") != options_list.num_options.end(),
bandpass = options_list.num_options.find("bandpass.indicator") != options_list.num_options.end(),
one_sided_hp = options_list.num_options.find("one_sided_hp_filter") != options_list.num_options.end();
(hp && bandpass) || (hp && one_sided_hp) || (bandpass && one_sided_hp))
{
cerr << "ERROR: stoch_simul: can only use one of hp, one-sided hp, and bandpass filters"
<< endl;
@ -2556,14 +2554,14 @@ MSSBVAREstimationStatement::checkPass(ModFileStructure &mod_file_struct, Warning
{
mod_file_struct.bvar_present = true;
if (options_list.num_options.find("ms.create_init") == options_list.num_options.end())
if (options_list.string_options.find("datafile") == options_list.string_options.end()
|| options_list.num_options.find("ms.initial_year") == options_list.num_options.end())
{
cerr << "ERROR: If you do not pass no_create_init to ms_estimation, "
<< "you must pass the datafile and initial_year options." << endl;
exit(EXIT_FAILURE);
}
if (options_list.num_options.find("ms.create_init") == options_list.num_options.end()
&& (options_list.string_options.find("datafile") == options_list.string_options.end()
|| options_list.num_options.find("ms.initial_year") == options_list.num_options.end()))
{
cerr << "ERROR: If you do not pass no_create_init to ms_estimation, "
<< "you must pass the datafile and initial_year options." << endl;
exit(EXIT_FAILURE);
}
}
void
@ -2708,11 +2706,10 @@ MSSBVARIrfStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli
{
mod_file_struct.bvar_present = true;
bool regime_present = options_list.num_options.find("ms.regime") != options_list.num_options.end();
bool regimes_present = options_list.num_options.find("ms.regimes") != options_list.num_options.end();
bool filtered_probabilities_present = options_list.num_options.find("ms.filtered_probabilities") != options_list.num_options.end();
if ((filtered_probabilities_present && regime_present)
if (bool regime_present = options_list.num_options.find("ms.regime") != options_list.num_options.end(),
regimes_present = options_list.num_options.find("ms.regimes") != options_list.num_options.end(),
filtered_probabilities_present = options_list.num_options.find("ms.filtered_probabilities") != options_list.num_options.end();
(filtered_probabilities_present && regime_present)
|| (filtered_probabilities_present && regimes_present)
|| (regimes_present && regime_present))
{
@ -2806,11 +2803,10 @@ MSSBVARVarianceDecompositionStatement::checkPass(ModFileStructure &mod_file_stru
{
mod_file_struct.bvar_present = true;
bool regime_present = options_list.num_options.find("ms.regime") != options_list.num_options.end();
bool regimes_present = options_list.num_options.find("ms.regimes") != options_list.num_options.end();
bool filtered_probabilities_present = options_list.num_options.find("ms.filtered_probabilities") != options_list.num_options.end();
if ((filtered_probabilities_present && regime_present)
if (bool regime_present = options_list.num_options.find("ms.regime") != options_list.num_options.end(),
regimes_present = options_list.num_options.find("ms.regimes") != options_list.num_options.end(),
filtered_probabilities_present = options_list.num_options.find("ms.filtered_probabilities") != options_list.num_options.end();
(filtered_probabilities_present && regime_present)
|| (filtered_probabilities_present && regimes_present)
|| (regimes_present && regime_present))
{
@ -3681,18 +3677,12 @@ SvarStatement::SvarStatement(OptionsList options_list_arg) :
void
SvarStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
{
auto it0 = options_list.string_options.find("ms.coefficients"),
it1 = options_list.string_options.find("ms.variances"),
it2 = options_list.string_options.find("ms.constants");
assert((it0 != options_list.string_options.end()
&& it1 == options_list.string_options.end()
&& it2 == options_list.string_options.end())
|| (it0 == options_list.string_options.end()
&& it1 != options_list.string_options.end()
&& it2 == options_list.string_options.end())
|| (it0 == options_list.string_options.end()
&& it1 == options_list.string_options.end()
&& it2 != options_list.string_options.end()));
bool has_coefficients = options_list.string_options.find("ms.coefficients") != options_list.string_options.end(),
has_variances = options_list.string_options.find("ms.variances") != options_list.string_options.end(),
has_constants = options_list.string_options.find("ms.constants") != options_list.string_options.end();
assert((has_coefficients && !has_variances && !has_constants)
|| (!has_coefficients && has_variances && !has_constants)
|| (!has_coefficients && !has_variances && has_constants));
}
void
@ -3795,15 +3785,14 @@ EstimationDataStatement::checkPass(ModFileStructure &mod_file_struct, WarningCon
exit(EXIT_FAILURE);
}
if (options_list.string_options.find("file") == options_list.string_options.end()
&& options_list.string_options.find("series") == options_list.string_options.end())
bool has_file = options_list.string_options.find("file") != options_list.string_options.end(),
has_series = options_list.string_options.find("series") != options_list.string_options.end();
if (!has_file && !has_series)
{
cerr << "ERROR: The file or series option must be passed to the data statement." << endl;
exit(EXIT_FAILURE);
}
if (options_list.string_options.find("file") != options_list.string_options.end()
&& options_list.string_options.find("series") != options_list.string_options.end())
if (has_file && has_series)
{
cerr << "ERROR: The file and series options cannot be used simultaneously in the data statement." << endl;
exit(EXIT_FAILURE);
@ -4206,9 +4195,8 @@ BasicPriorStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli
exit(EXIT_FAILURE);
}
if (auto it_stdev = options_list.num_options.find("stdev");
(it_stdev == options_list.num_options.end() && !variance)
|| (it_stdev != options_list.num_options.end() && variance))
if (bool has_stdev = options_list.num_options.find("stdev") != options_list.num_options.end();
(!has_stdev && !variance) || (has_stdev && variance))
{
cerr << "ERROR: You must pass exactly one of stdev and variance to the prior statement." << endl;
exit(EXIT_FAILURE);

View File

@ -1,5 +1,5 @@
/*
* Copyright © 2003-2021 Dynare Team
* Copyright © 2003-2022 Dynare Team
*
* This file is part of Dynare.
*
@ -733,8 +733,7 @@ DataTree::AddLocalVariable(int symb_id, expr_t value) noexcept(false)
assert(symbol_table.getType(symb_id) == SymbolType::modelLocalVariable);
// Throw an exception if symbol already declared
if (auto it = local_variables_table.find(symb_id);
it != local_variables_table.end())
if (local_variables_table.find(symb_id) != local_variables_table.end())
throw LocalVariableException(symbol_table.getName(symb_id));
local_variables_table[symb_id] = value;

View File

@ -54,7 +54,7 @@ EquationTags::getEqnByTag(const string &key, const string &value) const
void
EquationTags::erase(const set<int> &eqns, const map<int, int> &old_eqn_num_2_new)
{
for (const auto &eqn : eqns)
for (int eqn : eqns)
eqn_tags.erase(eqn);
for (const auto & [oldeqn, neweqn] : old_eqn_num_2_new)

View File

@ -70,8 +70,8 @@ public:
//! Get equation tags for a given equation
inline map<string, string> getTagsByEqn(const int eqn) const
{
if (eqn_tags.find(eqn) != eqn_tags.end())
return eqn_tags.find(eqn)->second;
if (auto it = eqn_tags.find(eqn); it != eqn_tags.end())
return it->second;
return map<string, string>{};
}
@ -118,13 +118,13 @@ public:
//! Returns true if equation tag with key exists for a given equation
inline bool exists(const int eqn, const string &key) const
{
return exists(eqn) ? eqn_tags.at(eqn).find(key) != eqn_tags.at(eqn).end() : false;
return exists(eqn) && eqn_tags.at(eqn).find(key) != eqn_tags.at(eqn).end();
}
//! Returns true if equation tag with key and value exists for a given equation
inline bool exists(const int eqn, const string &key, const string &value) const
{
return exists(eqn, key) ? eqn_tags.at(eqn).at(key) == value : false;
return exists(eqn, key) && eqn_tags.at(eqn).at(key) == value;
}
//! Various functions to write equation tags

View File

@ -39,7 +39,7 @@ ExprNode::getDerivative(int deriv_id)
prepareForDerivation();
// Return zero if derivative is necessarily null (using symbolic a priori)
if (auto it = non_null_derivatives.find(deriv_id); it == non_null_derivatives.end())
if (non_null_derivatives.find(deriv_id) == non_null_derivatives.end())
return datatree.Zero;
// If derivative is stored in cache, use the cached value, otherwise compute it (and cache it)
@ -93,7 +93,7 @@ ExprNode::checkIfTemporaryTermThenWrite(ostream &output, ExprNodeOutputType outp
const temporary_terms_t &temporary_terms,
const temporary_terms_idxs_t &temporary_terms_idxs) const
{
if (auto it = temporary_terms.find(const_cast<ExprNode *>(this)); it == temporary_terms.end())
if (temporary_terms.find(const_cast<ExprNode *>(this)) == temporary_terms.end())
return false;
auto it2 = temporary_terms_idxs.find(const_cast<ExprNode *>(this));
@ -6937,9 +6937,7 @@ AbstractExternalFunctionNode::differentiateForwardVars(const vector<string> &sub
bool
AbstractExternalFunctionNode::alreadyWrittenAsTefTerm(int the_symb_id, const deriv_node_temp_terms_t &tef_terms) const
{
if (tef_terms.find({ the_symb_id, arguments }) != tef_terms.end())
return true;
return false;
return tef_terms.find({ the_symb_id, arguments }) != tef_terms.end();
}
int
@ -6970,8 +6968,7 @@ AbstractExternalFunctionNode::computeTemporaryTerms(const pair<int, int> &derivO
expr_t this2 = const_cast<AbstractExternalFunctionNode *>(this);
for (auto &tt : temp_terms_map)
if (auto it = find_if(tt.second.cbegin(), tt.second.cend(), sameTefTermPredicate());
it != tt.second.cend())
if (find_if(tt.second.cbegin(), tt.second.cend(), sameTefTermPredicate()) != tt.second.cend())
{
tt.second.insert(this2);
return;
@ -6988,8 +6985,7 @@ AbstractExternalFunctionNode::computeBlockTemporaryTerms(int blk, int eq, vector
expr_t this2 = const_cast<AbstractExternalFunctionNode *>(this);
for (auto &btt : blocks_temporary_terms)
for (auto &tt : btt)
if (auto it = find_if(tt.cbegin(), tt.cend(), sameTefTermPredicate());
it != tt.cend())
if (find_if(tt.cbegin(), tt.cend(), sameTefTermPredicate()) != tt.cend())
{
tt.insert(this2);
return;

View File

@ -941,7 +941,7 @@ ModFile::writeMOutput(const string &basename, bool clear_all, bool clear_global,
mOutputFile << "'', '" << parallel_local_file << "';" << endl;
else
mOutputFile << "'" << parallel_local_file.substr(0, j+1) << "', '"
<< parallel_local_file.substr(j+1, string::npos) << "';" << endl;
<< parallel_local_file.substr(j+1) << "';" << endl;
}
mOutputFile << "};" << endl;
}

View File

@ -120,9 +120,7 @@ InitOrEndValStatement::getUninitializedVariables(SymbolType type)
}
for (auto [symb_id, value] : init_values)
if (auto sit = unused.find(symb_id);
sit != unused.end())
unused.erase(sit);
unused.erase(symb_id);
return unused;
}
@ -385,13 +383,8 @@ HistValStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidat
for (const auto &[key, value] : hist_values)
{
int symb_id = key.first;
if (auto sit = unused_endo.find(symb_id);
sit != unused_endo.end())
unused_endo.erase(sit);
if (auto sit = unused_exo.find(symb_id);
sit != unused_exo.end())
unused_exo.erase(sit);
unused_endo.erase(symb_id);
unused_exo.erase(symb_id);
}
if (unused_endo.size() > 0)

View File

@ -1364,7 +1364,7 @@ ParsingDriver::add_to_row_const(const string &v)
expr_t id;
if (v.at(0) == '-')
id = data_tree->AddUMinus(data_tree->AddNonNegativeConstant(v.substr(1, string::npos)));
id = data_tree->AddUMinus(data_tree->AddNonNegativeConstant(v.substr(1)));
else
id = data_tree->AddNonNegativeConstant(v);
@ -2420,20 +2420,14 @@ ParsingDriver::ms_variance_decomposition()
void
ParsingDriver::svar()
{
auto it0 = options_list.string_options.find("ms.coefficients"),
it1 = options_list.string_options.find("ms.variances"),
it2 = options_list.string_options.find("ms.constants");
if (it0 == options_list.string_options.end()
&& it1 == options_list.string_options.end()
&& it2 == options_list.string_options.end())
bool has_coefficients = options_list.string_options.find("ms.coefficients") != options_list.string_options.end(),
has_variances = options_list.string_options.find("ms.variances") != options_list.string_options.end(),
has_constants = options_list.string_options.find("ms.constants") != options_list.string_options.end();
if (!has_coefficients && !has_variances && !has_constants)
error("You must pass one of 'coefficients', 'variances', or 'constants'.");
if ((it0 != options_list.string_options.end()
&& it1 != options_list.string_options.end())
|| (it1 != options_list.string_options.end()
&& it2 != options_list.string_options.end())
|| (it0 != options_list.string_options.end()
&& it2 != options_list.string_options.end()))
if ((has_coefficients && has_variances) || (has_variances && has_constants)
|| (has_coefficients && has_constants))
error("You may only pass one of 'coefficients', 'variances', or 'constants'.");
if (auto itn = options_list.num_options.find("ms.chain");
@ -2467,8 +2461,7 @@ ParsingDriver::markov_switching()
else if (stoi(it0->second) <= 0)
error("The value passed to the number_of_regimes option must be greater than zero.");
it0 = options_list.num_options.find("ms.duration");
if (it0 == options_list.num_options.end())
if (options_list.num_options.find("ms.duration") == options_list.num_options.end())
error("A duration option must be passed to the markov_switching statement.");
mod_file->addStatement(make_unique<MarkovSwitchingStatement>(options_list));

View File

@ -198,11 +198,7 @@ SymbolTable::getPartitionsForType(SymbolType st) const noexcept(false)
for (const auto &it : partition_value_map)
if (getType(it.first) == st)
for (const auto &it1 : it.second)
{
if (partitions.find(it1.first) == partitions.end())
partitions[it1.first] = {};
partitions[it1.first][it.first] = it1.second;
}
partitions[it1.first][it.first] = it1.second;
return partitions;
}
@ -801,13 +797,13 @@ bool
SymbolTable::isPredetermined(int symb_id) const noexcept(false)
{
validateSymbID(symb_id);
return (predetermined_variables.find(symb_id) != predetermined_variables.end());
return predetermined_variables.find(symb_id) != predetermined_variables.end();
}
int
SymbolTable::predeterminedNbr() const
{
return (predetermined_variables.size());
return predetermined_variables.size();
}
void