diff --git a/dynare++/tl/cc/int_sequence.cc b/dynare++/tl/cc/int_sequence.cc index 8756a6d58..82bbec12d 100644 --- a/dynare++/tl/cc/int_sequence.cc +++ b/dynare++/tl/cc/int_sequence.cc @@ -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. */ diff --git a/dynare++/tl/cc/int_sequence.hh b/dynare++/tl/cc/int_sequence.hh index 54c2b380c..ad9aff3fb 100644 --- a/dynare++/tl/cc/int_sequence.hh +++ b/dynare++/tl/cc/int_sequence.hh @@ -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() diff --git a/dynare++/tl/cc/sparse_tensor.cc b/dynare++/tl/cc/sparse_tensor.cc index 7d69cff19..4bbabfaeb 100644 --- a/dynare++/tl/cc/sparse_tensor.cc +++ b/dynare++/tl/cc/sparse_tensor.cc @@ -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); } diff --git a/dynare++/tl/cc/symmetry.cc b/dynare++/tl/cc/symmetry.cc index fc56b4112..7b2218630 100644 --- a/dynare++/tl/cc/symmetry.cc +++ b/dynare++/tl/cc/symmetry.cc @@ -6,22 +6,6 @@ #include -/* 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 diff --git a/dynare++/tl/cc/symmetry.hh b/dynare++/tl/cc/symmetry.hh index 1670c7560..df533c6a6 100644 --- a/dynare++/tl/cc/symmetry.hh +++ b/dynare++/tl/cc/symmetry.hh @@ -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