Commit af722f43 authored by Sébastien Villemot's avatar Sébastien Villemot

Dynare++: drop remaining "using namespace std"

parent 798cecd8
......@@ -184,9 +184,9 @@ public:
/* Just for debugging. */
void
savePoints(const string &fname, int level) const
savePoints(const std::string &fname, int level) const
{
ofstream fd{fname, std::ios::out | std::ios::trunc};
std::ofstream fd{fname, std::ios::out | std::ios::trunc};
if (fd.fail())
{
// todo: raise
......
......@@ -83,7 +83,7 @@ private:
protected:
int num;
int maxn;
vector<RadicalInverse> ri;
std::vector<RadicalInverse> ri;
const PermutationScheme &per;
Vector pt;
public:
......
......@@ -101,9 +101,9 @@ class SmolyakQuadrature : public QuadratureImpl<smolpit>
friend class smolpit;
int level;
const OneDQuadrature &uquad;
vector<IntSequence> levels;
vector<IntSequence> levpoints;
vector<int> cumevals;
std::vector<IntSequence> levels;
std::vector<IntSequence> levpoints;
std::vector<int> cumevals;
PascalTriangle psc;
public:
SmolyakQuadrature(int d, int l, const OneDQuadrature &uq);
......
......@@ -22,8 +22,8 @@
struct QuadParams
{
string outname;
string vcovname;
std::string outname;
std::string vcovname;
int max_level{3};
double discard_weight{0.0};
QuadParams(int argc, char **argv);
......@@ -60,7 +60,7 @@ QuadParams::QuadParams(int argc, char **argv)
case opt_max_level:
try
{
max_level = std::stoi(string{optarg});
max_level = std::stoi(std::string{optarg});
}
catch (const std::invalid_argument &e)
{
......@@ -70,7 +70,7 @@ QuadParams::QuadParams(int argc, char **argv)
case opt_discard_weight:
try
{
discard_weight = std::stod(string{optarg});
discard_weight = std::stod(std::string{optarg});
}
catch (const std::invalid_argument &e)
{
......
......@@ -165,11 +165,11 @@ Function1Trans::eval(const Vector &point, const ParameterSignal &sig, Vector &ou
// with time information
class WallTimer
{
string mes;
std::string mes;
std::chrono::time_point<std::chrono::high_resolution_clock> start;
bool new_line;
public:
WallTimer(string m, bool nl = true)
WallTimer(std::string m, bool nl = true)
: mes{m}, start{std::chrono::high_resolution_clock::now()}, new_line{nl}
{
}
......@@ -189,10 +189,10 @@ public:
class TestRunnable
{
public:
const string name;
const std::string name;
int dim; // dimension of the solved problem
int nvar; // number of variable of the solved problem
TestRunnable(string name_arg, int d, int nv)
TestRunnable(std::string name_arg, int d, int nv)
: name{move(name_arg)}, dim(d), nvar(nv)
{
}
......@@ -211,7 +211,7 @@ protected:
bool
TestRunnable::test() const
{
cout << "Running test <" << name << ">" << endl;
std::cout << "Running test <" << name << ">" << std::endl;
bool passed;
{
WallTimer tim("Wall clock time ", false);
......@@ -286,7 +286,7 @@ TestRunnable::product_normal_moments(const GeneralMatrix &m, int imom, int level
// check against theoretical moments
UNormalMoments moments(imom, msq);
prod_out.add(-1.0, (moments.get(Symmetry(imom)))->getData());
std::cout << "\tError: " << std::setw(16) << std::setprecision(12) << prod_out.getMax() << endl;
std::cout << "\tError: " << std::setw(16) << std::setprecision(12) << prod_out.getMax() << std::endl;
return prod_out.getMax() < 1.e-7;
}
......
......@@ -437,7 +437,7 @@ RTSimResultsStats::writeMat(mat_t *fd, const char *lname)
}
IRFResults::IRFResults(const DynamicModel &mod, const DecisionRule &dr,
const SimResults &control, vector<int> ili,
const SimResults &control, std::vector<int> ili,
Journal &journal)
: model(mod), irf_list_ind(std::move(ili))
{
......@@ -639,6 +639,6 @@ GenShockRealization::get(int n, Vector &out)
Vector r(numShocks());
RandomShockRealization::get(n, r);
for (int j = 0; j < numShocks(); j++)
if (!isfinite(out[j]))
if (!std::isfinite(out[j]))
out[j] = r[j];
}
......@@ -728,9 +728,9 @@ protected:
int num_y;
int num_per;
int num_burn;
vector<TwoDMatrix *> data;
vector<ExplicitShockRealization *> shocks;
vector<ConstVector> start;
std::vector<TwoDMatrix *> data;
std::vector<ExplicitShockRealization *> shocks;
std::vector<ConstVector> start;
public:
SimResults(int ny, int nper, int nburn = 0)
: num_y(ny), num_per(nper), num_burn(nburn)
......@@ -902,12 +902,12 @@ public:
class DynamicModel;
class IRFResults
{
vector<SimResultsIRF *> irf_res;
std::vector<SimResultsIRF *> irf_res;
const DynamicModel &model;
vector<int> irf_list_ind;
std::vector<int> irf_list_ind;
public:
IRFResults(const DynamicModel &mod, const DecisionRule &dr,
const SimResults &control, vector<int> ili,
const SimResults &control, std::vector<int> ili,
Journal &journal);
~IRFResults();
void writeMat(mat_t *fd, const char *prefix) const;
......
......@@ -204,7 +204,7 @@ JournalRecordPair::~JournalRecordPair()
writePrefixForEnd(flash);
journal << prefix_end;
journal << mes;
journal << endl;
journal << std::endl;
journal.flush();
}
......@@ -213,7 +213,7 @@ endrec(JournalRecord &rec)
{
rec.journal << rec.prefix;
rec.journal << rec.mes;
rec.journal << endl;
rec.journal << std::endl;
rec.journal.flush();
rec.journal.incrementOrd();
return rec;
......
......@@ -39,13 +39,13 @@ struct SystemResourcesFlash
void diff(const SystemResourcesFlash &pre);
};
class Journal : public ofstream
class Journal : public std::ofstream
{
int ord;
int depth;
public:
Journal(const char *fname)
: ofstream(fname), ord(0), depth(0)
: std::ofstream(fname), ord(0), depth(0)
{
printHeader();
}
......
......@@ -19,10 +19,10 @@
/**************************************************************************************/
/* DynareNameList class */
/**************************************************************************************/
vector<int>
DynareNameList::selectIndices(const vector<const char *> &ns) const
std::vector<int>
DynareNameList::selectIndices(const std::vector<const char *> &ns) const
{
vector<int> res;
std::vector<int> res;
for (auto n : ns)
{
int j = 0;
......@@ -30,7 +30,7 @@ DynareNameList::selectIndices(const vector<const char *> &ns) const
j++;
if (j == getNum())
throw DynareException(__FILE__, __LINE__,
string("Couldn't find name for ") + n
std::string("Couldn't find name for ") + n
+" in DynareNameList::selectIndices");
res.push_back(j);
}
......@@ -47,7 +47,7 @@ Dynare::Dynare(const char *modname, int ord, double sstol, Journal &jr)
{
std::ifstream f{modname};
if (f.fail())
throw DynareException(__FILE__, __LINE__, string{"Could not open model file "}+modname);
throw DynareException(__FILE__, __LINE__, std::string{"Could not open model file "}+modname);
std::ostringstream buffer;
buffer << f.rdbuf();
......
......@@ -20,7 +20,7 @@ class Dynare;
class DynareNameList : public NameList
{
vector<const char *> names;
std::vector<const char *> names;
public:
DynareNameList(const Dynare &dynare);
int
......@@ -36,12 +36,12 @@ public:
/** This for each string of the input vector calculates its index
* in the names. And returns the resulting vector of indices. If
* the name cannot be found, then an exception is raised. */
vector<int> selectIndices(const vector<const char *> &ns) const;
std::vector<int> selectIndices(const std::vector<const char *> &ns) const;
};
class DynareExogNameList : public NameList
{
vector<const char *> names;
std::vector<const char *> names;
public:
DynareExogNameList(const Dynare &dynare);
int
......@@ -58,7 +58,7 @@ public:
class DynareStateNameList : public NameList
{
vector<const char *> names;
std::vector<const char *> names;
public:
DynareStateNameList(const Dynare &dynare, const DynareNameList &dnl,
const DynareExogNameList &denl);
......
......@@ -43,7 +43,7 @@ main(int argc, char **argv)
// make dynare object
Dynare dynare(params.modname, params.order, params.ss_tol, journal);
// make list of shocks for which we will do IRFs
vector<int> irf_list_ind;
std::vector<int> irf_list_ind;
if (params.do_irfs_all)
for (int i = 0; i < dynare.nexog(); i++)
irf_list_ind.push_back(i);
......
......@@ -313,7 +313,7 @@ EquivalenceSet::EquivalenceSet(int num)
: n(num),
equis()
{
list<Equivalence> added;
std::list<Equivalence> added;
Equivalence first(n);
equis.push_back(first);
addParents(first, added);
......@@ -359,7 +359,7 @@ EquivalenceSet::has(const Equivalence &e) const
void
EquivalenceSet::addParents(const Equivalence &e,
list<Equivalence> &added)
std::list<Equivalence> &added)
{
if (e.numClasses() == 2 || e.numClasses() == 1)
return;
......@@ -396,7 +396,7 @@ EquivalenceSet::print(const char *prefix) const
/* Construct the bundle. |nmax| is a maximum size of underlying set. */
EquivalenceBundle::EquivalenceBundle(int nmax)
{
nmax = max(nmax, 1);
nmax = std::max(nmax, 1);
generateUpTo(nmax);
}
......
......@@ -44,8 +44,6 @@
#include <vector>
#include <list>
using namespace std;
/* Here is the abstraction for an equivalence class. We implement it as
|vector<int>|. We have a constructor for empty class, copy
constructor. What is important here is the ordering operator
......@@ -55,7 +53,7 @@ using namespace std;
class OrdSequence
{
vector<int> data;
std::vector<int> data;
public:
OrdSequence() : data()
{
......@@ -68,7 +66,7 @@ public:
bool operator==(const OrdSequence &s) const;
int operator[](int i) const;
bool operator<(const OrdSequence &s) const;
const vector<int> &
const std::vector<int> &
getData() const
{
return data;
......@@ -97,10 +95,10 @@ class Equivalence
{
private:
int n;
list<OrdSequence> classes;
std::list<OrdSequence> classes;
public:
using const_seqit = list<OrdSequence>::const_iterator;
using seqit = list<OrdSequence>::iterator;
using const_seqit = std::list<OrdSequence>::const_iterator;
using seqit = std::list<OrdSequence>::iterator;
/* The first constructor constructs $\{\{0\},\{1\},\ldots,\{n-1\}\}$.
......@@ -183,9 +181,9 @@ protected:
class EquivalenceSet
{
int n;
list<Equivalence> equis;
std::list<Equivalence> equis;
public:
using const_iterator = list<Equivalence>::const_iterator;
using const_iterator = std::list<Equivalence>::const_iterator;
EquivalenceSet(int num);
void print(const char *prefix) const;
const_iterator
......@@ -200,7 +198,7 @@ public:
}
private:
bool has(const Equivalence &e) const;
void addParents(const Equivalence &e, list<Equivalence> &added);
void addParents(const Equivalence &e, std::list<Equivalence> &added);
};
/* The equivalence bundle class only encapsulates |EquivalenceSet|s
......@@ -212,7 +210,7 @@ private:
class EquivalenceBundle
{
vector<EquivalenceSet> bundle;
std::vector<EquivalenceSet> bundle;
public:
EquivalenceBundle(int nmax);
~EquivalenceBundle() = default;
......
......@@ -39,8 +39,8 @@
class SizeRefinement
{
vector<int> rsizes;
vector<int> ind_map;
std::vector<int> rsizes;
std::vector<int> ind_map;
int new_nc;
public:
SizeRefinement(const IntSequence &s, int nc, int max);
......
......@@ -29,7 +29,7 @@ IntSequence::IntSequence(const Symmetry &sy, const IntSequence &se)
constructed sequence must be $(1,1)$, meaning that we picked one $y$
and one $u$. */
IntSequence::IntSequence(const Symmetry &sy, const vector<int> &se)
IntSequence::IntSequence(const Symmetry &sy, const std::vector<int> &se)
: data(new int[sy.num()]), length(sy.num()), destroy(true)
{
TL_RAISE_IF(sy.dimen() <= se[se.size()-1],
......@@ -102,7 +102,7 @@ IntSequence::operator==(const IntSequence &s) const
bool
IntSequence::operator<(const IntSequence &s) const
{
int len = min(size(), s.size());
int len = std::min(size(), s.size());
int i = 0;
while (i < len && operator[](i) == s[i])
......
......@@ -28,7 +28,6 @@
#include <cstring>
#include <vector>
using namespace std;
/* The implementation of |IntSequence| is straightforward. It has a
pointer |data|, a |length| of the data, and a flag |destroy|, whether
......@@ -74,7 +73,7 @@ public:
{
memcpy(data, s.data+i1, sizeof(int)*length);
}
IntSequence(const Symmetry &sy, const vector<int> &se);
IntSequence(const Symmetry &sy, const std::vector<int> &se);
IntSequence(const Symmetry &sy, const IntSequence &se);
IntSequence(int i, const IntSequence &s);
IntSequence(int i, const IntSequence &s, int pos);
......
......@@ -340,7 +340,7 @@ KronProdAll::multRows(const IntSequence &irows) const
Vector *last = nullptr;
ConstVector *row;
vector<Vector *> to_delete;
std::vector<Vector *> to_delete;
for (int i = 0; i < dimen(); i++)
{
int j = dimen()-1-i;
......
......@@ -103,13 +103,13 @@ PermutationSet::~PermutationSet()
delete [] pers;
}
vector<const Permutation *>
std::vector<const Permutation *>
PermutationSet::getPreserving(const IntSequence &s) const
{
TL_RAISE_IF(s.size() != order,
"Wrong sequence length in PermutationSet::getPreserving");
vector<const Permutation *> res;
std::vector<const Permutation *> res;
IntSequence tmp(s.size());
for (int i = 0; i < size; i++)
{
......@@ -125,7 +125,7 @@ PermutationSet::getPreserving(const IntSequence &s) const
PermutationBundle::PermutationBundle(int nmax)
{
nmax = max(nmax, 1);
nmax = std::max(nmax, 1);
generateUpTo(nmax);
}
......
......@@ -155,7 +155,7 @@ public:
{
return *(pers[i]);
}
vector<const Permutation *> getPreserving(const IntSequence &s) const;
std::vector<const Permutation *> getPreserving(const IntSequence &s) const;
};
/* The permutation bundle encapsulates all permutations sets up to some
......@@ -163,7 +163,7 @@ public:
class PermutationBundle
{
vector<PermutationSet *> bundle;
std::vector<PermutationSet *> bundle;
public:
PermutationBundle(int nmax);
~PermutationBundle();
......
......@@ -215,7 +215,7 @@ UPSTensor::fillFromSparseTwo(const FSSparseTensor &t, const IntSequence &ss,
}
const PermutationSet &pset = tls.pbundle->get(coor.size());
vector<const Permutation *> pp = pset.getPreserving(coor);
std::vector<const Permutation *> pp = pset.getPreserving(coor);
Permutation unsort(coor);
zeros();
......
......@@ -19,7 +19,7 @@
USubTensor::USubTensor(const TensorDimens &bdims,
const TensorDimens &hdims,
const FGSContainer &cont,
const vector<IntSequence> &lst)
const std::vector<IntSequence> &lst)
: URTensor(lst.size(), hdims.getNVX()[0], hdims.dimen())
{
TL_RAISE_IF(!hdims.getNVX().isConstant(),
......@@ -31,7 +31,7 @@ USubTensor::USubTensor(const TensorDimens &bdims,
if (it.numClasses() == hdims.dimen())
{
Permutation per(it);
vector<const FGSTensor *> ts
std::vector<const FGSTensor *> ts
= cont.fetchTensors(bdims.getSym(), it);
for (int i = 0; i < (int) lst.size(); i++)
{
......@@ -58,10 +58,10 @@ USubTensor::USubTensor(const TensorDimens &bdims,
|i|-th column. */
void
USubTensor::addKronColumn(int i, const vector<const FGSTensor *> &ts,
USubTensor::addKronColumn(int i, const std::vector<const FGSTensor *> &ts,
const IntSequence &pindex)
{
vector<ConstVector> tmpcols;
std::vector<ConstVector> tmpcols;
int lastdim = 0;
for (auto t : ts)
{
......
......@@ -54,8 +54,6 @@
#include <vector>
using namespace std;
/* Here we define the new tensor for representing
$[G]_S^{\gamma_1\ldots\gamma_l}$. It allows a construction from
container of folded general symmetry tensors |cont|, and set of
......@@ -66,8 +64,8 @@ class USubTensor : public URTensor
{
public:
USubTensor(const TensorDimens &bdims, const TensorDimens &hdims,
const FGSContainer &cont, const vector<IntSequence> &lst);
void addKronColumn(int i, const vector<const FGSTensor *> &ts,
const FGSContainer &cont, const std::vector<IntSequence> &lst);
void addKronColumn(int i, const std::vector<const FGSTensor *> &ts,
const IntSequence &pindex);
};
......
......@@ -115,7 +115,7 @@ URTensor::getOffset(const IntSequence &v) const
/* Here we construct $v_1\otimes v_2\otimes\ldots\otimes v_n$, where
$v_1,v_2,\ldots,v_n$ are stored in |vector<ConstVector>|. */
URSingleTensor::URSingleTensor(const vector<ConstVector> &cols)
URSingleTensor::URSingleTensor(const std::vector<ConstVector> &cols)
: URTensor(1, cols[0].length(), cols.size())
{
if (dimen() == 1)
......
......@@ -131,7 +131,7 @@ public:
: URTensor(1, nvar, d)
{
}
URSingleTensor(const vector<ConstVector> &cols);
URSingleTensor(const std::vector<ConstVector> &cols);
URSingleTensor(const ConstVector &v, int d);
URSingleTensor(const URSingleTensor &ut)
......
......@@ -31,8 +31,6 @@
#include <map>
using namespace std;
// |ltseq| predicate
struct ltseq
{
......@@ -50,8 +48,8 @@ struct ltseq
class SparseTensor
{
public:
using Item = pair<int, double>;
using Map = multimap<IntSequence, Item, ltseq>;
using Item = std::pair<int, double>;
using Map = std::multimap<IntSequence, Item, ltseq>;
using const_iterator = Map::const_iterator;
protected:
using iterator = Map::iterator;
......
......@@ -215,7 +215,7 @@ public:
symmetries from the given equivalence and outer symmetry. A
permutation might optionally permute the classes of the equivalence. */
class InducedSymmetries : public vector<Symmetry>
class InducedSymmetries : public std::vector<Symmetry>
{
public:
InducedSymmetries(const Equivalence &e, const Symmetry &s);
......
......@@ -41,7 +41,7 @@ UGSContainer::multAndAdd(const UGSTensor &t, UGSTensor &out) const
{
if (it.numClasses() == l)
{
vector<const UGSTensor *> ts
std::vector<const UGSTensor *> ts
= fetchTensors(out.getSym(), it);
KronProdAllOptim kp(l);
for (int i = 0; i < l; i++)
......@@ -89,7 +89,7 @@ FGSContainer::multAndAdd(const UGSTensor &t, FGSTensor &out) const
{
if (it.numClasses() == l)
{
vector<const FGSTensor *> ts
std::vector<const FGSTensor *> ts
= fetchTensors(out.getSym(), it);
KronProdAllOptim kp(l);
for (int i = 0; i < l; i++)
......@@ -106,7 +106,7 @@ FGSContainer::multAndAdd(const UGSTensor &t, FGSTensor &out) const
(excluding). If there are not |num| of such indices, the shorter vector
is returned. */
Tensor::index
FGSContainer::getIndices(int num, vector<IntSequence> &out,
FGSContainer::getIndices(int num, std::vector<IntSequence> &out,
const Tensor::index &start,
const Tensor::index &end)
{
......
......@@ -96,7 +96,7 @@ class TensorContainer
protected:
using _const_ptr = const _Ttype *;
using _ptr = _Ttype *;
using _Map = map<Symmetry, _ptr, ltsym>;
using _Map = std::map<Symmetry, _ptr, ltsym>;
using _mvtype = typename _Map::value_type;
public:
using iterator = typename _Map::iterator;
......@@ -262,9 +262,9 @@ public:
/* Output to the Memory Map. */
void
writeMMap(map<string, ConstTwoDMatrix> &mm, const string &prefix) const
writeMMap(std::map<std::string, ConstTwoDMatrix> &mm, const std::string &prefix) const
{
ostringstream lname;
std::ostringstream lname;
for (const_iterator it = begin(); it != end(); ++it)
{
lname.str(prefix);
......@@ -280,10 +280,10 @@ public:
through all equivalence classes, calculate implied symmetry, and
fetch its tensor storing it in the same order to the vector. */
vector<_const_ptr>
std::vector<_const_ptr>
fetchTensors(const Symmetry &rsym, const Equivalence &e) const
{
vector<_const_ptr> res(e.numClasses());
std::vector<_const_ptr> res(e.numClasses());
int i = 0;
for (auto it = e.begin();
it != e.end(); ++it, i++)
......@@ -377,7 +377,7 @@ public:
void multAndAdd(const FGSTensor &t, FGSTensor &out) const;
void multAndAdd(const UGSTensor &t, FGSTensor &out) const;
private:
static Tensor::index getIndices(int num, vector<IntSequence> &out,
static Tensor::index getIndices(int num, std::vector<IntSequence> &out,
const Tensor::index &start,
const Tensor::index &end);
};
......
......@@ -340,7 +340,7 @@ public:
if (_Tparent::check(Symmetry(d)))
{
_Ttype *ten = _Tparent::get(Symmetry(d));
ten->mult((double) max((d-k), 0));
ten->mult((double) std::max((d-k), 0));
}
}
}
......
......@@ -21,9 +21,9 @@
#include <sstream>
DynamicModelDLL::DynamicModelDLL(const string &modName) noexcept(false)
DynamicModelDLL::DynamicModelDLL(const std::string &modName) noexcept(false)
{
string fName;
std::string fName;
#if !defined(__CYGWIN32__) && !defined(_WIN32)
fName = "./";
#endif
......@@ -57,7 +57,7 @@ DynamicModelDLL::DynamicModelDLL(const string &modName) noexcept(false)
dynamicHinstance = dlopen(fName.c_str(), RTLD_NOW);
if (dynamicHinstance == nullptr)
{
cerr << dlerror() << endl;
std::cerr << dlerror() << std::endl;
throw 1;
}
ntt = (int *) dlsym(dynamicHinstance, "ntt");
......@@ -76,7 +76,7 @@ DynamicModelDLL::DynamicModelDLL(const string &modName) noexcept(false)
|| dynamic_g3_tt == nullptr || dynamic_g3 == nullptr)
{
dlclose(dynamicHinstance); // Free the library
cerr << dlerror() << endl;
std::cerr << dlerror() << std::endl;
throw 2;
}
#endif
......@@ -84,7 +84,7 @@ DynamicModelDLL::DynamicModelDLL(const string &modName) noexcept(false)
}
catch (int i)
{
ostringstream msg;
std::ostringstream msg;
msg << "Error when loading " << fName << " (";
if (i == 1)
msg << "can't dynamically load the file";
......@@ -105,7 +105,7 @@ DynamicModelDLL::~DynamicModelDLL()
auto result = FreeLibrary(dynamicHinstance);
if (result == 0)
{
cerr << "Can't free the *_dynamic DLL" << endl;
std::cerr << "Can't free the *_dynamic DLL" << std::endl;
exit(EXIT_FAILURE);
}
#else
......
......@@ -61,7 +61,7 @@ private:
public:
// construct and load Dynamic model DLL
explicit DynamicModelDLL(const string &fname) noexcept(false);
explicit DynamicModelDLL(const std::string &fname) noexcept(false);
virtual ~DynamicModelDLL();
void eval(const Vector &y, const Vector &x, const Vector &params, const Vector &ySteady,
......
......@@ -19,7 +19,7 @@
#include "dynamic_m.hh"