class_docstr: Functor for translating Relay programs into Python ASTs.
class_docstr_tok: ["Functor","for","translating","Relay","programs","into","Python","ASTs","."]
docstr: Given an ADT match pattern and a (Python) expression pointing to
  an ADT value, this generates a Python expression that checks if the
  ADT value matches the given pattern (returning True or False).
docstr_tok: ["Given","an","ADT","match","pattern","and","a","(","Python",")","expression","pointing","to","an","ADT","value",",","this","generates","a","Python","expression","that","checks","if","the","ADT","value","matches","the","given","pattern","(","returning","True","or","False",")","."]
code: def create_match_check(self, pattern: Pattern, data):
      """Given an ADT match pattern and a (Python) expression pointing to
      an ADT value, this generates a Python expression that checks if the
      ADT value matches the given pattern (returning True or False)."""
  
      # wildcard or var match everything
      if isinstance(pattern, (relay.PatternWildcard, relay.PatternVar)):
          return NameConstant(True)
  
      conds = []
  
      if isinstance(pattern, relay.PatternConstructor):
          # constructor patterns check whether the constructors match
          # and also the matches of any nested patterns
  
          # equiv: (arg.tag == patern_constructor.tag)
          conds.append(
              ast.Compare(
                  ast.Attribute(data, "tag", Load()),
                  [ast.Eq()],
                  [ast.Num(pattern.constructor.tag)],
              )
          )
  
      assert isinstance(
          pattern, (relay.PatternConstructor, relay.PatternTuple)
      )
      # now check for any nested patterns
      for i in range(len(pattern.patterns)):
          nested_pat = pattern.patterns[i]
          # can safely skip var or wildcard patterns: they will
          # never cause a check to fail
          if not isinstance(nested_pat, relay.PatternConstructor):
              continue
  
          # index into the value corresponding to the subpattern
          field_index = ast.Subscript(
              ast.Attribute(data, "fields", Load()),
              ast.Index(Num(i)),
              Load(),
          )
          conds.append(self.create_match_check(nested_pat, field_index))
  
      # if we do not need to check nested pattern, just return the single check
      if len(conds) == 1:
          return conds[0]
      # otherwise AND together any nested checks
      return ast.BoolOp(ast.And(), conds)
  
imports: import sys
  import ast
  from ast import alias, Assign, Load, Name, NameConstant, Num, Return, Store, Str
  import re
  import tvm
  from tvm import relay
  from tvm.relay.adt import Pattern
  from tvm.relay.backend import te_compiler
  from tvm.relay.expr import Expr, GlobalVar, Var
  from tvm.relay.function import Function
  from tvm.relay.expr_functor import ExprFunctor
label_desc: Use image node_id 19 for calling the PythonConverter obj's underlying member method code with example usage: obj.create_match_check(pattern, data) and returns: ast, NameConstant, conds