Skip to content

Commit f963efd

Browse files
committed
[iss-44]
1 parent 50864db commit f963efd

9 files changed

Lines changed: 49 additions & 125 deletions

File tree

eval/defs.hpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,38 +40,6 @@ namespace Eval {
4040

4141
// Type definitions ------------------------------------------------------------
4242

43-
/** @brief Types NatBaseType, ContainerBaseType, LinearBaseType and MapBaseType
44-
* are defined to decrease the compilation memory consumption of eval_expr.cpp.
45-
* When evaluating an AST::Call, multiple std::visit are invoked, where each
46-
* one generates a function table with size dependent of the number types in
47-
* the variant. Initially ExprBaseType was used.
48-
*/
49-
/*
50-
typedef std::variant<Util::NAT
51-
, Util::MD_NAT> NatType;
52-
53-
typedef std::variant<LIB::Interval
54-
, LIB::SetPiece
55-
, LIB::UnordSet
56-
, LIB::OrdSet> ContainerBaseType;
57-
58-
typedef std::variant<LIB::LExp
59-
, LIB::Exp> ExprBaseType;
60-
61-
typedef std::variant<LIB::BaseMap
62-
, LIB::CanonMap
63-
, LIB::BasePWMap
64-
, LIB::CanonPWMap> MapBaseType;
65-
66-
typedef std::variant<LIB::BaseSBG
67-
, LIB::CanonSBG
68-
, LIB::BaseDSBG
69-
, LIB::CanonDSBG> SBGBaseType;
70-
71-
typedef std::variant<LIB::MatchInfo<LIB::UnordSet>
72-
, LIB::MatchInfo<LIB::OrdSet>> InfoBaseType;
73-
*/
74-
7543
typedef std::variant<LIB::MD_NAT
7644
, LIB::RATIONAL
7745
, LIB::Interval

eval/main.cpp

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@
3131
#include "parser/sbg_program.hpp"
3232
#include "eval/visitors/program_visitor.hpp"
3333

34-
void parseEvalProgramFromFile(std::string fname, bool debug)
34+
struct Impl {
35+
int set_impl_;
36+
int pw_impl_;
37+
38+
Impl(int set_impl, int pw_impl) : set_impl_(set_impl), pw_impl_(pw_impl) {};
39+
};
40+
41+
void parseEvalProgramFromFile(std::string fname, Impl impl, bool debug)
3542
{
3643
std::ifstream in(fname.c_str());
3744
if (in.fail())
@@ -57,7 +64,26 @@ void parseEvalProgramFromFile(std::string fname, bool debug)
5764
std::cout << ">>>>>> Eval result <<<<<<\n";
5865
std::cout << "-------------------------\n\n";
5966

60-
SBG::Eval::ProgramVisitor program_visit(debug);
67+
std::unique_ptr<SBG::LIB::SetAF> set_fact
68+
= std::make_unique<SBG::LIB::UnordAF>();
69+
70+
switch (impl.set_impl_) {
71+
case 2:
72+
set_fact = std::make_unique<SBG::LIB::OrdDenseAF>();
73+
74+
default:
75+
break;
76+
}
77+
78+
SBG::LIB::MapAF map_fact(*set_fact);
79+
std::unique_ptr<SBG::LIB::PWMapAF> fact
80+
= std::make_unique<SBG::LIB::UnordPWMapAF>(map_fact);
81+
switch (impl.pw_impl_) {
82+
default:
83+
break;
84+
}
85+
86+
SBG::Eval::ProgramVisitor program_visit(*fact, debug);
6187
SBG::Eval::ProgramIO visit_result = boost::apply_visitor(
6288
program_visit, parser_result
6389
);
@@ -78,6 +104,8 @@ void usage()
78104
std::cout << "Usage evaluator: ./bin/sbg-eval -f filename [options]\n";
79105
std::cout << "Parses and evaluates a SBG program.\n\n";
80106
std::cout << "-f, --file SBG program file used as input\n";
107+
std::cout << "-s, --set_impl Choose set implementation: 0 unordered sets,\n";
108+
std::cout << " 1 ordered sets, 2 ordered dense sets.\n";
81109
std::cout << "-h, --help Display this information and exit\n";
82110
std::cout << "-d, --debug Activate debug info\n";
83111
std::cout << "-v, --version Display version information and exit\n\n";
@@ -201,27 +229,30 @@ void version()
201229
std::cout << "There is NO WARRANTY, to the extent permitted by law.\n";
202230
}
203231

204-
205232
int main(int argc, char**argv)
206233
{
207234
std::string filename;
208-
int opt;
235+
int opt, set_impl = 0, pw_impl = 0;
209236
extern char* optarg;
210237
bool debug = false;
211238

212239
while (true) {
213240
static struct option long_options[] = {{"file", required_argument, 0, 'f'}
241+
, {"set_impl", required_argument, 0, 's'}
214242
, {"help", no_argument, 0, 'h'}
215243
, {"debug", no_argument, 0, 'd'}
216244
, {"version", no_argument, 0, 'v'}
217245
, {0, 0, 0, 0}};
218-
opt = getopt_long(argc, argv, "f:hdv", long_options, nullptr);
246+
opt = getopt_long(argc, argv, "f:s:hdv", long_options, nullptr);
219247
if (opt == EOF)
220248
break;
221249
switch (opt) {
222250
case 'f':
223251
filename = optarg;
224252
break;
253+
case 's':
254+
set_impl = std::stoi(optarg);
255+
break;
225256
case 'h':
226257
usage();
227258
exit(0);
@@ -241,7 +272,7 @@ int main(int argc, char**argv)
241272
}
242273

243274
if (!filename.empty())
244-
parseEvalProgramFromFile(filename, debug);
275+
parseEvalProgramFromFile(filename, Impl(set_impl, pw_impl), debug);
245276
else
246277
SBG::Util::ERROR("A filename should be provided\n");
247278

eval/visitors/program_visitor.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ namespace SBG {
2323

2424
namespace Eval {
2525

26-
ProgramVisitor::ProgramVisitor(bool debug) : env_(), debug_(debug) {}
26+
ProgramVisitor::ProgramVisitor(const LIB::PWMapAF &fact, bool debug)
27+
: fact_(fact), env_(), debug_(debug) {}
2728

2829
ProgramIO ProgramVisitor::operator()(AST::Program p) const
2930
{
@@ -43,19 +44,7 @@ ProgramIO ProgramVisitor::operator()(AST::Program p) const
4344
}
4445
}
4546

46-
bool check = true;
47-
OptConds opt_conds(stm_visit.env());
48-
for (AST::Expr e : p.exprs())
49-
check = check && boost::apply_visitor(opt_conds, e);
50-
51-
// Choose concrete factory according to the desired implementation
52-
std::unique_ptr<LIB::SetAF> set_fact = std::make_unique<LIB::UnordAF>();
53-
if (check)
54-
set_fact = std::make_unique<LIB::OrdDenseAF>();
55-
LIB::MapAF map_fact(*set_fact);
56-
LIB::UnordPWMapAF pw_fact(map_fact);
57-
58-
EvalExpression eval_expr(dims, pw_fact, stm_visit.env(), debug_);
47+
EvalExpression eval_expr(dims, fact_, stm_visit.env(), debug_);
5948
for (AST::Expr e : p.exprs()) {
6049
ExprBaseType expr_res = boost::apply_visitor(eval_expr, e);
6150
exprs.push_back(ExprEval(e, expr_res));

eval/visitors/program_visitor.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ namespace Eval {
3939

4040
struct ProgramVisitor : public boost::static_visitor<ProgramIO> {
4141
public:
42-
ProgramVisitor(bool debug);
42+
ProgramVisitor(const LIB::PWMapAF &fact, bool debug);
4343

4444
ProgramIO operator()(AST::Program p) const;
4545

4646
private:
47+
const LIB::PWMapAF &fact_;
4748
mutable VarEnv env_;
4849
mutable bool debug_;
4950
};

sbg/af_map.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ struct MapAF : public SetAF {
3737
public:
3838
MapAF(const SetAF &set_fact);
3939

40-
Set createSet() const;
41-
Set createSet(const MD_NAT &x) const;
42-
Set createSet(const Interval &i) const;
43-
Set createSet(const SetPiece &mdi) const;
40+
Set createSet() const override;
41+
Set createSet(const MD_NAT &x) const override;
42+
Set createSet(const Interval &i) const override;
43+
Set createSet(const SetPiece &mdi) const override;
4444

4545
Map createMap() const;
4646
Map createMap(MD_NAT x, Exp exp) const;

sbg/map.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,11 @@ Set Map::image(const Set &subdom) const
173173

174174
if (cond) {
175175
for (const SetPiece &mdi : capdom)
176-
res.emplace(SBG::LIB::image(mdi, exp_));
176+
res.emplaceBack(SBG::LIB::image(mdi, exp_));
177177
}
178178
else {
179-
// TODO: optimization?
180-
for (const SetPiece &mdi : capdom) {
179+
for (const SetPiece &mdi : capdom)
181180
res = res.cup(fact_.createSet(SBG::LIB::image(mdi, exp_)));
182-
}
183181
}
184182
}
185183

sbg/pw_map.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,6 @@ PWMapDelegPtr UnordPWMap::offsetImage(const Exp &off) const
689689
return res;
690690
}
691691

692-
// TODO
693692
PWMapDelegPtr UnordPWMap::compact() const
694693
{
695694
UnordPWMap res(fact_);

sbg/sbg_algorithms.cpp

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -655,68 +655,6 @@ const PWMapAF &SBGSCC::fact() const { return fact_; }
655655
// Topological sort ------------------------------------------------------------
656656
////////////////////////////////////////////////////////////////////////////////
657657

658-
/* TODO
659-
DSBG partitionSE(const DSBG &dg)
660-
{
661-
const PWMapAF &fact_ = dg.fact();
662-
663-
Set V = dg.V();
664-
unsigned int dims = V.arity(), j = 1;
665-
PWMap mapB = dg.mapB(), mapD = dg.mapD(), Emap = dg.Emap();
666-
PWMap subE = dg.subEmap();
667-
668-
std::vector<Map> vs;
669-
for (const Map &map : dg.Vmap())
670-
vs.emplace_back(map.dom());
671-
672-
Set univ = fact_.createSet(SetPiece(dims, Interval(0, 1, Inf)));
673-
for (const Map &map : subE) {
674-
Set ith_edge = mapB.image(map.dom());
675-
Set not_ith_edge = univ.difference(ith_edge);
676-
std::vector<Set> aux_vs;
677-
aux_vs.reserve(2*vs.size());
678-
for (const Set &ith_vs : vs) {
679-
Set s1 = ith_edge.intersection(ith_vs);
680-
Set s2 = not_ith_edge.intersection(ith_vs);
681-
682-
if (!s1.isEmpty())
683-
aux_vs.emplace_back(s1);
684-
685-
if (!s2.isEmpty())
686-
aux_vs.emplace_back(s2);
687-
}
688-
vs = aux_vs;
689-
}
690-
691-
for (const Map &map : subE) {
692-
Set ith_edge = mapD.image(map.dom());
693-
Set not_ith_edge = univ.difference(ith_edge);
694-
std::vector aux_vs;
695-
aux_vs.reserve(2*vs.size());
696-
for (const Set &ith_vs : vs) {
697-
Set s1 = ith_edge.intersection(ith_vs);
698-
Set s2 = not_ith_edge.intersection(ith_vs);
699-
700-
if (!s1.isEmpty())
701-
aux_vs.emplace_back(s1);
702-
703-
if (!s2.isEmpty())
704-
aux_vs.emplace_back(s2);
705-
}
706-
vs = aux_vs;
707-
}
708-
709-
PWMap Vmap;
710-
for (const Set &dom : vs) {
711-
MD_NAT v(dims, j);
712-
Vmap.emplaceBack(Map(dom, Exp(v)));
713-
++j;
714-
}
715-
716-
return DSBG(V, Vmap, mapB, mapD, Emap, subE);
717-
}
718-
*/
719-
720658
SBGTopSort::SBGTopSort(const DSBG &dsbg, bool debug)
721659
: fact_(dsbg.fact()), dsbg_(dsbg), debug_(debug) {}
722660

test/matching1.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ matching(
4242
map1: <<{[1:1:E1]} -> 1*x+off1b, {[E1+1:1:E2]} -> 1*x+off2b, {[E2+1:1:E3]} -> 1*x+off3b>>
4343
map2: <<{[1:1:E1]} -> 1*x+off1d, {[E1+1:1:E2]} -> 1*x+off2d, {[E2+1:1:E3]} -> 1*x+off3d>>
4444
Emap: <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2], [E2+1:1:E3]} -> 0*x+2>>
45-
, 64
45+
, 1
4646
);

0 commit comments

Comments
 (0)