32 out.reserve(
args_.size());
33 for (
const auto& vpair :
args_)
37 if (vargs.size() !=
args.size())
43 for (
size_t i = 0, n =
args.size(); i < n; ++i)
45 if (
false == vargs[i].match(ctxs,
args[i]))
56 out[vpair.second].insert(ctxs.begin(), ctxs.end());
65 std::unordered_map<VoterArgsT,Symbol,OrdrHasher>
args_;
91 segs.
anys_.push_back(arg);
96 logs::fatal(
"implementation limit: " 97 "cannot have more than 1 operator as an argument of the " 98 "commutative operator for the source subgraph");
102 args_.emplace(segs, sym);
109 out.reserve(
args_.size());
110 for (
const auto& vpair :
args_)
112 const SegVArgs& vargs = vpair.first;
118 std::list<CandArg> unmatched(
args.begin(),
args.end());
120 bool match_failed =
false;
124 for (
auto it = unmatched.begin(), et = unmatched.end();
127 if (sarg.
match(ctxs, *it))
130 match_failed =
false;
149 for (
auto it = unmatched.begin(), et = unmatched.end();
152 if (barg.
match(ctxs, *it))
155 match_failed =
false;
172 std::vector<CandArg> remaining(unmatched.begin(), unmatched.end());
173 size_t nremaining = remaining.
size();
174 std::vector<size_t> indices(nremaining);
175 std::iota(indices.begin(), indices.end(), 0);
179 CtxsT local_ctxs = ctxs;
180 for (
size_t i = 0; i < nremaining && matched; ++i)
182 matched = vargs.
anys_[i].match(local_ctxs,
183 remaining[indices[i]]);
185 if (
false == matched)
189 out[vpair.second].insert(local_ctxs.begin(), local_ctxs.end());
191 while (std::next_permutation(indices.begin(), indices.end()));
200 std::unordered_map<SegVArgs,Symbol,CommHasher>
args_;
226 segs.
anys_.push_back(arg);
231 logs::fatal(
"implementation limit: " 232 "cannot have more than 1 operator as an argument of the " 233 "commutative operator for the source subgraph");
237 args_.emplace(segs, sym);
244 out.reserve(
args_.size());
245 for (
const auto& vpair :
args_)
247 const SegVArgs& vargs = vpair.first;
254 std::list<CandArg> unmatched(
args.begin(),
args.end());
256 bool match_failed =
false;
260 for (
auto it = unmatched.begin(), et = unmatched.end();
263 if (sarg.
match(ctxs, *it))
266 match_failed =
false;
285 for (
auto it = unmatched.begin(), et = unmatched.end();
288 if (barg.
match(ctxs, *it))
291 match_failed =
false;
308 std::vector<CandArg> remaining(unmatched.begin(), unmatched.end());
309 size_t nremaining = remaining.
size();
310 std::vector<size_t> indices(nremaining);
311 std::iota(indices.begin(), indices.end(), 0);
313 size_t nanys = vargs.
anys_.size();
319 CtxsT local_ctxs = ctxs;
320 for (
size_t i = 0; i < nanys && matched; ++i)
322 matched = vargs.
anys_[i].match(local_ctxs,
323 remaining[indices[i]]);
325 if (
false == matched)
330 for (
size_t i = nanys; i < nremaining; ++i)
333 cvals.emplace(remaining[indices[i]].tensor_);
335 CtxsT& out_ctxs = out[vpair.second];
339 out_ctxs.emplace(ctx);
342 while (std::next_permutation(indices.begin(), indices.end()));
354 std::unordered_map<SegVArgs,Symbol,CommHasher>
args_;
359 #endif // OPT_VOTER_HPP std::string label_
Label type of the functor.
Definition: voter.hpp:197
CandsT inspect(const CandArgsT &args) const override
Implementation of iVoter.
Definition: voter.hpp:241
args
Definition: csv_to_png.py:105
VariadicVoter(std::string label, std::string variadic)
Definition: voter.hpp:206
std::set< teq::TensptrT > CtxValT
Set of tensors that potentially matches some id.
Definition: candidate.hpp:23
VoterArgsT branches_
Branch-typed arguments (functors/groups)
Definition: ivoter.hpp:157
std::unordered_map< SegVArgs, Symbol, CommHasher > args_
Map functor arguments to emplaced symbols.
Definition: voter.hpp:200
std::string label_
Label type of the functor.
Definition: voter.hpp:62
std::string variadic_
Symbol of variadic argument.
Definition: voter.hpp:351
Definition: candidate.hpp:19
std::unordered_map< VoterArgsT, Symbol, OrdrHasher > args_
Map functor arguments to emplaced symbols.
Definition: voter.hpp:65
VoterArgsT anys_
Any-typed leaf arguments.
Definition: ivoter.hpp:160
Branching node.
Definition: def.h:33
void emplace(VoterArgsT args, Symbol sym) override
Implementation of iVoter.
Definition: voter.hpp:210
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::vector< CandArg > CandArgsT
Vector of candidate arguments.
Definition: candidate.hpp:95
void emplace(VoterArgsT args, Symbol sym) override
Implementation of iVoter.
Definition: voter.hpp:75
Implement voter for variadic groups.
Definition: voter.hpp:204
void emplace(VoterArgsT args, Symbol sym) override
Implementation of iVoter.
Definition: voter.hpp:23
Variadic/communtative branch voter arguments.
Definition: ivoter.hpp:146
std::map< std::string, CtxValT > ContexT
Map of rule graph leaf identifiers to corresponding matches.
Definition: candidate.hpp:26
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
VoterArgsT scalars_
Scalar-typed arguments.
Definition: ivoter.hpp:154
void sort_vargs(VoterArgsT &args)
Normalize voter arguments to facilitate matching.
Rule tree node that identify and selects matching candidates.
Definition: ivoter.hpp:234
CommVoter(std::string label)
Definition: voter.hpp:72
std::string label_
Label type of group.
Definition: voter.hpp:348
CandsT inspect(const CandArgsT &args) const override
Implementation of iVoter.
Definition: voter.hpp:29
Generic representation of a conversion rule.
Definition: candidate.hpp:45
OrdrVoter(std::string label)
Definition: voter.hpp:20
size_t size(void) const
Definition: ivoter.hpp:148
std::vector< VoterArg > VoterArgsT
Vector of voter arguments for branching nodes.
Definition: ivoter.hpp:143
std::unordered_map< SegVArgs, Symbol, CommHasher > args_
Map functor arguments to emplaced symbols.
Definition: voter.hpp:354
CandsT inspect(const CandArgsT &args) const override
Implementation of iVoter.
Definition: voter.hpp:106
Implement voter for ordered (non-commutative) functors.
Definition: voter.hpp:18
Definitive scalar constant.
Definition: def.h:29
Implement voter for commutative functors.
Definition: voter.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