diff --git a/dynare++/tl/cc/int_sequence.cc b/dynare++/tl/cc/int_sequence.cc index 8756a6d581d74f361e460fa3b857ec7431477757..82bbec12d3533f4dfbb02f2c1cbfc00b76ab1cca 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 54c2b380cff7f1435d63d2585dad43bf6c1041e3..ad9aff3fb775809479ca88f526e035078753d7dc 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 7d69cff19df2461b2ad1012996c119b8c89a3044..4bbabfaeb9e2a24ca3b378004ec87a005ba84d9d 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 fc56b411224b4150d30d71ff4bfa19d0414afa66..7b2218630aad686b1fa57d10b17576c7148cb4bd 100644 --- a/dynare++/tl/cc/symmetry.cc +++ b/dynare++/tl/cc/symmetry.cc @@ -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 diff --git a/dynare++/tl/cc/symmetry.hh b/dynare++/tl/cc/symmetry.hh index 1670c7560eef981b89c716de8cf72f2ba544a935..df533c6a6bfd8f39c4098b8a5728222558d02c3e 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