From fc35f3a3843fbba8cc06874fc1068070ce378eb3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Wed, 27 Feb 2019 17:00:53 +0100
Subject: [PATCH] Dynare++: make more explicit the interface for extracting the
 Symmetry of an IntSequence

---
 dynare++/tl/cc/int_sequence.cc  | 16 ++++++++++++++++
 dynare++/tl/cc/int_sequence.hh  |  5 +++++
 dynare++/tl/cc/sparse_tensor.cc |  2 +-
 dynare++/tl/cc/symmetry.cc      | 16 ----------------
 dynare++/tl/cc/symmetry.hh      |  4 ----
 5 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/dynare++/tl/cc/int_sequence.cc b/dynare++/tl/cc/int_sequence.cc
index 8756a6d581..82bbec12d3 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 54c2b380cf..ad9aff3fb7 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 7d69cff19d..4bbabfaeb9 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 fc56b41122..7b2218630a 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 1670c7560e..df533c6a6b 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
-- 
GitLab