Skip to content

Commit

Permalink
Updated eval interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalashnikovni committed Oct 9, 2024
1 parent c336451 commit aabb070
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 48 deletions.
10 changes: 5 additions & 5 deletions eval/defs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ MaybeVValue VarEnv::operator[](VKey k) const

FuncEnv::FuncEnv() {}
FuncEnvType FuncEnv::mapping_ = {
{"isEmpty", 0}, {"isMember", 1}, {"minElem", 2}, {"maxElem", 3}
, {"compose", 4}, {"inv", 5}, {"image", 6}, {"preImage", 7}, {"dom", 8}
, {"combine", 9}, {"firstInv", 10}, {"minMap", 11}, {"reduce", 12}
, {"minAdj", 13}, {"mapInf", 14}, {"CC", 15}, {"matching", 16}, {"scc", 17}
, {"sort", 18}, {"matchSCC", 19}, {"matchSCCTS", 20}, {"cut", 21}
{"isEmpty", 0}, {"minElem", 1}, {"maxElem", 2}
, {"compose", 3}, {"inv", 4}, {"image", 5}, {"preImage", 6}, {"dom", 7}
, {"combine", 8}, {"firstInv", 9}, {"minMap", 10}, {"reduce", 11}
, {"minAdj", 12}, {"mapInf", 13}, {"CC", 14}, {"matching", 15}, {"scc", 16}
, {"sort", 17}, {"matchSCC", 18}, {"matchSCCTS", 19}, {"cut", 20}
};

MaybeFValue FuncEnv::operator[](FKey k) const
Expand Down
2 changes: 1 addition & 1 deletion eval/defs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ struct FuncEnv{
static FuncEnvType mapping_;
};

typedef enum { empty, member, min, max, comp, inv, im, preim, dom, comb
typedef enum { empty, min, max, comp, inv, im, preim, dom, comb
, first_inv, min_map, red, min_adj, inf, connected, matching, scc, ts
, match_scc, match_scc_ts, cut_set } Func;

Expand Down
42 changes: 8 additions & 34 deletions eval/visitors/eval_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ namespace Eval {
// Function visitors -----------------------------------------------------------
// -----------------------------------------------------------------------------

auto member_visitor_ = Util::Overload {
[](Util::NAT a, LIB::Interval b) { return b.isMember(a); },
[](auto a, auto b) {
Util::ERROR("member_visitor_: wrong arguments ", a, ", ", b
, " for isMember\n");
return false;
}
};

auto min_visitor_ = Util::Overload {
[](LIB::Interval a) { return Util::MD_NAT(a.begin()); },
[](LIB::MultiDimInter a) { return a.minElem(); },
Expand Down Expand Up @@ -407,24 +398,6 @@ ExprBaseType EvalExpression::operator()(AST::Call v) const
}
break;

case Eval::Func::member:
if (eval_args.size() == 2) {
arity_ok = true;

NatBaseType x = std::visit(EvalNatBT{}, eval_args[0]);
Util::MD_NAT aux = std::get<Util::MD_NAT>(x);
if (aux.arity() == 1) {
ContainerBaseType container
= std::visit(EvalContainer{}, eval_args[1]);
bool result = std::visit(member_visitor_, NatBaseType(aux[0])
, container);
return Util::MD_NAT(result);
}

return Util::MD_NAT(0);
}
break;

case Eval::Func::min:
if (eval_args.size() == 1) {
arity_ok = true;
Expand Down Expand Up @@ -754,8 +727,8 @@ ExprBaseType EvalExpression::operator()(AST::MultiDimInter v) const
{
SBG::LIB::SetPiece mdi = boost::apply_visitor(EvalMDI(env_), AST::Expr(v));

Util::ERROR_UNLESS(mdi.arity() == nmbr_dims_
, "EvalExpr: nmbr_dims_: ", nmbr_dims_, "!= arity(", mdi, ")\n");
Util::ERROR_UNLESS(mdi.arity() == nmbr_dims_ || mdi.arity() == 0
, "EvalExpr: nmbr_dims_: ", nmbr_dims_, " != arity(", mdi, ")\n");

return mdi;
}
Expand All @@ -765,8 +738,8 @@ ExprBaseType EvalExpression::operator()(AST::MDInterUnaryOp v) const
EvalMDI visit_mdi(env_);
LIB::MultiDimInter mdi = boost::apply_visitor(visit_mdi, v.e());

Util::ERROR_UNLESS(mdi.arity() == nmbr_dims_
, "EvalExpr: nmbr_dims_: ", nmbr_dims_, "!= arity(", mdi, ")\n");
Util::ERROR_UNLESS(mdi.arity() == nmbr_dims_ || mdi.arity() == 0
, "EvalExpr: nmbr_dims_: ", nmbr_dims_, " != arity(", mdi, ")\n");

switch (v.op()) {
case AST::ContainerUOp::card:
Expand All @@ -786,9 +759,10 @@ ExprBaseType EvalExpression::operator()(AST::MDInterBinOp v) const
LIB::MultiDimInter l = boost::apply_visitor(visit_mdi, v.left());
LIB::MultiDimInter r = boost::apply_visitor(visit_mdi, v.right());

Util::ERROR_UNLESS(l.arity() == nmbr_dims_ && r.arity() == nmbr_dims_
,"EvalExpr: nmbr_dims_: ", nmbr_dims_
, " != arity(", l, ") or arity(", r, ")\n");
Util::ERROR_UNLESS((l.arity() == nmbr_dims_ && r.arity() == nmbr_dims_)
|| l.arity() == 0 || r.arity() == 0
,"EvalExpr: nmbr_dims_: ", nmbr_dims_, " != arity(", l, ") or arity(", r
, ")\n");

switch (v.op()) {
case AST::ContainerOp::cap:
Expand Down
4 changes: 2 additions & 2 deletions parser/expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ ExprRule<Iterator>::ExprRule(Iterator &it) :
| lexp_expr
| arithmetic_expr
| set_expr
| interval_expr
| mdi_expr;
| mdi_expr
| interval_expr;

expr_list = expr[phx::push_back(qi::_val, qi::_1)]
>> *(COMA >> expr)[phx::push_back(qi::_val, qi::_1)];
Expand Down
12 changes: 6 additions & 6 deletions test/eval/gt_data/interval/SBG.log
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,31 @@ isEmpty([100:1:5])
--> 1

[1:1:0]/\[100:1:500]
--> [1:0]
-->

[100:1:500]/\[1:1:0]
--> [1:0]
-->

[1:2:20]/\[4:3:20]
--> [7:6:19]

[1:2:20]/\[2:2:20]
--> [1:0]
-->

[201:2:399]/\[200:4:400]
--> [1:0]
-->

[300:1:1000000]/\[300:1:500]
--> [300:500]

minElem([500:5:499])
--> 1
-->

minElem([500:5:600])
--> 500

maxElem([500:5:499])
--> 0
-->

maxElem([500:5:600])
--> 600
Expand Down

0 comments on commit aabb070

Please sign in to comment.