Dynare++: simplify IntSequence by moving a special-purpose constructor into Symmetry

time-shift
Sébastien Villemot 2019-02-27 15:43:03 +01:00
parent 07ef21fdc7
commit 9751e6e199
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
4 changed files with 22 additions and 27 deletions

View File

@ -20,26 +20,6 @@ IntSequence::unfold(const Symmetry &sy) const
return r;
}
/* This constructs an implied symmetry (implemented as |IntSequence|
from a more general symmetry and equivalence class (implemented as
|vector<int>|). For example, let the general symmetry be $y^3u^2$ and
the equivalence class is $\{0,4\}$ picking up first and fifth
variable, we calculate symmetry (at this point only |IntSequence|)
corresponding to the picked variables. These are $yu$. Thus the
constructed sequence must be $(1,1)$, meaning that we picked one $y$
and one $u$. */
IntSequence::IntSequence(const Symmetry &sy, const std::vector<int> &se)
: data{new int[sy.num()]}, length{sy.num()}
{
TL_RAISE_IF(sy.dimen() <= se[se.size()-1],
"Sequence is not reachable by symmetry in IntSequence()");
for (int i = 0; i < length; i++)
operator[](i) = 0;
for (int i : se)
operator[](sy.findClass(i))++;
}
/* This constructs an ordered integer sequence from the given ordered
sequence inserting the given number to the sequence. */

View File

@ -88,9 +88,6 @@ public:
{
std::copy_n(s.data+i1, length, data);
}
/* Constructor used for calculating implied symmetry from a more general
symmetry and one equivalence class */
IntSequence(const Symmetry &sy, const std::vector<int> &se);
/* Unfolds a given integer sequence with respect to a given symmetry. If for
example the sequence is $(a,b)$ and the symmetry is $(2,3)$, then the
result is $(a,a,b,b,b)$. */

View File

@ -2,6 +2,7 @@
#include "symmetry.hh"
#include "permutation.hh"
#include "tl_exception.hh"
#include <iostream>
@ -21,6 +22,26 @@ Symmetry::Symmetry(const IntSequence &s)
}
}
/* 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
calculate symmetry corresponding to the picked variables. These are $yu$.
Thus the constructed sequence must be $(1,1)$, meaning that we picked one
$y$ and one $u$. */
Symmetry::Symmetry(const Symmetry &sy, const OrdSequence &cl)
: IntSequence(sy.num())
{
const std::vector<int> &se = cl.getData();
TL_RAISE_IF(sy.dimen() <= se[se.size()-1],
"Sequence is not reachable by symmetry in IntSequence()");
for (int i = 0; i < size(); i++)
operator[](i) = 0;
for (int i : se)
operator[](sy.findClass(i))++;
}
/* Find a class of the symmetry containing a given index. */
int

View File

@ -72,10 +72,7 @@ public:
{
}
// Constructor of implied symmetry for a symmetry and an equivalence class
Symmetry(const Symmetry &s, const OrdSequence &cl)
: IntSequence(s, cl.getData())
{
}
Symmetry(const Symmetry &s, const OrdSequence &cl);
/* Subsymmetry, which takes the given length of symmetry from the end (shares
data pointer) */
Symmetry(Symmetry &s, int len)