parameters: (list_var)
return_statement: return None
docstring: Returns types.tensor. None if failed to infer element type.
      Example:
  
      Given:
  
      main(%update: (2,fp32)) {
        block0() {
          %list: List[unknown] = tf_make_list(...) # unknown elem type
          %while_loop_0:0: (i32), %while_loop_0:1: List[(2,fp32)] = while_loop(loop_vars=(...))
            while_loop_0_body(...) {
              %list_write_0: List[(2,fp32)] = list_write(index=..., ls=%list, value=%update)
            } -> (%add_0, %list_write_0)
  
          Result:
  
          main(%update: (2,fp32)) {
            block0() {
          %list: List[(2,fp32)] = tf_make_list(...) # Get the elem type from list_write
          %while_loop_0:0: (i32), %while_loop_0:1: List[(2,fp32)] = while_loop(loop_vars=(...))
            while_loop_0_body(...) {
              %list_write_0: List[(2,fp32)] = list_write(index=..., ls=%list, value=%update)
            } -> (%add_0, %list_write_0)
docstring_summary: Returns types.tensor. None if failed to infer element type.
      Example:
docstring_tokens: Returns types . tensor . None if failed to infer element type . Example :
function: def infer_elem_type(list_var):
      """
      Returns types.tensor. None if failed to infer element type.
      Example:
  
      Given:
  
      main(%update: (2,fp32)) {
        block0() {
          %list: List[unknown] = tf_make_list(...) # unknown elem type
          %while_loop_0:0: (i32), %while_loop_0:1: List[(2,fp32)] = while_loop(loop_vars=(...))
            while_loop_0_body(...) {
              %list_write_0: List[(2,fp32)] = list_write(index=..., ls=%list, value=%update)
            } -> (%add_0, %list_write_0)
  
          Result:
  
          main(%update: (2,fp32)) {
            block0() {
          %list: List[(2,fp32)] = tf_make_list(...) # Get the elem type from list_write
          %while_loop_0:0: (i32), %while_loop_0:1: List[(2,fp32)] = while_loop(loop_vars=(...))
            while_loop_0_body(...) {
              %list_write_0: List[(2,fp32)] = list_write(index=..., ls=%list, value=%update)
            } -> (%add_0, %list_write_0)
      """
      # Search for child op that have informative element types
      for o in list_var.child_ops:
          if o.op_type in ["list_write", "list_scatter"]:
              return o.outputs[0].elem_type
          if o.op_type == "while_loop":
              idx = list(o.loop_vars).index(list_var)
              block = o.blocks[0]
              # the corresponding Var in body block
              block_var = block.inputs[idx]
              elem_type = infer_elem_type(block_var)
              if elem_type is not None:
                  return elem_type
              # otherwise continue to other block_var (a list_var can be
              # passed into while_loop twice).
      return None
function_tokens: def infer_elem_type ( list_var ) : # Search for child op that have informative element types for o in list_var . child_ops : if o . op_type in [ "list_write" , "list_scatter" ] : return o . outputs [ 0 ] . elem_type if o . op_type == "while_loop" : idx = list ( o . loop_vars ) . index ( list_var ) block = o . blocks [ 0 ] # the corresponding Var in body block block_var = block . inputs [ idx ] elem_type = infer_elem_type ( block_var ) if elem_type is not None : return elem_type # otherwise continue to other block_var (a list_var can be # passed into while_loop twice). return None