23 #ifndef TVM_NODE_STRUCTURAL_EQUAL_H_ 24 #define TVM_NODE_STRUCTURAL_EQUAL_H_ 39 bool operator()(
const double& lhs,
const double& rhs)
const {
41 constexpr
double atol = 1e-9;
42 if (lhs == rhs)
return true;
43 double diff = lhs - rhs;
44 return diff > -atol && diff < atol;
47 bool operator()(
const int64_t& lhs,
const int64_t& rhs)
const {
return lhs == rhs; }
48 bool operator()(
const uint64_t& lhs,
const uint64_t& rhs)
const {
return lhs == rhs; }
49 bool operator()(
const int& lhs,
const int& rhs)
const {
return lhs == rhs; }
50 bool operator()(
const bool& lhs,
const bool& rhs)
const {
return lhs == rhs; }
51 bool operator()(
const std::string& lhs,
const std::string& rhs)
const {
return lhs == rhs; }
53 template <typename ENum, typename = typename std::enable_if<std::is_enum<ENum>::value>::type>
54 bool operator()(
const ENum& lhs,
const ENum& rhs)
const {
84 using BaseValueEqual::operator();
118 virtual bool SEqualReduce(
const ObjectRef& lhs,
const ObjectRef& rhs,
bool map_free_vars) = 0;
131 virtual void MarkGraphNode() = 0;
134 using BaseValueEqual::operator();
144 : handler_(handler), map_free_vars_(map_free_vars) {}
152 return handler_->SEqualReduce(lhs, rhs, map_free_vars_);
166 return handler_->SEqualReduce(lhs, rhs,
true);
174 template <
typename T>
178 if (lhs.
size() != rhs.
size())
return false;
179 for (
size_t i = 0; i < lhs.
size(); ++i) {
180 if (!(
operator()(lhs[i], rhs[i])))
return false;
192 handler_->MarkGraphNode();
195 return lhs == rhs || map_free_vars_;
209 #endif // TVM_NODE_STRUCTURAL_EQUAL_H_ bool DefEqual(const ObjectRef &lhs, const ObjectRef &rhs)
Reduce condition to comparison of two definitions, where free vars can be mapped. ...
Definition: structural_equal.h:165
bool operator()(const uint64_t &lhs, const uint64_t &rhs) const
Definition: structural_equal.h:48
bool operator()(const std::string &lhs, const std::string &rhs) const
Definition: structural_equal.h:51
bool operator()(const double &lhs, const double &rhs) const
Definition: structural_equal.h:39
bool FreeVarEqualImpl(const runtime::Object *lhs, const runtime::Object *rhs) const
Implementation for equality rule of var type objects(e.g. TypeVar, tir::Var).
Definition: structural_equal.h:190
bool operator()(const int &lhs, const int &rhs) const
Definition: structural_equal.h:49
A Reducer class to reduce the structural equality result of two objects.
Definition: structural_equal.h:102
bool operator()(const DataType &lhs, const DataType &rhs) const
Definition: structural_equal.h:52
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
bool operator()(const bool &lhs, const bool &rhs) const
Definition: structural_equal.h:50
bool operator()(const ObjectRef &lhs, const ObjectRef &rhs) const
Reduce condition to comparison of two objects.
Definition: structural_equal.h:151
base class of all object containers.
Definition: object.h:167
bool operator()(const ENum &lhs, const ENum &rhs) const
Definition: structural_equal.h:54
Content-aware structural equality comparator for objects.
Definition: structural_equal.h:81
Runtime Array container types.
bool operator()(const int64_t &lhs, const int64_t &rhs) const
Definition: structural_equal.h:47
SEqualReducer(Handler *handler, bool map_free_vars)
Constructor with a specific handler.
Definition: structural_equal.h:143
size_t size() const
Definition: array.h:399
Runtime primitive data type.
Definition: data_type.h:41
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:270
bool operator()(const Array< T > &lhs, const Array< T > &rhs) const
Reduce condition to comparison of two arrays.
Definition: structural_equal.h:175
Defines the Functor data structures.
Base class of all object reference.
Definition: object.h:511
Internal handler that defines custom behaviors..
Definition: structural_equal.h:105
Equality definition of base value class.
Definition: structural_equal.h:37
Handler * operator->() const
Definition: structural_equal.h:199