Dynare++: more explicit interface for inserting into a IntSequence

time-shift
Sébastien Villemot 2019-02-27 14:34:28 +01:00
parent 05d1c6967d
commit d86101327e
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
4 changed files with 30 additions and 25 deletions

View File

@ -31,7 +31,7 @@ FFSTensor::FFSTensor(const FFSTensor &t, const ConstVector &x)
for (Tensor::index to = begin(); to != end(); ++to)
for (int i = 0; i < nvar(); i++)
{
IntSequence from_ind(i, to.getCoor());
IntSequence from_ind(to.getCoor().insert(i));
Tensor::index from(t, from_ind);
addColumn(x[i], t, *from, *to);
}

View File

@ -46,29 +46,32 @@ IntSequence::IntSequence(const Symmetry &sy, const std::vector<int> &se)
/* This constructs an ordered integer sequence from the given ordered
sequence inserting the given number to the sequence. */
IntSequence::IntSequence(int i, const IntSequence &s)
: data{new int[s.size()+1]}, length{s.size()+1}
IntSequence
IntSequence::insert(int i) const
{
int j = 0;
while (j < s.size() && s[j] < i)
j++;
for (int jj = 0; jj < j; jj++)
operator[](jj) = s[jj];
operator[](j) = i;
for (int jj = j; jj < s.size(); jj++)
operator[](jj+1) = s[jj];
IntSequence r(size()+1);
int j;
for (j = 0; j < size() && operator[](j) < i; j++)
r[j] = operator[](j);
r[j] = i;
for (; j < size(); j++)
r[j+1] = operator[](j);
return r;
}
IntSequence::IntSequence(int i, const IntSequence &s, int pos)
: data{new int[s.size()+1]}, length{s.size()+1}
IntSequence
IntSequence::insert(int i, int pos) const
{
TL_RAISE_IF(pos < 0 || pos > s.size(),
"Wrong position for insertion IntSequence constructor");
for (int jj = 0; jj < pos; jj++)
operator[](jj) = s[jj];
operator[](pos) = i;
for (int jj = pos; jj < s.size(); jj++)
operator[](jj+1) = s[jj];
TL_RAISE_IF(pos < 0 || pos > size(),
"Wrong position for IntSequence::insert()");
IntSequence r(size()+1);
int j;
for (j = 0; j < pos; j++)
r[j] = operator[](j);
r[j] = i;
for (; j < size(); j++)
r[j+1] = operator[](j);
return r;
}
IntSequence &

View File

@ -93,10 +93,6 @@ public:
IntSequence(const Symmetry &sy, const std::vector<int> &se);
// Unfolds a given integer sequence with respect to a given symmetry
IntSequence(const Symmetry &sy, const IntSequence &se);
// Inserts an element in an ordered sequence
IntSequence(int i, const IntSequence &s);
// Inserts an element at a given position
IntSequence(int i, const IntSequence &s, int pos);
IntSequence &operator=(const IntSequence &s);
IntSequence &operator=(IntSequence &&s);
@ -139,6 +135,12 @@ public:
bool lessEq(const IntSequence &s) const;
bool less(const IntSequence &s) const;
// Inserts an element into an ordered sequence
IntSequence insert(int i) const;
// Inserts an element at a given position
/* For appending at the end, use pos = size() */
IntSequence insert(int i, int pos) const;
void sort();
void monotone();
void pmonotone(const Symmetry &s);

View File

@ -84,7 +84,7 @@ public:
p1.apply(permap);
}
Permutation(const Permutation &p, int i)
: permap(p.size(), p.permap, i)
: permap(p.permap.insert(p.size(), i))
{
}
Permutation &operator=(const Permutation &) = default;