tvm
Classes | Public Member Functions | List of all members
tvm::SEqualReducer Class Reference

A Reducer class to reduce the structural equality result of two objects. More...

#include <structural_equal.h>

Collaboration diagram for tvm::SEqualReducer:

Classes

class  Handler
 Internal handler that defines custom behaviors.. More...
 

Public Member Functions

 SEqualReducer ()=default
 default constructor More...
 
 SEqualReducer (Handler *handler, const PathTracingData *tracing_data, bool map_free_vars)
 Constructor with a specific handler. More...
 
bool operator() (const double &lhs, const double &rhs, Optional< ObjectPathPair > paths=NullOpt) const
 Reduce condition to comparison of two attribute values. More...
 
bool operator() (const int64_t &lhs, const int64_t &rhs, Optional< ObjectPathPair > paths=NullOpt) const
 
bool operator() (const uint64_t &lhs, const uint64_t &rhs, Optional< ObjectPathPair > paths=NullOpt) const
 
bool operator() (const int &lhs, const int &rhs, Optional< ObjectPathPair > paths=NullOpt) const
 
bool operator() (const bool &lhs, const bool &rhs, Optional< ObjectPathPair > paths=NullOpt) const
 
bool operator() (const std::string &lhs, const std::string &rhs, Optional< ObjectPathPair > paths=NullOpt) const
 
bool operator() (const DataType &lhs, const DataType &rhs, Optional< ObjectPathPair > paths=NullOpt) const
 
template<typename ENum , typename = typename std::enable_if<std::is_enum<ENum>::value>::type>
bool operator() (const ENum &lhs, const ENum &rhs, Optional< ObjectPathPair > paths=NullOpt) const
 
template<typename T , typename Callable , typename = std::enable_if_t< std::is_same_v<std::invoke_result_t<Callable, const ObjectPath&>, ObjectPath>>>
bool operator() (const T &lhs, const T &rhs, const Callable &callable)
 
bool operator() (const ObjectRef &lhs, const ObjectRef &rhs) const
 Reduce condition to comparison of two objects. More...
 
bool operator() (const ObjectRef &lhs, const ObjectRef &rhs, const ObjectPathPair &paths) const
 Reduce condition to comparison of two objects. More...
 
bool DefEqual (const ObjectRef &lhs, const ObjectRef &rhs)
 Reduce condition to comparison of two definitions, where free vars can be mapped. More...
 
template<typename T >
bool operator() (const Array< T > &lhs, const Array< T > &rhs) const
 Reduce condition to comparison of two arrays. More...
 
bool FreeVarEqualImpl (const runtime::Object *lhs, const runtime::Object *rhs) const
 Implementation for equality rule of var type objects(e.g. TypeVar, tir::Var). More...
 
Handleroperator-> () const
 
bool IsPathTracingEnabled () const
 Check if this reducer is tracing paths to the first mismatch. More...
 
const ObjectPathPairGetCurrentObjectPaths () const
 Get the paths of the currently compared objects. More...
 
void RecordMismatchPaths (const ObjectPathPair &paths) const
 Specify the object paths of a detected mismatch. More...
 

Detailed Description

A Reducer class to reduce the structural equality result of two objects.

The reducer will call the SEqualReduce function of each objects recursively. Importantly, the reducer may not directly use recursive calls to resolve the equality checking. Instead, it can store the necessary equality conditions and check later via an internally managed stack.

Constructor & Destructor Documentation

◆ SEqualReducer() [1/2]

tvm::SEqualReducer::SEqualReducer ( )
default

default constructor

◆ SEqualReducer() [2/2]

tvm::SEqualReducer::SEqualReducer ( Handler handler,
const PathTracingData *  tracing_data,
bool  map_free_vars 
)
inlineexplicit

Constructor with a specific handler.

Parameters
handlerThe equal handler for objects.
tracing_dataOptional pointer to the path tracing data.
map_free_varsWhether or not to map free variables.

Member Function Documentation

◆ DefEqual()

bool tvm::SEqualReducer::DefEqual ( const ObjectRef lhs,
const ObjectRef rhs 
)

Reduce condition to comparison of two definitions, where free vars can be mapped.

Call this function to compare definition points such as function params and var in a let-binding.

Parameters
lhsThe left operand.
rhsThe right operand.
Returns
the immediate check result.

◆ FreeVarEqualImpl()

bool tvm::SEqualReducer::FreeVarEqualImpl ( const runtime::Object lhs,
const runtime::Object rhs 
) const
inline

Implementation for equality rule of var type objects(e.g. TypeVar, tir::Var).

Parameters
lhsThe left operand.
rhsThe right operand.
Returns
the result.

◆ GetCurrentObjectPaths()

const ObjectPathPair& tvm::SEqualReducer::GetCurrentObjectPaths ( ) const

Get the paths of the currently compared objects.

Can only be called when IsPathTracingEnabled() is true.

◆ IsPathTracingEnabled()

bool tvm::SEqualReducer::IsPathTracingEnabled ( ) const
inline

Check if this reducer is tracing paths to the first mismatch.

◆ operator()() [1/12]

template<typename T >
bool tvm::SEqualReducer::operator() ( const Array< T > &  lhs,
const Array< T > &  rhs 
) const
inline

Reduce condition to comparison of two arrays.

Parameters
lhsThe left operand.
rhsThe right operand.
Returns
the immediate check result.

◆ operator()() [2/12]

bool tvm::SEqualReducer::operator() ( const bool &  lhs,
const bool &  rhs,
Optional< ObjectPathPair paths = NullOpt 
) const

◆ operator()() [3/12]

bool tvm::SEqualReducer::operator() ( const DataType lhs,
const DataType rhs,
Optional< ObjectPathPair paths = NullOpt 
) const

◆ operator()() [4/12]

bool tvm::SEqualReducer::operator() ( const double &  lhs,
const double &  rhs,
Optional< ObjectPathPair paths = NullOpt 
) const

Reduce condition to comparison of two attribute values.

Parameters
lhsThe left operand.
rhsThe right operand.
pathsThe paths to the LHS and RHS operands. If unspecified, will attempt to identify the attribute's address within the most recent ObjectRef. In general, the paths only require explicit handling for computed parameters (e.g. array.size())
Returns
the immediate check result.

◆ operator()() [5/12]

template<typename ENum , typename = typename std::enable_if<std::is_enum<ENum>::value>::type>
bool tvm::SEqualReducer::operator() ( const ENum &  lhs,
const ENum &  rhs,
Optional< ObjectPathPair paths = NullOpt 
) const
inline

◆ operator()() [6/12]

bool tvm::SEqualReducer::operator() ( const int &  lhs,
const int &  rhs,
Optional< ObjectPathPair paths = NullOpt 
) const

◆ operator()() [7/12]

bool tvm::SEqualReducer::operator() ( const int64_t &  lhs,
const int64_t &  rhs,
Optional< ObjectPathPair paths = NullOpt 
) const

◆ operator()() [8/12]

bool tvm::SEqualReducer::operator() ( const ObjectRef lhs,
const ObjectRef rhs 
) const

Reduce condition to comparison of two objects.

Parameters
lhsThe left operand.
rhsThe right operand.
Returns
the immediate check result.

◆ operator()() [9/12]

bool tvm::SEqualReducer::operator() ( const ObjectRef lhs,
const ObjectRef rhs,
const ObjectPathPair paths 
) const
inline

Reduce condition to comparison of two objects.

Like operator(), but with an additional paths parameter that specifies explicit object paths for lhs and rhs. This is useful for implementing SEqualReduce() methods for container objects like Array and Map, or other custom objects that store nested objects that are not simply attributes.

Can only be called when IsPathTracingEnabled() is true.

Parameters
lhsThe left operand.
rhsThe right operand.
pathsObject paths for lhs and rhs.
Returns
the immediate check result.

◆ operator()() [10/12]

bool tvm::SEqualReducer::operator() ( const std::string &  lhs,
const std::string &  rhs,
Optional< ObjectPathPair paths = NullOpt 
) const

◆ operator()() [11/12]

template<typename T , typename Callable , typename = std::enable_if_t< std::is_same_v<std::invoke_result_t<Callable, const ObjectPath&>, ObjectPath>>>
bool tvm::SEqualReducer::operator() ( const T &  lhs,
const T &  rhs,
const Callable &  callable 
)
inline

◆ operator()() [12/12]

bool tvm::SEqualReducer::operator() ( const uint64_t &  lhs,
const uint64_t &  rhs,
Optional< ObjectPathPair paths = NullOpt 
) const

◆ operator->()

Handler* tvm::SEqualReducer::operator-> ( ) const
inline
Returns
Get the internal handler.

◆ RecordMismatchPaths()

void tvm::SEqualReducer::RecordMismatchPaths ( const ObjectPathPair paths) const

Specify the object paths of a detected mismatch.

Can only be called when IsPathTracingEnabled() is true.


The documentation for this class was generated from the following file: