Port to C++11 range-based for loops

Performed using modernize-loop-convert from clang-tidy.

https://clang.llvm.org/extra/clang-tidy/checks/modernize-loop-convert.html
time-shift
Sébastien Villemot 2019-01-09 15:44:26 +01:00
parent 618e2c5400
commit 2024330568
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
34 changed files with 335 additions and 407 deletions

View File

@ -122,8 +122,8 @@ HaltonSequence::operator=(const HaltonSequence &hs)
num = hs.num; num = hs.num;
maxn = hs.maxn; maxn = hs.maxn;
ri.clear(); ri.clear();
for (unsigned int i = 0; i < hs.ri.size(); i++) for (const auto & i : hs.ri)
ri.push_back(RadicalInverse(hs.ri[i])); ri.push_back(RadicalInverse(i));
pt = hs.pt; pt = hs.pt;
return *this; return *this;
} }
@ -134,8 +134,8 @@ HaltonSequence::operator=(const HaltonSequence &hs)
void void
HaltonSequence::increase() HaltonSequence::increase()
{ {
for (unsigned int i = 0; i < ri.size(); i++) for (auto & i : ri)
ri[i].increase(); i.increase();
num++; num++;
if (num <= maxn) if (num <= maxn)
eval(); eval();
@ -153,8 +153,8 @@ HaltonSequence::eval()
void void
HaltonSequence::print() const HaltonSequence::print() const
{ {
for (unsigned int i = 0; i < ri.size(); i++) for (const auto & i : ri)
ri[i].print(); i.print();
printf("point=[ "); printf("point=[ ");
for (unsigned int i = 0; i < ri.size(); i++) for (unsigned int i = 0; i < ri.size(); i++)
printf("%7.6f ", pt[i]); printf("%7.6f ", pt[i]);

View File

@ -160,17 +160,17 @@ main(int argc, char **argv)
// calculate weights and mass // calculate weights and mass
double mass = 0.0; double mass = 0.0;
std::vector<double> weights; std::vector<double> weights;
for (int i = 0; i < (int) points.size(); i++) for (auto & point : points)
{ {
weights.push_back(std::exp(-points[i]->dot(*(points[i])))); weights.push_back(std::exp(-point->dot(*point)));
mass += weights.back(); mass += weights.back();
} }
// calculate discarded mass // calculate discarded mass
double discard_mass = 0.0; double discard_mass = 0.0;
for (int i = 0; i < (int) weights.size(); i++) for (double weight : weights)
if (weights[i]/mass < params.discard_weight) if (weight/mass < params.discard_weight)
discard_mass += weights[i]; discard_mass += weight;
printf("Total mass discarded: %f\n", discard_mass/mass); printf("Total mass discarded: %f\n", discard_mass/mass);

View File

@ -259,9 +259,9 @@ Approximation::saveRuleDerivs(const FGSContainer &g)
} }
rule_ders = new FGSContainer(g); rule_ders = new FGSContainer(g);
rule_ders_ss = new FGSContainer(4); rule_ders_ss = new FGSContainer(4);
for (FGSContainer::iterator run = (*rule_ders).begin(); run != (*rule_ders).end(); ++run) for (auto & run : (*rule_ders))
{ {
FGSTensor *ten = new FGSTensor(ypart.nstat+ypart.npred, ypart.nyss(), *((*run).second)); FGSTensor *ten = new FGSTensor(ypart.nstat+ypart.npred, ypart.nyss(), *(run.second));
rule_ders_ss->insert(ten); rule_ders_ss->insert(ten);
} }
} }

View File

@ -32,10 +32,9 @@ FoldDecisionRule::FoldDecisionRule(const UnfoldDecisionRule &udr)
: DecisionRuleImpl<KOrder::fold>(ctraits<KOrder::fold>::Tpol(udr.nrows(), udr.nvars()), : DecisionRuleImpl<KOrder::fold>(ctraits<KOrder::fold>::Tpol(udr.nrows(), udr.nvars()),
udr.ypart, udr.nu, udr.ysteady) udr.ypart, udr.nu, udr.ysteady)
{ {
for (ctraits<KOrder::unfold>::Tpol::const_iterator it = udr.begin(); for (const auto & it : udr)
it != udr.end(); ++it)
{ {
insert(new ctraits<KOrder::fold>::Ttensym(*((*it).second))); insert(new ctraits<KOrder::fold>::Ttensym(*(it.second)));
} }
} }
@ -44,10 +43,9 @@ UnfoldDecisionRule::UnfoldDecisionRule(const FoldDecisionRule &fdr)
: DecisionRuleImpl<KOrder::unfold>(ctraits<KOrder::unfold>::Tpol(fdr.nrows(), fdr.nvars()), : DecisionRuleImpl<KOrder::unfold>(ctraits<KOrder::unfold>::Tpol(fdr.nrows(), fdr.nvars()),
fdr.ypart, fdr.nu, fdr.ysteady) fdr.ypart, fdr.nu, fdr.ysteady)
{ {
for (ctraits<KOrder::fold>::Tpol::const_iterator it = fdr.begin(); for (const auto & it : fdr)
it != fdr.end(); ++it)
{ {
insert(new ctraits<KOrder::unfold>::Ttensym(*((*it).second))); insert(new ctraits<KOrder::unfold>::Ttensym(*(it.second)));
} }
} }
@ -196,11 +194,11 @@ SimResultsStats::calcMean()
if (data.size()*num_per > 0) if (data.size()*num_per > 0)
{ {
double mult = 1.0/data.size()/num_per; double mult = 1.0/data.size()/num_per;
for (unsigned int i = 0; i < data.size(); i++) for (auto & i : data)
{ {
for (int j = 0; j < num_per; j++) for (int j = 0; j < num_per; j++)
{ {
ConstVector col(*data[i], j); ConstVector col(*i, j);
mean.add(mult, col); mean.add(mult, col);
} }
} }
@ -214,9 +212,9 @@ SimResultsStats::calcVcov()
{ {
vcov.zeros(); vcov.zeros();
double mult = 1.0/(data.size()*num_per - 1); double mult = 1.0/(data.size()*num_per - 1);
for (unsigned int i = 0; i < data.size(); i++) for (auto & i : data)
{ {
const TwoDMatrix &d = *(data[i]); const TwoDMatrix &d = *i;
for (int j = 0; j < num_per; j++) for (int j = 0; j < num_per; j++)
{ {
for (int m = 0; m < num_y; m++) for (int m = 0; m < num_y; m++)
@ -276,9 +274,9 @@ SimResultsDynamicStats::calcMean()
for (int j = 0; j < num_per; j++) for (int j = 0; j < num_per; j++)
{ {
Vector meanj(mean, j); Vector meanj(mean, j);
for (unsigned int i = 0; i < data.size(); i++) for (auto & i : data)
{ {
ConstVector col(*data[i], j); ConstVector col(*i, j);
meanj.add(mult, col); meanj.add(mult, col);
} }
} }
@ -296,9 +294,9 @@ SimResultsDynamicStats::calcVariance()
{ {
ConstVector meanj(mean, j); ConstVector meanj(mean, j);
Vector varj(variance, j); Vector varj(variance, j);
for (int i = 0; i < (int) data.size(); i++) for (auto & i : data)
{ {
Vector col(ConstVector((*data[i]), j)); Vector col(ConstVector((*i), j));
col.add(-1.0, meanj); col.add(-1.0, meanj);
for (int k = 0; k < col.length(); k++) for (int k = 0; k < col.length(); k++)
col[k] = col[k]*col[k]; col[k] = col[k]*col[k];
@ -350,8 +348,8 @@ SimResultsIRF::calcMeans()
means.zeros(); means.zeros();
if (data.size() > 0) if (data.size() > 0)
{ {
for (unsigned int i = 0; i < data.size(); i++) for (auto & i : data)
means.add(1.0, *(data[i])); means.add(1.0, *i);
means.mult(1.0/data.size()); means.mult(1.0/data.size());
} }
} }
@ -362,9 +360,9 @@ SimResultsIRF::calcVariances()
if (data.size() > 1) if (data.size() > 1)
{ {
variances.zeros(); variances.zeros();
for (unsigned int i = 0; i < data.size(); i++) for (auto & i : data)
{ {
TwoDMatrix d((const TwoDMatrix &)(*(data[i]))); TwoDMatrix d((const TwoDMatrix &)(*i));
d.add(-1.0, means); d.add(-1.0, means);
for (int j = 0; j < d.nrows(); j++) for (int j = 0; j < d.nrows(); j++)
for (int k = 0; k < d.ncols(); k++) for (int k = 0; k < d.ncols(); k++)
@ -450,9 +448,8 @@ IRFResults::IRFResults(const DynamicModel &mod, const DecisionRule &dr,
pa << "Calculating IRFs against control for " << (int) irf_list_ind.size() << " shocks and for " pa << "Calculating IRFs against control for " << (int) irf_list_ind.size() << " shocks and for "
<< num_per << " periods" << endrec; << num_per << " periods" << endrec;
const TwoDMatrix &vcov = mod.getVcov(); const TwoDMatrix &vcov = mod.getVcov();
for (unsigned int ii = 0; ii < irf_list_ind.size(); ii++) for (int ishock : irf_list_ind)
{ {
int ishock = irf_list_ind[ii];
double stderror = sqrt(vcov.get(ishock, ishock)); double stderror = sqrt(vcov.get(ishock, ishock));
irf_res.push_back(new SimResultsIRF(control, model.numeq(), num_per, irf_res.push_back(new SimResultsIRF(control, model.numeq(), num_per,
ishock, stderror)); ishock, stderror));
@ -469,8 +466,8 @@ IRFResults::IRFResults(const DynamicModel &mod, const DecisionRule &dr,
IRFResults::~IRFResults() IRFResults::~IRFResults()
{ {
for (unsigned int i = 0; i < irf_res.size(); i++) for (auto & irf_re : irf_res)
delete irf_res[i]; delete irf_re;
} }
void void

View File

@ -166,8 +166,8 @@ JournalRecord::operator<<(const IntSequence &s)
void void
JournalRecord::writePrefix(const SystemResourcesFlash &f) JournalRecord::writePrefix(const SystemResourcesFlash &f)
{ {
for (int i = 0; i < MAXLEN; i++) for (char & i : prefix)
prefix[i] = ' '; i = ' ';
double mb = 1024*1024; double mb = 1024*1024;
sprintf(prefix, "%07.6g", f.elapsed); sprintf(prefix, "%07.6g", f.elapsed);
sprintf(prefix+7, ":%c%05d", recChar, ord); sprintf(prefix+7, ":%c%05d", recChar, ord);
@ -182,8 +182,8 @@ JournalRecord::writePrefix(const SystemResourcesFlash &f)
void void
JournalRecordPair::writePrefixForEnd(const SystemResourcesFlash &f) JournalRecordPair::writePrefixForEnd(const SystemResourcesFlash &f)
{ {
for (int i = 0; i < MAXLEN; i++) for (char & i : prefix_end)
prefix_end[i] = ' '; i = ' ';
double mb = 1024*1024; double mb = 1024*1024;
SystemResourcesFlash difnow; SystemResourcesFlash difnow;
difnow.diff(f); difnow.diff(f);

View File

@ -18,9 +18,8 @@ AtomAssignings::AtomAssignings(const AtomAssignings &aa, ogp::StaticAtoms &a)
order(aa.order) order(aa.order)
{ {
// fill the lname2expr // fill the lname2expr
for (Tvarintmap::const_iterator it = aa.lname2expr.begin(); for (auto it : aa.lname2expr)
it != aa.lname2expr.end(); ++it) lname2expr.insert(Tvarintmap::value_type(left_names.query(it.first), it.second));
lname2expr.insert(Tvarintmap::value_type(left_names.query((*it).first), (*it).second));
} }
/** A global symbol for passing info to the AtomAssignings from /** A global symbol for passing info to the AtomAssignings from
@ -153,11 +152,10 @@ AtomAssignings::apply_subst(const AtomSubstitutions::Toldnamemap &mm)
{ {
// go through all old variables and see what are their derived new // go through all old variables and see what are their derived new
// variables // variables
for (AtomSubstitutions::Toldnamemap::const_iterator it = mm.begin(); for (const auto & it : mm)
it != mm.end(); ++it)
{ {
const char *oldname = (*it).first; const char *oldname = it.first;
const AtomSubstitutions::Tshiftnameset &sset = (*it).second; const AtomSubstitutions::Tshiftnameset &sset = it.second;
if (!sset.empty()) if (!sset.empty())
{ {
int told = atoms.index(oldname); int told = atoms.index(oldname);
@ -171,10 +169,9 @@ AtomAssignings::apply_subst(const AtomSubstitutions::Toldnamemap &mm)
order.push_back(-1); order.push_back(-1);
// now go through all new names derived from the old name and // now go through all new names derived from the old name and
// reference to the newly added formula // reference to the newly added formula
for (AtomSubstitutions::Tshiftnameset::const_iterator itt = sset.begin(); for (const auto & itt : sset)
itt != sset.end(); ++itt)
{ {
const char *newname = (*itt).first; const char *newname = itt.first;
const char *nn = left_names.insert(newname); const char *nn = left_names.insert(newname);
lname2expr.insert(Tvarintmap::value_type(nn, expr.nformulas()-1)); lname2expr.insert(Tvarintmap::value_type(nn, expr.nformulas()-1));
} }
@ -188,9 +185,8 @@ AtomAssignings::print() const
printf("Atom Assignings\nExpressions:\n"); printf("Atom Assignings\nExpressions:\n");
expr.print(); expr.print();
printf("Left names:\n"); printf("Left names:\n");
for (Tvarintmap::const_iterator it = lname2expr.begin(); for (auto it : lname2expr)
it != lname2expr.end(); ++it) printf("%s ==> %d (t=%d)\n", it.first, expr.formula(it.second), order[it.second]);
printf("%s ==> %d (t=%d)\n", (*it).first, expr.formula((*it).second), order[(*it).second]);
} }
void void

View File

@ -14,20 +14,18 @@ AtomSubstitutions::AtomSubstitutions(const AtomSubstitutions &as, const FineAtom
const NameStorage &ns = na.get_name_storage(); const NameStorage &ns = na.get_name_storage();
// fill new2old // fill new2old
for (Tshiftmap::const_iterator it = as.new2old.begin(); for (const auto & it : as.new2old)
it != as.new2old.end(); ++it) new2old.insert(Tshiftmap::value_type(ns.query(it.first),
new2old.insert(Tshiftmap::value_type(ns.query((*it).first), Tshiftname(ns.query(it.second.first),
Tshiftname(ns.query((*it).second.first), it.second.second)));
(*it).second.second)));
// fill old2new // fill old2new
for (Toldnamemap::const_iterator it = as.old2new.begin(); for (const auto & it : as.old2new)
it != as.old2new.end(); ++it)
{ {
Tshiftnameset sset; Tshiftnameset sset;
for (Tshiftnameset::const_iterator itt = (*it).second.begin(); for (Tshiftnameset::const_iterator itt = it.second.begin();
itt != (*it).second.end(); ++itt) itt != it.second.end(); ++itt)
sset.insert(Tshiftname(ns.query((*itt).first), (*itt).second)); sset.insert(Tshiftname(ns.query((*itt).first), (*itt).second));
old2new.insert(Toldnamemap::value_type(ns.query((*it).first), sset)); old2new.insert(Toldnamemap::value_type(ns.query(it.first), sset));
} }
} }
@ -64,17 +62,15 @@ AtomSubstitutions::substitutions_finished(VarOrdering::ord_type ot)
// create an external ordering of new_atoms from old_atoms // create an external ordering of new_atoms from old_atoms
const vector<const char *> &oa_ext = old_atoms.get_allvar(); const vector<const char *> &oa_ext = old_atoms.get_allvar();
vector<const char *> na_ext; vector<const char *> na_ext;
for (unsigned int i = 0; i < oa_ext.size(); i++) for (auto oname : oa_ext)
{ {
const char *oname = oa_ext[i];
// add the old name itself // add the old name itself
na_ext.push_back(oname); na_ext.push_back(oname);
// add all new names derived from the old name // add all new names derived from the old name
Toldnamemap::const_iterator it = old2new.find(oname); Toldnamemap::const_iterator it = old2new.find(oname);
if (it != old2new.end()) if (it != old2new.end())
for (Tshiftnameset::const_iterator itt = (*it).second.begin(); for (const auto & itt : (*it).second)
itt != (*it).second.end(); ++itt) na_ext.push_back(itt.first);
na_ext.push_back((*itt).first);
} }
// call parsing finished for the new_atoms // call parsing finished for the new_atoms
@ -88,10 +84,9 @@ AtomSubstitutions::get_new4old(const char *oldname, int tshift) const
if (it != old2new.end()) if (it != old2new.end())
{ {
const Tshiftnameset &sset = (*it).second; const Tshiftnameset &sset = (*it).second;
for (Tshiftnameset::const_iterator itt = sset.begin(); for (const auto & itt : sset)
itt != sset.end(); ++itt) if (itt.second == -tshift)
if ((*itt).second == -tshift) return itt.first;
return (*itt).first;
} }
return NULL; return NULL;
} }
@ -100,14 +95,14 @@ void
AtomSubstitutions::print() const AtomSubstitutions::print() const
{ {
printf("Atom Substitutions:\nOld ==> New:\n"); printf("Atom Substitutions:\nOld ==> New:\n");
for (Toldnamemap::const_iterator it = old2new.begin(); it != old2new.end(); ++it) for (const auto & it : old2new)
for (Tshiftnameset::const_iterator itt = (*it).second.begin(); for (Tshiftnameset::const_iterator itt = it.second.begin();
itt != (*it).second.end(); ++itt) itt != it.second.end(); ++itt)
printf(" %s ==> [%s, %d]\n", (*it).first, (*itt).first, (*itt).second); printf(" %s ==> [%s, %d]\n", it.first, (*itt).first, (*itt).second);
printf("Old <== New:\n"); printf("Old <== New:\n");
for (Tshiftmap::const_iterator it = new2old.begin(); it != new2old.end(); ++it) for (const auto & it : new2old)
printf(" [%s, %d] <== %s\n", (*it).second.first, (*it).second.second, (*it).first); printf(" [%s, %d] <== %s\n", it.second.first, it.second.second, it.first);
} }
void void
@ -167,16 +162,14 @@ const char *
SAtoms::findNameWithLeadInInterval(const vector<const char *> &names, SAtoms::findNameWithLeadInInterval(const vector<const char *> &names,
int ll1, int ll2) const int ll1, int ll2) const
{ {
for (unsigned int i = 0; i < names.size(); i++) for (auto name : names)
{ {
const char *name = names[i];
DynamicAtoms::Tvarmap::const_iterator it = vars.find(name); DynamicAtoms::Tvarmap::const_iterator it = vars.find(name);
if (it != vars.end()) if (it != vars.end())
{ {
const DynamicAtoms::Tlagmap &lmap = (*it).second; const DynamicAtoms::Tlagmap &lmap = (*it).second;
for (DynamicAtoms::Tlagmap::const_iterator itt = lmap.begin(); for (auto itt : lmap)
itt != lmap.end(); ++itt) if (itt.first >= ll1 && itt.first <= ll2)
if ((*itt).first >= ll1 && (*itt).first <= ll2)
return name; return name;
} }
} }

View File

@ -12,10 +12,10 @@ using namespace ogp;
NameStorage::NameStorage(const NameStorage &stor) NameStorage::NameStorage(const NameStorage &stor)
{ {
for (unsigned int i = 0; i < stor.name_store.size(); i++) for (auto i : stor.name_store)
{ {
char *str = new char[strlen(stor.name_store[i])+1]; char *str = new char[strlen(i)+1];
strcpy(str, stor.name_store[i]); strcpy(str, i);
name_store.push_back(str); name_store.push_back(str);
name_set.insert(str); name_set.insert(str);
} }
@ -61,20 +61,19 @@ NameStorage::insert(const char *name)
void void
NameStorage::print() const NameStorage::print() const
{ {
for (unsigned int i = 0; i < name_store.size(); i++) for (auto i : name_store)
printf("%s\n", name_store[i]); printf("%s\n", i);
} }
void void
Constants::import_constants(const Constants &c, OperationTree &otree, Tintintmap &tmap) Constants::import_constants(const Constants &c, OperationTree &otree, Tintintmap &tmap)
{ {
for (Tconstantmap::const_iterator it = c.cmap.begin(); for (auto it : c.cmap)
it != c.cmap.end(); ++it)
{ {
int told = (*it).first; int told = it.first;
int tnew = otree.add_nulary(); int tnew = otree.add_nulary();
tmap.insert(Tintintmap::value_type(told, tnew)); tmap.insert(Tintintmap::value_type(told, tnew));
add_constant(tnew, (*it).second); add_constant(tnew, it.second);
} }
} }
@ -147,15 +146,13 @@ DynamicAtoms::DynamicAtoms(const DynamicAtoms &da)
nv(da.nv), minlag(da.minlag), maxlead(da.maxlead) nv(da.nv), minlag(da.minlag), maxlead(da.maxlead)
{ {
// copy vars // copy vars
for (Tvarmap::const_iterator it = da.vars.begin(); for (const auto & var : da.vars)
it != da.vars.end(); ++it) vars.insert(Tvarmap::value_type(varnames.query(var.first),
vars.insert(Tvarmap::value_type(varnames.query((*it).first), var.second));
(*it).second));
// copy indices // copy indices
for (Tindexmap::const_iterator it = da.indices.begin(); for (auto indice : da.indices)
it != da.indices.end(); ++it) indices.insert(Tindexmap::value_type(indice.first,
indices.insert(Tindexmap::value_type((*it).first, varnames.query(indice.second)));
varnames.query((*it).second)));
} }
int int
@ -294,9 +291,9 @@ DynamicAtoms::update_minmaxll()
for (Tvarmap::const_iterator it = vars.begin(); it != vars.end(); ++it) for (Tvarmap::const_iterator it = vars.begin(); it != vars.end(); ++it)
{ {
const Tlagmap &lmap = (*it).second; const Tlagmap &lmap = (*it).second;
for (Tlagmap::const_iterator itt = lmap.begin(); itt != lmap.end(); ++itt) for (auto itt : lmap)
{ {
int ll = (*itt).first; int ll = itt.first;
if (ll < minlag) if (ll < minlag)
minlag = ll; minlag = ll;
if (ll > maxlead) if (ll > maxlead)
@ -309,13 +306,11 @@ vector<int>
DynamicAtoms::variables() const DynamicAtoms::variables() const
{ {
vector<int> res; vector<int> res;
for (Tvarmap::const_iterator it = vars.begin(); for (const auto & var : vars)
it != vars.end(); ++it)
{ {
const Tlagmap &lmap = (*it).second; const Tlagmap &lmap = var.second;
for (Tlagmap::const_iterator itt = lmap.begin(); for (auto itt : lmap)
itt != lmap.end(); ++itt) res.push_back(itt.second);
res.push_back((*itt).second);
} }
return res; return res;
} }
@ -355,10 +350,10 @@ DynamicAtoms::varspan(const vector<const char *> &names, int &mlead, int &mlag)
{ {
mlead = INT_MIN; mlead = INT_MIN;
mlag = INT_MAX; mlag = INT_MAX;
for (unsigned int i = 0; i < names.size(); i++) for (auto name : names)
{ {
int lag, lead; int lag, lead;
varspan(names[i], lead, lag); varspan(name, lead, lag);
if (lead > mlead) if (lead > mlead)
mlead = lead; mlead = lead;
if (lag < mlag) if (lag < mlag)
@ -436,18 +431,15 @@ DynamicAtoms::print() const
printf("constants:\n"); printf("constants:\n");
Constants::print(); Constants::print();
printf("variables:\n"); printf("variables:\n");
for (Tvarmap::const_iterator it = vars.begin(); for (const auto & var : vars)
it != vars.end(); ++it)
{ {
const Tlagmap &lmap = (*it).second; const Tlagmap &lmap = var.second;
for (Tlagmap::const_iterator itt = lmap.begin(); for (auto itt : lmap)
itt != lmap.end(); ++itt) printf("$%d: %s(%d)\n", itt.second, var.first, itt.first);
printf("$%d: %s(%d)\n", (*itt).second, (*it).first, (*itt).first);
} }
printf("indices:\n"); printf("indices:\n");
for (Tindexmap::const_iterator it = indices.begin(); for (auto indice : indices)
it != indices.end(); ++it) printf("t=%d ==> %s\n", indice.first, indice.second);
printf("t=%d ==> %s\n", (*it).first, (*it).second);
} }
/** Note that the str has been parsed by the lexicographic /** Note that the str has been parsed by the lexicographic
@ -578,12 +570,12 @@ VarOrdering::do_general(ord_type ordering)
// make der_atoms and positions // make der_atoms and positions
int off = 0; int off = 0;
for (unsigned int i = 0; i < 8; i++) for (auto & ord : ords)
for (unsigned int j = 0; j < (ords[i])->size(); j++, off++) for (unsigned int j = 0; j < ord->size(); j++, off++)
if ((*(ords[i]))[j] != -1) if ((*ord)[j] != -1)
{ {
der_atoms.push_back((*(ords[i]))[j]); der_atoms.push_back((*ord)[j]);
positions.insert(std::pair<int, int>((*(ords[i]))[j], off)); positions.insert(std::pair<int, int>((*ord)[j], off));
} }
// set integer constants // set integer constants
@ -618,11 +610,10 @@ VarOrdering::do_increasing_time()
try try
{ {
const DynamicAtoms::Tlagmap &lmap = atoms.lagmap(varnames[iv]); const DynamicAtoms::Tlagmap &lmap = atoms.lagmap(varnames[iv]);
for (DynamicAtoms::Tlagmap::const_iterator it = lmap.begin(); for (auto it : lmap)
it != lmap.end(); ++it)
{ {
int ll = (*it).first; int ll = it.first;
int t = (*it).second; int t = it.second;
tree_ind[ll-mlag][iv] = t; tree_ind[ll-mlag][iv] = t;
} }
} }
@ -653,10 +644,10 @@ VarOrdering::do_increasing_time()
} }
// set n_stat, n_pred, n_both, and n_forw // set n_stat, n_pred, n_both, and n_forw
for (unsigned int iv = 0; iv < varnames.size(); iv++) for (auto varname : varnames)
{ {
int mmlag, mmlead; int mmlag, mmlead;
atoms.varspan(varnames[iv], mmlead, mmlag); atoms.varspan(varname, mmlead, mmlag);
if (mmlead == 0 && mmlag == 0) if (mmlead == 0 && mmlag == 0)
{ {
n_stat++; n_stat++;
@ -691,17 +682,17 @@ VarOrdering::print() const
{ {
printf("nstat=%d, npred=%d, nboth=%d, nforw=%d\n", n_stat, n_pred, n_both, n_forw); printf("nstat=%d, npred=%d, nboth=%d, nforw=%d\n", n_stat, n_pred, n_both, n_forw);
printf("der_atoms:\n"); printf("der_atoms:\n");
for (unsigned int i = 0; i < der_atoms.size(); i++) for (int der_atom : der_atoms)
printf(" %d", der_atoms[i]); printf(" %d", der_atom);
printf("\nmap:\n"); printf("\nmap:\n");
for (map<int, int>::const_iterator it = positions.begin(); it != positions.end(); ++it) for (auto position : positions)
printf(" [%d->%d]", (*it).first, (*it).second); printf(" [%d->%d]", position.first, position.second);
printf("\ny2outer:\n"); printf("\ny2outer:\n");
for (unsigned int i = 0; i < y2outer.size(); i++) for (int i : y2outer)
printf(" %d", y2outer[i]); printf(" %d", i);
printf("\nouter2y:\n"); printf("\nouter2y:\n");
for (unsigned int i = 0; i < outer2y.size(); i++) for (int i : outer2y)
printf(" %d", outer2y[i]); printf(" %d", i);
printf("\n"); printf("\n");
} }

View File

@ -16,14 +16,14 @@ AllvarOuterOrdering::AllvarOuterOrdering(const vector<const char *> &allvar_oute
exo2all(a.get_exovars().size(), -1) exo2all(a.get_exovars().size(), -1)
{ {
// fill in the allvar from allvar_outer // fill in the allvar from allvar_outer
for (unsigned int i = 0; i < allvar_outer.size(); i++) for (auto i : allvar_outer)
{ {
const char *s = atoms.varnames.query(allvar_outer[i]); const char *s = atoms.varnames.query(i);
if (s) if (s)
allvar.push_back(s); allvar.push_back(s);
else else
throw ogu::Exception(__FILE__, __LINE__, throw ogu::Exception(__FILE__, __LINE__,
string("Variable ") + allvar_outer[i] + " is not a declared symbol in AllvarOuterOrdering constructor"); string("Variable ") + i + " is not a declared symbol in AllvarOuterOrdering constructor");
} }
// fill in endo2all and exo2all // fill in endo2all and exo2all
@ -67,9 +67,9 @@ AllvarOuterOrdering::AllvarOuterOrdering(const AllvarOuterOrdering &avo,
exo2all(avo.exo2all) exo2all(avo.exo2all)
{ {
// fill in the allvar from avo.allvar // fill in the allvar from avo.allvar
for (unsigned int i = 0; i < avo.allvar.size(); i++) for (auto i : avo.allvar)
{ {
const char *s = atoms.varnames.query(avo.allvar[i]); const char *s = atoms.varnames.query(i);
allvar.push_back(s); allvar.push_back(s);
} }
} }
@ -82,32 +82,32 @@ FineAtoms::FineAtoms(const FineAtoms &fa)
exo_atoms_map(fa.exo_atoms_map) exo_atoms_map(fa.exo_atoms_map)
{ {
// fill in params // fill in params
for (unsigned int i = 0; i < fa.params.size(); i++) for (auto param : fa.params)
{ {
const char *s = varnames.query(fa.params[i]); const char *s = varnames.query(param);
if (!s) if (!s)
throw ogu::Exception(__FILE__, __LINE__, throw ogu::Exception(__FILE__, __LINE__,
string("Parameter ") + fa.params[i] + " does not exist in FineAtoms copy cosntructor"); string("Parameter ") + param + " does not exist in FineAtoms copy cosntructor");
params.push_back(s); params.push_back(s);
param_outer_map.insert(Tvarintmap::value_type(s, params.size()-1)); param_outer_map.insert(Tvarintmap::value_type(s, params.size()-1));
} }
// fill in endovars // fill in endovars
for (unsigned int i = 0; i < fa.endovars.size(); i++) for (auto endovar : fa.endovars)
{ {
const char *s = varnames.query(fa.endovars[i]); const char *s = varnames.query(endovar);
if (!s) if (!s)
throw ogu::Exception(__FILE__, __LINE__, throw ogu::Exception(__FILE__, __LINE__,
string("Endo variable ") + fa.endovars[i] + " does not exist in FineAtoms copy constructor"); string("Endo variable ") + endovar + " does not exist in FineAtoms copy constructor");
endovars.push_back(s); endovars.push_back(s);
endo_outer_map.insert(Tvarintmap::value_type(s, endovars.size()-1)); endo_outer_map.insert(Tvarintmap::value_type(s, endovars.size()-1));
} }
// fill in exovars // fill in exovars
for (unsigned int i = 0; i < fa.exovars.size(); i++) for (auto exovar : fa.exovars)
{ {
const char *s = varnames.query(fa.exovars[i]); const char *s = varnames.query(exovar);
if (!s) if (!s)
throw ogu::Exception(__FILE__, __LINE__, throw ogu::Exception(__FILE__, __LINE__,
string("Exo variable ") + fa.exovars[i] + " does not exist in FineAtoms copy cosntructor"); string("Exo variable ") + exovar + " does not exist in FineAtoms copy cosntructor");
exovars.push_back(s); exovars.push_back(s);
exo_outer_map.insert(Tvarintmap::value_type(s, exovars.size()-1)); exo_outer_map.insert(Tvarintmap::value_type(s, exovars.size()-1));
} }

View File

@ -20,8 +20,8 @@ FormulaParser::FormulaParser(const FormulaParser &fp, Atoms &a)
: otree(fp.otree), atoms(a), formulas(fp.formulas), ders() : otree(fp.otree), atoms(a), formulas(fp.formulas), ders()
{ {
// create derivatives // create derivatives
for (unsigned int i = 0; i < fp.ders.size(); i++) for (auto der : fp.ders)
ders.push_back(new FormulaDerivatives(*(fp.ders[i]))); ders.push_back(new FormulaDerivatives(*der));
} }
FormulaParser::~FormulaParser() FormulaParser::~FormulaParser()
@ -35,8 +35,8 @@ FormulaParser::differentiate(int max_order)
destroy_derivatives(); destroy_derivatives();
vector<int> vars; vector<int> vars;
vars = atoms.variables(); vars = atoms.variables();
for (unsigned int i = 0; i < formulas.size(); i++) for (int formula : formulas)
ders.push_back(new FormulaDerivatives(otree, vars, formulas[i], max_order)); ders.push_back(new FormulaDerivatives(otree, vars, formula, max_order));
} }
const FormulaDerivatives & const FormulaDerivatives &
@ -156,9 +156,9 @@ int
FormulaParser::last_formula() const FormulaParser::last_formula() const
{ {
int res = -1; int res = -1;
for (unsigned int i = 0; i < formulas.size(); i++) for (int formula : formulas)
if (res < formulas[i]) if (res < formula)
res = formulas[i]; res = formula;
return std::max(res, otree.get_last_nulary()); return std::max(res, otree.get_last_nulary());
} }
@ -181,10 +181,10 @@ void
FormulaParser::print() const FormulaParser::print() const
{ {
atoms.print(); atoms.print();
for (unsigned int i = 0; i < formulas.size(); i++) for (int formula : formulas)
{ {
printf("formula %d:\n", formulas[i]); printf("formula %d:\n", formula);
otree.print_operation(formulas[i]); otree.print_operation(formula);
} }
for (unsigned int i = 0; i < ders.size(); i++) for (unsigned int i = 0; i < ders.size(); i++)
{ {
@ -283,13 +283,12 @@ FormulaDerivatives::derivative(const FoldMultiIndex &mi) const
void void
FormulaDerivatives::print(const OperationTree &otree) const FormulaDerivatives::print(const OperationTree &otree) const
{ {
for (Tfmiintmap::const_iterator it = ind2der.begin(); for (const auto & it : ind2der)
it != ind2der.end(); ++it)
{ {
printf("derivative "); printf("derivative ");
(*it).first.print(); it.first.print();
printf(" is formula %d\n", tder[(*it).second]); printf(" is formula %d\n", tder[it.second]);
otree.print_operation(tder[(*it).second]); otree.print_operation(tder[it.second]);
} }
} }
@ -480,8 +479,8 @@ ltfmi::operator()(const FoldMultiIndex &i1, const FoldMultiIndex &i2) const
FormulaDerEvaluator::FormulaDerEvaluator(const FormulaParser &fp) FormulaDerEvaluator::FormulaDerEvaluator(const FormulaParser &fp)
: etree(fp.otree, -1) : etree(fp.otree, -1)
{ {
for (unsigned int i = 0; i < fp.ders.size(); i++) for (auto der : fp.ders)
ders.push_back((const FormulaDerivatives *) (fp.ders[i])); ders.push_back((const FormulaDerivatives *) der);
der_atoms = fp.atoms.variables(); der_atoms = fp.atoms.variables();
} }

View File

@ -12,26 +12,24 @@ StaticAtoms::StaticAtoms(const StaticAtoms &a)
varorder(), vars(), indices() varorder(), vars(), indices()
{ {
// fill varorder // fill varorder
for (unsigned int i = 0; i < a.varorder.size(); i++) for (auto i : a.varorder)
{ {
const char *s = varnames.query(a.varorder[i]); const char *s = varnames.query(i);
varorder.push_back(s); varorder.push_back(s);
} }
// fill vars // fill vars
for (Tvarmap::const_iterator it = a.vars.begin(); for (auto var : a.vars)
it != a.vars.end(); ++it)
{ {
const char *s = varnames.query((*it).first); const char *s = varnames.query(var.first);
vars.insert(Tvarmap::value_type(s, (*it).second)); vars.insert(Tvarmap::value_type(s, var.second));
} }
// fill indices // fill indices
for (Tinvmap::const_iterator it = a.indices.begin(); for (auto indice : a.indices)
it != a.indices.end(); ++it)
{ {
const char *s = varnames.query((*it).second); const char *s = varnames.query(indice.second);
indices.insert(Tinvmap::value_type((*it).first, s)); indices.insert(Tinvmap::value_type(indice.first, s));
} }
} }
@ -49,10 +47,9 @@ StaticAtoms::import_atoms(const DynamicAtoms &da, OperationTree &otree, Tintintm
if (da.is_referenced(name)) if (da.is_referenced(name))
{ {
const DynamicAtoms::Tlagmap &lmap = da.lagmap(name); const DynamicAtoms::Tlagmap &lmap = da.lagmap(name);
for (DynamicAtoms::Tlagmap::const_iterator it = lmap.begin(); for (auto it : lmap)
it != lmap.end(); ++it)
{ {
int told = (*it).second; int told = it.second;
tmap.insert(Tintintmap::value_type(told, tnew)); tmap.insert(Tintintmap::value_type(told, tnew));
} }
} }
@ -113,10 +110,9 @@ vector<int>
StaticAtoms::variables() const StaticAtoms::variables() const
{ {
vector<int> res; vector<int> res;
for (Tvarmap::const_iterator it = vars.begin(); for (auto var : vars)
it != vars.end(); ++it)
{ {
res.push_back((*it).second); res.push_back(var.second);
} }
return res; return res;
} }
@ -136,6 +132,6 @@ StaticAtoms::print() const
printf("variable names:\n"); printf("variable names:\n");
varnames.print(); varnames.print();
printf("map to tree indices:\n"); printf("map to tree indices:\n");
for (Tvarmap::const_iterator it = vars.begin(); it != vars.end(); ++it) for (auto var : vars)
printf("%s\t->\t%d\n", (*it).first, (*it).second); printf("%s\t->\t%d\n", var.first, var.second);
} }

View File

@ -50,18 +50,18 @@ StaticFineAtoms::import_atoms(const FineAtoms &fa, OperationTree &otree, Tintint
// parameters // parameters
const vector<const char *> &fa_params = fa.get_params(); const vector<const char *> &fa_params = fa.get_params();
for (unsigned int i = 0; i < fa_params.size(); i++) for (auto fa_param : fa_params)
register_param(fa_params[i]); register_param(fa_param);
// endogenous // endogenous
const vector<const char *> &fa_endovars = fa.get_endovars(); const vector<const char *> &fa_endovars = fa.get_endovars();
for (unsigned int i = 0; i < fa_endovars.size(); i++) for (auto fa_endovar : fa_endovars)
register_endo(fa_endovars[i]); register_endo(fa_endovar);
// exogenous // exogenous
const vector<const char *> &fa_exovars = fa.get_exovars(); const vector<const char *> &fa_exovars = fa.get_exovars();
for (unsigned int i = 0; i < fa_exovars.size(); i++) for (auto fa_exovar : fa_exovars)
register_exo(fa_exovars[i]); register_exo(fa_exovar);
parsing_finished(); parsing_finished();
} }
@ -77,8 +77,8 @@ StaticFineAtoms::import_atoms(const FineAtoms &fa, OperationTree &otree, Tintint
// parameters // parameters
const vector<const char *> &fa_params = fa.get_params(); const vector<const char *> &fa_params = fa.get_params();
for (unsigned int i = 0; i < fa_params.size(); i++) for (auto fa_param : fa_params)
register_param(fa_params[i]); register_param(fa_param);
// endogenous // endogenous
const vector<const char *> &fa_endovars = fa.get_endovars(); const vector<const char *> &fa_endovars = fa.get_endovars();
@ -112,18 +112,18 @@ StaticFineAtoms::parsing_finished()
// go through all endo and exo insert tree indices, ignore names // go through all endo and exo insert tree indices, ignore names
// whose tree index is -1 (those which are not referenced) // whose tree index is -1 (those which are not referenced)
for (unsigned int i = 0; i < endovars.size(); i++) for (auto & endovar : endovars)
{ {
int t = index(endovars[i]); int t = index(endovar);
if (t != -1) if (t != -1)
{ {
endo_atoms_map.push_back(der_atoms.size()); endo_atoms_map.push_back(der_atoms.size());
der_atoms.push_back(t); der_atoms.push_back(t);
} }
} }
for (unsigned int i = 0; i < exovars.size(); i++) for (auto & exovar : exovars)
{ {
int t = index(exovars[i]); int t = index(exovar);
if (t != -1) if (t != -1)
{ {
exo_atoms_map.push_back(der_atoms.size()); exo_atoms_map.push_back(der_atoms.size());

View File

@ -468,8 +468,8 @@ OperationTree::select_terms_inv(int t, const opselector &sel, unordered_set<int>
void void
OperationTree::forget_derivative_maps() OperationTree::forget_derivative_maps()
{ {
for (unsigned int i = 0; i < derivatives.size(); i++) for (auto & derivative : derivatives)
derivatives[i].clear(); derivative.clear();
} }
void void

View File

@ -21,14 +21,14 @@ vector<int>
DynareNameList::selectIndices(const vector<const char *> &ns) const DynareNameList::selectIndices(const vector<const char *> &ns) const
{ {
vector<int> res; vector<int> res;
for (unsigned int i = 0; i < ns.size(); i++) for (auto n : ns)
{ {
int j = 0; int j = 0;
while (j < getNum() && strcmp(getName(j), ns[i]) != 0) while (j < getNum() && strcmp(getName(j), n) != 0)
j++; j++;
if (j == getNum()) if (j == getNum())
throw DynareException(__FILE__, __LINE__, throw DynareException(__FILE__, __LINE__,
string("Couldn't find name for ") + ns[i] string("Couldn't find name for ") + n
+" in DynareNameList::selectIndices"); +" in DynareNameList::selectIndices");
res.push_back(j); res.push_back(j);
} }

View File

@ -37,9 +37,8 @@ DynareDynamicAtoms::DynareDynamicAtoms(const DynareDynamicAtoms &dda)
: SAtoms(dda) : SAtoms(dda)
{ {
// fill atom_type // fill atom_type
for (Tatypemap::const_iterator it = dda.atom_type.begin(); for (auto it : dda.atom_type)
it != dda.atom_type.end(); ++it) atom_type.insert(Tatypemap::value_type(varnames.query(it.first), it.second));
atom_type.insert(Tatypemap::value_type(varnames.query((*it).first), (*it).second));
} }
void void
@ -101,10 +100,9 @@ DynareDynamicAtoms::print() const
{ {
SAtoms::print(); SAtoms::print();
printf("Name types:\n"); printf("Name types:\n");
for (Tatypemap::const_iterator it = atom_type.begin(); for (auto it : atom_type)
it != atom_type.end(); ++it) printf("name=%s type=%s\n", it.first,
printf("name=%s type=%s\n", (*it).first, (it.second == endovar) ? "endovar" : ((it.second == exovar) ? "exovar" : "param"));
((*it).second == endovar) ? "endovar" : (((*it).second == exovar) ? "exovar" : "param"));
} }
std::string std::string
@ -154,10 +152,9 @@ DynareAtomValues::setValues(ogp::EvalTree &et) const
if (atoms.is_referenced(atoms.get_params()[i])) if (atoms.is_referenced(atoms.get_params()[i]))
{ {
const ogp::DynamicAtoms::Tlagmap &lmap = atoms.lagmap(atoms.get_params()[i]); const ogp::DynamicAtoms::Tlagmap &lmap = atoms.lagmap(atoms.get_params()[i]);
for (ogp::DynamicAtoms::Tlagmap::const_iterator it = lmap.begin(); for (auto it : lmap)
it != lmap.end(); ++it)
{ {
int t = (*it).second; int t = it.second;
et.set_nulary(t, paramvals[i]); et.set_nulary(t, paramvals[i]);
} }
} }
@ -169,11 +166,10 @@ DynareAtomValues::setValues(ogp::EvalTree &et) const
if (atoms.is_referenced(atoms.get_endovars()[outer_i])) if (atoms.is_referenced(atoms.get_endovars()[outer_i]))
{ {
const ogp::DynamicAtoms::Tlagmap &lmap = atoms.lagmap(atoms.get_endovars()[outer_i]); const ogp::DynamicAtoms::Tlagmap &lmap = atoms.lagmap(atoms.get_endovars()[outer_i]);
for (ogp::DynamicAtoms::Tlagmap::const_iterator it = lmap.begin(); for (auto it : lmap)
it != lmap.end(); ++it)
{ {
int ll = (*it).first; int ll = it.first;
int t = (*it).second; int t = it.second;
int i = atoms.outer2y_endo()[outer_i]; int i = atoms.outer2y_endo()[outer_i];
if (ll == -1) if (ll == -1)
{ {
@ -193,13 +189,12 @@ DynareAtomValues::setValues(ogp::EvalTree &et) const
if (atoms.is_referenced(atoms.get_exovars()[outer_i])) if (atoms.is_referenced(atoms.get_exovars()[outer_i]))
{ {
const ogp::DynamicAtoms::Tlagmap &lmap = atoms.lagmap(atoms.get_exovars()[outer_i]); const ogp::DynamicAtoms::Tlagmap &lmap = atoms.lagmap(atoms.get_exovars()[outer_i]);
for (ogp::DynamicAtoms::Tlagmap::const_iterator it = lmap.begin(); for (auto it : lmap)
it != lmap.end(); ++it)
{ {
int ll = (*it).first; int ll = it.first;
if (ll == 0) // this is always true because of checks if (ll == 0) // this is always true because of checks
{ {
int t = (*it).second; int t = it.second;
int i = atoms.outer2y_exo()[outer_i]; int i = atoms.outer2y_exo()[outer_i];
et.set_nulary(t, xx[i]); et.set_nulary(t, xx[i]);
} }
@ -215,9 +210,8 @@ DynareStaticSteadyAtomValues::setValues(ogp::EvalTree &et) const
atoms_static.setValues(et); atoms_static.setValues(et);
// set parameters // set parameters
for (unsigned int i = 0; i < atoms_static.get_params().size(); i++) for (auto name : atoms_static.get_params())
{ {
const char *name = atoms_static.get_params()[i];
int t = atoms_static.index(name); int t = atoms_static.index(name);
if (t != -1) if (t != -1)
{ {
@ -227,9 +221,8 @@ DynareStaticSteadyAtomValues::setValues(ogp::EvalTree &et) const
} }
// set endogenous // set endogenous
for (unsigned int i = 0; i < atoms_static.get_endovars().size(); i++) for (auto name : atoms_static.get_endovars())
{ {
const char *name = atoms_static.get_endovars()[i];
int t = atoms_static.index(name); int t = atoms_static.index(name);
if (t != -1) if (t != -1)
{ {
@ -239,9 +232,8 @@ DynareStaticSteadyAtomValues::setValues(ogp::EvalTree &et) const
} }
// set exogenous // set exogenous
for (unsigned int i = 0; i < atoms_static.get_exovars().size(); i++) for (auto name : atoms_static.get_exovars())
{ {
const char *name = atoms_static.get_exovars()[i];
int t = atoms_static.index(name); int t = atoms_static.index(name);
if (t != -1) if (t != -1)
et.set_nulary(t, 0.0); et.set_nulary(t, 0.0);
@ -255,11 +247,10 @@ DynareSteadySubstitutions::DynareSteadySubstitutions(const ogp::FineAtoms &a,
: atoms(a), y(yy) : atoms(a), y(yy)
{ {
// fill the vector of left and right hand sides // fill the vector of left and right hand sides
for (Tsubstmap::const_iterator it = subst.begin(); for (auto it : subst)
it != subst.end(); ++it)
{ {
left_hand_sides.push_back((*it).first); left_hand_sides.push_back(it.first);
right_hand_sides.push_back((*it).second); right_hand_sides.push_back(it.second);
} }
// evaluate right hand sides // evaluate right hand sides
@ -286,11 +277,10 @@ DynareStaticSteadySubstitutions(const ogp::FineAtoms &a, const ogp::StaticFineAt
: atoms(a), atoms_static(sa), y(yy) : atoms(a), atoms_static(sa), y(yy)
{ {
// fill the vector of left and right hand sides // fill the vector of left and right hand sides
for (Tsubstmap::const_iterator it = subst.begin(); for (auto it : subst)
it != subst.end(); ++it)
{ {
left_hand_sides.push_back((*it).first); left_hand_sides.push_back(it.first);
right_hand_sides.push_back((*it).second); right_hand_sides.push_back(it.second);
} }
// evaluate right hand sides // evaluate right hand sides

View File

@ -130,20 +130,20 @@ DynareModel::dump_model(std::ostream &os) const
{ {
// endogenous variable declaration // endogenous variable declaration
os << "var"; os << "var";
for (int i = 0; i < (int) atoms.get_endovars().size(); i++) for (auto i : atoms.get_endovars())
os << " " << atoms.get_endovars()[i]; os << " " << i;
os << ";\n\n"; os << ";\n\n";
// exogenous variables // exogenous variables
os << "varexo"; os << "varexo";
for (int i = 0; i < (int) atoms.get_exovars().size(); i++) for (auto i : atoms.get_exovars())
os << " " << atoms.get_exovars()[i]; os << " " << i;
os << ";\n\n"; os << ";\n\n";
// parameters // parameters
os << "parameters"; os << "parameters";
for (int i = 0; i < (int) atoms.get_params().size(); i++) for (auto i : atoms.get_params())
os << " " << atoms.get_params()[i]; os << " " << i;
os << ";\n\n"; os << ";\n\n";
// parameter values // parameter values
@ -216,9 +216,8 @@ DynareModel::check_model() const
{ {
int ft = eqs.formula(i); int ft = eqs.formula(i);
const unordered_set<int> &nuls = eqs.nulary_of_term(ft); const unordered_set<int> &nuls = eqs.nulary_of_term(ft);
for (unordered_set<int>::const_iterator it = nuls.begin(); for (int nul : nuls)
it != nuls.end(); ++it) if (!atoms.is_constant(nul) && !atoms.is_named_atom(nul))
if (!atoms.is_constant(*it) && !atoms.is_named_atom(*it))
throw DynareException(__FILE__, __LINE__, throw DynareException(__FILE__, __LINE__,
"Dangling nulary term found, internal error."); "Dangling nulary term found, internal error.");
} }
@ -268,10 +267,8 @@ DynareModel::variable_shift_map(const unordered_set<int> &a_set, int tshift,
map<int, int> &s_map) map<int, int> &s_map)
{ {
s_map.clear(); s_map.clear();
for (unordered_set<int>::const_iterator it = a_set.begin(); for (int t : a_set)
it != a_set.end(); ++it)
{ {
int t = *it;
// make shift map only for non-constants and non-parameters // make shift map only for non-constants and non-parameters
if (!atoms.is_constant(t)) if (!atoms.is_constant(t))
{ {
@ -292,14 +289,13 @@ DynareModel::termspan(int t, int &mlead, int &mlag) const
mlead = INT_MIN; mlead = INT_MIN;
mlag = INT_MAX; mlag = INT_MAX;
const unordered_set<int> &nul_terms = eqs.nulary_of_term(t); const unordered_set<int> &nul_terms = eqs.nulary_of_term(t);
for (unordered_set<int>::const_iterator ni = nul_terms.begin(); for (int nul_term : nul_terms)
ni != nul_terms.end(); ++ni)
{ {
if (!atoms.is_constant(*ni) if (!atoms.is_constant(nul_term)
&& (atoms.is_type(atoms.name(*ni), DynareDynamicAtoms::endovar) && (atoms.is_type(atoms.name(nul_term), DynareDynamicAtoms::endovar)
|| atoms.is_type(atoms.name(*ni), DynareDynamicAtoms::exovar))) || atoms.is_type(atoms.name(nul_term), DynareDynamicAtoms::exovar)))
{ {
int ll = atoms.lead(*ni); int ll = atoms.lead(nul_term);
if (ll < mlag) if (ll < mlag)
mlag = ll; mlag = ll;
if (ll > mlead) if (ll > mlead)
@ -312,10 +308,9 @@ bool
DynareModel::is_constant_term(int t) const DynareModel::is_constant_term(int t) const
{ {
const unordered_set<int> &nul_terms = eqs.nulary_of_term(t); const unordered_set<int> &nul_terms = eqs.nulary_of_term(t);
for (unordered_set<int>::const_iterator ni = nul_terms.begin(); for (int nul_term : nul_terms)
ni != nul_terms.end(); ++ni) if (!atoms.is_constant(nul_term)
if (!atoms.is_constant(*ni) && !atoms.is_type(atoms.name(nul_term), DynareDynamicAtoms::param))
&& !atoms.is_type(atoms.name(*ni), DynareDynamicAtoms::param))
return false; return false;
return true; return true;
} }
@ -827,9 +822,9 @@ ModelSSWriter::write_der1(FILE *fd)
for (int i = 0; i < model.getParser().nformulas(); i++) for (int i = 0; i < model.getParser().nformulas(); i++)
{ {
const ogp::FormulaDerivatives &fder = model.getParser().derivatives(i); const ogp::FormulaDerivatives &fder = model.getParser().derivatives(i);
for (unsigned int j = 0; j < eam.size(); j++) for (int j : eam)
{ {
int t = fder.derivative(ogp::FoldMultiIndex(variables.size(), 1, eam[j])); int t = fder.derivative(ogp::FoldMultiIndex(variables.size(), 1, j));
if (t > 0) if (t > 0)
otree.print_operation_tree(t, fd, *this); otree.print_operation_tree(t, fd, *this);
} }
@ -891,16 +886,14 @@ MatlabSSWriter::write_common1_preamble(FILE *fd) const
model.getAtoms().ny(), DYNVERSION); model.getAtoms().ny(), DYNVERSION);
// write ordering of parameters // write ordering of parameters
fprintf(fd, "\n%% params ordering\n%% =====================\n"); fprintf(fd, "\n%% params ordering\n%% =====================\n");
for (unsigned int ip = 0; ip < model.getAtoms().get_params().size(); ip++) for (auto parname : model.getAtoms().get_params())
{ {
const char *parname = model.getAtoms().get_params()[ip];
fprintf(fd, "%% %s\n", parname); fprintf(fd, "%% %s\n", parname);
} }
// write endogenous variables // write endogenous variables
fprintf(fd, "%%\n%% y ordering\n%% =====================\n"); fprintf(fd, "%%\n%% y ordering\n%% =====================\n");
for (unsigned int ie = 0; ie < model.getAtoms().get_endovars().size(); ie++) for (auto endoname : model.getAtoms().get_endovars())
{ {
const char *endoname = model.getAtoms().get_endovars()[ie];
fprintf(fd, "%% %s\n", endoname); fprintf(fd, "%% %s\n", endoname);
} }
fprintf(fd, "\n"); fprintf(fd, "\n");
@ -933,11 +926,10 @@ MatlabSSWriter::write_atom_assignment(FILE *fd) const
// write numerical constants // write numerical constants
fprintf(fd, "%% numerical constants\n"); fprintf(fd, "%% numerical constants\n");
const ogp::Constants::Tconstantmap &cmap = model.getAtoms().get_constantmap(); const ogp::Constants::Tconstantmap &cmap = model.getAtoms().get_constantmap();
for (ogp::Constants::Tconstantmap::const_iterator it = cmap.begin(); for (auto it : cmap)
it != cmap.end(); ++it)
{ {
format_nulary((*it).first, fd); format_nulary(it.first, fd);
fprintf(fd, " = %12.8g;\n", (*it).second); fprintf(fd, " = %12.8g;\n", it.second);
} }
// write parameters // write parameters
fprintf(fd, "%% parameter values\n"); fprintf(fd, "%% parameter values\n");
@ -963,10 +955,9 @@ MatlabSSWriter::write_atom_assignment(FILE *fd) const
try try
{ {
const ogp::DynamicAtoms::Tlagmap &lmap = model.getAtoms().lagmap(exoname); const ogp::DynamicAtoms::Tlagmap &lmap = model.getAtoms().lagmap(exoname);
for (ogp::DynamicAtoms::Tlagmap::const_iterator it = lmap.begin(); for (auto it : lmap)
it != lmap.end(); ++it)
{ {
format_nulary((*it).second, fd); format_nulary(it.second, fd);
fprintf(fd, " = 0.0; %% %s\n", exoname); fprintf(fd, " = 0.0; %% %s\n", exoname);
} }
} }
@ -981,10 +972,9 @@ MatlabSSWriter::write_atom_assignment(FILE *fd) const
{ {
const char *endoname = model.getAtoms().get_endovars()[ie]; const char *endoname = model.getAtoms().get_endovars()[ie];
const ogp::DynamicAtoms::Tlagmap &lmap = model.getAtoms().lagmap(endoname); const ogp::DynamicAtoms::Tlagmap &lmap = model.getAtoms().lagmap(endoname);
for (ogp::DynamicAtoms::Tlagmap::const_iterator it = lmap.begin(); for (auto it : lmap)
it != lmap.end(); ++it)
{ {
format_nulary((*it).second, fd); format_nulary(it.second, fd);
fprintf(fd, " = y(%d); %% %s\n", ie+1, endoname); fprintf(fd, " = y(%d); %% %s\n", ie+1, endoname);
} }
} }
@ -1021,12 +1011,12 @@ MatlabSSWriter::write_der1_assignment(FILE *fd) const
for (int i = 0; i < model.getParser().nformulas(); i++) for (int i = 0; i < model.getParser().nformulas(); i++)
{ {
const ogp::FormulaDerivatives &fder = model.getParser().derivatives(i); const ogp::FormulaDerivatives &fder = model.getParser().derivatives(i);
for (unsigned int j = 0; j < eam.size(); j++) for (int j : eam)
{ {
int tvar = variables[eam[j]]; int tvar = variables[j];
const char *name = model.getAtoms().name(tvar); const char *name = model.getAtoms().name(tvar);
int yi = model.getAtoms().name2outer_endo(name); int yi = model.getAtoms().name2outer_endo(name);
int t = fder.derivative(ogp::FoldMultiIndex(variables.size(), 1, eam[j])); int t = fder.derivative(ogp::FoldMultiIndex(variables.size(), 1, j));
if (t != ogp::OperationTree::zero) if (t != ogp::OperationTree::zero)
{ {
fprintf(fd, "out(%d,%d) = out(%d,%d) + ", i+1, yi+1, i+1, yi+1); fprintf(fd, "out(%d,%d) = out(%d,%d) + ", i+1, yi+1, i+1, yi+1);

View File

@ -114,20 +114,19 @@ void
ForwSubstBuilder::unassign_gt_1_leads() ForwSubstBuilder::unassign_gt_1_leads()
{ {
const vector<const char *> &endovars = model.atoms.get_endovars(); const vector<const char *> &endovars = model.atoms.get_endovars();
for (unsigned int i = 0; i < endovars.size(); i++) for (auto endovar : endovars)
unassign_gt_1_leads(endovars[i]); unassign_gt_1_leads(endovar);
const vector<const char *> &exovars = model.atoms.get_exovars(); const vector<const char *> &exovars = model.atoms.get_exovars();
for (unsigned int i = 0; i < exovars.size(); i++) for (auto exovar : exovars)
unassign_gt_1_leads(exovars[i]); unassign_gt_1_leads(exovar);
} }
ForwSubstBuilder::ForwSubstBuilder(const ForwSubstBuilder &b, DynareModel &m) ForwSubstBuilder::ForwSubstBuilder(const ForwSubstBuilder &b, DynareModel &m)
: model(m) : model(m)
{ {
for (Tsubstmap::const_iterator it = b.aux_map.begin(); for (auto it : b.aux_map)
it != b.aux_map.end(); ++it)
{ {
const char *ss = m.atoms.get_name_storage().query((*it).first); const char *ss = m.atoms.get_name_storage().query(it.first);
aux_map.insert(Tsubstmap::value_type(ss, (*it).second)); aux_map.insert(Tsubstmap::value_type(ss, it.second));
} }
} }

View File

@ -302,8 +302,8 @@ void
PlannerBuilder::fill_yset(const ogp::NameStorage &ns, PlannerBuilder::fill_yset(const ogp::NameStorage &ns,
const PlannerBuilder::Tvarset &yyset) const PlannerBuilder::Tvarset &yyset)
{ {
for (Tvarset::const_iterator it = yyset.begin(); it != yyset.end(); ++it) for (auto it : yyset)
yset.insert(ns.query(*it)); yset.insert(ns.query(it));
} }
void void
@ -311,15 +311,13 @@ PlannerBuilder::fill_aux_map(const ogp::NameStorage &ns, const Tsubstmap &aaux_m
const Tsubstmap &astatic_aux_map) const Tsubstmap &astatic_aux_map)
{ {
// fill aux_map // fill aux_map
for (Tsubstmap::const_iterator it = aaux_map.begin(); for (auto it : aaux_map)
it != aaux_map.end(); ++it) aux_map.insert(Tsubstmap::value_type(ns.query(it.first), it.second));
aux_map.insert(Tsubstmap::value_type(ns.query((*it).first), (*it).second));
// fill static_aux_map // fill static_aux_map
for (Tsubstmap::const_iterator it = astatic_aux_map.begin(); for (auto it : astatic_aux_map)
it != astatic_aux_map.end(); ++it) static_aux_map.insert(Tsubstmap::value_type(static_atoms.get_name_storage().query(it.first),
static_aux_map.insert(Tsubstmap::value_type(static_atoms.get_name_storage().query((*it).first), it.second));
(*it).second));
} }
MultInitSS::MultInitSS(const PlannerBuilder &pb, const Vector &pvals, Vector &yy) MultInitSS::MultInitSS(const PlannerBuilder &pb, const Vector &pvals, Vector &yy)
@ -380,10 +378,9 @@ MultInitSS::MultInitSS(const PlannerBuilder &pb, const Vector &pvals, Vector &yy
if (it != old2new.end()) if (it != old2new.end())
{ {
const ogp::AtomSubstitutions::Tshiftnameset &sset = (*it).second; const ogp::AtomSubstitutions::Tshiftnameset &sset = (*it).second;
for (ogp::AtomSubstitutions::Tshiftnameset::const_iterator itt = sset.begin(); for (const auto & itt : sset)
itt != sset.end(); ++itt)
{ {
const char *newname = (*itt).first; const char *newname = itt.first;
int iouter = builder.model.atoms.name2outer_endo(newname); int iouter = builder.model.atoms.name2outer_endo(newname);
int iy = builder.model.atoms.outer2y_endo()[iouter]; int iy = builder.model.atoms.outer2y_endo()[iouter];
if (!std::isfinite(yy[iy])) if (!std::isfinite(yy[iy]))

View File

@ -100,9 +100,8 @@ Diagonal::Diagonal(double *data, const Diagonal &d)
num_all = d.num_all; num_all = d.num_all;
num_real = d.num_real; num_real = d.num_real;
int d_size = d.getSize(); int d_size = d.getSize();
for (const_diag_iter it = d.begin(); it != d.end(); ++it) for (const auto & dit : d)
{ {
const DiagonalBlock &dit = *it;
double *beta1 = NULL; double *beta1 = NULL;
double *beta2 = NULL; double *beta2 = NULL;
int id = dit.getIndex()*(d_size+1); int id = dit.getIndex()*(d_size+1);
@ -150,22 +149,22 @@ void
Diagonal::changeBase(double *p) Diagonal::changeBase(double *p)
{ {
int d_size = getSize(); int d_size = getSize();
for (diag_iter it = begin(); it != end(); ++it) for (auto & it : *this)
{ {
const DiagonalBlock &b = *it; const DiagonalBlock &b = it;
int jbar = b.getIndex(); int jbar = b.getIndex();
int base = d_size*jbar + jbar; int base = d_size*jbar + jbar;
if (b.isReal()) if (b.isReal())
{ {
DiagonalBlock bnew(jbar, true, &p[base], &p[base], DiagonalBlock bnew(jbar, true, &p[base], &p[base],
NULL, NULL); NULL, NULL);
*it = bnew; it = bnew;
} }
else else
{ {
DiagonalBlock bnew(jbar, false, &p[base], &p[base+d_size+1], DiagonalBlock bnew(jbar, false, &p[base], &p[base+d_size+1],
&p[base+d_size], &p[base+1]); &p[base+d_size], &p[base+1]);
*it = bnew; it = bnew;
} }
} }
} }
@ -181,9 +180,8 @@ Diagonal::getEigenValues(Vector &eig) const
eig.length(), 2*d_size); eig.length(), 2*d_size);
throw SYLV_MES_EXCEPTION(mes); throw SYLV_MES_EXCEPTION(mes);
} }
for (const_diag_iter it = begin(); it != end(); ++it) for (const auto & b : *this)
{ {
const DiagonalBlock &b = *it;
int ind = b.getIndex(); int ind = b.getIndex();
eig[2*ind] = *(b.getAlpha()); eig[2*ind] = *(b.getAlpha());
if (b.isReal()) if (b.isReal())
@ -307,16 +305,16 @@ void
Diagonal::print() const Diagonal::print() const
{ {
printf("Num real: %d, num complex: %d\n", getNumReal(), getNumComplex()); printf("Num real: %d, num complex: %d\n", getNumReal(), getNumComplex());
for (const_diag_iter it = begin(); it != end(); ++it) for (const auto & it : *this)
{ {
if ((*it).isReal()) if (it.isReal())
{ {
printf("real: jbar=%d, alpha=%f\n", (*it).getIndex(), *((*it).getAlpha())); printf("real: jbar=%d, alpha=%f\n", it.getIndex(), *(it.getAlpha()));
} }
else else
{ {
printf("complex: jbar=%d, alpha=%f, beta1=%f, beta2=%f\n", printf("complex: jbar=%d, alpha=%f, beta1=%f, beta2=%f\n",
(*it).getIndex(), *((*it).getAlpha()), (*it).getBeta1(), (*it).getBeta2()); it.getIndex(), *(it.getAlpha()), it.getBeta1(), it.getBeta2());
} }
} }
} }

View File

@ -413,6 +413,6 @@ ConstVector::print() const
ZeroPad::ZeroPad() ZeroPad::ZeroPad()
{ {
for (int i = 0; i < length; i++) for (double & i : pad)
pad[i] = 0.0; i = 0.0;
} }

View File

@ -84,8 +84,8 @@ double
OrdSequence::average() const OrdSequence::average() const
{ {
double res = 0; double res = 0;
for (unsigned int i = 0; i < data.size(); i++) for (int i : data)
res += data[i]; res += i;
TL_RAISE_IF(data.size() == 0, TL_RAISE_IF(data.size() == 0,
"Attempt to take average of empty class in OrdSequence::average"); "Attempt to take average of empty class in OrdSequence::average");
return res/data.size(); return res/data.size();
@ -96,8 +96,8 @@ void
OrdSequence::print(const char *prefix) const OrdSequence::print(const char *prefix) const
{ {
printf("%s", prefix); printf("%s", prefix);
for (unsigned int i = 0; i < data.size(); i++) for (int i : data)
printf("%d ", data[i]); printf("%d ", i);
printf("\n"); printf("\n");
} }
@ -404,8 +404,8 @@ EquivalenceBundle::EquivalenceBundle(int nmax)
/* Destruct bundle. Just free all pointers. */ /* Destruct bundle. Just free all pointers. */
EquivalenceBundle::~EquivalenceBundle() EquivalenceBundle::~EquivalenceBundle()
{ {
for (unsigned int i = 0; i < bundle.size(); i++) for (auto & i : bundle)
delete bundle[i]; delete i;
} }
/* Remember, that the first item is |EquivalenceSet(1)|. */ /* Remember, that the first item is |EquivalenceSet(1)|. */

View File

@ -60,11 +60,10 @@ FFSTensor::FFSTensor(const FSSparseTensor &t)
nv(t.nvar()) nv(t.nvar())
{ {
zeros(); zeros();
for (FSSparseTensor::const_iterator it = t.getMap().begin(); for (const auto & it : t.getMap())
it != t.getMap().end(); ++it)
{ {
index ind(this, (*it).first); index ind(this, it.first);
get((*it).second.first, *ind) = (*it).second.second; get(it.second.first, *ind) = it.second.second;
} }
} }

View File

@ -249,11 +249,10 @@ FGSTensor::FGSTensor(const GSSparseTensor &t)
t.getDims().calcFoldMaxOffset(), t.dimen()), tdims(t.getDims()) t.getDims().calcFoldMaxOffset(), t.dimen()), tdims(t.getDims())
{ {
zeros(); zeros();
for (FSSparseTensor::const_iterator it = t.getMap().begin(); for (const auto & it : t.getMap())
it != t.getMap().end(); ++it)
{ {
index ind(this, (*it).first); index ind(this, it.first);
get((*it).second.first, *ind) = (*it).second.second; get(it.second.first, *ind) = it.second.second;
} }
} }

View File

@ -37,8 +37,8 @@ IntSequence::IntSequence(const Symmetry &sy, const vector<int> &se)
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++)
operator[](i) = 0; operator[](i) = 0;
for (unsigned int i = 0; i < se.size(); i++) for (int i : se)
operator[](sy.findClass(se[i]))++; operator[](sy.findClass(i))++;
} }
/* This constructs an ordered integer sequence from the given ordered /* This constructs an ordered integer sequence from the given ordered

View File

@ -382,8 +382,8 @@ KronProdAll::multRows(const IntSequence &irows) const
delete row; delete row;
} }
for (unsigned int i = 0; i < to_delete.size(); i++) for (auto & i : to_delete)
delete to_delete[i]; delete i;
return last; return last;
} }

View File

@ -52,12 +52,11 @@ UNormalMoments::generateMoments(int maxdim, const TwoDMatrix &v)
how the |Equivalence::apply| method works. */ how the |Equivalence::apply| method works. */
mom->zeros(); mom->zeros();
const EquivalenceSet eset = ebundle.get(d); const EquivalenceSet eset = ebundle.get(d);
for (EquivalenceSet::const_iterator cit = eset.begin(); for (const auto & cit : eset)
cit != eset.end(); cit++)
{ {
if (selectEquiv(*cit)) if (selectEquiv(cit))
{ {
Permutation per(*cit); Permutation per(cit);
per.inverse(); per.inverse();
for (Tensor::index it = kronv->begin(); it != kronv->end(); ++it) for (Tensor::index it = kronv->begin(); it != kronv->end(); ++it)
{ {
@ -80,10 +79,9 @@ UNormalMoments::selectEquiv(const Equivalence &e)
{ {
if (2*e.numClasses() != e.getN()) if (2*e.numClasses() != e.getN())
return false; return false;
for (Equivalence::const_seqit si = e.begin(); for (const auto & si : e)
si != e.end(); ++si)
{ {
if ((*si).length() != 2) if (si.length() != 2)
return false; return false;
} }
return true; return true;
@ -94,10 +92,9 @@ UNormalMoments::selectEquiv(const Equivalence &e)
FNormalMoments::FNormalMoments(const UNormalMoments &moms) FNormalMoments::FNormalMoments(const UNormalMoments &moms)
: TensorContainer<FRSingleTensor>(1) : TensorContainer<FRSingleTensor>(1)
{ {
for (UNormalMoments::const_iterator it = moms.begin(); for (const auto & mom : moms)
it != moms.end(); ++it)
{ {
FRSingleTensor *fm = new FRSingleTensor(*((*it).second)); FRSingleTensor *fm = new FRSingleTensor(*(mom.second));
insert(fm); insert(fm);
} }
} }

View File

@ -131,8 +131,8 @@ PermutationBundle::PermutationBundle(int nmax)
PermutationBundle::~PermutationBundle() PermutationBundle::~PermutationBundle()
{ {
for (unsigned int i = 0; i < bundle.size(); i++) for (auto & i : bundle)
delete bundle[i]; delete i;
} }
const PermutationSet & const PermutationSet &

View File

@ -228,10 +228,10 @@ UPSTensor::fillFromSparseTwo(const FSSparseTensor &t, const IntSequence &ss,
IntSequence c((*run).first); IntSequence c((*run).first);
c.add(-1, lb_srt); c.add(-1, lb_srt);
unsort.apply(c); unsort.apply(c);
for (unsigned int i = 0; i < pp.size(); i++) for (auto & i : pp)
{ {
IntSequence cp(coor.size()); IntSequence cp(coor.size());
pp[i]->apply(c, cp); i->apply(c, cp);
Tensor::index ind(this, cp); Tensor::index ind(this, cp);
TL_RAISE_IF(*ind < 0 || *ind >= ncols(), TL_RAISE_IF(*ind < 0 || *ind >= ncols(),
"Internal error in slicing constructor of UPSTensor"); "Internal error in slicing constructor of UPSTensor");

View File

@ -26,14 +26,13 @@ USubTensor::USubTensor(const TensorDimens &bdims,
"Tensor has not full symmetry in USubTensor()"); "Tensor has not full symmetry in USubTensor()");
const EquivalenceSet &eset = cont.getEqBundle().get(bdims.dimen()); const EquivalenceSet &eset = cont.getEqBundle().get(bdims.dimen());
zeros(); zeros();
for (EquivalenceSet::const_iterator it = eset.begin(); for (const auto & it : eset)
it != eset.end(); ++it)
{ {
if ((*it).numClasses() == hdims.dimen()) if (it.numClasses() == hdims.dimen())
{ {
Permutation per(*it); Permutation per(it);
vector<const FGSTensor *> ts vector<const FGSTensor *> ts
= cont.fetchTensors(bdims.getSym(), *it); = cont.fetchTensors(bdims.getSym(), it);
for (int i = 0; i < (int) lst.size(); i++) for (int i = 0; i < (int) lst.size(); i++)
{ {
IntSequence perindex(lst[i].size()); IntSequence perindex(lst[i].size());
@ -64,12 +63,12 @@ USubTensor::addKronColumn(int i, const vector<const FGSTensor *> &ts,
{ {
vector<ConstVector> tmpcols; vector<ConstVector> tmpcols;
int lastdim = 0; int lastdim = 0;
for (unsigned int j = 0; j < ts.size(); j++) for (auto t : ts)
{ {
IntSequence ind(pindex, lastdim, lastdim+ts[j]->dimen()); IntSequence ind(pindex, lastdim, lastdim+t->dimen());
lastdim += ts[j]->dimen(); lastdim += t->dimen();
index in(ts[j], ind); index in(t, ind);
tmpcols.push_back(ConstVector(*(ts[j]), *in)); tmpcols.push_back(ConstVector(*t, *in));
} }
URSingleTensor kronmult(tmpcols); URSingleTensor kronmult(tmpcols);

View File

@ -111,12 +111,11 @@ WorkerFoldMAASparse1::operator()()
const Permutation &per = pset.get(iper); const Permutation &per = pset.get(iper);
IntSequence percoor(coor.size()); IntSequence percoor(coor.size());
per.apply(coor, percoor); per.apply(coor, percoor);
for (EquivalenceSet::const_iterator it = eset.begin(); for (const auto & it : eset)
it != eset.end(); ++it)
{ {
if ((*it).numClasses() == t.dimen()) if (it.numClasses() == t.dimen())
{ {
StackProduct<FGSTensor> sp(cont, *it, out.getSym()); StackProduct<FGSTensor> sp(cont, it, out.getSym());
if (!sp.isZero(percoor)) if (!sp.isZero(percoor))
{ {
KronProdStack<FGSTensor> kp(sp, percoor); KronProdStack<FGSTensor> kp(sp, percoor);
@ -124,7 +123,7 @@ WorkerFoldMAASparse1::operator()()
const Permutation &oper = kp.getPer(); const Permutation &oper = kp.getPer();
if (Permutation(oper, per) == iden) if (Permutation(oper, per) == iden)
{ {
FPSTensor fps(out.getDims(), *it, slice, kp); FPSTensor fps(out.getDims(), it, slice, kp);
{ {
SYNCHRO syn(&out, "WorkerUnfoldMAASparse1"); SYNCHRO syn(&out, "WorkerUnfoldMAASparse1");
fps.addTo(out); fps.addTo(out);
@ -226,12 +225,11 @@ FoldedStackContainer::multAndAddSparse3(const FSSparseTensor &t,
Vector outcol(out, *run); Vector outcol(out, *run);
FRSingleTensor sumcol(t.nvar(), t.dimen()); FRSingleTensor sumcol(t.nvar(), t.dimen());
sumcol.zeros(); sumcol.zeros();
for (EquivalenceSet::const_iterator it = eset.begin(); for (const auto & it : eset)
it != eset.end(); ++it)
{ {
if ((*it).numClasses() == t.dimen()) if (it.numClasses() == t.dimen())
{ {
StackProduct<FGSTensor> sp(*this, *it, out.getSym()); StackProduct<FGSTensor> sp(*this, it, out.getSym());
IrregTensorHeader header(sp, run.getCoor()); IrregTensorHeader header(sp, run.getCoor());
IrregTensor irten(header); IrregTensor irten(header);
irten.addTo(sumcol); irten.addTo(sumcol);
@ -308,18 +306,17 @@ FoldedStackContainer::multAndAddStacks(const IntSequence &coor,
{ {
Permutation sort_per(ui.getCoor()); Permutation sort_per(ui.getCoor());
sort_per.inverse(); sort_per.inverse();
for (EquivalenceSet::const_iterator it = eset.begin(); for (const auto & it : eset)
it != eset.end(); ++it)
{ {
if ((*it).numClasses() == g.dimen()) if (it.numClasses() == g.dimen())
{ {
StackProduct<FGSTensor> sp(*this, *it, sort_per, out.getSym()); StackProduct<FGSTensor> sp(*this, it, sort_per, out.getSym());
if (!sp.isZero(coor)) if (!sp.isZero(coor))
{ {
KronProdStack<FGSTensor> kp(sp, coor); KronProdStack<FGSTensor> kp(sp, coor);
if (ug.getSym().isFull()) if (ug.getSym().isFull())
kp.optimizeOrder(); kp.optimizeOrder();
FPSTensor fps(out.getDims(), *it, sort_per, ug, kp); FPSTensor fps(out.getDims(), it, sort_per, ug, kp);
{ {
SYNCHRO syn(ad, "multAndAddStacks"); SYNCHRO syn(ad, "multAndAddStacks");
fps.addTo(out); fps.addTo(out);
@ -352,16 +349,15 @@ FoldedStackContainer::multAndAddStacks(const IntSequence &coor,
{ {
Permutation sort_per(ui.getCoor()); Permutation sort_per(ui.getCoor());
sort_per.inverse(); sort_per.inverse();
for (EquivalenceSet::const_iterator it = eset.begin(); for (const auto & it : eset)
it != eset.end(); ++it)
{ {
if ((*it).numClasses() == g.dimen()) if (it.numClasses() == g.dimen())
{ {
StackProduct<FGSTensor> sp(*this, *it, sort_per, out.getSym()); StackProduct<FGSTensor> sp(*this, it, sort_per, out.getSym());
if (!sp.isZero(coor)) if (!sp.isZero(coor))
{ {
KronProdStack<FGSTensor> kp(sp, coor); KronProdStack<FGSTensor> kp(sp, coor);
FPSTensor fps(out.getDims(), *it, sort_per, g, kp); FPSTensor fps(out.getDims(), it, sort_per, g, kp);
{ {
SYNCHRO syn(ad, "multAndAddStacks"); SYNCHRO syn(ad, "multAndAddStacks");
fps.addTo(out); fps.addTo(out);
@ -507,12 +503,11 @@ WorkerUnfoldMAASparse1::operator()()
const Permutation &per = pset.get(iper); const Permutation &per = pset.get(iper);
IntSequence percoor(coor.size()); IntSequence percoor(coor.size());
per.apply(coor, percoor); per.apply(coor, percoor);
for (EquivalenceSet::const_iterator it = eset.begin(); for (const auto & it : eset)
it != eset.end(); ++it)
{ {
if ((*it).numClasses() == t.dimen()) if (it.numClasses() == t.dimen())
{ {
StackProduct<UGSTensor> sp(cont, *it, out.getSym()); StackProduct<UGSTensor> sp(cont, it, out.getSym());
if (!sp.isZero(percoor)) if (!sp.isZero(percoor))
{ {
KronProdStack<UGSTensor> kp(sp, percoor); KronProdStack<UGSTensor> kp(sp, percoor);
@ -520,7 +515,7 @@ WorkerUnfoldMAASparse1::operator()()
const Permutation &oper = kp.getPer(); const Permutation &oper = kp.getPer();
if (Permutation(oper, per) == iden) if (Permutation(oper, per) == iden)
{ {
UPSTensor ups(out.getDims(), *it, slice, kp); UPSTensor ups(out.getDims(), it, slice, kp);
{ {
SYNCHRO syn(&out, "WorkerUnfoldMAASparse1"); SYNCHRO syn(&out, "WorkerUnfoldMAASparse1");
ups.addTo(out); ups.addTo(out);
@ -638,18 +633,17 @@ UnfoldedStackContainer::multAndAddStacks(const IntSequence &fi,
{ {
Permutation sort_per(ui.getCoor()); Permutation sort_per(ui.getCoor());
sort_per.inverse(); sort_per.inverse();
for (EquivalenceSet::const_iterator it = eset.begin(); for (const auto & it : eset)
it != eset.end(); ++it)
{ {
if ((*it).numClasses() == g.dimen()) if (it.numClasses() == g.dimen())
{ {
StackProduct<UGSTensor> sp(*this, *it, sort_per, out.getSym()); StackProduct<UGSTensor> sp(*this, it, sort_per, out.getSym());
if (!sp.isZero(fi)) if (!sp.isZero(fi))
{ {
KronProdStack<UGSTensor> kp(sp, fi); KronProdStack<UGSTensor> kp(sp, fi);
if (g.getSym().isFull()) if (g.getSym().isFull())
kp.optimizeOrder(); kp.optimizeOrder();
UPSTensor ups(out.getDims(), *it, sort_per, g, kp); UPSTensor ups(out.getDims(), it, sort_per, g, kp);
{ {
SYNCHRO syn(ad, "multAndAddStacks"); SYNCHRO syn(ad, "multAndAddStacks");
ups.addTo(out); ups.addTo(out);

View File

@ -116,9 +116,9 @@ symiterator::operator++()
InducedSymmetries::InducedSymmetries(const Equivalence &e, const Symmetry &s) InducedSymmetries::InducedSymmetries(const Equivalence &e, const Symmetry &s)
{ {
for (Equivalence::const_seqit i = e.begin(); i != e.end(); ++i) for (const auto & i : e)
{ {
push_back(Symmetry(s, *i)); push_back(Symmetry(s, i));
} }
} }

View File

@ -11,10 +11,9 @@ const int FGSContainer::num_one_time = 10;
UGSContainer::UGSContainer(const FGSContainer &c) UGSContainer::UGSContainer(const FGSContainer &c)
: TensorContainer<UGSTensor>(c.num()) : TensorContainer<UGSTensor>(c.num())
{ {
for (FGSContainer::const_iterator it = c.begin(); for (const auto & it : c)
it != c.end(); ++it)
{ {
UGSTensor *unfolded = new UGSTensor(*((*it).second)); UGSTensor *unfolded = new UGSTensor(*(it.second));
insert(unfolded); insert(unfolded);
} }
} }
@ -38,18 +37,17 @@ UGSContainer::multAndAdd(const UGSTensor &t, UGSTensor &out) const
int k = out.dimen(); int k = out.dimen();
const EquivalenceSet &eset = ebundle.get(k); const EquivalenceSet &eset = ebundle.get(k);
for (EquivalenceSet::const_iterator it = eset.begin(); for (const auto & it : eset)
it != eset.end(); ++it)
{ {
if ((*it).numClasses() == l) if (it.numClasses() == l)
{ {
vector<const UGSTensor *> ts vector<const UGSTensor *> ts
= fetchTensors(out.getSym(), *it); = fetchTensors(out.getSym(), it);
KronProdAllOptim kp(l); KronProdAllOptim kp(l);
for (int i = 0; i < l; i++) for (int i = 0; i < l; i++)
kp.setMat(i, *(ts[i])); kp.setMat(i, *(ts[i]));
kp.optimizeOrder(); kp.optimizeOrder();
UPSTensor ups(out.getDims(), *it, t, kp); UPSTensor ups(out.getDims(), it, t, kp);
ups.addTo(out); ups.addTo(out);
} }
} }
@ -59,10 +57,9 @@ UGSContainer::multAndAdd(const UGSTensor &t, UGSTensor &out) const
FGSContainer::FGSContainer(const UGSContainer &c) FGSContainer::FGSContainer(const UGSContainer &c)
: TensorContainer<FGSTensor>(c.num()) : TensorContainer<FGSTensor>(c.num())
{ {
for (UGSContainer::const_iterator it = c.begin(); for (const auto & it : c)
it != c.end(); ++it)
{ {
FGSTensor *folded = new FGSTensor(*((*it).second)); FGSTensor *folded = new FGSTensor(*(it.second));
insert(folded); insert(folded);
} }
} }
@ -88,18 +85,17 @@ FGSContainer::multAndAdd(const UGSTensor &t, FGSTensor &out) const
int k = out.dimen(); int k = out.dimen();
const EquivalenceSet &eset = ebundle.get(k); const EquivalenceSet &eset = ebundle.get(k);
for (EquivalenceSet::const_iterator it = eset.begin(); for (const auto & it : eset)
it != eset.end(); ++it)
{ {
if ((*it).numClasses() == l) if (it.numClasses() == l)
{ {
vector<const FGSTensor *> ts vector<const FGSTensor *> ts
= fetchTensors(out.getSym(), *it); = fetchTensors(out.getSym(), it);
KronProdAllOptim kp(l); KronProdAllOptim kp(l);
for (int i = 0; i < l; i++) for (int i = 0; i < l; i++)
kp.setMat(i, *(ts[i])); kp.setMat(i, *(ts[i]));
kp.optimizeOrder(); kp.optimizeOrder();
FPSTensor fps(out.getDims(), *it, t, kp); FPSTensor fps(out.getDims(), it, t, kp);
fps.addTo(out); fps.addTo(out);
} }
} }

View File

@ -50,19 +50,17 @@ PowerProvider::~PowerProvider()
UTensorPolynomial::UTensorPolynomial(const FTensorPolynomial &fp) UTensorPolynomial::UTensorPolynomial(const FTensorPolynomial &fp)
: TensorPolynomial<UFSTensor, UGSTensor, URSingleTensor>(fp.nrows(), fp.nvars()) : TensorPolynomial<UFSTensor, UGSTensor, URSingleTensor>(fp.nrows(), fp.nvars())
{ {
for (FTensorPolynomial::const_iterator it = fp.begin(); for (const auto & it : fp)
it != fp.end(); ++it)
{ {
insert(new UFSTensor(*((*it).second))); insert(new UFSTensor(*(it.second)));
} }
} }
FTensorPolynomial::FTensorPolynomial(const UTensorPolynomial &up) FTensorPolynomial::FTensorPolynomial(const UTensorPolynomial &up)
: TensorPolynomial<FFSTensor, FGSTensor, FRSingleTensor>(up.nrows(), up.nvars()) : TensorPolynomial<FFSTensor, FGSTensor, FRSingleTensor>(up.nrows(), up.nvars())
{ {
for (UTensorPolynomial::const_iterator it = up.begin(); for (const auto & it : up)
it != up.end(); ++it)
{ {
insert(new FFSTensor(*((*it).second))); insert(new FFSTensor(*(it.second)));
} }
} }

View File

@ -96,6 +96,6 @@ PascalTriangle::noverk(int n, int k)
void void
PascalTriangle::print() const PascalTriangle::print() const
{ {
for (unsigned int i = 0; i < tr.size(); i++) for (const auto & i : tr)
tr[i].print(); i.print();
} }