Skip to content

Commit

Permalink
Debugged findRecursion
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalashnikovni committed Mar 20, 2024
1 parent b3e1aec commit fba98a5
Show file tree
Hide file tree
Showing 15 changed files with 356 additions and 66 deletions.
29 changes: 20 additions & 9 deletions eval/visitors/eval_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,21 @@ auto scc_visitor_ = Util::Overload {
};

auto ts_visitor_ = Util::Overload {
[](LIB::BaseDSBG a, bool b) {
LIB::BaseTopSort ts(a, b);
return InfoBaseType(ts.calculate());
[](LIB::BaseDSBG a, LIB::BasePWMap b, bool c) {
LIB::BaseTopSort ts(a, c);
LIB::BaseVO ts_res = ts.calculate();
LIB::RecInfo rec_info = buildRecursionInfo(ts.dsbg(), ts.rec_map(), b);
std::cout << rec_info << "\n\n";
return InfoBaseType(ts_res);
},
[](LIB::CanonDSBG a, bool b) {
LIB::CanonTopSort ts(a, b);
return InfoBaseType(ts.calculate());
[](LIB::CanonDSBG a, LIB::CanonPWMap b, bool c) {
LIB::CanonTopSort ts(a, c);
LIB::CanonVO ts_res = ts.calculate();
LIB::RecInfo rec_info = buildRecursionInfo(ts.dsbg(), ts.rec_map(), b);
std::cout << rec_info << "\n\n";
return InfoBaseType(ts_res);
},
[](auto a, auto b) {
[](auto a, auto b, auto c) {
Util::ERROR("Wrong arguments for ts");
return InfoBaseType();
}
Expand Down Expand Up @@ -330,6 +336,8 @@ auto match_scc_ts_visitor_ = Util::Overload {
LIB::BasePWMap scc_res = scc.calculate();
LIB::BaseTopSort ts(buildSortFromSCC(scc, scc_res), d);
LIB::BaseVO ts_res = ts.calculate();
LIB::RecInfo rec_info = buildRecursionInfo(ts.dsbg(), ts.rec_map(), a.subE_map());
std::cout << rec_info << "\n";
buildJson(match_res, scc.transformResult(scc_res), ts_res);
return InfoBaseType(ts_res);
},
Expand All @@ -340,6 +348,8 @@ auto match_scc_ts_visitor_ = Util::Overload {
LIB::CanonPWMap scc_res = scc.calculate();
LIB::CanonTopSort ts(buildSortFromSCC(scc, scc_res), d);
LIB::CanonVO ts_res = ts.calculate();
LIB::RecInfo rec_info = buildRecursionInfo(ts.dsbg(), ts.rec_map(), a.subE_map());
std::cout << rec_info << "\n";
buildJson(match_res, scc.transformResult(scc_res), ts_res);
return InfoBaseType(ts_res);
},
Expand Down Expand Up @@ -702,12 +712,13 @@ ExprBaseType EvalExpression::operator()(AST::Call v) const


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

SBGBaseType g = std::visit(EvalGraph{}, eval_args[0]);
MapBaseType pw = std::visit(EvalMap(), eval_args[1]);
InfoBaseType result = std::visit(
ts_visitor_, g, std::variant<bool>(debug_)
ts_visitor_, g, pw, std::variant<bool>(debug_)
);
return result;
}
Expand Down
13 changes: 13 additions & 0 deletions sbg/interval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,19 @@ Interval Interval::least(const Interval &other) const
return std::min(*this, other);
}

Util::NAT Interval::midElem() const
{
Util::NAT res;

if ((end_ - begin_) % 2 == 0)
res = (end_ - begin_) / 2 + begin_;

else
res = (end_ - begin_ + 1) / 2 + begin_;

return res;
}

Interval::MaybeInterval Interval::compact(const Interval &other) const
{
if (step_ == other.step_) {
Expand Down
1 change: 1 addition & 0 deletions sbg/interval.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ struct Interval {
*/
Interval offset(Util::NAT off) const;
Interval least(const Interval &i2) const;
Util::NAT midElem() const;
MaybeInterval compact(const Interval &i2) const;
};
std::ostream &operator<<(std::ostream &out, const Interval &i);
Expand Down
11 changes: 11 additions & 0 deletions sbg/multidim_inter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
******************************************************************************/

#include <iostream>
#include "sbg/multidim_inter.hpp"

namespace SBG {
Expand Down Expand Up @@ -224,6 +225,16 @@ MultiDimInter MultiDimInter::least(const MultiDimInter &other) const

bool MultiDimInter::isUnidim() const { return size() <= 1; }

Util::MD_NAT MultiDimInter::midElem() const
{
Util::MD_NAT res;

for (unsigned int j = 0; j < size(); ++j)
res.emplaceBack(operator[](j).midElem());

return res;
}

MultiDimInter::MaybeMDI MultiDimInter::compact(const MultiDimInter &other) const
{
MultiDimInter res;
Expand Down
1 change: 1 addition & 0 deletions sbg/multidim_inter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ struct MultiDimInter {
MultiDimInter offset(const MD_NAT &off) const;
MultiDimInter least(const MultiDimInter &other) const;
bool isUnidim() const;
Util::MD_NAT midElem() const;
MaybeMDI compact(const MultiDimInter &other) const;
};
std::ostream &operator<<(std::ostream &out, const MultiDimInter &mi);
Expand Down
7 changes: 7 additions & 0 deletions sbg/ord_pw_mdinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,13 @@ OrdPWMDInter OrdPWMDInter::difference(const OrdPWMDInter &other) const

// Extra operations ------------------------------------------------------------

Util::MD_NAT OrdPWMDInter::midElem() const
{
Util::ERROR_UNLESS(!isEmpty(), "LIB::Ord::midElem: shouldn't be empty");

return begin()->midElem();
}

OrdPWMDInter OrdPWMDInter::concatenation(const OrdPWMDInter &other) const
{
OrdPWMDInter res;
Expand Down
1 change: 1 addition & 0 deletions sbg/ord_pw_mdinter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ struct OrdPWMDInter {
/**
* @brief Extra operations.
*/
Util::MD_NAT midElem() const;

/** @function concatenation
*
Expand Down
Loading

0 comments on commit fba98a5

Please sign in to comment.