16 #ifndef OPT_IVOTER_HPP 17 #define OPT_IVOTER_HPP 62 auto& cand_ctxs = it->second;
66 matching_ctxs = cand_ctxs;
70 for (
ContexT cand_tx : cand_ctxs)
74 if (std::all_of(ctx.begin(), ctx.end(),
75 [&](
const std::pair<std::string,CtxValT>& ctxpair)
77 auto ait = cand_tx.find(ctxpair.first);
78 if (cand_tx.end() == ait)
82 auto& ctens = ctxpair.second;
83 auto& cand_ctens = ait->second;
84 return std::equal(ctens.begin(), ctens.end(),
89 cand_tx.insert(ctx.begin(), ctx.end());
90 matching_ctxs.emplace(cand_tx);
94 bool has_match = matching_ctxs.size() > 0;
110 auto it = ctx.find(
label_);
111 if (ctx.end() == it || estd::has(it->second, arg.
tensor_))
115 matching_ctxs.emplace(ctx);
118 bool has_match = matching_ctxs.size() > 0;
121 ctxs = matching_ctxs;
182 std::tuple<std::string,std::string,std::string,size_t>
189 boost::hash_combine(seed, hash_target);
197 return lhs.size() == rhs.size() &&
198 std::equal(lhs.begin(), lhs.end(), rhs.begin(),
201 return l.
label_ == r.label_ &&
236 virtual ~iVoter (
void) =
default;
261 #endif // OPT_IVOTER_HPP bool is_equal(teq::CoordptrT a, teq::CoordptrT b)
Return true if a is equal to b.
CandsT candidates_
Potential rules contexts that can match subgraph of tensor_.
Definition: candidate.hpp:85
args
Definition: csv_to_png.py:105
virtual ~iVoter(void)=default
size_t operator()(const SegVArgs &args) const
Return hash of arguments.
Definition: ivoter.hpp:212
std::set< teq::TensptrT > CtxValT
Set of tensors that potentially matches some id.
Definition: candidate.hpp:23
teq::CoordptrT shaper_
Real shaper in the argument.
Definition: candidate.hpp:88
virtual CandsT inspect(const CandArgsT &args) const =0
Return virtual node graph candidates given candidate arguments.
VoterArgsT branches_
Branch-typed arguments (functors/groups)
Definition: ivoter.hpp:157
std::unordered_map< std::string, VotptrT > branches_
Map voter identifier to associated branch voters.
Definition: ivoter.hpp:256
std::shared_ptr< iCoordMap > CoordptrT
Type of iCoordMap smartpointer.
Definition: coord.hpp:106
teq::CoordptrT coorder_
Real coorder in the argument.
Definition: candidate.hpp:91
Definition: candidate.hpp:19
VoterArgsT anys_
Any-typed leaf arguments.
Definition: ivoter.hpp:160
Branching node.
Definition: def.h:33
teq::CoordptrT shaper_
Converted shape mapper.
Definition: ivoter.hpp:133
std::unordered_set< ContexT, boost::hash< ContexT > > CtxsT
Set of contexts that serve as a candidates of a conversion rule.
Definition: candidate.hpp:29
std::shared_ptr< iVoter > VotptrT
Smart pointer of rule tree.
Definition: ivoter.hpp:247
std::vector< CandArg > CandArgsT
Vector of candidate arguments.
Definition: candidate.hpp:95
std::string label_
Argument node identifier.
Definition: ivoter.hpp:130
VoterArg(std::string label, teq::CoordptrT shaper, teq::CoordptrT coorder, SUBGRAPH_TYPE type)
Definition: ivoter.hpp:25
Variadic/communtative branch voter arguments.
Definition: ivoter.hpp:146
void hash_combine(size_t &seed, const VoterArgsT &args) const
Apply boost::hash_combine for each argument.
Definition: ivoter.hpp:178
std::map< std::string, CtxValT > ContexT
Map of rule graph leaf identifiers to corresponding matches.
Definition: candidate.hpp:26
SUBGRAPH_TYPE type_
Subgraph type of the argument.
Definition: ivoter.hpp:139
Hash voter arguments while preserving order of arguments.
Definition: ivoter.hpp:167
Intermediate conversion.
Definition: candidate.hpp:39
Rule tree leaf that represents any real node.
Definition: def.h:31
std::unordered_map< Symbol, CtxsT, SymbolHash > CandsT
Map of convers symbols to its potential candidate conversion rules.
Definition: candidate.hpp:76
Encapsulation of match output argument.
Definition: candidate.hpp:79
teq::TensptrT tensor_
Real tensor of the argument.
Definition: candidate.hpp:82
VoterArgsT scalars_
Scalar-typed arguments.
Definition: ivoter.hpp:154
void sort_vargs(VoterArgsT &args)
Normalize voter arguments to facilitate matching.
size_t operator()(const VoterArgsT &args) const
Return hash of arguments.
Definition: ivoter.hpp:170
std::string to_string(teq::CoordptrT c)
Return brief hashable string representation of coordinate mapper.
Rule tree node that identify and selects matching candidates.
Definition: ivoter.hpp:234
SUBGRAPH_TYPE
Rule tree node type.
Definition: def.h:26
OrdrHasher hasher_
Internal ordered hasher used against normalized commutative args.
Definition: ivoter.hpp:222
std::unordered_set< std::string > immutables_
Set of immutable ids under rule tree.
Definition: ivoter.hpp:253
Hash variadic/commutative arguments that ignores order.
Definition: ivoter.hpp:209
Generic representation of a conversion rule.
Definition: candidate.hpp:45
size_t size(void) const
Definition: ivoter.hpp:148
std::vector< VoterArg > VoterArgsT
Vector of voter arguments for branching nodes.
Definition: ivoter.hpp:143
teq::CoordptrT coorder_
Converted coordinate mapping meta-structure.
Definition: ivoter.hpp:136
virtual void emplace(VoterArgsT args, Symbol cand)=0
Definitive scalar constant.
Definition: def.h:29
Parsed representation of a rule tree.
Definition: ivoter.hpp:250
bool operator==(const Symbol &lhs, const Symbol &rhs)
Compare equality of Symbols.
Definition: candidate.hpp:70
Argument voter for functors.
Definition: ivoter.hpp:23
bool match(CtxsT &ctxs, const CandArg &arg) const
Return true if arg matches this only add to ctxs if matches.
Definition: ivoter.hpp:35