Dynare++: make more explicit the interface for extracting the Symmetry of an IntSequence

time-shift
Sébastien Villemot 2019-02-27 17:00:53 +01:00
parent 9751e6e199
commit fc35f3a384
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
5 changed files with 22 additions and 21 deletions

View File

@ -20,6 +20,22 @@ IntSequence::unfold(const Symmetry &sy) const
return r;
}
Symmetry
IntSequence::getSymmetry() const
{
Symmetry r(getNumDistinct());
int p = 0;
if (size() > 0)
r[p] = 1;
for (int i = 1; i < size(); i++)
{
if (operator[](i) != operator[](i-1))
p++;
r[p]++;
}
return r;
}
/* This constructs an ordered integer sequence from the given ordered
sequence inserting the given number to the sequence. */

View File

@ -93,6 +93,11 @@ public:
result is $(a,a,b,b,b)$. */
IntSequence unfold(const Symmetry &sy) const;
/* Constructs a symmetry from the integer sequence (supposed to be ordered) as
a symmetry counting successively equal items. For instance the sequence
$(a,a,a,b,c,c,d,d,d,d)$ produces symmetry $(3,1,2,4)$. */
Symmetry getSymmetry() const;
IntSequence &operator=(const IntSequence &s);
IntSequence &operator=(IntSequence &&s);
virtual ~IntSequence()

View File

@ -78,7 +78,7 @@ SparseTensor::getUnfoldIndexFillFactor() const
while (start_col != m.end())
{
const IntSequence &key = (*start_col).first;
cnt += Symmetry(key).noverseq();
cnt += key.getSymmetry().noverseq();
start_col = m.upper_bound(key);
}

View File

@ -6,22 +6,6 @@
#include <iostream>
/* Construct symmetry as numbers of successively equal items in the sequence. */
Symmetry::Symmetry(const IntSequence &s)
: IntSequence(s.getNumDistinct(), 0)
{
int p = 0;
if (s.size() > 0)
operator[](p) = 1;
for (int i = 1; i < s.size(); i++)
{
if (s[i] != s[i-1])
p++;
operator[](p)++;
}
}
/* This constructs an implied symmetry from a more general symmetry and
equivalence class. For example, let the general symmetry be $y^3u^2$ and the
equivalence class is $\{0,4\}$ picking up first and fifth variable, we

View File

@ -79,10 +79,6 @@ public:
: IntSequence(s, s.size()-len, s.size())
{
}
/* Constructs a symmetry from an integer sequence (supposed to be ordered) as
a symmetry counting successively equal items. For instance the sequence
$(a,a,a,b,c,c,d,d,d,d)$ produces symmetry $(3,1,2,4)$. */
Symmetry(const IntSequence &s);
int
num() const