Tenncor
candidate.hpp
Go to the documentation of this file.
1 
9 #include <string>
10 #include <unordered_map>
11 
12 #include <boost/functional/hash.hpp>
13 
14 #include "teq/itensor.hpp"
15 
16 #ifndef OPT_CAND_HPP
17 #define OPT_CAND_HPP
18 
19 namespace opt
20 {
21 
23 using CtxValT = std::set<teq::TensptrT>;
24 
26 using ContexT = std::map<std::string,CtxValT>;
27 
29 using CtxsT = std::unordered_set<ContexT,boost::hash<ContexT>>;
30 
33 {
35  SCALAR = 0,
42 };
43 
45 struct Symbol final
46 {
49 
50  // type_=SCALAR: scalar label
51  // type_=INTERM: intermediate id
52  // type_=CONVRT: conversion ref
53  std::string reference_;
54 };
55 
57 struct SymbolHash final
58 {
60  size_t operator() (const Symbol& sym) const
61  {
62  size_t seed = 0;
63  boost::hash_combine(seed, sym.type_);
64  boost::hash_combine(seed, sym.reference_);
65  return seed;
66  }
67 };
68 
70 inline bool operator == (const Symbol& lhs, const Symbol& rhs)
71 {
72  return lhs.type_ == rhs.type_ && lhs.reference_ == rhs.reference_;
73 }
74 
76 using CandsT = std::unordered_map<Symbol,CtxsT,SymbolHash>;
77 
79 struct CandArg
80 {
83 
86 
89 
92 };
93 
95 using CandArgsT = std::vector<CandArg>;
96 
97 }
98 
99 #endif // OPT_CAND_HPP
CandsT candidates_
Potential rules contexts that can match subgraph of tensor_.
Definition: candidate.hpp:85
Convert to a non-scalar constant.
Definition: candidate.hpp:37
std::set< teq::TensptrT > CtxValT
Set of tensors that potentially matches some id.
Definition: candidate.hpp:23
std::string reference_
Definition: candidate.hpp:53
teq::CoordptrT shaper_
Real shaper in the argument.
Definition: candidate.hpp:88
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
std::unordered_set< ContexT, boost::hash< ContexT > > CtxsT
Set of contexts that serve as a candidates of a conversion rule.
Definition: candidate.hpp:29
size_t operator()(const Symbol &sym) const
Return hash of Symbol.
Definition: candidate.hpp:60
std::vector< CandArg > CandArgsT
Vector of candidate arguments.
Definition: candidate.hpp:95
Hasher to encode rule key.
Definition: candidate.hpp:57
CAND_TYPE
Conversion type.
Definition: candidate.hpp:32
std::map< std::string, CtxValT > ContexT
Map of rule graph leaf identifiers to corresponding matches.
Definition: candidate.hpp:26
Intermediate conversion.
Definition: candidate.hpp:39
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
std::shared_ptr< iTensor > TensptrT
Tensor smart pointer.
Definition: itensor.hpp:51
CAND_TYPE type_
Type of rule.
Definition: candidate.hpp:48
Generic representation of a conversion rule.
Definition: candidate.hpp:45
Full conversion to a subgraph.
Definition: candidate.hpp:41
Convert to a scalar.
Definition: candidate.hpp:35
bool operator==(const Symbol &lhs, const Symbol &rhs)
Compare equality of Symbols.
Definition: candidate.hpp:70